display.js
3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
/* globals org, request, resource, use, com */
use(['../../helper.js'], function(helper) {
'use strict';
var resourceResolver = resource.resourceResolver;
// Retrieve the display resource and its properties from the request suffix
var displayPath = request.requestPathInfo.suffix;
if (displayPath == null) { // eslint-disable-line
return null;
}
var displayResource = resourceResolver.resolve(displayPath);
var displayContentResource = displayResource.getChild(helper.constants.cq.NN_CONTENT);
if (displayContentResource == null) { // eslint-disable-line
return null;
}
var displayContentProperties = displayContentResource.adaptTo(org.apache.sling.api.resource.ValueMap);
if (displayContentProperties == null) { // eslint-disable-line
return null;
}
var activeChannelResource, displayAssignment, displayAssignmentProps, resolvedResource, role;
var activeChannel = displayContentProperties.get(helper.constants.screens.PN_ACTIVE_CHANNEL);
var displayService = resourceResolver.adaptTo(com.adobe.cq.screens.display.DisplayService);
var assignmentService = resourceResolver.adaptTo(com.adobe.cq.screens.assignment.AssignmentService);
var displayAssignments = displayService.getAssignments(resourceResolver, displayResource);
while (displayAssignments.hasNext()) {
displayAssignment = displayAssignments.next();
displayAssignmentProps = displayAssignment.adaptTo(org.apache.sling.api.resource.ValueMap);
role = displayAssignmentProps.get(helper.constants.screens.PN_ROLE);
resolvedResource = assignmentService.resolveEntity(displayAssignment, displayResource);
// Ignore schedule assignments for now as they would break the "current channel" logic.
if (displayAssignment.isResourceType(com.adobe.cq.screens.binding.ScreensConstants.RT_SCHEDULE_ASSIGNMENT_ABSOLUTE)) {
continue;
}
if (!resolvedResource || !role) {
continue;
}
if (displayAssignmentProps.get(helper.constants.screens.PN_ROLE).equals(activeChannel)) {
activeChannelResource = resolvedResource.adaptTo(com.day.cq.wcm.api.Page).contentResource;
}
}
return {
windowPreference: helper.windowPreference,
properties: displayContentProperties,
activeChannel: activeChannelResource
};
});