@reldens/cms 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  *
@@ -1,258 +1,258 @@
1
- /**
2
- *
3
- * Reldens - ContentsBuilder
4
- *
5
- */
6
-
7
- const { sc } = require('@reldens/utils');
8
-
9
- class ContentsBuilder
10
- {
11
-
12
- constructor(props)
13
- {
14
- this.renderCallback = props.renderCallback;
15
- this.adminFilesContents = props.adminFilesContents;
16
- this.stylesFilePath = props.stylesFilePath;
17
- this.scriptsFilePath = props.scriptsFilePath;
18
- this.rootPath = props.rootPath;
19
- this.branding = props.branding;
20
- this.translations = props.translations;
21
- this.resources = props.resources;
22
- this.buildAdminCssOnActivation = props.buildAdminCssOnActivation;
23
- this.buildAdminScriptsOnActivation = props.buildAdminScriptsOnActivation;
24
- this.updateAdminAssetsDistOnActivation = props.updateAdminAssetsDistOnActivation;
25
- this.emitEvent = props.emitEvent;
26
- this.editPath = props.editPath;
27
- this.savePath = props.savePath;
28
- this.deletePath = props.deletePath;
29
- this.fetchUploadProperties = props.fetchUploadProperties;
30
- this.fetchTranslation = props.fetchTranslation;
31
- this.fetchEntityIdPropertyKey = props.fetchEntityIdPropertyKey;
32
- this.adminContents = {};
33
- }
34
-
35
- async buildAdminContents()
36
- {
37
- this.adminContents.layout = await this.buildLayout();
38
- this.adminContents.sideBar = await this.buildSideBar();
39
- this.adminContents.login = await this.renderRoute(this.adminFilesContents.login, '');
40
- this.adminContents.dashboard = await this.renderRoute(
41
- this.adminFilesContents.dashboard,
42
- this.adminContents.sideBar
43
- );
44
- this.adminContents.entities = await this.buildEntitiesContents();
45
- await this.emitEvent('reldens.buildAdminContentsAfter');
46
- return this.adminContents;
47
- }
48
-
49
- async buildLayout()
50
- {
51
- return await this.render(
52
- this.adminFilesContents.layout,
53
- {
54
- sideBar: '{{&sideBar}}',
55
- pageContent: '{{&pageContent}}',
56
- stylesFilePath: this.stylesFilePath,
57
- scriptsFilePath: this.scriptsFilePath,
58
- rootPath: this.rootPath,
59
- brandingCompanyName: this.branding.companyName,
60
- copyRight: this.branding.copyRight
61
- }
62
- );
63
- }
64
-
65
- async buildSideBar()
66
- {
67
- let navigationContents = {};
68
- let eventBuildSideBarBefore = {navigationContents};
69
- await this.emitEvent('reldens.eventBuildSideBarBefore', eventBuildSideBarBefore);
70
- navigationContents = eventBuildSideBarBefore.navigationContents;
71
- for(let driverResource of this.resources()){
72
- let navigation = driverResource.options?.navigation;
73
- let name = this.translations.labels[driverResource.id()]
74
- || this.translations.labels[driverResource.entityKey];
75
- let path = this.rootPath+'/'+(driverResource.id().replace(/_/g, '-'));
76
- if(navigation?.name){
77
- if(!navigationContents[navigation.name]){
78
- navigationContents[navigation.name] = {};
79
- }
80
- navigationContents[navigation.name][driverResource.id()] = await this.render(
81
- this.adminFilesContents.sideBarItem,
82
- {name, path}
83
- );
84
- continue;
85
- }
86
- navigationContents[driverResource.id()] = await this.render(
87
- this.adminFilesContents.sideBarItem,
88
- {name, path}
89
- );
90
- }
91
- let eventAdminSideBarBeforeSubItems = {navigationContents};
92
- await this.emitEvent('reldens.adminSideBarBeforeSubItems', eventAdminSideBarBeforeSubItems);
93
- let navigationView = '';
94
- for(let id of Object.keys(navigationContents)){
95
- if(sc.isObject(navigationContents[id])){
96
- let subItems = '';
97
- for(let subId of Object.keys(navigationContents[id])){
98
- subItems += navigationContents[id][subId];
99
- }
100
- navigationView += await this.render(this.adminFilesContents.sideBarHeader, {name: id, subItems});
101
- continue;
102
- }
103
- navigationView += navigationContents[id];
104
- }
105
- let eventAdminSideBarBeforeRender = {navigationContents, navigationView};
106
- await this.emitEvent('reldens.adminSideBarBeforeRender', eventAdminSideBarBeforeRender);
107
- return await this.render(
108
- this.adminFilesContents.sideBar,
109
- {
110
- rootPath: this.rootPath,
111
- navigationView: eventAdminSideBarBeforeRender.navigationView
112
- }
113
- );
114
- }
115
-
116
- async buildEntitiesContents()
117
- {
118
- let entitiesContents = {};
119
- for(let driverResource of this.resources()){
120
- let templateTitle = this.translations.labels[driverResource.id()];
121
- let entityName = (driverResource.id().replace(/_/g, '-'));
122
- let entityListRoute = this.rootPath+'/'+entityName;
123
- let entityEditRoute = entityListRoute+this.editPath;
124
- let entitySaveRoute = entityListRoute+this.savePath;
125
- let entityDeleteRoute = entityListRoute+this.deletePath;
126
- let uploadProperties = this.fetchUploadProperties(driverResource);
127
- let multipartFormData = 0 < Object.keys(uploadProperties).length ? ' enctype="multipart/form-data"' : '';
128
- let idProperty = this.fetchEntityIdPropertyKey(driverResource);
129
- let editProperties = Object.keys(driverResource.options.properties);
130
- editProperties.splice(editProperties.indexOf(idProperty), 1);
131
- let filters = driverResource.options.filterProperties.map((property) => {
132
- return {
133
- propertyKey: property,
134
- name: this.fetchTranslation(property),
135
- value: '{{&'+property+'}}'
136
- };
137
- });
138
- let fields = driverResource.options.showProperties.map((property) => {
139
- return {
140
- name: this.fetchTranslation(property),
141
- value: '{{&'+property+'}}'
142
- };
143
- });
144
- let editFields = editProperties.map((property) => {
145
- return {
146
- name: this.fetchTranslation(property),
147
- value: '{{&'+property+'}}'
148
- };
149
- });
150
- let sectionsContents = this.adminFilesContents?.sections;
151
- let extraContentForList = sc.get(sectionsContents?.list, driverResource.entityPath, '');
152
- let extraContentForView = await this.render(
153
- sc.get(sectionsContents?.view, driverResource.entityPath, ''),
154
- {
155
- id: '{{&id}}',
156
- entitySerializedData: '{{&entitySerializedData}}'
157
- }
158
- );
159
- let extraFormContentForView = sc.get(sectionsContents?.viewForm, driverResource.entityPath, '');
160
- let extraContentForEdit = sc.get(sectionsContents?.edit, driverResource.entityPath, '');
161
- let extraFormContentForEdit = sc.get(sectionsContents?.editForm, driverResource.entityPath, '');
162
- entitiesContents[entityName] = {
163
- list: await this.render(
164
- this.adminFilesContents.list,
165
- {
166
- entityName,
167
- templateTitle,
168
- entityListRoute,
169
- entityEditRoute,
170
- entityFilterTermValue: '{{&entityFilterTermValue}}',
171
- filters,
172
- list: '{{&list}}',
173
- pagination: '{{&pagination}}',
174
- extraContent: '{{&extraContentForList}}'+extraContentForList,
175
- }
176
- ),
177
- view: await this.render(
178
- this.adminFilesContents.view,
179
- {
180
- entityName,
181
- templateTitle,
182
- entityDeleteRoute,
183
- entityListRoute,
184
- fields,
185
- id: '{{&id}}',
186
- entityEditRoute: '{{&entityEditRoute}}',
187
- entityNewRoute: '{{&entityNewRoute}}',
188
- extraContent: '{{&extraContentForView}}'+extraContentForView,
189
- extraFormContent: '{{&extraFormContentForView}}'+extraFormContentForView
190
- }
191
- ),
192
- edit: await this.render(
193
- this.adminFilesContents.edit,
194
- {
195
- entityName,
196
- entitySaveRoute,
197
- multipartFormData,
198
- editFields,
199
- idValue: '{{&idValue}}',
200
- idProperty: '{{&idProperty}}',
201
- templateTitle: '{{&templateTitle}}',
202
- entityViewRoute: '{{&entityViewRoute}}',
203
- extraContent: '{{&extraContentForEdit}}'+extraContentForEdit,
204
- extraFormContent: '{{&extraFormContentForEdit}}'+extraFormContentForEdit
205
- }
206
- )
207
- };
208
- }
209
- return entitiesContents;
210
- }
211
-
212
- async render(content, params)
213
- {
214
- return await this.renderCallback(content, params);
215
- }
216
-
217
- async renderRoute(pageContent, sideBar)
218
- {
219
- return await this.render(
220
- this.adminContents.layout,
221
- {
222
- stylesFilePath: this.stylesFilePath,
223
- scriptsFilePath: this.scriptsFilePath,
224
- brandingCompanyName: this.branding.companyName,
225
- copyRight: this.branding.copyRight,
226
- pageContent,
227
- sideBar
228
- }
229
- );
230
- }
231
-
232
- async buildAdminScripts()
233
- {
234
- if(!sc.isFunction(this.buildAdminScriptsOnActivation)){
235
- return false;
236
- }
237
- return this.buildAdminScriptsOnActivation();
238
- }
239
-
240
- async updateAdminAssets()
241
- {
242
- if(!sc.isFunction(this.updateAdminAssetsDistOnActivation)){
243
- return false;
244
- }
245
- return this.updateAdminAssetsDistOnActivation();
246
- }
247
-
248
- async buildAdminCss()
249
- {
250
- if(!sc.isFunction(this.buildAdminCssOnActivation)){
251
- return false;
252
- }
253
- return this.buildAdminCssOnActivation();
254
- }
255
-
256
- }
257
-
258
- module.exports.ContentsBuilder = ContentsBuilder;
1
+ /**
2
+ *
3
+ * Reldens - ContentsBuilder
4
+ *
5
+ */
6
+
7
+ const { sc } = require('@reldens/utils');
8
+
9
+ class ContentsBuilder
10
+ {
11
+
12
+ constructor(props)
13
+ {
14
+ this.renderCallback = props.renderCallback;
15
+ this.adminFilesContents = props.adminFilesContents;
16
+ this.stylesFilePath = props.stylesFilePath;
17
+ this.scriptsFilePath = props.scriptsFilePath;
18
+ this.rootPath = props.rootPath;
19
+ this.branding = props.branding;
20
+ this.translations = props.translations;
21
+ this.resources = props.resources;
22
+ this.buildAdminCssOnActivation = props.buildAdminCssOnActivation;
23
+ this.buildAdminScriptsOnActivation = props.buildAdminScriptsOnActivation;
24
+ this.updateAdminAssetsDistOnActivation = props.updateAdminAssetsDistOnActivation;
25
+ this.emitEvent = props.emitEvent;
26
+ this.editPath = props.editPath;
27
+ this.savePath = props.savePath;
28
+ this.deletePath = props.deletePath;
29
+ this.fetchUploadProperties = props.fetchUploadProperties;
30
+ this.fetchTranslation = props.fetchTranslation;
31
+ this.fetchEntityIdPropertyKey = props.fetchEntityIdPropertyKey;
32
+ this.adminContents = {};
33
+ }
34
+
35
+ async buildAdminContents()
36
+ {
37
+ this.adminContents.layout = await this.buildLayout();
38
+ this.adminContents.sideBar = await this.buildSideBar();
39
+ this.adminContents.login = await this.renderRoute(this.adminFilesContents.login, '');
40
+ this.adminContents.dashboard = await this.renderRoute(
41
+ this.adminFilesContents.dashboard,
42
+ this.adminContents.sideBar
43
+ );
44
+ this.adminContents.entities = await this.buildEntitiesContents();
45
+ await this.emitEvent('reldens.buildAdminContentsAfter');
46
+ return this.adminContents;
47
+ }
48
+
49
+ async buildLayout()
50
+ {
51
+ return await this.render(
52
+ this.adminFilesContents.layout,
53
+ {
54
+ sideBar: '{{&sideBar}}',
55
+ pageContent: '{{&pageContent}}',
56
+ stylesFilePath: this.stylesFilePath,
57
+ scriptsFilePath: this.scriptsFilePath,
58
+ rootPath: this.rootPath,
59
+ brandingCompanyName: this.branding.companyName,
60
+ copyRight: this.branding.copyRight
61
+ }
62
+ );
63
+ }
64
+
65
+ async buildSideBar()
66
+ {
67
+ let navigationContents = {};
68
+ let eventBuildSideBarBefore = {navigationContents};
69
+ await this.emitEvent('reldens.eventBuildSideBarBefore', eventBuildSideBarBefore);
70
+ navigationContents = eventBuildSideBarBefore.navigationContents;
71
+ for(let driverResource of this.resources()){
72
+ let navigation = driverResource.options?.navigation;
73
+ let name = this.translations.labels[driverResource.id()]
74
+ || this.translations.labels[driverResource.entityKey];
75
+ let path = this.rootPath+'/'+(driverResource.id().replace(/_/g, '-'));
76
+ if(navigation?.name){
77
+ if(!navigationContents[navigation.name]){
78
+ navigationContents[navigation.name] = {};
79
+ }
80
+ navigationContents[navigation.name][driverResource.id()] = await this.render(
81
+ this.adminFilesContents.sideBarItem,
82
+ {name, path}
83
+ );
84
+ continue;
85
+ }
86
+ navigationContents[driverResource.id()] = await this.render(
87
+ this.adminFilesContents.sideBarItem,
88
+ {name, path}
89
+ );
90
+ }
91
+ let eventAdminSideBarBeforeSubItems = {navigationContents};
92
+ await this.emitEvent('reldens.adminSideBarBeforeSubItems', eventAdminSideBarBeforeSubItems);
93
+ let navigationView = '';
94
+ for(let id of Object.keys(navigationContents)){
95
+ if(sc.isObject(navigationContents[id])){
96
+ let subItems = '';
97
+ for(let subId of Object.keys(navigationContents[id])){
98
+ subItems += navigationContents[id][subId];
99
+ }
100
+ navigationView += await this.render(this.adminFilesContents.sideBarHeader, {name: id, subItems});
101
+ continue;
102
+ }
103
+ navigationView += navigationContents[id];
104
+ }
105
+ let eventAdminSideBarBeforeRender = {navigationContents, navigationView};
106
+ await this.emitEvent('reldens.adminSideBarBeforeRender', eventAdminSideBarBeforeRender);
107
+ return await this.render(
108
+ this.adminFilesContents.sideBar,
109
+ {
110
+ rootPath: this.rootPath,
111
+ navigationView: eventAdminSideBarBeforeRender.navigationView
112
+ }
113
+ );
114
+ }
115
+
116
+ async buildEntitiesContents()
117
+ {
118
+ let entitiesContents = {};
119
+ for(let driverResource of this.resources()){
120
+ let templateTitle = this.translations.labels[driverResource.id()];
121
+ let entityName = (driverResource.id().replace(/_/g, '-'));
122
+ let entityListRoute = this.rootPath+'/'+entityName;
123
+ let entityEditRoute = entityListRoute+this.editPath;
124
+ let entitySaveRoute = entityListRoute+this.savePath;
125
+ let entityDeleteRoute = entityListRoute+this.deletePath;
126
+ let uploadProperties = this.fetchUploadProperties(driverResource);
127
+ let multipartFormData = 0 < Object.keys(uploadProperties).length ? ' enctype="multipart/form-data"' : '';
128
+ let idProperty = this.fetchEntityIdPropertyKey(driverResource);
129
+ let editProperties = Object.keys(driverResource.options.properties);
130
+ editProperties.splice(editProperties.indexOf(idProperty), 1);
131
+ let filters = driverResource.options.filterProperties.map((property) => {
132
+ return {
133
+ propertyKey: property,
134
+ name: this.fetchTranslation(property),
135
+ value: '{{&'+property+'}}'
136
+ };
137
+ });
138
+ let fields = driverResource.options.showProperties.map((property) => {
139
+ return {
140
+ name: this.fetchTranslation(property),
141
+ value: '{{&'+property+'}}'
142
+ };
143
+ });
144
+ let editFields = editProperties.map((property) => {
145
+ return {
146
+ name: this.fetchTranslation(property),
147
+ value: '{{&'+property+'}}'
148
+ };
149
+ });
150
+ let sectionsContents = this.adminFilesContents?.sections;
151
+ let extraContentForList = sc.get(sectionsContents?.list, driverResource.entityPath, '');
152
+ let extraContentForView = await this.render(
153
+ sc.get(sectionsContents?.view, driverResource.entityPath, ''),
154
+ {
155
+ id: '{{&id}}',
156
+ entitySerializedData: '{{&entitySerializedData}}'
157
+ }
158
+ );
159
+ let extraFormContentForView = sc.get(sectionsContents?.viewForm, driverResource.entityPath, '');
160
+ let extraContentForEdit = sc.get(sectionsContents?.edit, driverResource.entityPath, '');
161
+ let extraFormContentForEdit = sc.get(sectionsContents?.editForm, driverResource.entityPath, '');
162
+ entitiesContents[entityName] = {
163
+ list: await this.render(
164
+ this.adminFilesContents.list,
165
+ {
166
+ entityName,
167
+ templateTitle,
168
+ entityListRoute,
169
+ entityEditRoute,
170
+ entityFilterTermValue: '{{&entityFilterTermValue}}',
171
+ filters,
172
+ list: '{{&list}}',
173
+ pagination: '{{&pagination}}',
174
+ extraContent: '{{&extraContentForList}}'+extraContentForList,
175
+ }
176
+ ),
177
+ view: await this.render(
178
+ this.adminFilesContents.view,
179
+ {
180
+ entityName,
181
+ templateTitle,
182
+ entityDeleteRoute,
183
+ entityListRoute,
184
+ fields,
185
+ id: '{{&id}}',
186
+ entityEditRoute: '{{&entityEditRoute}}',
187
+ entityNewRoute: '{{&entityNewRoute}}',
188
+ extraContent: '{{&extraContentForView}}'+extraContentForView,
189
+ extraFormContent: '{{&extraFormContentForView}}'+extraFormContentForView
190
+ }
191
+ ),
192
+ edit: await this.render(
193
+ this.adminFilesContents.edit,
194
+ {
195
+ entityName,
196
+ entitySaveRoute,
197
+ multipartFormData,
198
+ editFields,
199
+ idValue: '{{&idValue}}',
200
+ idProperty: '{{&idProperty}}',
201
+ templateTitle: '{{&templateTitle}}',
202
+ entityViewRoute: '{{&entityViewRoute}}',
203
+ extraContent: '{{&extraContentForEdit}}'+extraContentForEdit,
204
+ extraFormContent: '{{&extraFormContentForEdit}}'+extraFormContentForEdit
205
+ }
206
+ )
207
+ };
208
+ }
209
+ return entitiesContents;
210
+ }
211
+
212
+ async render(content, params)
213
+ {
214
+ return await this.renderCallback(content, params);
215
+ }
216
+
217
+ async renderRoute(pageContent, sideBar)
218
+ {
219
+ return await this.render(
220
+ this.adminContents.layout,
221
+ {
222
+ stylesFilePath: this.stylesFilePath,
223
+ scriptsFilePath: this.scriptsFilePath,
224
+ brandingCompanyName: this.branding.companyName,
225
+ copyRight: this.branding.copyRight,
226
+ pageContent,
227
+ sideBar
228
+ }
229
+ );
230
+ }
231
+
232
+ async buildAdminScripts()
233
+ {
234
+ if(!sc.isFunction(this.buildAdminScriptsOnActivation)){
235
+ return false;
236
+ }
237
+ return this.buildAdminScriptsOnActivation();
238
+ }
239
+
240
+ async updateAdminAssets()
241
+ {
242
+ if(!sc.isFunction(this.updateAdminAssetsDistOnActivation)){
243
+ return false;
244
+ }
245
+ return this.updateAdminAssetsDistOnActivation();
246
+ }
247
+
248
+ async buildAdminCss()
249
+ {
250
+ if(!sc.isFunction(this.buildAdminCssOnActivation)){
251
+ return false;
252
+ }
253
+ return this.buildAdminCssOnActivation();
254
+ }
255
+
256
+ }
257
+
258
+ module.exports.ContentsBuilder = ContentsBuilder;