Skip to content

Commit

Permalink
Merge pull request #4565 from enonic/issue-4535
Browse files Browse the repository at this point in the history
Implement undo of Pending Delete flag
  • Loading branch information
Runar Myklebust committed Mar 14, 2017
2 parents 3ef43a9 + 0d90771 commit 6e978a5
Show file tree
Hide file tree
Showing 15 changed files with 426 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
import com.enonic.xp.admin.impl.rest.resource.content.json.SetActiveVersionJson;
import com.enonic.xp.admin.impl.rest.resource.content.json.SetChildOrderJson;
import com.enonic.xp.admin.impl.rest.resource.content.json.TaskResultJson;
import com.enonic.xp.admin.impl.rest.resource.content.json.UndoPendingDeleteContentJson;
import com.enonic.xp.admin.impl.rest.resource.content.json.UndoPendingDeleteContentResultJson;
import com.enonic.xp.admin.impl.rest.resource.content.json.UnpublishContentJson;
import com.enonic.xp.admin.impl.rest.resource.content.json.UpdateContentJson;
import com.enonic.xp.admin.impl.rest.resource.schema.content.ContentTypeIconResolver;
Expand Down Expand Up @@ -144,6 +146,7 @@
import com.enonic.xp.content.ResolveRequiredDependenciesParams;
import com.enonic.xp.content.SetActiveContentVersionResult;
import com.enonic.xp.content.SetContentChildOrderParams;
import com.enonic.xp.content.UndoPendingDeleteContentParams;
import com.enonic.xp.content.UnpublishContentParams;
import com.enonic.xp.content.UnpublishContentsResult;
import com.enonic.xp.content.UpdateContentParams;
Expand Down Expand Up @@ -428,6 +431,16 @@ public ContentJson update( final UpdateContentJson json )
}
}

@POST
@Path("undoPendingDelete")
public UndoPendingDeleteContentResultJson undoPendingDelete( final UndoPendingDeleteContentJson params )
{
UndoPendingDeleteContentResultJson result = new UndoPendingDeleteContentResultJson();
int numberOfContents = this.contentService.undoPendingDelete(
new UndoPendingDeleteContentParams( ContentIds.from( params.getContentIds() ), ContentConstants.BRANCH_MASTER ) );
return result.setSuccess( numberOfContents );
}

@POST
@Path("delete")
public TaskResultJson delete( final DeleteContentJson params )
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.enonic.xp.admin.impl.rest.resource.content.json;


import java.util.List;

public class UndoPendingDeleteContentJson
{
private List<String> contentIds;

public List<String> getContentIds()
{
return contentIds;
}

@SuppressWarnings("unused")
public void setContentIds( final List<String> contentIds )
{
this.contentIds = contentIds;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.enonic.xp.admin.impl.rest.resource.content.json;

public class UndoPendingDeleteContentResultJson
{
private Integer success = 0;

@SuppressWarnings("unused")
public Integer getSuccess()
{
return success;
}

public UndoPendingDeleteContentResultJson setSuccess( final Integer success )
{
if ( success != null )
{
this.success = success;
}

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {PublishTreeContentAction} from './PublishTreeContentAction';
import {UnpublishContentAction} from './UnpublishContentAction';
import {ContentBrowseItem} from '../ContentBrowseItem';
import {PreviewContentHandler} from './handler/PreviewContentHandler';
import {UndoPendingDeleteContentAction} from './UndoPendingDeleteContentAction';

import Action = api.ui.Action;
import TreeGridActions = api.ui.treegrid.actions.TreeGridActions;
Expand Down Expand Up @@ -42,6 +43,7 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd
public PUBLISH_TREE_CONTENT: Action;
public UNPUBLISH_CONTENT: Action;
public TOGGLE_SEARCH_PANEL: Action;
public UNDO_PENDING_DELETE: Action;

private actions: api.ui.Action[] = [];

Expand All @@ -58,6 +60,7 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd
this.PUBLISH_CONTENT = new PublishContentAction(grid);
this.PUBLISH_TREE_CONTENT = new PublishTreeContentAction(grid);
this.UNPUBLISH_CONTENT = new UnpublishContentAction(grid);
this.UNDO_PENDING_DELETE = new UndoPendingDeleteContentAction(grid);

this.actions.push(
this.SHOW_NEW_CONTENT_DIALOG_ACTION,
Expand All @@ -77,15 +80,16 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd
}

getAllActions(): api.ui.Action[] {
return [...this.actions, this.PUBLISH_CONTENT, this.UNPUBLISH_CONTENT];
return [...this.actions, this.PUBLISH_CONTENT, this.UNPUBLISH_CONTENT, this.UNDO_PENDING_DELETE];
}

getAllActionsNoPublish(): api.ui.Action[] {
return this.actions;
}

// tslint:disable-next-line:max-line-length
updateActionsEnabledState(contentBrowseItems: ContentBrowseItem[], changes?: BrowseItemsChanges<ContentSummaryAndCompareStatus>): wemQ.Promise<BrowseItem<ContentSummaryAndCompareStatus>[]> {
updateActionsEnabledState(contentBrowseItems: ContentBrowseItem[],
changes?: BrowseItemsChanges<ContentSummaryAndCompareStatus>): wemQ.Promise<BrowseItem<ContentSummaryAndCompareStatus>[]> {

this.TOGGLE_SEARCH_PANEL.setVisible(false);

Expand All @@ -111,10 +115,11 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd
this.DUPLICATE_CONTENT.setEnabled(false);
this.MOVE_CONTENT.setEnabled(false);
this.SORT_CONTENT.setEnabled(false);
this.UNDO_PENDING_DELETE.setEnabled(false);

this.PUBLISH_TREE_CONTENT.setEnabled(false);
this.PUBLISH_CONTENT.setEnabled(false);
this.PUBLISH_CONTENT.setVisible(true);
this.PUBLISH_TREE_CONTENT.setEnabled(false);
this.UNPUBLISH_CONTENT.setEnabled(false);
this.UNPUBLISH_CONTENT.setVisible(false);
}
Expand Down Expand Up @@ -145,12 +150,16 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd
unpublishEnabled = anyPublished;
}

let undoDeleteEnabled = contentBrowseItems.length === 1 &&
contentBrowseItems[0].getModel().getCompareStatus() === api.content.CompareStatus.PENDING_DELETE;

this.SHOW_NEW_CONTENT_DIALOG_ACTION.setEnabled(contentSummaries.length < 2);
this.EDIT_CONTENT.setEnabled(this.anyEditable(contentSummaries));
this.DELETE_CONTENT.setEnabled(this.anyDeletable(contentSummaries));
this.DUPLICATE_CONTENT.setEnabled(contentSummaries.length === 1);
this.MOVE_CONTENT.setEnabled(true);
this.SORT_CONTENT.setEnabled(contentSummaries.length === 1 && contentSummaries[0].hasChildren());
this.UNDO_PENDING_DELETE.setEnabled(undoDeleteEnabled);

this.PUBLISH_CONTENT.setEnabled(publishEnabled);
this.PUBLISH_TREE_CONTENT.setEnabled(treePublishEnabled);
Expand Down Expand Up @@ -191,8 +200,8 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd
}

private updateActionsByPermissionsNoItemsSelected(): wemQ.Promise<any> {
return new api.content.resource.GetPermittedActionsRequest().addPermissionsToBeChecked(Permission.CREATE).sendAndParse().
then((allowedPermissions: Permission[]) => {
return new api.content.resource.GetPermittedActionsRequest().addPermissionsToBeChecked(Permission.CREATE).sendAndParse().then(
(allowedPermissions: Permission[]) => {
this.resetDefaultActionsNoItemsSelected();

let canCreate = allowedPermissions.indexOf(Permission.CREATE) > -1;
Expand All @@ -213,35 +222,33 @@ export class ContentTreeGridActions implements TreeGridActions<ContentSummaryAnd

private updateActionsByPermissionsMultipleItemsSelected(contentBrowseItems: ContentBrowseItem[],
contentTypesAllowChildren: boolean = true): wemQ.Promise<any> {
return new api.content.resource.GetPermittedActionsRequest().
addContentIds(...contentBrowseItems.map(contentBrowseItem => contentBrowseItem.getModel().getContentId())).
addPermissionsToBeChecked(Permission.CREATE, Permission.DELETE, Permission.PUBLISH).
sendAndParse().
then((allowedPermissions: Permission[]) => {
this.resetDefaultActionsMultipleItemsSelected(contentBrowseItems);
return new api.content.resource.GetPermittedActionsRequest().addContentIds(
...contentBrowseItems.map(contentBrowseItem => contentBrowseItem.getModel().getContentId())).addPermissionsToBeChecked(
Permission.CREATE, Permission.DELETE, Permission.PUBLISH).sendAndParse().then((allowedPermissions: Permission[]) => {
this.resetDefaultActionsMultipleItemsSelected(contentBrowseItems);

let canCreate = allowedPermissions.indexOf(Permission.CREATE) > -1;
let canCreate = allowedPermissions.indexOf(Permission.CREATE) > -1;

let canDelete = allowedPermissions.indexOf(Permission.DELETE) > -1;
let canDelete = allowedPermissions.indexOf(Permission.DELETE) > -1;

let canPublish = allowedPermissions.indexOf(Permission.PUBLISH) > -1;
let canPublish = allowedPermissions.indexOf(Permission.PUBLISH) > -1;

if (!contentTypesAllowChildren || !canCreate) {
this.SHOW_NEW_CONTENT_DIALOG_ACTION.setEnabled(false);
this.SORT_CONTENT.setEnabled(false);
}
if (!contentTypesAllowChildren || !canCreate) {
this.SHOW_NEW_CONTENT_DIALOG_ACTION.setEnabled(false);
this.SORT_CONTENT.setEnabled(false);
}

if (!canDelete) {
this.DELETE_CONTENT.setEnabled(false);
this.MOVE_CONTENT.setEnabled(false);
}
if (!canDelete) {
this.DELETE_CONTENT.setEnabled(false);
this.MOVE_CONTENT.setEnabled(false);
}

if (!canPublish) {
this.PUBLISH_CONTENT.setEnabled(false);
this.PUBLISH_TREE_CONTENT.setEnabled(false);
this.UNPUBLISH_CONTENT.setEnabled(false);
}
});
if (!canPublish) {
this.PUBLISH_CONTENT.setEnabled(false);
this.PUBLISH_TREE_CONTENT.setEnabled(false);
this.UNPUBLISH_CONTENT.setEnabled(false);
}
});
}

private checkIsChildrenAllowedByContentType(contentSummary: ContentSummary): wemQ.Promise<Boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import '../../../api.ts';
import {ContentTreeGrid} from '../ContentTreeGrid';

import Action = api.ui.Action;
import UndoPendingDeleteContentRequest = api.content.resource.UndoPendingDeleteContentRequest;

export class UndoPendingDeleteContentAction extends Action {

constructor(grid: ContentTreeGrid) {
super('Undo delete');

this.setEnabled(false);

this.onExecuted(() => {
let contents: api.content.ContentSummaryAndCompareStatus[]
= grid.getSelectedDataList();
new UndoPendingDeleteContentRequest(contents.map((content) => content.getContentId()))
.sendAndParse().then((result: number) => {
if (result > 0) {
api.notify.showFeedback(`The item has been successfully undeleted`);
} else {
api.notify.showWarning(`No item found to undelete`);
}
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module api.content.json {

export interface UndoPendingDeleteContentResultJson {

success: number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
///<reference path='ContentPublishTimeRangeJson.ts' />
///<reference path='GetPublishStatusResultJson.ts' />
///<reference path='GetPublishStatusesResultJson.ts' />
///<reference path='UndoPendingDeleteContentResultJson.ts' />
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module api.content.resource {

import UndoPendingDeleteContentResultJson = api.content.json.UndoPendingDeleteContentResultJson;

export class UndoPendingDeleteContentRequest extends ContentResourceRequest<UndoPendingDeleteContentResultJson, number> {

private ids: ContentId[];

constructor(ids: ContentId[]) {
super();
super.setMethod('POST');
this.ids = ids;
}

getParams(): Object {
return {
contentIds: this.ids.map((contentId: ContentId) => contentId.toString())
};
}

getRequestPath(): api.rest.Path {
return api.rest.Path.fromParent(super.getResourcePath(), 'undoPendingDelete');
}

sendAndParse(): wemQ.Promise<number> {
return this.send().then((response: api.rest.JsonResponse<UndoPendingDeleteContentResultJson>) => {
return response.getResult().success;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
///<reference path='GetDescendantsOfContentsRequest.ts' />
///<reference path='GetEffectivePermissionsRequest.ts' />
///<reference path='GetContentIdsByParentRequest.ts' />
///<reference path='UndoPendingDeleteContentRequest.ts' />
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public interface ContentService

DeleteContentsResult deleteWithoutFetch( DeleteContentParams params );

int undoPendingDelete( UndoPendingDeleteContentParams params );

@Deprecated
PushContentsResult push( PushContentParams params );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.enonic.xp.content;

import com.google.common.annotations.Beta;

import com.enonic.xp.branch.Branch;

@Beta
public final class UndoPendingDeleteContentParams
{
private final ContentIds contentIds;

private final Branch target;

public UndoPendingDeleteContentParams( final ContentIds contentIds, final Branch target )
{
this.contentIds = contentIds;
this.target = target;
}

public ContentIds getContentIds()
{
return contentIds;
}

public Branch getBranch()
{
return target;
}
}
Loading

0 comments on commit 6e978a5

Please sign in to comment.