Skip to content

Commit 8998dc5

Browse files
committed
fixed script, history delete
1 parent a306b14 commit 8998dc5

File tree

8 files changed

+191
-6
lines changed

8 files changed

+191
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* ========================LICENSE_START=================================
3+
* AEM Permission Management
4+
* %%
5+
* Copyright (C) 2013 Wunderman Thompson Technology
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
21+
package com.cognifide.apm.core.endpoints;
22+
23+
import com.cognifide.apm.core.endpoints.params.RequestParameter;
24+
import javax.inject.Inject;
25+
import org.apache.sling.api.SlingHttpServletRequest;
26+
import org.apache.sling.models.annotations.Model;
27+
28+
@Model(adaptables = SlingHttpServletRequest.class)
29+
public class ScriptDeleteForm {
30+
31+
@Inject
32+
@RequestParameter("paths")
33+
private String[] paths;
34+
35+
public String[] getPaths() {
36+
return paths;
37+
}
38+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* ========================LICENSE_START=================================
3+
* AEM Permission Management
4+
* %%
5+
* Copyright (C) 2013 Wunderman Thompson Technology
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package com.cognifide.apm.core.endpoints;
21+
22+
import com.cognifide.apm.core.Property;
23+
import com.cognifide.apm.core.endpoints.response.ResponseEntity;
24+
import com.cognifide.apm.core.endpoints.utils.RequestProcessor;
25+
import java.io.IOException;
26+
import javax.jcr.Session;
27+
import javax.servlet.Servlet;
28+
import org.apache.commons.lang3.StringUtils;
29+
import org.apache.sling.api.SlingHttpServletRequest;
30+
import org.apache.sling.api.SlingHttpServletResponse;
31+
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
32+
import org.apache.sling.models.factory.ModelFactory;
33+
import org.osgi.service.component.annotations.Component;
34+
import org.osgi.service.component.annotations.Reference;
35+
36+
@Component(
37+
service = Servlet.class,
38+
property = {
39+
Property.PATH + "/bin/apm/scripts/delete",
40+
Property.METHOD + "POST",
41+
Property.DESCRIPTION + "APM Script Delete Servlet",
42+
Property.VENDOR
43+
}
44+
)
45+
public class ScriptDeleteServlet extends SlingAllMethodsServlet {
46+
47+
@Reference
48+
private ModelFactory modelFactory;
49+
50+
@Override
51+
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
52+
RequestProcessor.process(modelFactory, ScriptDeleteForm.class, request, response, (form, resourceResolver) -> {
53+
try {
54+
Session session = resourceResolver.adaptTo(Session.class);
55+
for (String path : form.getPaths()) {
56+
if (session.nodeExists(path)) {
57+
session.removeItem(path);
58+
}
59+
}
60+
session.save();
61+
return ResponseEntity.ok("Item(s) successfully deleted");
62+
} catch (Exception e) {
63+
return ResponseEntity.badRequest(StringUtils.defaultString(e.getMessage(), "Errors while deleting item(s)"));
64+
}
65+
});
66+
}
67+
}

app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/RequestParameterInjector.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ private Object getValue(SlingHttpServletRequest request, Class<?> type, String p
8989
} else if (type.isEnum()) {
9090
return toEnum(type, parameterValue);
9191
} else if (type == String[].class) {
92-
return parameterValue.getString().split(",");
92+
if (parameterValue.getString().contains(",")) {
93+
return parameterValue.getString().split(",");
94+
} else {
95+
return Arrays.stream(request.getRequestParameters(parameterName))
96+
.map(org.apache.sling.api.request.RequestParameter::getString)
97+
.toArray(String[]::new);
98+
}
9399
}
94100
return parameterValue.getString();
95101
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#base=js
22
apm-scripts.js
33
fileupload.js
4-
view-mode.js
4+
view-mode.js
5+
deleteitem.js
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(function (window, document, $) {
2+
function deletePages(collection, paths) {
3+
const ui = $(window).adaptTo('foundation-ui');
4+
ui.wait();
5+
$.ajax({
6+
url: '/bin/apm/scripts/delete',
7+
type: 'POST',
8+
data: {
9+
paths: paths
10+
},
11+
dataType: 'json',
12+
success: function () {
13+
ui.clearWait();
14+
const api = collection.adaptTo('foundation-collection');
15+
if (api && 'reload' in api) {
16+
api.reload();
17+
return
18+
}
19+
const contentApi = $('.foundation-content').adaptTo('foundation-content');
20+
if (contentApi) {
21+
contentApi.refresh();
22+
}
23+
},
24+
error: function () {
25+
ui.clearWait();
26+
ui.alert('Error', 'Errors while deleting item(s)', 'error');
27+
}
28+
});
29+
}
30+
31+
function createEl(name) {
32+
return $(document.createElement(name));
33+
}
34+
35+
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', {
36+
name: 'com.cognifide.apm.delete',
37+
handler: function (name, el, config, collection, selections) {
38+
const message = createEl('div');
39+
const intro = createEl('p').appendTo(message);
40+
if (selections.length === 1) {
41+
intro.text('You are going to delete the following item:');
42+
} else {
43+
intro.text('You are going to delete the following ' + selections.length + ' items:');
44+
}
45+
let list = [];
46+
const maxCount = Math.min(selections.length, 12);
47+
for (let i = 0; i < maxCount; i++) {
48+
const title = $(selections[i]).find('.foundation-collection-item-title').text();
49+
const time = $(selections[i]).find('.foundation-collection-item-time').text();
50+
list.push(createEl('b').text(time ? title + ' (' + time.trim() + ')' : title).prop('outerHTML'))
51+
}
52+
if (selections.length > maxCount) {
53+
list.push('\x26#8230;');
54+
}
55+
createEl('p').html(list.join('\x3cbr\x3e')).appendTo(message);
56+
const ui = $(window).adaptTo('foundation-ui');
57+
ui.prompt('Delete', message.html(), 'notice', [{
58+
text: 'Cancel'
59+
}, {
60+
text: 'Delete',
61+
warning: true,
62+
handler: function () {
63+
const paths = selections.map(function (value) {
64+
return $(value).data('foundationCollectionItemId');
65+
});
66+
deletePages($(collection), paths);
67+
}
68+
}]);
69+
}
70+
});
71+
})(window, document, Granite.$);

app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/components/historyRow/historyRow.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
</td>
2828
<td is="coral-table-cell" value="${item.scriptName}">
2929
<a href="${item.scriptContentPath}" download="${item.scriptName}"
30+
class="foundation-collection-item-title"
3031
style="text-decoration:none; color:#4b4b4b">${item.scriptName}</a>
3132
</td>
3233
<td is="coral-table-cell" value="${item.executionTime.timeInMillis || 0}">
3334
<time data-sly-test="${item.executionTime}" datetime="${item.executionTime.timeInMillis || 0}"
35+
class="foundation-collection-item-time"
3436
data-sly-use.execLast="${'com.adobe.cq.xf.ui.DateFormatter' @ date=item.executionTimeCalendar, simpleFormat='yyyy-MM-dd HH:mm:ss'}">
3537
${execLast.date}
3638
</time>

app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/views/history/.content.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@
111111
href.uritemplate="/apm/viewer.html{+item}"/>
112112
</view>
113113
<deletepage
114-
granite:class="foundation-collection-action"
114+
granite:class="foundation-collection-action dialog-delete-history"
115115
granite:rel="cq-siteadmin-admin-actions-delete-activator"
116116
jcr:primaryType="nt:unstructured"
117117
sling:resourceType="granite/ui/components/coral/foundation/collection/action"
118-
action="cq.wcm.delete"
118+
action="com.cognifide.apm.delete"
119119
icon="delete"
120120
relScope="collection"
121121
target=".cq-experience-fragments-admin-childpages"

app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/views/scripts/.content.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@
258258
href.uritemplate="/apps/apm/views/move.html{+item}"/>
259259
</move>
260260
<deletepage
261-
granite:class="foundation-collection-action"
261+
granite:class="foundation-collection-action dialog-delete-script"
262262
granite:rel="cq-siteadmin-admin-actions-delete-activator"
263263
jcr:primaryType="nt:unstructured"
264264
sling:resourceType="granite/ui/components/coral/foundation/collection/action"
265-
action="cq.wcm.delete"
265+
action="com.cognifide.apm.delete"
266266
icon="delete"
267267
relScope="collection"
268268
target=".cq-experience-fragments-admin-childpages"

0 commit comments

Comments
 (0)