resource.util.js
8.51 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* 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 com, org, properties, request, resource, use */
use(['helper.js', 'actionRelationships.js'], function(helper, actionRels) {
'use strict';
var resourceResolver = resource.resourceResolver;
var isFolder = false;
var isApp = false;
var isLocation = false;
var isDisplay = false;
var isScreen = false;
var isDevice = false;
var isDeviceConfig = false;
var isChannel = false;
var isSchedule = false;
var hasChildren = false;
var canDrillDown = true;
var isOmnisearch = request.getAttribute('isOmnisearch');
var path, thumbnailPath;
// Check if the resource is a folder
isFolder = helper.isResourceType(resourceResolver.resolve(resource.path),
[helper.constants.sling.NT_SLING_FOLDER, helper.constants.sling.NT_SLING_ORDERED_FOLDER]);
if (isFolder) {
path = resource.path;
return {
image: path + '.folderthumbnail.jpg',
path: path,
properties: properties,
isFolder: isFolder,
hasChildren: helper.hasChildren(resource),
navigationHref: '/screens.html' + path
};
}
// The resource is a page, so get its content resource properties
var res, locationProperties, mapProperties, deviceProperties, props;
var page = resource.adaptTo(com.day.cq.wcm.api.Page);
if (page == null) { // eslint-disable-line
page = resource.parent.adaptTo(com.day.cq.wcm.api.Page);
}
// Handle Resources that are not cq:pages
if (page == null) { // eslint-disable-line
res = resource.resourceResolver.getResource(resource, helper.constants.device.DEVICE_PROFILE_NAME);
if (res) {
props = res.adaptTo(org.apache.sling.api.resource.ValueMap);
path = resource.path;
thumbnailPath = '/libs/screens/dcc/content/common/layouts/icons/240x180/device.png';
}
// Other Resources like Assignments
else {
res = resource;
props = res.adaptTo(org.apache.sling.api.resource.ValueMap);
path = resource.path;
thumbnailPath = '';
}
}
// Default pages
else {
props = page.properties;
path = page.path;
res = page.getContentResource();
thumbnailPath = props && props.get(helper.constants.screens.PN_THUMBNAIL_PATH, page.path);
}
hasChildren = helper.hasChildren(resource);
// Check if the page is an app
isApp = helper.isResourceType(res, helper.constants.screens.RT_APPLICATION);
// Check if the page is a location
isLocation = helper.isResourceType(res, helper.constants.screens.RT_LOCATION);
isDisplay = helper.isResourceType(res, helper.constants.screens.RT_DISPLAY);
// Check if the page is a device
isDevice = helper.isResourceType(res, helper.constants.screens.RT_DEVICE);
// Check if the page is a device
isDeviceConfig = helper.isResourceType(res, helper.constants.screens.RT_DEVICE_CONFIG);
// Check if the page is a screen
isScreen = helper.isResourceType(res, helper.constants.screens.RT_SCREEN);
// Check if the page is a channel
isChannel = helper.isResourceType(res, helper.constants.screens.RT_CHANNEL);
// Check if the page is a schedule
isSchedule = helper.isResourceType(res, helper.constants.screens.RT_SCHEDULE);
if (props) {
// Set map properties
mapProperties = {
file: resourceResolver.getResource(res,
helper.constants.screens.NN_MAP + '/' + helper.constants.screens.NN_IMAGE),
address: props.get(helper.constants.screens.PN_ADDRESS)
};
// Set location properties
locationProperties = {
position: props.get(helper.constants.screens.PN_IMAGE_PIN_COORDINATES)
&& props.get(helper.constants.screens.PN_IMAGE_PIN_COORDINATES).split(','),
refId: props.get(helper.constants.screens.PN_SVG_REFERENCE),
coordinates: props.get(helper.constants.screens.PN_GEO_COORDINATES)
&& props.get(helper.constants.screens.PN_GEO_COORDINATES).split(',')
};
// Set device properties
deviceProperties = {
id: props.get(helper.constants.screens.PN_ID),
type: props.get(helper.constants.screens.PN_TYPE),
brand: props.get(helper.constants.screens.PN_BRAND),
model: props.get(helper.constants.screens.PN_MODEL),
platform: props.get(helper.constants.screens.PN_PLATFORM),
uuid: props.get(helper.constants.screens.PN_UUID),
version: props.get(helper.constants.screens.PN_VERSION),
dimensions: props.get(helper.constants.screens.PN_DIMENSIONS)
&& props.get(helper.constants.screens.PN_DIMENSIONS).split('x'),
resolution: props.get(helper.constants.screens.PN_RESOLUTION),
width: props.get(helper.constants.screens.PN_WIDTH),
height: props.get(helper.constants.screens.PN_HEIGHT),
features: props.get(helper.constants.screens.PN_FEATURES)
};
}
var navigationHref = '';
if (isChannel) {
navigationHref = '/screens/dashboard/channel.html' + path;
}
else if (isDisplay) {
navigationHref = '/screens/dashboard/display.html' + path;
}
else if (isSchedule) {
navigationHref = '/screens/dashboard/schedule.html' + path;
}
else if (isApp || isScreen) {
navigationHref = '';
}
else if (isDevice) {
navigationHref = path && '/screens/dashboard/device.html' + path + '?returnPage=/screens/devices.html' + request.requestPathInfo.suffix || '#';
}
else if (isDeviceConfig) {
path = page.parent.path;
navigationHref = path && '/screens/dashboard/display.html' + path || '#';
}
else if (helper.isResourceType(res, ['screens/core/components/devicefolder'])) {
navigationHref = '/screens/devices.html' + path;
}
// apps may have sub pages we do not want to show (content), same goes for channels
if (isApp || isChannel || isDisplay || isDeviceConfig || isScreen || isDevice || isSchedule) {
hasChildren = false;
canDrillDown = false;
}
// Folders should be rendered as such
isFolder = helper.isResourceType(res, [
helper.constants.screens.RT_APPLICATION_FOLDER,
helper.constants.screens.RT_CHANNEL_FOLDER,
helper.constants.screens.RT_DEVICE_FOLDER,
helper.constants.screens.RT_LOCATION_FOLDER,
helper.constants.screens.RT_SCHEDULE_FOLDER
]);
// additional flags
/*eslint-disable */
var isNew =
// created less than 24h ago created
(props['jcr:created'] != null && props['jcr:created'].getTimeInMillis() - ((new Date()).getTime() - 24 * 60 * 60 * 1000) > 0) &&
// and not yet modified
(!props['cq:lastModifiedBy']);
/*eslint-enable */
var liveRelationshipManager = resourceResolver.adaptTo(com.day.cq.wcm.msm.api.LiveRelationshipManager);
var isLiveCopy = liveRelationshipManager.hasLiveRelationship(res);
return {
image: thumbnailPath,
path: path,
resourceType: res.getResourceType(),
resourceSuperType: res.getResourceSuperType(),
properties: props,
isFolder: isFolder,
isApp: isApp,
isLocation: isLocation,
isDisplay: isDisplay,
isDevice: isDevice,
isDeviceConfig: isDeviceConfig,
isScreen: isScreen,
isChannel: isChannel,
isSchedule: isSchedule,
hasChildren: hasChildren,
canDrillDown: canDrillDown,
location: locationProperties,
map: mapProperties,
device: deviceProperties,
navigationHref: navigationHref ? request.contextPath + navigationHref : null,
windowPreference: helper.windowPreference,
actionRels: actionRels(resource),
isNew: isNew,
isLiveCopy: isLiveCopy,
isOmnisearchRequest: isOmnisearch
};
});