-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from wttech/fix-delete-items
fixed script, history delete
- Loading branch information
Showing
9 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptDeleteForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
|
||
package com.cognifide.apm.core.endpoints; | ||
|
||
import com.cognifide.apm.core.endpoints.params.RequestParameter; | ||
import javax.inject.Inject; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.models.annotations.Model; | ||
|
||
@Model(adaptables = SlingHttpServletRequest.class) | ||
public class ScriptDeleteForm { | ||
|
||
@Inject | ||
@RequestParameter("paths") | ||
private String[] paths; | ||
|
||
public String[] getPaths() { | ||
return paths; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptDeleteServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.endpoints; | ||
|
||
import com.cognifide.apm.core.Property; | ||
import com.cognifide.apm.core.endpoints.response.ResponseEntity; | ||
import com.cognifide.apm.core.endpoints.utils.RequestProcessor; | ||
import java.io.IOException; | ||
import javax.jcr.Session; | ||
import javax.servlet.Servlet; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.SlingHttpServletResponse; | ||
import org.apache.sling.api.servlets.SlingAllMethodsServlet; | ||
import org.apache.sling.models.factory.ModelFactory; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Component( | ||
service = Servlet.class, | ||
property = { | ||
Property.PATH + "/bin/apm/scripts/delete", | ||
Property.METHOD + "POST", | ||
Property.DESCRIPTION + "APM Script Delete Servlet", | ||
Property.VENDOR | ||
} | ||
) | ||
public class ScriptDeleteServlet extends SlingAllMethodsServlet { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ScriptDeleteServlet.class); | ||
|
||
@Reference | ||
private ModelFactory modelFactory; | ||
|
||
@Override | ||
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { | ||
RequestProcessor.process(modelFactory, ScriptDeleteForm.class, request, response, (form, resourceResolver) -> { | ||
try { | ||
Session session = resourceResolver.adaptTo(Session.class); | ||
for (String path : form.getPaths()) { | ||
if (session.nodeExists(path)) { | ||
session.removeItem(path); | ||
LOGGER.info("Item {} successfully deleted", path); | ||
} | ||
} | ||
session.save(); | ||
return ResponseEntity.ok("Item(s) successfully deleted"); | ||
} catch (Exception e) { | ||
LOGGER.error("Error while deleting item(s)", e); | ||
return ResponseEntity.badRequest(StringUtils.defaultString(e.getMessage(), "Errors while deleting item(s)")); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/clientlibs/views/scripts/js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#base=js | ||
apm-scripts.js | ||
fileupload.js | ||
view-mode.js | ||
view-mode.js | ||
deleteitem.js |
90 changes: 90 additions & 0 deletions
90
...ui.apps.base/src/main/content/jcr_root/apps/apm/clientlibs/views/scripts/js/deleteitem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*- | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 - 2016 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
(function (window, document, $) { | ||
function deletePages(collection, paths) { | ||
const ui = $(window).adaptTo('foundation-ui'); | ||
ui.wait(); | ||
$.ajax({ | ||
url: '/bin/apm/scripts/delete', | ||
type: 'POST', | ||
data: { | ||
paths: paths | ||
}, | ||
dataType: 'json', | ||
success: function () { | ||
ui.clearWait(); | ||
const api = collection.adaptTo('foundation-collection'); | ||
if (api && 'reload' in api) { | ||
api.reload(); | ||
return | ||
} | ||
const contentApi = $('.foundation-content').adaptTo('foundation-content'); | ||
if (contentApi) { | ||
contentApi.refresh(); | ||
} | ||
}, | ||
error: function () { | ||
ui.clearWait(); | ||
ui.alert('Error', 'Errors while deleting item(s)', 'error'); | ||
} | ||
}); | ||
} | ||
|
||
function createEl(name) { | ||
return $(document.createElement(name)); | ||
} | ||
|
||
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', { | ||
name: 'com.cognifide.apm.delete', | ||
handler: function (name, el, config, collection, selections) { | ||
const message = createEl('div'); | ||
const intro = createEl('p').appendTo(message); | ||
if (selections.length === 1) { | ||
intro.text('You are going to delete the following item:'); | ||
} else { | ||
intro.text('You are going to delete the following ' + selections.length + ' items:'); | ||
} | ||
let list = []; | ||
const maxCount = Math.min(selections.length, 12); | ||
for (let i = 0; i < maxCount; i++) { | ||
const title = $(selections[i]).find('.foundation-collection-item-title').text(); | ||
const time = $(selections[i]).find('.foundation-collection-item-time').text(); | ||
list.push(createEl('b').text(time ? title + ' (' + time.trim() + ')' : title).prop('outerHTML')) | ||
} | ||
if (selections.length > maxCount) { | ||
list.push('\x26#8230;'); | ||
} | ||
createEl('p').html(list.join('\x3cbr\x3e')).appendTo(message); | ||
const ui = $(window).adaptTo('foundation-ui'); | ||
ui.prompt('Delete', message.html(), 'notice', [{ | ||
text: 'Cancel' | ||
}, { | ||
text: 'Delete', | ||
warning: true, | ||
handler: function () { | ||
const paths = selections.map(function (value) { | ||
return $(value).data('foundationCollectionItemId'); | ||
}); | ||
deletePages($(collection), paths); | ||
} | ||
}]); | ||
} | ||
}); | ||
})(window, document, Granite.$); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters