Skip to content

Commit

Permalink
Merged in admin-plugin-delete (pull request #38)
Browse files Browse the repository at this point in the history
Allow to delete reviewLocation

Approved-by: Bartosz Sekuła <bartek.sekula@gmail.com>
  • Loading branch information
gregwiechec committed Apr 14, 2019
2 parents 6965ea3 + 895fabd commit fa5cd0f
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
.reviews-list .list > li { margin-bottom: 15px; }
.reviews-list .delete {
display: none;
float: right;
}
.reviews-list .list .row:hover .delete {
display: inline-block;
}
.reviews-list .details {
padding-left: 10px;
}
Expand All @@ -41,6 +50,13 @@

<script type="text/javascript">
var allReviewLocations = <%= this.AllReviewLocations %>;
function onDeleteClick(contentLink) {
if (confirm("Delete " + contentLink + "?")) {
<%= ClientScript.GetPostBackEventReference(this, string.Empty) %>;
__doPostBack("delete_review", contentLink);
}
}
</script>

<div id="admin-plugin-container"></div>
Expand Down
10 changes: 10 additions & 0 deletions src/approval-reviews/DdsApprovalReviewsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public IEnumerable<ApprovalReview> LoadAll()
return GetStore().Items<ApprovalReview>();
}

public void Delete(ContentReference contentLink)
{
var review = GetStore().Items<ApprovalReview>().FirstOrDefault(x => x.ContentLink == contentLink);
if (review == null)
{
throw new ArgumentOutOfRangeException($"Can't find review location for: {contentLink}");
}
GetStore().Delete(review.Id);
}

public ReviewLocation Update(ContentReference contentLink, ReviewLocation reviewLocation)
{
var data = reviewLocation.Data;
Expand Down
2 changes: 2 additions & 0 deletions src/approval-reviews/IApprovalReviewsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface IApprovalReviewsRepository
IEnumerable<ReviewLocation> Load(ContentReference contentLink);

IEnumerable<ApprovalReview> LoadAll();

void Delete(ContentReference contentLink);
}

public class ReviewLocation
Expand Down
18 changes: 16 additions & 2 deletions src/approval-reviews/ReviewLocationsPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using EPiServer.Core;
using EPiServer.DataAccess.Internal;
using EPiServer.Framework.Serialization;
using EPiServer.PlugIn;
using EPiServer.ServiceLocation;
Expand All @@ -24,19 +25,32 @@ protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

var targetCtrl = Page.Request.Params.Get("__EVENTTARGET");
if (targetCtrl == "delete_review")
{
var contentLink = Page.Request.Params.Get("__EVENTARGUMENT");
DeleteReviewLocation(
string.IsNullOrWhiteSpace(contentLink) ? null: ContentReference.Parse(contentLink));
}

SystemMessageContainer.Heading = "Review locations";
SystemMessageContainer.Description = "List of all review locations";
DataBind();
}

private void DeleteReviewLocation(ContentReference contentLink)
{
_repository.Service.Delete(contentLink);
}

protected string AllReviewLocations
{
get
{
var result = _repository.Service.LoadAll().GroupBy(x=>x.ContentLink.ToReferenceWithoutVersion()).Select(x => new
var result = _repository.Service.LoadAll().GroupBy(x => x.ContentLink.ToReferenceWithoutVersion()).Select(x => new
{
Id = x.Key,
ContentLinks = x.Select( c=> new { c.ContentLink, c.SerializedReview } )
ContentLinks = x.Select(c => new { c.ContentLink, c.SerializedReview })
});

return _serializerFactory.Service.GetSerializer(KnownContentTypes.Json).Serialize(result);
Expand Down
59 changes: 43 additions & 16 deletions src/ui/src/admin/admin-plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,64 @@ interface ReviewGroup {

interface AdminPluginProps {
data: ReviewGroup[];
onDeleteClick(contentLink: string): void
}

function AdminPluginComponent(props: AdminPluginProps) {
const [currentLocation, setCurrentLocation] = useState<ReviewLocation>(null);
const [currentContentLink, setCurrentContentLink] = useState<string>(null);
const [currentJSON, setCurrentJSON] = useState<string>(null);
const [currentException, setCurrentException] = useState<string>(null);

const changeReviewLocation = (reviewLocation: ReviewLocation): string => {
setCurrentContentLink(reviewLocation.contentLink);
try {
var parsed = JSON.parse(reviewLocation.serializedReview);
parsed.forEach((reviewLocation) => {
try {
reviewLocation.data = JSON.parse(reviewLocation.data);
} catch(ex) {
}
});
parsed = JSON.stringify(parsed, null, 2);
setCurrentJSON(parsed);
setCurrentException(null);
return parsed;
} catch (ex) {
setCurrentException(ex.message);
setCurrentJSON(reviewLocation.serializedReview);
}
};

return (
<div className="reviews-list">
<ul className="list">
{props.data.map(x =>
{props.data.map(x =>
<li key={x.id || '[no ContentLink]'}>
<span className="main-link">{x.id || '[no ContentLink]'}</span>
<ul>
{x.contentLinks.map(c=>
<li key={c.contentLink || '[empty]'}>
<a href="#" onClick={() => setCurrentLocation(c)}>{c.contentLink || '[empty]'}</a>
</li>
<span className="main-link">{x.id || '[no ContentLink]'}</span>
<ul>
{x.contentLinks.map(c =>
<li className="row" key={c.contentLink || '[empty]'}>
<a href="#" onClick={() => changeReviewLocation(c)}>{c.contentLink || '[empty]'}</a>
<a className="delete" href="#" onClick={() => props.onDeleteClick(c.contentLink)}>Delete</a>
</li>
)}
</ul>
</ul>
</li>
)}
)}
</ul>
{currentLocation &&
<div className="details">
<h3>{currentLocation.contentLink}</h3>
<div>{currentLocation.serializedReview}</div>
</div>
{currentJSON &&
<div className="details">
<h3>{currentContentLink}</h3>
{currentException &&
<div>{currentException}</div>
}
<div><pre>{currentJSON}</pre></div>
</div>
}
</div>
);
}

ReactDOM.render(
<AdminPluginComponent data={window["allReviewLocations"]} />, document.getElementById("admin-plugin-container")
<AdminPluginComponent data={window["allReviewLocations"]} onDeleteClick={window["onDeleteClick"]} />, document.getElementById("admin-plugin-container")
);

0 comments on commit fa5cd0f

Please sign in to comment.