pict-docuserve 0.0.1
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.
- package/LICENSE +21 -0
- package/build-site.js +172 -0
- package/css/docuserve.css +73 -0
- package/dist/css/docuserve.css +73 -0
- package/dist/index.html +32 -0
- package/dist/js/pict.compatible.js +7793 -0
- package/dist/js/pict.compatible.js.map +1 -0
- package/dist/js/pict.compatible.min.js +12 -0
- package/dist/js/pict.compatible.min.js.map +1 -0
- package/dist/js/pict.js +7792 -0
- package/dist/js/pict.js.map +1 -0
- package/dist/js/pict.min.js +12 -0
- package/dist/js/pict.min.js.map +1 -0
- package/dist/pict-docuserve.compatible.js +5148 -0
- package/dist/pict-docuserve.compatible.js.map +1 -0
- package/dist/pict-docuserve.compatible.min.js +2 -0
- package/dist/pict-docuserve.compatible.min.js.map +1 -0
- package/dist/pict-docuserve.js +4670 -0
- package/dist/pict-docuserve.js.map +1 -0
- package/dist/pict-docuserve.min.js +2 -0
- package/dist/pict-docuserve.min.js.map +1 -0
- package/html/index.html +32 -0
- package/package.json +52 -0
- package/source/Pict-Application-Docuserve-Configuration.json +15 -0
- package/source/Pict-Application-Docuserve.js +246 -0
- package/source/cli/Docuserve-CLI-Program.js +16 -0
- package/source/cli/Docuserve-CLI-Run.js +3 -0
- package/source/cli/commands/Docuserve-Command-Inject.js +127 -0
- package/source/cli/commands/Docuserve-Command-Serve.js +135 -0
- package/source/providers/Pict-Provider-Docuserve-Documentation.js +1156 -0
- package/source/providers/PictRouter-Docuserve-Configuration.json +26 -0
- package/source/views/PictView-Docuserve-Content.js +208 -0
- package/source/views/PictView-Docuserve-Layout.js +105 -0
- package/source/views/PictView-Docuserve-Sidebar.js +362 -0
- package/source/views/PictView-Docuserve-Splash.js +264 -0
- package/source/views/PictView-Docuserve-TopBar.js +213 -0
|
@@ -0,0 +1,4670 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
(function (f) {
|
|
7
|
+
if (typeof exports === "object" && typeof module !== "undefined") {
|
|
8
|
+
module.exports = f();
|
|
9
|
+
} else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define([], f);
|
|
11
|
+
} else {
|
|
12
|
+
var g;
|
|
13
|
+
if (typeof window !== "undefined") {
|
|
14
|
+
g = window;
|
|
15
|
+
} else if (typeof global !== "undefined") {
|
|
16
|
+
g = global;
|
|
17
|
+
} else if (typeof self !== "undefined") {
|
|
18
|
+
g = self;
|
|
19
|
+
} else {
|
|
20
|
+
g = this;
|
|
21
|
+
}
|
|
22
|
+
g.PictDocuserve = f();
|
|
23
|
+
}
|
|
24
|
+
})(function () {
|
|
25
|
+
var define, module, exports;
|
|
26
|
+
return function () {
|
|
27
|
+
function r(e, n, t) {
|
|
28
|
+
function o(i, f) {
|
|
29
|
+
if (!n[i]) {
|
|
30
|
+
if (!e[i]) {
|
|
31
|
+
var c = "function" == typeof require && require;
|
|
32
|
+
if (!f && c) return c(i, !0);
|
|
33
|
+
if (u) return u(i, !0);
|
|
34
|
+
var a = new Error("Cannot find module '" + i + "'");
|
|
35
|
+
throw a.code = "MODULE_NOT_FOUND", a;
|
|
36
|
+
}
|
|
37
|
+
var p = n[i] = {
|
|
38
|
+
exports: {}
|
|
39
|
+
};
|
|
40
|
+
e[i][0].call(p.exports, function (r) {
|
|
41
|
+
var n = e[i][1][r];
|
|
42
|
+
return o(n || r);
|
|
43
|
+
}, p, p.exports, r, e, n, t);
|
|
44
|
+
}
|
|
45
|
+
return n[i].exports;
|
|
46
|
+
}
|
|
47
|
+
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
|
|
48
|
+
return o;
|
|
49
|
+
}
|
|
50
|
+
return r;
|
|
51
|
+
}()({
|
|
52
|
+
1: [function (require, module, exports) {
|
|
53
|
+
module.exports = {
|
|
54
|
+
"name": "fable-serviceproviderbase",
|
|
55
|
+
"version": "3.0.15",
|
|
56
|
+
"description": "Simple base classes for fable services.",
|
|
57
|
+
"main": "source/Fable-ServiceProviderBase.js",
|
|
58
|
+
"scripts": {
|
|
59
|
+
"start": "node source/Fable-ServiceProviderBase.js",
|
|
60
|
+
"test": "npx mocha -u tdd -R spec",
|
|
61
|
+
"tests": "npx mocha -u tdd --exit -R spec --grep",
|
|
62
|
+
"coverage": "npx nyc --reporter=lcov --reporter=text-lcov npx mocha -- -u tdd -R spec",
|
|
63
|
+
"build": "npx quack build"
|
|
64
|
+
},
|
|
65
|
+
"mocha": {
|
|
66
|
+
"diff": true,
|
|
67
|
+
"extension": ["js"],
|
|
68
|
+
"package": "./package.json",
|
|
69
|
+
"reporter": "spec",
|
|
70
|
+
"slow": "75",
|
|
71
|
+
"timeout": "5000",
|
|
72
|
+
"ui": "tdd",
|
|
73
|
+
"watch-files": ["source/**/*.js", "test/**/*.js"],
|
|
74
|
+
"watch-ignore": ["lib/vendor"]
|
|
75
|
+
},
|
|
76
|
+
"repository": {
|
|
77
|
+
"type": "git",
|
|
78
|
+
"url": "https://github.com/stevenvelozo/fable-serviceproviderbase.git"
|
|
79
|
+
},
|
|
80
|
+
"keywords": ["entity", "behavior"],
|
|
81
|
+
"author": "Steven Velozo <steven@velozo.com> (http://velozo.com/)",
|
|
82
|
+
"license": "MIT",
|
|
83
|
+
"bugs": {
|
|
84
|
+
"url": "https://github.com/stevenvelozo/fable-serviceproviderbase/issues"
|
|
85
|
+
},
|
|
86
|
+
"homepage": "https://github.com/stevenvelozo/fable-serviceproviderbase",
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"fable": "^3.0.143",
|
|
89
|
+
"quackage": "^1.0.33"
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}, {}],
|
|
93
|
+
2: [function (require, module, exports) {
|
|
94
|
+
/**
|
|
95
|
+
* Fable Service Base
|
|
96
|
+
* @author <steven@velozo.com>
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
const libPackage = require('../package.json');
|
|
100
|
+
class FableServiceProviderBase {
|
|
101
|
+
// The constructor can be used in two ways:
|
|
102
|
+
// 1) With a fable, options object and service hash (the options object and service hash are optional)
|
|
103
|
+
// 2) With an object or nothing as the first parameter, where it will be treated as the options object
|
|
104
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
105
|
+
// Check if a fable was passed in; connect it if so
|
|
106
|
+
if (typeof pFable === 'object' && pFable.isFable) {
|
|
107
|
+
this.connectFable(pFable);
|
|
108
|
+
} else {
|
|
109
|
+
this.fable = false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Initialize the services map if it wasn't passed in
|
|
113
|
+
/** @type {Object} */
|
|
114
|
+
this._PackageFableServiceProvider = libPackage;
|
|
115
|
+
|
|
116
|
+
// initialize options and UUID based on whether the fable was passed in or not.
|
|
117
|
+
if (this.fable) {
|
|
118
|
+
this.UUID = pFable.getUUID();
|
|
119
|
+
this.options = typeof pOptions === 'object' ? pOptions : {};
|
|
120
|
+
} else {
|
|
121
|
+
// With no fable, check to see if there was an object passed into either of the first two
|
|
122
|
+
// Parameters, and if so, treat it as the options object
|
|
123
|
+
this.options = typeof pFable === 'object' && !pFable.isFable ? pFable : typeof pOptions === 'object' ? pOptions : {};
|
|
124
|
+
this.UUID = "CORE-SVC-".concat(Math.floor(Math.random() * (99999 - 10000) + 10000));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// It's expected that the deriving class will set this
|
|
128
|
+
this.serviceType = "Unknown-".concat(this.UUID);
|
|
129
|
+
|
|
130
|
+
// The service hash is used to identify the specific instantiation of the service in the services map
|
|
131
|
+
this.Hash = typeof pServiceHash === 'string' ? pServiceHash : !this.fable && typeof pOptions === 'string' ? pOptions : "".concat(this.UUID);
|
|
132
|
+
}
|
|
133
|
+
connectFable(pFable) {
|
|
134
|
+
if (typeof pFable !== 'object' || !pFable.isFable) {
|
|
135
|
+
let tmpErrorMessage = "Fable Service Provider Base: Cannot connect to Fable, invalid Fable object passed in. The pFable parameter was a [".concat(typeof pFable, "].}");
|
|
136
|
+
console.log(tmpErrorMessage);
|
|
137
|
+
return new Error(tmpErrorMessage);
|
|
138
|
+
}
|
|
139
|
+
if (!this.fable) {
|
|
140
|
+
this.fable = pFable;
|
|
141
|
+
}
|
|
142
|
+
if (!this.log) {
|
|
143
|
+
this.log = this.fable.Logging;
|
|
144
|
+
}
|
|
145
|
+
if (!this.services) {
|
|
146
|
+
this.services = this.fable.services;
|
|
147
|
+
}
|
|
148
|
+
if (!this.servicesMap) {
|
|
149
|
+
this.servicesMap = this.fable.servicesMap;
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
_defineProperty(FableServiceProviderBase, "isFableService", true);
|
|
155
|
+
module.exports = FableServiceProviderBase;
|
|
156
|
+
|
|
157
|
+
// This is left here in case we want to go back to having different code/base class for "core" services
|
|
158
|
+
module.exports.CoreServiceProviderBase = FableServiceProviderBase;
|
|
159
|
+
}, {
|
|
160
|
+
"../package.json": 1
|
|
161
|
+
}],
|
|
162
|
+
3: [function (require, module, exports) {
|
|
163
|
+
module.exports = {
|
|
164
|
+
"name": "pict-application",
|
|
165
|
+
"version": "1.0.30",
|
|
166
|
+
"description": "Application base class for a pict view-based application",
|
|
167
|
+
"main": "source/Pict-Application.js",
|
|
168
|
+
"scripts": {
|
|
169
|
+
"test": "npx mocha -u tdd -R spec",
|
|
170
|
+
"start": "node source/Pict-Application.js",
|
|
171
|
+
"coverage": "npx nyc --reporter=lcov --reporter=text-lcov npx mocha -- -u tdd -R spec",
|
|
172
|
+
"build": "npx quack build",
|
|
173
|
+
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t pict-application-image:local",
|
|
174
|
+
"docker-dev-run": "docker run -it -d --name pict-application-dev -p 30001:8080 -p 38086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/pict-application\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" pict-application-image:local",
|
|
175
|
+
"docker-dev-shell": "docker exec -it pict-application-dev /bin/bash",
|
|
176
|
+
"tests": "npx mocha -u tdd --exit -R spec --grep",
|
|
177
|
+
"lint": "eslint source/**",
|
|
178
|
+
"types": "tsc -p ."
|
|
179
|
+
},
|
|
180
|
+
"types": "types/source/Pict-Application.d.ts",
|
|
181
|
+
"repository": {
|
|
182
|
+
"type": "git",
|
|
183
|
+
"url": "git+https://github.com/stevenvelozo/pict-application.git"
|
|
184
|
+
},
|
|
185
|
+
"author": "steven velozo <steven@velozo.com>",
|
|
186
|
+
"license": "MIT",
|
|
187
|
+
"bugs": {
|
|
188
|
+
"url": "https://github.com/stevenvelozo/pict-application/issues"
|
|
189
|
+
},
|
|
190
|
+
"homepage": "https://github.com/stevenvelozo/pict-application#readme",
|
|
191
|
+
"devDependencies": {
|
|
192
|
+
"@eslint/js": "^9.28.0",
|
|
193
|
+
"browser-env": "^3.3.0",
|
|
194
|
+
"eslint": "^9.28.0",
|
|
195
|
+
"pict": "^1.0.343",
|
|
196
|
+
"pict-provider": "^1.0.7",
|
|
197
|
+
"pict-view": "^1.0.64",
|
|
198
|
+
"quackage": "^1.0.45",
|
|
199
|
+
"typescript": "^5.9.3"
|
|
200
|
+
},
|
|
201
|
+
"mocha": {
|
|
202
|
+
"diff": true,
|
|
203
|
+
"extension": ["js"],
|
|
204
|
+
"package": "./package.json",
|
|
205
|
+
"reporter": "spec",
|
|
206
|
+
"slow": "75",
|
|
207
|
+
"timeout": "5000",
|
|
208
|
+
"ui": "tdd",
|
|
209
|
+
"watch-files": ["source/**/*.js", "test/**/*.js"],
|
|
210
|
+
"watch-ignore": ["lib/vendor"]
|
|
211
|
+
},
|
|
212
|
+
"dependencies": {
|
|
213
|
+
"fable-serviceproviderbase": "^3.0.15"
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}, {}],
|
|
217
|
+
4: [function (require, module, exports) {
|
|
218
|
+
const libFableServiceBase = require('fable-serviceproviderbase');
|
|
219
|
+
const libPackage = require('../package.json');
|
|
220
|
+
const defaultPictSettings = {
|
|
221
|
+
Name: 'DefaultPictApplication',
|
|
222
|
+
// The main "viewport" is the view that is used to host our application
|
|
223
|
+
MainViewportViewIdentifier: 'Default-View',
|
|
224
|
+
MainViewportRenderableHash: false,
|
|
225
|
+
MainViewportDestinationAddress: false,
|
|
226
|
+
MainViewportDefaultDataAddress: false,
|
|
227
|
+
// Whether or not we should automatically render the main viewport and other autorender views after we initialize the pict application
|
|
228
|
+
AutoSolveAfterInitialize: true,
|
|
229
|
+
AutoRenderMainViewportViewAfterInitialize: true,
|
|
230
|
+
AutoRenderViewsAfterInitialize: false,
|
|
231
|
+
AutoLoginAfterInitialize: false,
|
|
232
|
+
AutoLoadDataAfterLogin: false,
|
|
233
|
+
ConfigurationOnlyViews: [],
|
|
234
|
+
Manifests: {},
|
|
235
|
+
// The prefix to prepend on all template destination hashes
|
|
236
|
+
IdentifierAddressPrefix: 'PICT-'
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Base class for pict applications.
|
|
241
|
+
*/
|
|
242
|
+
class PictApplication extends libFableServiceBase {
|
|
243
|
+
/**
|
|
244
|
+
* @param {import('fable')} pFable
|
|
245
|
+
* @param {Record<string, any>} [pOptions]
|
|
246
|
+
* @param {string} [pServiceHash]
|
|
247
|
+
*/
|
|
248
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
249
|
+
let tmpCarryOverConfiguration = typeof pFable.settings.PictApplicationConfiguration === 'object' ? pFable.settings.PictApplicationConfiguration : {};
|
|
250
|
+
let tmpOptions = Object.assign({}, JSON.parse(JSON.stringify(defaultPictSettings)), tmpCarryOverConfiguration, pOptions);
|
|
251
|
+
super(pFable, tmpOptions, pServiceHash);
|
|
252
|
+
|
|
253
|
+
/** @type {any} */
|
|
254
|
+
this.options;
|
|
255
|
+
/** @type {any} */
|
|
256
|
+
this.log;
|
|
257
|
+
/** @type {import('pict') & import('fable')} */
|
|
258
|
+
this.fable;
|
|
259
|
+
/** @type {string} */
|
|
260
|
+
this.UUID;
|
|
261
|
+
/** @type {string} */
|
|
262
|
+
this.Hash;
|
|
263
|
+
/**
|
|
264
|
+
* @type {{ [key: string]: any }}
|
|
265
|
+
*/
|
|
266
|
+
this.servicesMap;
|
|
267
|
+
this.serviceType = 'PictApplication';
|
|
268
|
+
/** @type {Record<string, any>} */
|
|
269
|
+
this._Package = libPackage;
|
|
270
|
+
|
|
271
|
+
// Convenience and consistency naming
|
|
272
|
+
this.pict = this.fable;
|
|
273
|
+
// Wire in the essential Pict state
|
|
274
|
+
/** @type {Record<string, any>} */
|
|
275
|
+
this.AppData = this.fable.AppData;
|
|
276
|
+
/** @type {Record<string, any>} */
|
|
277
|
+
this.Bundle = this.fable.Bundle;
|
|
278
|
+
|
|
279
|
+
/** @type {number} */
|
|
280
|
+
this.initializeTimestamp;
|
|
281
|
+
/** @type {number} */
|
|
282
|
+
this.lastSolvedTimestamp;
|
|
283
|
+
/** @type {number} */
|
|
284
|
+
this.lastLoginTimestamp;
|
|
285
|
+
/** @type {number} */
|
|
286
|
+
this.lastMarshalFromViewsTimestamp;
|
|
287
|
+
/** @type {number} */
|
|
288
|
+
this.lastMarshalToViewsTimestamp;
|
|
289
|
+
/** @type {number} */
|
|
290
|
+
this.lastAutoRenderTimestamp;
|
|
291
|
+
/** @type {number} */
|
|
292
|
+
this.lastLoadDataTimestamp;
|
|
293
|
+
|
|
294
|
+
// Load all the manifests for the application
|
|
295
|
+
let tmpManifestKeys = Object.keys(this.options.Manifests);
|
|
296
|
+
if (tmpManifestKeys.length > 0) {
|
|
297
|
+
for (let i = 0; i < tmpManifestKeys.length; i++) {
|
|
298
|
+
// Load each manifest
|
|
299
|
+
let tmpManifestKey = tmpManifestKeys[i];
|
|
300
|
+
this.fable.instantiateServiceProvider('Manifest', this.options.Manifests[tmpManifestKey], tmpManifestKey);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/* -------------------------------------------------------------------------- */
|
|
306
|
+
/* Code Section: Solve All Views */
|
|
307
|
+
/* -------------------------------------------------------------------------- */
|
|
308
|
+
/**
|
|
309
|
+
* @return {boolean}
|
|
310
|
+
*/
|
|
311
|
+
onPreSolve() {
|
|
312
|
+
if (this.pict.LogNoisiness > 3) {
|
|
313
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onPreSolve:"));
|
|
314
|
+
}
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @param {(error?: Error) => void} fCallback
|
|
319
|
+
*/
|
|
320
|
+
onPreSolveAsync(fCallback) {
|
|
321
|
+
this.onPreSolve();
|
|
322
|
+
return fCallback();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* @return {boolean}
|
|
327
|
+
*/
|
|
328
|
+
onBeforeSolve() {
|
|
329
|
+
if (this.pict.LogNoisiness > 3) {
|
|
330
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeSolve:"));
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* @param {(error?: Error) => void} fCallback
|
|
336
|
+
*/
|
|
337
|
+
onBeforeSolveAsync(fCallback) {
|
|
338
|
+
this.onBeforeSolve();
|
|
339
|
+
return fCallback();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @return {boolean}
|
|
344
|
+
*/
|
|
345
|
+
onSolve() {
|
|
346
|
+
if (this.pict.LogNoisiness > 3) {
|
|
347
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onSolve:"));
|
|
348
|
+
}
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @param {(error?: Error) => void} fCallback
|
|
353
|
+
*/
|
|
354
|
+
onSolveAsync(fCallback) {
|
|
355
|
+
this.onSolve();
|
|
356
|
+
return fCallback();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @return {boolean}
|
|
361
|
+
*/
|
|
362
|
+
solve() {
|
|
363
|
+
if (this.pict.LogNoisiness > 2) {
|
|
364
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " executing solve() function..."));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Walk through any loaded providers and solve them as well.
|
|
368
|
+
let tmpLoadedProviders = Object.keys(this.pict.providers);
|
|
369
|
+
let tmpProvidersToSolve = [];
|
|
370
|
+
for (let i = 0; i < tmpLoadedProviders.length; i++) {
|
|
371
|
+
let tmpProvider = this.pict.providers[tmpLoadedProviders[i]];
|
|
372
|
+
if (tmpProvider.options.AutoSolveWithApp) {
|
|
373
|
+
tmpProvidersToSolve.push(tmpProvider);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// Sort the providers by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
377
|
+
tmpProvidersToSolve.sort((a, b) => {
|
|
378
|
+
return a.options.AutoSolveOrdinal - b.options.AutoSolveOrdinal;
|
|
379
|
+
});
|
|
380
|
+
for (let i = 0; i < tmpProvidersToSolve.length; i++) {
|
|
381
|
+
tmpProvidersToSolve[i].solve(tmpProvidersToSolve[i]);
|
|
382
|
+
}
|
|
383
|
+
this.onBeforeSolve();
|
|
384
|
+
// Now walk through any loaded views and initialize them as well.
|
|
385
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
386
|
+
let tmpViewsToSolve = [];
|
|
387
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
388
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
389
|
+
if (tmpView.options.AutoInitialize) {
|
|
390
|
+
tmpViewsToSolve.push(tmpView);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Sort the views by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
394
|
+
tmpViewsToSolve.sort((a, b) => {
|
|
395
|
+
return a.options.AutoInitializeOrdinal - b.options.AutoInitializeOrdinal;
|
|
396
|
+
});
|
|
397
|
+
for (let i = 0; i < tmpViewsToSolve.length; i++) {
|
|
398
|
+
tmpViewsToSolve[i].solve();
|
|
399
|
+
}
|
|
400
|
+
this.onSolve();
|
|
401
|
+
this.onAfterSolve();
|
|
402
|
+
this.lastSolvedTimestamp = this.fable.log.getTimeStamp();
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* @param {(error?: Error) => void} fCallback
|
|
407
|
+
*/
|
|
408
|
+
solveAsync(fCallback) {
|
|
409
|
+
let tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
410
|
+
tmpAnticipate.anticipate(this.onBeforeSolveAsync.bind(this));
|
|
411
|
+
|
|
412
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
413
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : false;
|
|
414
|
+
if (!tmpCallback) {
|
|
415
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " solveAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
416
|
+
tmpCallback = pError => {
|
|
417
|
+
if (pError) {
|
|
418
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " solveAsync Auto Callback Error: ").concat(pError), pError);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
// Walk through any loaded providers and solve them as well.
|
|
423
|
+
let tmpLoadedProviders = Object.keys(this.pict.providers);
|
|
424
|
+
let tmpProvidersToSolve = [];
|
|
425
|
+
for (let i = 0; i < tmpLoadedProviders.length; i++) {
|
|
426
|
+
let tmpProvider = this.pict.providers[tmpLoadedProviders[i]];
|
|
427
|
+
if (tmpProvider.options.AutoSolveWithApp) {
|
|
428
|
+
tmpProvidersToSolve.push(tmpProvider);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// Sort the providers by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
432
|
+
tmpProvidersToSolve.sort((a, b) => {
|
|
433
|
+
return a.options.AutoSolveOrdinal - b.options.AutoSolveOrdinal;
|
|
434
|
+
});
|
|
435
|
+
for (let i = 0; i < tmpProvidersToSolve.length; i++) {
|
|
436
|
+
tmpAnticipate.anticipate(tmpProvidersToSolve[i].solveAsync.bind(tmpProvidersToSolve[i]));
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Walk through any loaded views and solve them as well.
|
|
440
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
441
|
+
let tmpViewsToSolve = [];
|
|
442
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
443
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
444
|
+
if (tmpView.options.AutoSolveWithApp) {
|
|
445
|
+
tmpViewsToSolve.push(tmpView);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
// Sort the views by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
449
|
+
tmpViewsToSolve.sort((a, b) => {
|
|
450
|
+
return a.options.AutoSolveOrdinal - b.options.AutoSolveOrdinal;
|
|
451
|
+
});
|
|
452
|
+
for (let i = 0; i < tmpViewsToSolve.length; i++) {
|
|
453
|
+
tmpAnticipate.anticipate(tmpViewsToSolve[i].solveAsync.bind(tmpViewsToSolve[i]));
|
|
454
|
+
}
|
|
455
|
+
tmpAnticipate.anticipate(this.onSolveAsync.bind(this));
|
|
456
|
+
tmpAnticipate.anticipate(this.onAfterSolveAsync.bind(this));
|
|
457
|
+
tmpAnticipate.wait(pError => {
|
|
458
|
+
if (this.pict.LogNoisiness > 2) {
|
|
459
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " solveAsync() complete."));
|
|
460
|
+
}
|
|
461
|
+
this.lastSolvedTimestamp = this.fable.log.getTimeStamp();
|
|
462
|
+
return tmpCallback(pError);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* @return {boolean}
|
|
468
|
+
*/
|
|
469
|
+
onAfterSolve() {
|
|
470
|
+
if (this.pict.LogNoisiness > 3) {
|
|
471
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterSolve:"));
|
|
472
|
+
}
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* @param {(error?: Error) => void} fCallback
|
|
477
|
+
*/
|
|
478
|
+
onAfterSolveAsync(fCallback) {
|
|
479
|
+
this.onAfterSolve();
|
|
480
|
+
return fCallback();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/* -------------------------------------------------------------------------- */
|
|
484
|
+
/* Code Section: Application Login */
|
|
485
|
+
/* -------------------------------------------------------------------------- */
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* @param {(error?: Error) => void} fCallback
|
|
489
|
+
*/
|
|
490
|
+
onBeforeLoginAsync(fCallback) {
|
|
491
|
+
if (this.pict.LogNoisiness > 3) {
|
|
492
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeLoginAsync:"));
|
|
493
|
+
}
|
|
494
|
+
return fCallback();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @param {(error?: Error) => void} fCallback
|
|
499
|
+
*/
|
|
500
|
+
onLoginAsync(fCallback) {
|
|
501
|
+
if (this.pict.LogNoisiness > 3) {
|
|
502
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onLoginAsync:"));
|
|
503
|
+
}
|
|
504
|
+
return fCallback();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @param {(error?: Error) => void} fCallback
|
|
509
|
+
*/
|
|
510
|
+
loginAsync(fCallback) {
|
|
511
|
+
const tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
512
|
+
let tmpCallback = fCallback;
|
|
513
|
+
if (typeof tmpCallback !== 'function') {
|
|
514
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " loginAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
515
|
+
tmpCallback = pError => {
|
|
516
|
+
if (pError) {
|
|
517
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " loginAsync Auto Callback Error: ").concat(pError), pError);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
tmpAnticipate.anticipate(this.onBeforeLoginAsync.bind(this));
|
|
522
|
+
tmpAnticipate.anticipate(this.onLoginAsync.bind(this));
|
|
523
|
+
tmpAnticipate.anticipate(this.onAfterLoginAsync.bind(this));
|
|
524
|
+
|
|
525
|
+
// check and see if we should automatically trigger a data load
|
|
526
|
+
if (this.options.AutoLoadDataAfterLogin) {
|
|
527
|
+
tmpAnticipate.anticipate(fNext => {
|
|
528
|
+
if (!this.isLoggedIn()) {
|
|
529
|
+
return fNext();
|
|
530
|
+
}
|
|
531
|
+
if (this.pict.LogNoisiness > 1) {
|
|
532
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " auto loading data after login..."));
|
|
533
|
+
}
|
|
534
|
+
//TODO: should data load errors funnel here? this creates a weird coupling between login and data load callbacks
|
|
535
|
+
this.loadDataAsync(pError => {
|
|
536
|
+
fNext(pError);
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
tmpAnticipate.wait(pError => {
|
|
541
|
+
if (this.pict.LogNoisiness > 2) {
|
|
542
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " loginAsync() complete."));
|
|
543
|
+
}
|
|
544
|
+
this.lastLoginTimestamp = this.fable.log.getTimeStamp();
|
|
545
|
+
return tmpCallback(pError);
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Check if the application state is logged in. Defaults to true. Override this method in your application based on login requirements.
|
|
551
|
+
*
|
|
552
|
+
* @return {boolean}
|
|
553
|
+
*/
|
|
554
|
+
isLoggedIn() {
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* @param {(error?: Error) => void} fCallback
|
|
560
|
+
*/
|
|
561
|
+
onAfterLoginAsync(fCallback) {
|
|
562
|
+
if (this.pict.LogNoisiness > 3) {
|
|
563
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterLoginAsync:"));
|
|
564
|
+
}
|
|
565
|
+
return fCallback();
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/* -------------------------------------------------------------------------- */
|
|
569
|
+
/* Code Section: Application LoadData */
|
|
570
|
+
/* -------------------------------------------------------------------------- */
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @param {(error?: Error) => void} fCallback
|
|
574
|
+
*/
|
|
575
|
+
onBeforeLoadDataAsync(fCallback) {
|
|
576
|
+
if (this.pict.LogNoisiness > 3) {
|
|
577
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeLoadDataAsync:"));
|
|
578
|
+
}
|
|
579
|
+
return fCallback();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* @param {(error?: Error) => void} fCallback
|
|
584
|
+
*/
|
|
585
|
+
onLoadDataAsync(fCallback) {
|
|
586
|
+
if (this.pict.LogNoisiness > 3) {
|
|
587
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onLoadDataAsync:"));
|
|
588
|
+
}
|
|
589
|
+
return fCallback();
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* @param {(error?: Error) => void} fCallback
|
|
594
|
+
*/
|
|
595
|
+
loadDataAsync(fCallback) {
|
|
596
|
+
const tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
597
|
+
let tmpCallback = fCallback;
|
|
598
|
+
if (typeof tmpCallback !== 'function') {
|
|
599
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " loadDataAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
600
|
+
tmpCallback = pError => {
|
|
601
|
+
if (pError) {
|
|
602
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " loadDataAsync Auto Callback Error: ").concat(pError), pError);
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
tmpAnticipate.anticipate(this.onBeforeLoadDataAsync.bind(this));
|
|
607
|
+
|
|
608
|
+
// Walk through any loaded providers and load their data as well.
|
|
609
|
+
let tmpLoadedProviders = Object.keys(this.pict.providers);
|
|
610
|
+
let tmpProvidersToLoadData = [];
|
|
611
|
+
for (let i = 0; i < tmpLoadedProviders.length; i++) {
|
|
612
|
+
let tmpProvider = this.pict.providers[tmpLoadedProviders[i]];
|
|
613
|
+
if (tmpProvider.options.AutoLoadDataWithApp) {
|
|
614
|
+
tmpProvidersToLoadData.push(tmpProvider);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
// Sort the providers by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
618
|
+
tmpProvidersToLoadData.sort((a, b) => {
|
|
619
|
+
return a.options.AutoLoadDataOrdinal - b.options.AutoLoadDataOrdinal;
|
|
620
|
+
});
|
|
621
|
+
for (const tmpProvider of tmpProvidersToLoadData) {
|
|
622
|
+
tmpAnticipate.anticipate(tmpProvider.onBeforeLoadDataAsync.bind(tmpProvider));
|
|
623
|
+
}
|
|
624
|
+
tmpAnticipate.anticipate(this.onLoadDataAsync.bind(this));
|
|
625
|
+
|
|
626
|
+
//TODO: think about ways to parallelize these
|
|
627
|
+
for (const tmpProvider of tmpProvidersToLoadData) {
|
|
628
|
+
tmpAnticipate.anticipate(tmpProvider.onLoadDataAsync.bind(tmpProvider));
|
|
629
|
+
}
|
|
630
|
+
tmpAnticipate.anticipate(this.onAfterLoadDataAsync.bind(this));
|
|
631
|
+
for (const tmpProvider of tmpProvidersToLoadData) {
|
|
632
|
+
tmpAnticipate.anticipate(tmpProvider.onAfterLoadDataAsync.bind(tmpProvider));
|
|
633
|
+
}
|
|
634
|
+
tmpAnticipate.wait(/** @param {Error} [pError] */
|
|
635
|
+
pError => {
|
|
636
|
+
if (this.pict.LogNoisiness > 2) {
|
|
637
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " loadDataAsync() complete."));
|
|
638
|
+
}
|
|
639
|
+
this.lastLoadDataTimestamp = this.fable.log.getTimeStamp();
|
|
640
|
+
return tmpCallback(pError);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* @param {(error?: Error) => void} fCallback
|
|
646
|
+
*/
|
|
647
|
+
onAfterLoadDataAsync(fCallback) {
|
|
648
|
+
if (this.pict.LogNoisiness > 3) {
|
|
649
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterLoadDataAsync:"));
|
|
650
|
+
}
|
|
651
|
+
return fCallback();
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/* -------------------------------------------------------------------------- */
|
|
655
|
+
/* Code Section: Application SaveData */
|
|
656
|
+
/* -------------------------------------------------------------------------- */
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* @param {(error?: Error) => void} fCallback
|
|
660
|
+
*/
|
|
661
|
+
onBeforeSaveDataAsync(fCallback) {
|
|
662
|
+
if (this.pict.LogNoisiness > 3) {
|
|
663
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeSaveDataAsync:"));
|
|
664
|
+
}
|
|
665
|
+
return fCallback();
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* @param {(error?: Error) => void} fCallback
|
|
670
|
+
*/
|
|
671
|
+
onSaveDataAsync(fCallback) {
|
|
672
|
+
if (this.pict.LogNoisiness > 3) {
|
|
673
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onSaveDataAsync:"));
|
|
674
|
+
}
|
|
675
|
+
return fCallback();
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* @param {(error?: Error) => void} fCallback
|
|
680
|
+
*/
|
|
681
|
+
saveDataAsync(fCallback) {
|
|
682
|
+
const tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
683
|
+
let tmpCallback = fCallback;
|
|
684
|
+
if (typeof tmpCallback !== 'function') {
|
|
685
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " saveDataAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
686
|
+
tmpCallback = pError => {
|
|
687
|
+
if (pError) {
|
|
688
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " saveDataAsync Auto Callback Error: ").concat(pError), pError);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
tmpAnticipate.anticipate(this.onBeforeSaveDataAsync.bind(this));
|
|
693
|
+
|
|
694
|
+
// Walk through any loaded providers and load their data as well.
|
|
695
|
+
let tmpLoadedProviders = Object.keys(this.pict.providers);
|
|
696
|
+
let tmpProvidersToSaveData = [];
|
|
697
|
+
for (let i = 0; i < tmpLoadedProviders.length; i++) {
|
|
698
|
+
let tmpProvider = this.pict.providers[tmpLoadedProviders[i]];
|
|
699
|
+
if (tmpProvider.options.AutoSaveDataWithApp) {
|
|
700
|
+
tmpProvidersToSaveData.push(tmpProvider);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// Sort the providers by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
704
|
+
tmpProvidersToSaveData.sort((a, b) => {
|
|
705
|
+
return a.options.AutoSaveDataOrdinal - b.options.AutoSaveDataOrdinal;
|
|
706
|
+
});
|
|
707
|
+
for (const tmpProvider of tmpProvidersToSaveData) {
|
|
708
|
+
tmpAnticipate.anticipate(tmpProvider.onBeforeSaveDataAsync.bind(tmpProvider));
|
|
709
|
+
}
|
|
710
|
+
tmpAnticipate.anticipate(this.onSaveDataAsync.bind(this));
|
|
711
|
+
|
|
712
|
+
//TODO: think about ways to parallelize these
|
|
713
|
+
for (const tmpProvider of tmpProvidersToSaveData) {
|
|
714
|
+
tmpAnticipate.anticipate(tmpProvider.onSaveDataAsync.bind(tmpProvider));
|
|
715
|
+
}
|
|
716
|
+
tmpAnticipate.anticipate(this.onAfterSaveDataAsync.bind(this));
|
|
717
|
+
for (const tmpProvider of tmpProvidersToSaveData) {
|
|
718
|
+
tmpAnticipate.anticipate(tmpProvider.onAfterSaveDataAsync.bind(tmpProvider));
|
|
719
|
+
}
|
|
720
|
+
tmpAnticipate.wait(/** @param {Error} [pError] */
|
|
721
|
+
pError => {
|
|
722
|
+
if (this.pict.LogNoisiness > 2) {
|
|
723
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " saveDataAsync() complete."));
|
|
724
|
+
}
|
|
725
|
+
this.lastSaveDataTimestamp = this.fable.log.getTimeStamp();
|
|
726
|
+
return tmpCallback(pError);
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* @param {(error?: Error) => void} fCallback
|
|
732
|
+
*/
|
|
733
|
+
onAfterSaveDataAsync(fCallback) {
|
|
734
|
+
if (this.pict.LogNoisiness > 3) {
|
|
735
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterSaveDataAsync:"));
|
|
736
|
+
}
|
|
737
|
+
return fCallback();
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/* -------------------------------------------------------------------------- */
|
|
741
|
+
/* Code Section: Initialize Application */
|
|
742
|
+
/* -------------------------------------------------------------------------- */
|
|
743
|
+
/**
|
|
744
|
+
* @return {boolean}
|
|
745
|
+
*/
|
|
746
|
+
onBeforeInitialize() {
|
|
747
|
+
if (this.pict.LogNoisiness > 3) {
|
|
748
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeInitialize:"));
|
|
749
|
+
}
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* @param {(error?: Error) => void} fCallback
|
|
754
|
+
*/
|
|
755
|
+
onBeforeInitializeAsync(fCallback) {
|
|
756
|
+
this.onBeforeInitialize();
|
|
757
|
+
return fCallback();
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* @return {boolean}
|
|
762
|
+
*/
|
|
763
|
+
onInitialize() {
|
|
764
|
+
if (this.pict.LogNoisiness > 3) {
|
|
765
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onInitialize:"));
|
|
766
|
+
}
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* @param {(error?: Error) => void} fCallback
|
|
771
|
+
*/
|
|
772
|
+
onInitializeAsync(fCallback) {
|
|
773
|
+
this.onInitialize();
|
|
774
|
+
return fCallback();
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* @return {boolean}
|
|
779
|
+
*/
|
|
780
|
+
initialize() {
|
|
781
|
+
if (this.pict.LogControlFlow) {
|
|
782
|
+
this.log.trace("PICT-ControlFlow APPLICATION [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initialize:"));
|
|
783
|
+
}
|
|
784
|
+
if (!this.initializeTimestamp) {
|
|
785
|
+
this.onBeforeInitialize();
|
|
786
|
+
if ('ConfigurationOnlyViews' in this.options) {
|
|
787
|
+
// Load all the configuration only views
|
|
788
|
+
for (let i = 0; i < this.options.ConfigurationOnlyViews.length; i++) {
|
|
789
|
+
let tmpViewIdentifier = typeof this.options.ConfigurationOnlyViews[i].ViewIdentifier === 'undefined' ? "AutoView-".concat(this.fable.getUUID()) : this.options.ConfigurationOnlyViews[i].ViewIdentifier;
|
|
790
|
+
this.log.info("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " adding configuration only view: ").concat(tmpViewIdentifier));
|
|
791
|
+
this.pict.addView(tmpViewIdentifier, this.options.ConfigurationOnlyViews[i]);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
this.onInitialize();
|
|
795
|
+
|
|
796
|
+
// Walk through any loaded providers and initialize them as well.
|
|
797
|
+
let tmpLoadedProviders = Object.keys(this.pict.providers);
|
|
798
|
+
let tmpProvidersToInitialize = [];
|
|
799
|
+
for (let i = 0; i < tmpLoadedProviders.length; i++) {
|
|
800
|
+
let tmpProvider = this.pict.providers[tmpLoadedProviders[i]];
|
|
801
|
+
if (tmpProvider.options.AutoInitialize) {
|
|
802
|
+
tmpProvidersToInitialize.push(tmpProvider);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
// Sort the providers by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
806
|
+
tmpProvidersToInitialize.sort((a, b) => {
|
|
807
|
+
return a.options.AutoInitializeOrdinal - b.options.AutoInitializeOrdinal;
|
|
808
|
+
});
|
|
809
|
+
for (let i = 0; i < tmpProvidersToInitialize.length; i++) {
|
|
810
|
+
tmpProvidersToInitialize[i].initialize();
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Now walk through any loaded views and initialize them as well.
|
|
814
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
815
|
+
let tmpViewsToInitialize = [];
|
|
816
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
817
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
818
|
+
if (tmpView.options.AutoInitialize) {
|
|
819
|
+
tmpViewsToInitialize.push(tmpView);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// Sort the views by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
823
|
+
tmpViewsToInitialize.sort((a, b) => {
|
|
824
|
+
return a.options.AutoInitializeOrdinal - b.options.AutoInitializeOrdinal;
|
|
825
|
+
});
|
|
826
|
+
for (let i = 0; i < tmpViewsToInitialize.length; i++) {
|
|
827
|
+
tmpViewsToInitialize[i].initialize();
|
|
828
|
+
}
|
|
829
|
+
this.onAfterInitialize();
|
|
830
|
+
if (this.options.AutoSolveAfterInitialize) {
|
|
831
|
+
if (this.pict.LogNoisiness > 1) {
|
|
832
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " auto solving after initialization..."));
|
|
833
|
+
}
|
|
834
|
+
// Solve the template synchronously
|
|
835
|
+
this.solve();
|
|
836
|
+
}
|
|
837
|
+
// Now check and see if we should automatically render as well
|
|
838
|
+
if (this.options.AutoRenderMainViewportViewAfterInitialize) {
|
|
839
|
+
if (this.pict.LogNoisiness > 1) {
|
|
840
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " auto rendering after initialization..."));
|
|
841
|
+
}
|
|
842
|
+
// Render the template synchronously
|
|
843
|
+
this.render();
|
|
844
|
+
}
|
|
845
|
+
this.initializeTimestamp = this.fable.log.getTimeStamp();
|
|
846
|
+
this.onCompletionOfInitialize();
|
|
847
|
+
return true;
|
|
848
|
+
} else {
|
|
849
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initialize called but initialization is already completed. Aborting."));
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* @param {(error?: Error) => void} fCallback
|
|
855
|
+
*/
|
|
856
|
+
initializeAsync(fCallback) {
|
|
857
|
+
if (this.pict.LogControlFlow) {
|
|
858
|
+
this.log.trace("PICT-ControlFlow APPLICATION [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initializeAsync:"));
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
862
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : false;
|
|
863
|
+
if (!tmpCallback) {
|
|
864
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initializeAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
865
|
+
tmpCallback = pError => {
|
|
866
|
+
if (pError) {
|
|
867
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initializeAsync Auto Callback Error: ").concat(pError), pError);
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
if (!this.initializeTimestamp) {
|
|
872
|
+
let tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
873
|
+
if (this.pict.LogNoisiness > 3) {
|
|
874
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " beginning initialization..."));
|
|
875
|
+
}
|
|
876
|
+
if ('ConfigurationOnlyViews' in this.options) {
|
|
877
|
+
// Load all the configuration only views
|
|
878
|
+
for (let i = 0; i < this.options.ConfigurationOnlyViews.length; i++) {
|
|
879
|
+
let tmpViewIdentifier = typeof this.options.ConfigurationOnlyViews[i].ViewIdentifier === 'undefined' ? "AutoView-".concat(this.fable.getUUID()) : this.options.ConfigurationOnlyViews[i].ViewIdentifier;
|
|
880
|
+
this.log.info("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " adding configuration only view: ").concat(tmpViewIdentifier));
|
|
881
|
+
this.pict.addView(tmpViewIdentifier, this.options.ConfigurationOnlyViews[i]);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
tmpAnticipate.anticipate(this.onBeforeInitializeAsync.bind(this));
|
|
885
|
+
tmpAnticipate.anticipate(this.onInitializeAsync.bind(this));
|
|
886
|
+
|
|
887
|
+
// Walk through any loaded providers and solve them as well.
|
|
888
|
+
let tmpLoadedProviders = Object.keys(this.pict.providers);
|
|
889
|
+
let tmpProvidersToInitialize = [];
|
|
890
|
+
for (let i = 0; i < tmpLoadedProviders.length; i++) {
|
|
891
|
+
let tmpProvider = this.pict.providers[tmpLoadedProviders[i]];
|
|
892
|
+
if (tmpProvider.options.AutoInitialize) {
|
|
893
|
+
tmpProvidersToInitialize.push(tmpProvider);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
// Sort the providers by their priority (if they are all priority 0, it will end up being add order due to JSON Object Property Key order stuff)
|
|
897
|
+
tmpProvidersToInitialize.sort((a, b) => {
|
|
898
|
+
return a.options.AutoInitializeOrdinal - b.options.AutoInitializeOrdinal;
|
|
899
|
+
});
|
|
900
|
+
for (let i = 0; i < tmpProvidersToInitialize.length; i++) {
|
|
901
|
+
tmpAnticipate.anticipate(tmpProvidersToInitialize[i].initializeAsync.bind(tmpProvidersToInitialize[i]));
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// Now walk through any loaded views and initialize them as well.
|
|
905
|
+
// TODO: Some optimization cleverness could be gained by grouping them into a parallelized async operation, by ordinal.
|
|
906
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
907
|
+
let tmpViewsToInitialize = [];
|
|
908
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
909
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
910
|
+
if (tmpView.options.AutoInitialize) {
|
|
911
|
+
tmpViewsToInitialize.push(tmpView);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
// Sort the views by their priority
|
|
915
|
+
// If they are all the default priority 0, it will end up being add order due to JSON Object Property Key order stuff
|
|
916
|
+
tmpViewsToInitialize.sort((a, b) => {
|
|
917
|
+
return a.options.AutoInitializeOrdinal - b.options.AutoInitializeOrdinal;
|
|
918
|
+
});
|
|
919
|
+
for (let i = 0; i < tmpViewsToInitialize.length; i++) {
|
|
920
|
+
let tmpView = tmpViewsToInitialize[i];
|
|
921
|
+
tmpAnticipate.anticipate(tmpView.initializeAsync.bind(tmpView));
|
|
922
|
+
}
|
|
923
|
+
tmpAnticipate.anticipate(this.onAfterInitializeAsync.bind(this));
|
|
924
|
+
if (this.options.AutoLoginAfterInitialize) {
|
|
925
|
+
if (this.pict.LogNoisiness > 1) {
|
|
926
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " auto login (asynchronously) after initialization..."));
|
|
927
|
+
}
|
|
928
|
+
tmpAnticipate.anticipate(this.loginAsync.bind(this));
|
|
929
|
+
}
|
|
930
|
+
if (this.options.AutoSolveAfterInitialize) {
|
|
931
|
+
if (this.pict.LogNoisiness > 1) {
|
|
932
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " auto solving (asynchronously) after initialization..."));
|
|
933
|
+
}
|
|
934
|
+
tmpAnticipate.anticipate(this.solveAsync.bind(this));
|
|
935
|
+
}
|
|
936
|
+
if (this.options.AutoRenderMainViewportViewAfterInitialize) {
|
|
937
|
+
if (this.pict.LogNoisiness > 1) {
|
|
938
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " auto rendering (asynchronously) after initialization..."));
|
|
939
|
+
}
|
|
940
|
+
tmpAnticipate.anticipate(this.renderMainViewportAsync.bind(this));
|
|
941
|
+
}
|
|
942
|
+
tmpAnticipate.wait(pError => {
|
|
943
|
+
if (pError) {
|
|
944
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initializeAsync Error: ").concat(pError.message || pError), {
|
|
945
|
+
stack: pError.stack
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
this.initializeTimestamp = this.fable.log.getTimeStamp();
|
|
949
|
+
if (this.pict.LogNoisiness > 2) {
|
|
950
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " initialization complete."));
|
|
951
|
+
}
|
|
952
|
+
return tmpCallback();
|
|
953
|
+
});
|
|
954
|
+
} else {
|
|
955
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " async initialize called but initialization is already completed. Aborting."));
|
|
956
|
+
// TODO: Should this be an error?
|
|
957
|
+
return this.onCompletionOfInitializeAsync(tmpCallback);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* @return {boolean}
|
|
963
|
+
*/
|
|
964
|
+
onAfterInitialize() {
|
|
965
|
+
if (this.pict.LogNoisiness > 3) {
|
|
966
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterInitialize:"));
|
|
967
|
+
}
|
|
968
|
+
return true;
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* @param {(error?: Error) => void} fCallback
|
|
972
|
+
*/
|
|
973
|
+
onAfterInitializeAsync(fCallback) {
|
|
974
|
+
this.onAfterInitialize();
|
|
975
|
+
return fCallback();
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* @return {boolean}
|
|
980
|
+
*/
|
|
981
|
+
onCompletionOfInitialize() {
|
|
982
|
+
if (this.pict.LogNoisiness > 3) {
|
|
983
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onCompletionOfInitialize:"));
|
|
984
|
+
}
|
|
985
|
+
return true;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* @param {(error?: Error) => void} fCallback
|
|
989
|
+
*/
|
|
990
|
+
onCompletionOfInitializeAsync(fCallback) {
|
|
991
|
+
this.onCompletionOfInitialize();
|
|
992
|
+
return fCallback();
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/* -------------------------------------------------------------------------- */
|
|
996
|
+
/* Code Section: Marshal Data From All Views */
|
|
997
|
+
/* -------------------------------------------------------------------------- */
|
|
998
|
+
/**
|
|
999
|
+
* @return {boolean}
|
|
1000
|
+
*/
|
|
1001
|
+
onBeforeMarshalFromViews() {
|
|
1002
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1003
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeMarshalFromViews:"));
|
|
1004
|
+
}
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* @param {(error?: Error) => void} fCallback
|
|
1009
|
+
*/
|
|
1010
|
+
onBeforeMarshalFromViewsAsync(fCallback) {
|
|
1011
|
+
this.onBeforeMarshalFromViews();
|
|
1012
|
+
return fCallback();
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* @return {boolean}
|
|
1017
|
+
*/
|
|
1018
|
+
onMarshalFromViews() {
|
|
1019
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1020
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onMarshalFromViews:"));
|
|
1021
|
+
}
|
|
1022
|
+
return true;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* @param {(error?: Error) => void} fCallback
|
|
1026
|
+
*/
|
|
1027
|
+
onMarshalFromViewsAsync(fCallback) {
|
|
1028
|
+
this.onMarshalFromViews();
|
|
1029
|
+
return fCallback();
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* @return {boolean}
|
|
1034
|
+
*/
|
|
1035
|
+
marshalFromViews() {
|
|
1036
|
+
if (this.pict.LogNoisiness > 2) {
|
|
1037
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " executing marshalFromViews() function..."));
|
|
1038
|
+
}
|
|
1039
|
+
this.onBeforeMarshalFromViews();
|
|
1040
|
+
// Now walk through any loaded views and initialize them as well.
|
|
1041
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
1042
|
+
let tmpViewsToMarshalFromViews = [];
|
|
1043
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
1044
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
1045
|
+
tmpViewsToMarshalFromViews.push(tmpView);
|
|
1046
|
+
}
|
|
1047
|
+
for (let i = 0; i < tmpViewsToMarshalFromViews.length; i++) {
|
|
1048
|
+
tmpViewsToMarshalFromViews[i].marshalFromView();
|
|
1049
|
+
}
|
|
1050
|
+
this.onMarshalFromViews();
|
|
1051
|
+
this.onAfterMarshalFromViews();
|
|
1052
|
+
this.lastMarshalFromViewsTimestamp = this.fable.log.getTimeStamp();
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* @param {(error?: Error) => void} fCallback
|
|
1058
|
+
*/
|
|
1059
|
+
marshalFromViewsAsync(fCallback) {
|
|
1060
|
+
let tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
1061
|
+
|
|
1062
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
1063
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : false;
|
|
1064
|
+
if (!tmpCallback) {
|
|
1065
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalFromViewsAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
1066
|
+
tmpCallback = pError => {
|
|
1067
|
+
if (pError) {
|
|
1068
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalFromViewsAsync Auto Callback Error: ").concat(pError), pError);
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
tmpAnticipate.anticipate(this.onBeforeMarshalFromViewsAsync.bind(this));
|
|
1073
|
+
// Walk through any loaded views and marshalFromViews them as well.
|
|
1074
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
1075
|
+
let tmpViewsToMarshalFromViews = [];
|
|
1076
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
1077
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
1078
|
+
tmpViewsToMarshalFromViews.push(tmpView);
|
|
1079
|
+
}
|
|
1080
|
+
for (let i = 0; i < tmpViewsToMarshalFromViews.length; i++) {
|
|
1081
|
+
tmpAnticipate.anticipate(tmpViewsToMarshalFromViews[i].marshalFromViewAsync.bind(tmpViewsToMarshalFromViews[i]));
|
|
1082
|
+
}
|
|
1083
|
+
tmpAnticipate.anticipate(this.onMarshalFromViewsAsync.bind(this));
|
|
1084
|
+
tmpAnticipate.anticipate(this.onAfterMarshalFromViewsAsync.bind(this));
|
|
1085
|
+
tmpAnticipate.wait(pError => {
|
|
1086
|
+
if (this.pict.LogNoisiness > 2) {
|
|
1087
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalFromViewsAsync() complete."));
|
|
1088
|
+
}
|
|
1089
|
+
this.lastMarshalFromViewsTimestamp = this.fable.log.getTimeStamp();
|
|
1090
|
+
return tmpCallback(pError);
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* @return {boolean}
|
|
1096
|
+
*/
|
|
1097
|
+
onAfterMarshalFromViews() {
|
|
1098
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1099
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterMarshalFromViews:"));
|
|
1100
|
+
}
|
|
1101
|
+
return true;
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* @param {(error?: Error) => void} fCallback
|
|
1105
|
+
*/
|
|
1106
|
+
onAfterMarshalFromViewsAsync(fCallback) {
|
|
1107
|
+
this.onAfterMarshalFromViews();
|
|
1108
|
+
return fCallback();
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/* -------------------------------------------------------------------------- */
|
|
1112
|
+
/* Code Section: Marshal Data To All Views */
|
|
1113
|
+
/* -------------------------------------------------------------------------- */
|
|
1114
|
+
/**
|
|
1115
|
+
* @return {boolean}
|
|
1116
|
+
*/
|
|
1117
|
+
onBeforeMarshalToViews() {
|
|
1118
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1119
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeMarshalToViews:"));
|
|
1120
|
+
}
|
|
1121
|
+
return true;
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* @param {(error?: Error) => void} fCallback
|
|
1125
|
+
*/
|
|
1126
|
+
onBeforeMarshalToViewsAsync(fCallback) {
|
|
1127
|
+
this.onBeforeMarshalToViews();
|
|
1128
|
+
return fCallback();
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* @return {boolean}
|
|
1133
|
+
*/
|
|
1134
|
+
onMarshalToViews() {
|
|
1135
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1136
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onMarshalToViews:"));
|
|
1137
|
+
}
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* @param {(error?: Error) => void} fCallback
|
|
1142
|
+
*/
|
|
1143
|
+
onMarshalToViewsAsync(fCallback) {
|
|
1144
|
+
this.onMarshalToViews();
|
|
1145
|
+
return fCallback();
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* @return {boolean}
|
|
1150
|
+
*/
|
|
1151
|
+
marshalToViews() {
|
|
1152
|
+
if (this.pict.LogNoisiness > 2) {
|
|
1153
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " executing marshalToViews() function..."));
|
|
1154
|
+
}
|
|
1155
|
+
this.onBeforeMarshalToViews();
|
|
1156
|
+
// Now walk through any loaded views and initialize them as well.
|
|
1157
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
1158
|
+
let tmpViewsToMarshalToViews = [];
|
|
1159
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
1160
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
1161
|
+
tmpViewsToMarshalToViews.push(tmpView);
|
|
1162
|
+
}
|
|
1163
|
+
for (let i = 0; i < tmpViewsToMarshalToViews.length; i++) {
|
|
1164
|
+
tmpViewsToMarshalToViews[i].marshalToView();
|
|
1165
|
+
}
|
|
1166
|
+
this.onMarshalToViews();
|
|
1167
|
+
this.onAfterMarshalToViews();
|
|
1168
|
+
this.lastMarshalToViewsTimestamp = this.fable.log.getTimeStamp();
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* @param {(error?: Error) => void} fCallback
|
|
1173
|
+
*/
|
|
1174
|
+
marshalToViewsAsync(fCallback) {
|
|
1175
|
+
let tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
1176
|
+
|
|
1177
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
1178
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : false;
|
|
1179
|
+
if (!tmpCallback) {
|
|
1180
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalToViewsAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
1181
|
+
tmpCallback = pError => {
|
|
1182
|
+
if (pError) {
|
|
1183
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalToViewsAsync Auto Callback Error: ").concat(pError), pError);
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
tmpAnticipate.anticipate(this.onBeforeMarshalToViewsAsync.bind(this));
|
|
1188
|
+
// Walk through any loaded views and marshalToViews them as well.
|
|
1189
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
1190
|
+
let tmpViewsToMarshalToViews = [];
|
|
1191
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
1192
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
1193
|
+
tmpViewsToMarshalToViews.push(tmpView);
|
|
1194
|
+
}
|
|
1195
|
+
for (let i = 0; i < tmpViewsToMarshalToViews.length; i++) {
|
|
1196
|
+
tmpAnticipate.anticipate(tmpViewsToMarshalToViews[i].marshalToViewAsync.bind(tmpViewsToMarshalToViews[i]));
|
|
1197
|
+
}
|
|
1198
|
+
tmpAnticipate.anticipate(this.onMarshalToViewsAsync.bind(this));
|
|
1199
|
+
tmpAnticipate.anticipate(this.onAfterMarshalToViewsAsync.bind(this));
|
|
1200
|
+
tmpAnticipate.wait(pError => {
|
|
1201
|
+
if (this.pict.LogNoisiness > 2) {
|
|
1202
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalToViewsAsync() complete."));
|
|
1203
|
+
}
|
|
1204
|
+
this.lastMarshalToViewsTimestamp = this.fable.log.getTimeStamp();
|
|
1205
|
+
return tmpCallback(pError);
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
* @return {boolean}
|
|
1211
|
+
*/
|
|
1212
|
+
onAfterMarshalToViews() {
|
|
1213
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1214
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterMarshalToViews:"));
|
|
1215
|
+
}
|
|
1216
|
+
return true;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* @param {(error?: Error) => void} fCallback
|
|
1220
|
+
*/
|
|
1221
|
+
onAfterMarshalToViewsAsync(fCallback) {
|
|
1222
|
+
this.onAfterMarshalToViews();
|
|
1223
|
+
return fCallback();
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
/* -------------------------------------------------------------------------- */
|
|
1227
|
+
/* Code Section: Render View */
|
|
1228
|
+
/* -------------------------------------------------------------------------- */
|
|
1229
|
+
/**
|
|
1230
|
+
* @return {boolean}
|
|
1231
|
+
*/
|
|
1232
|
+
onBeforeRender() {
|
|
1233
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1234
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onBeforeRender:"));
|
|
1235
|
+
}
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* @param {(error?: Error) => void} fCallback
|
|
1240
|
+
*/
|
|
1241
|
+
onBeforeRenderAsync(fCallback) {
|
|
1242
|
+
this.onBeforeRender();
|
|
1243
|
+
return fCallback();
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
/**
|
|
1247
|
+
* @param {string} [pViewIdentifier] - The hash of the view to render. By default, the main viewport view is rendered.
|
|
1248
|
+
* @param {string} [pRenderableHash] - The hash of the renderable to render.
|
|
1249
|
+
* @param {string} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
1250
|
+
* @param {string} [pTemplateDataAddress] - The address where the data for the template is stored.
|
|
1251
|
+
*
|
|
1252
|
+
* TODO: Should we support objects for pTemplateDataAddress for parity with pict-view?
|
|
1253
|
+
*/
|
|
1254
|
+
render(pViewIdentifier, pRenderableHash, pRenderDestinationAddress, pTemplateDataAddress) {
|
|
1255
|
+
let tmpViewIdentifier = typeof pViewIdentifier !== 'string' ? this.options.MainViewportViewIdentifier : pViewIdentifier;
|
|
1256
|
+
let tmpRenderableHash = typeof pRenderableHash !== 'string' ? this.options.MainViewportRenderableHash : pRenderableHash;
|
|
1257
|
+
let tmpRenderDestinationAddress = typeof pRenderDestinationAddress !== 'string' ? this.options.MainViewportDestinationAddress : pRenderDestinationAddress;
|
|
1258
|
+
let tmpTemplateDataAddress = typeof pTemplateDataAddress !== 'string' ? this.options.MainViewportDefaultDataAddress : pTemplateDataAddress;
|
|
1259
|
+
if (this.pict.LogControlFlow) {
|
|
1260
|
+
this.log.trace("PICT-ControlFlow APPLICATION [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " VIEW Renderable[").concat(tmpRenderableHash, "] Destination[").concat(tmpRenderDestinationAddress, "] TemplateDataAddress[").concat(tmpTemplateDataAddress, "] render:"));
|
|
1261
|
+
}
|
|
1262
|
+
this.onBeforeRender();
|
|
1263
|
+
|
|
1264
|
+
// Now get the view (by hash) from the loaded views
|
|
1265
|
+
let tmpView = typeof tmpViewIdentifier === 'string' ? this.servicesMap.PictView[tmpViewIdentifier] : false;
|
|
1266
|
+
if (!tmpView) {
|
|
1267
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " could not render from View ").concat(tmpViewIdentifier, " because it is not a valid view."));
|
|
1268
|
+
return false;
|
|
1269
|
+
}
|
|
1270
|
+
this.onRender();
|
|
1271
|
+
tmpView.render(tmpRenderableHash, tmpRenderDestinationAddress, tmpTemplateDataAddress);
|
|
1272
|
+
this.onAfterRender();
|
|
1273
|
+
return true;
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* @return {boolean}
|
|
1277
|
+
*/
|
|
1278
|
+
onRender() {
|
|
1279
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1280
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onRender:"));
|
|
1281
|
+
}
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* @param {(error?: Error) => void} fCallback
|
|
1286
|
+
*/
|
|
1287
|
+
onRenderAsync(fCallback) {
|
|
1288
|
+
this.onRender();
|
|
1289
|
+
return fCallback();
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
/**
|
|
1293
|
+
* @param {string|((error?: Error) => void)} pViewIdentifier - The hash of the view to render. By default, the main viewport view is rendered. (or the callback)
|
|
1294
|
+
* @param {string|((error?: Error) => void)} [pRenderableHash] - The hash of the renderable to render. (or the callback)
|
|
1295
|
+
* @param {string|((error?: Error) => void)} [pRenderDestinationAddress] - The address where the renderable will be rendered. (or the callback)
|
|
1296
|
+
* @param {string|((error?: Error) => void)} [pTemplateDataAddress] - The address where the data for the template is stored. (or the callback)
|
|
1297
|
+
* @param {(error?: Error) => void} [fCallback] - The callback, if all other parameters are provided.
|
|
1298
|
+
*
|
|
1299
|
+
* TODO: Should we support objects for pTemplateDataAddress for parity with pict-view?
|
|
1300
|
+
*/
|
|
1301
|
+
renderAsync(pViewIdentifier, pRenderableHash, pRenderDestinationAddress, pTemplateDataAddress, fCallback) {
|
|
1302
|
+
let tmpViewIdentifier = typeof pViewIdentifier !== 'string' ? this.options.MainViewportViewIdentifier : pViewIdentifier;
|
|
1303
|
+
let tmpRenderableHash = typeof pRenderableHash !== 'string' ? this.options.MainViewportRenderableHash : pRenderableHash;
|
|
1304
|
+
let tmpRenderDestinationAddress = typeof pRenderDestinationAddress !== 'string' ? this.options.MainViewportDestinationAddress : pRenderDestinationAddress;
|
|
1305
|
+
let tmpTemplateDataAddress = typeof pTemplateDataAddress !== 'string' ? this.options.MainViewportDefaultDataAddress : pTemplateDataAddress;
|
|
1306
|
+
|
|
1307
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
1308
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : typeof pTemplateDataAddress === 'function' ? pTemplateDataAddress : typeof pRenderDestinationAddress === 'function' ? pRenderDestinationAddress : typeof pRenderableHash === 'function' ? pRenderableHash : typeof pViewIdentifier === 'function' ? pViewIdentifier : false;
|
|
1309
|
+
if (!tmpCallback) {
|
|
1310
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
1311
|
+
tmpCallback = pError => {
|
|
1312
|
+
if (pError) {
|
|
1313
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAsync Auto Callback Error: ").concat(pError), pError);
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
if (this.pict.LogControlFlow) {
|
|
1318
|
+
this.log.trace("PICT-ControlFlow APPLICATION [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " VIEW Renderable[").concat(tmpRenderableHash, "] Destination[").concat(tmpRenderDestinationAddress, "] TemplateDataAddress[").concat(tmpTemplateDataAddress, "] renderAsync:"));
|
|
1319
|
+
}
|
|
1320
|
+
let tmpRenderAnticipate = this.fable.newAnticipate();
|
|
1321
|
+
tmpRenderAnticipate.anticipate(this.onBeforeRenderAsync.bind(this));
|
|
1322
|
+
let tmpView = typeof tmpViewIdentifier === 'string' ? this.servicesMap.PictView[tmpViewIdentifier] : false;
|
|
1323
|
+
if (!tmpView) {
|
|
1324
|
+
let tmpErrorMessage = "PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " could not asynchronously render from View ").concat(tmpViewIdentifier, " because it is not a valid view.");
|
|
1325
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1326
|
+
this.log.error(tmpErrorMessage);
|
|
1327
|
+
}
|
|
1328
|
+
return tmpCallback(new Error(tmpErrorMessage));
|
|
1329
|
+
}
|
|
1330
|
+
tmpRenderAnticipate.anticipate(this.onRenderAsync.bind(this));
|
|
1331
|
+
tmpRenderAnticipate.anticipate(fNext => {
|
|
1332
|
+
tmpView.renderAsync.call(tmpView, tmpRenderableHash, tmpRenderDestinationAddress, tmpTemplateDataAddress, fNext);
|
|
1333
|
+
});
|
|
1334
|
+
tmpRenderAnticipate.anticipate(this.onAfterRenderAsync.bind(this));
|
|
1335
|
+
return tmpRenderAnticipate.wait(tmpCallback);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* @return {boolean}
|
|
1340
|
+
*/
|
|
1341
|
+
onAfterRender() {
|
|
1342
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1343
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " onAfterRender:"));
|
|
1344
|
+
}
|
|
1345
|
+
return true;
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* @param {(error?: Error) => void} fCallback
|
|
1349
|
+
*/
|
|
1350
|
+
onAfterRenderAsync(fCallback) {
|
|
1351
|
+
this.onAfterRender();
|
|
1352
|
+
return fCallback();
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* @return {boolean}
|
|
1357
|
+
*/
|
|
1358
|
+
renderMainViewport() {
|
|
1359
|
+
if (this.pict.LogControlFlow) {
|
|
1360
|
+
this.log.trace("PICT-ControlFlow APPLICATION [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderMainViewport:"));
|
|
1361
|
+
}
|
|
1362
|
+
return this.render();
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* @param {(error?: Error) => void} fCallback
|
|
1366
|
+
*/
|
|
1367
|
+
renderMainViewportAsync(fCallback) {
|
|
1368
|
+
if (this.pict.LogControlFlow) {
|
|
1369
|
+
this.log.trace("PICT-ControlFlow APPLICATION [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderMainViewportAsync:"));
|
|
1370
|
+
}
|
|
1371
|
+
return this.renderAsync(fCallback);
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* @return {void}
|
|
1375
|
+
*/
|
|
1376
|
+
renderAutoViews() {
|
|
1377
|
+
if (this.pict.LogNoisiness > 0) {
|
|
1378
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " beginning renderAutoViews..."));
|
|
1379
|
+
}
|
|
1380
|
+
// Now walk through any loaded views and sort them by the AutoRender ordinal
|
|
1381
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
1382
|
+
// Sort the views by their priority
|
|
1383
|
+
// If they are all the default priority 0, it will end up being add order due to JSON Object Property Key order stuff
|
|
1384
|
+
tmpLoadedViews.sort((a, b) => {
|
|
1385
|
+
return this.pict.views[a].options.AutoRenderOrdinal - this.pict.views[b].options.AutoRenderOrdinal;
|
|
1386
|
+
});
|
|
1387
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
1388
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
1389
|
+
if (tmpView.options.AutoRender) {
|
|
1390
|
+
tmpView.render();
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
if (this.pict.LogNoisiness > 0) {
|
|
1394
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAutoViewsAsync complete."));
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* @param {(error?: Error) => void} fCallback
|
|
1399
|
+
*/
|
|
1400
|
+
renderAutoViewsAsync(fCallback) {
|
|
1401
|
+
let tmpAnticipate = this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
1402
|
+
|
|
1403
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
1404
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : false;
|
|
1405
|
+
if (!tmpCallback) {
|
|
1406
|
+
this.log.warn("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAutoViewsAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
1407
|
+
tmpCallback = pError => {
|
|
1408
|
+
if (pError) {
|
|
1409
|
+
this.log.error("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAutoViewsAsync Auto Callback Error: ").concat(pError), pError);
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
if (this.pict.LogNoisiness > 0) {
|
|
1414
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " beginning renderAutoViewsAsync..."));
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// Now walk through any loaded views and sort them by the AutoRender ordinal
|
|
1418
|
+
// TODO: Some optimization cleverness could be gained by grouping them into a parallelized async operation, by ordinal.
|
|
1419
|
+
let tmpLoadedViews = Object.keys(this.pict.views);
|
|
1420
|
+
// Sort the views by their priority
|
|
1421
|
+
// If they are all the default priority 0, it will end up being add order due to JSON Object Property Key order stuff
|
|
1422
|
+
tmpLoadedViews.sort((a, b) => {
|
|
1423
|
+
return this.pict.views[a].options.AutoRenderOrdinal - this.pict.views[b].options.AutoRenderOrdinal;
|
|
1424
|
+
});
|
|
1425
|
+
for (let i = 0; i < tmpLoadedViews.length; i++) {
|
|
1426
|
+
let tmpView = this.pict.views[tmpLoadedViews[i]];
|
|
1427
|
+
if (tmpView.options.AutoRender) {
|
|
1428
|
+
tmpAnticipate.anticipate(tmpView.renderAsync.bind(tmpView));
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
tmpAnticipate.wait(pError => {
|
|
1432
|
+
this.lastAutoRenderTimestamp = this.fable.log.getTimeStamp();
|
|
1433
|
+
if (this.pict.LogNoisiness > 0) {
|
|
1434
|
+
this.log.trace("PictApp [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAutoViewsAsync complete."));
|
|
1435
|
+
}
|
|
1436
|
+
return tmpCallback(pError);
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
/**
|
|
1441
|
+
* @return {boolean}
|
|
1442
|
+
*/
|
|
1443
|
+
get isPictApplication() {
|
|
1444
|
+
return true;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
module.exports = PictApplication;
|
|
1448
|
+
}, {
|
|
1449
|
+
"../package.json": 3,
|
|
1450
|
+
"fable-serviceproviderbase": 2
|
|
1451
|
+
}],
|
|
1452
|
+
5: [function (require, module, exports) {
|
|
1453
|
+
module.exports = {
|
|
1454
|
+
"name": "pict-provider",
|
|
1455
|
+
"version": "1.0.7",
|
|
1456
|
+
"description": "Pict Provider Base Class",
|
|
1457
|
+
"main": "source/Pict-Provider.js",
|
|
1458
|
+
"scripts": {
|
|
1459
|
+
"start": "node source/Pict-Provider.js",
|
|
1460
|
+
"test": "npx mocha -u tdd -R spec",
|
|
1461
|
+
"tests": "npx mocha -u tdd --exit -R spec --grep",
|
|
1462
|
+
"coverage": "npx nyc --reporter=lcov --reporter=text-lcov npx mocha -- -u tdd -R spec",
|
|
1463
|
+
"build": "npx quack build",
|
|
1464
|
+
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t pict-provider-image:local",
|
|
1465
|
+
"docker-dev-run": "docker run -it -d --name pict-provider-dev -p 24125:8080 -p 30027:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/pict-provider\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" pict-provider-image:local",
|
|
1466
|
+
"docker-dev-shell": "docker exec -it pict-provider-dev /bin/bash",
|
|
1467
|
+
"lint": "eslint source/**",
|
|
1468
|
+
"types": "tsc -p ."
|
|
1469
|
+
},
|
|
1470
|
+
"types": "types/source/Pict-Provider.d.ts",
|
|
1471
|
+
"repository": {
|
|
1472
|
+
"type": "git",
|
|
1473
|
+
"url": "git+https://github.com/stevenvelozo/pict-provider.git"
|
|
1474
|
+
},
|
|
1475
|
+
"author": "steven velozo <steven@velozo.com>",
|
|
1476
|
+
"license": "MIT",
|
|
1477
|
+
"bugs": {
|
|
1478
|
+
"url": "https://github.com/stevenvelozo/pict-provider/issues"
|
|
1479
|
+
},
|
|
1480
|
+
"homepage": "https://github.com/stevenvelozo/pict-provider#readme",
|
|
1481
|
+
"devDependencies": {
|
|
1482
|
+
"@eslint/js": "^9.39.1",
|
|
1483
|
+
"eslint": "^9.39.1",
|
|
1484
|
+
"pict": "^1.0.342",
|
|
1485
|
+
"quackage": "^1.0.45",
|
|
1486
|
+
"typescript": "^5.9.3"
|
|
1487
|
+
},
|
|
1488
|
+
"dependencies": {
|
|
1489
|
+
"fable-serviceproviderbase": "^3.0.15"
|
|
1490
|
+
},
|
|
1491
|
+
"mocha": {
|
|
1492
|
+
"diff": true,
|
|
1493
|
+
"extension": ["js"],
|
|
1494
|
+
"package": "./package.json",
|
|
1495
|
+
"reporter": "spec",
|
|
1496
|
+
"slow": "75",
|
|
1497
|
+
"timeout": "5000",
|
|
1498
|
+
"ui": "tdd",
|
|
1499
|
+
"watch-files": ["source/**/*.js", "test/**/*.js"],
|
|
1500
|
+
"watch-ignore": ["lib/vendor"]
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
}, {}],
|
|
1504
|
+
6: [function (require, module, exports) {
|
|
1505
|
+
const libFableServiceBase = require('fable-serviceproviderbase');
|
|
1506
|
+
const libPackage = require('../package.json');
|
|
1507
|
+
const defaultPictProviderSettings = {
|
|
1508
|
+
ProviderIdentifier: false,
|
|
1509
|
+
// If this is set to true, when the App initializes this will.
|
|
1510
|
+
// After the App initializes, initialize will be called as soon as it's added.
|
|
1511
|
+
AutoInitialize: true,
|
|
1512
|
+
AutoInitializeOrdinal: 0,
|
|
1513
|
+
AutoLoadDataWithApp: true,
|
|
1514
|
+
AutoSolveWithApp: true,
|
|
1515
|
+
AutoSolveOrdinal: 0,
|
|
1516
|
+
Manifests: {},
|
|
1517
|
+
Templates: []
|
|
1518
|
+
};
|
|
1519
|
+
class PictProvider extends libFableServiceBase {
|
|
1520
|
+
/**
|
|
1521
|
+
* @param {import('fable')} pFable - The Fable instance.
|
|
1522
|
+
* @param {Record<string, any>} [pOptions] - The options for the provider.
|
|
1523
|
+
* @param {string} [pServiceHash] - The service hash for the provider.
|
|
1524
|
+
*/
|
|
1525
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
1526
|
+
// Intersect default options, parent constructor, service information
|
|
1527
|
+
let tmpOptions = Object.assign({}, JSON.parse(JSON.stringify(defaultPictProviderSettings)), pOptions);
|
|
1528
|
+
super(pFable, tmpOptions, pServiceHash);
|
|
1529
|
+
|
|
1530
|
+
/** @type {import('fable') & import('pict') & { instantiateServiceProviderWithoutRegistration(pServiceType: string, pOptions?: Record<string, any>, pCustomServiceHash?: string): any }} */
|
|
1531
|
+
this.fable;
|
|
1532
|
+
/** @type {import('fable') & import('pict') & { instantiateServiceProviderWithoutRegistration(pServiceType: string, pOptions?: Record<string, any>, pCustomServiceHash?: string): any }} */
|
|
1533
|
+
this.pict;
|
|
1534
|
+
/** @type {any} */
|
|
1535
|
+
this.log;
|
|
1536
|
+
/** @type {Record<string, any>} */
|
|
1537
|
+
this.options;
|
|
1538
|
+
/** @type {string} */
|
|
1539
|
+
this.UUID;
|
|
1540
|
+
/** @type {string} */
|
|
1541
|
+
this.Hash;
|
|
1542
|
+
if (!this.options.ProviderIdentifier) {
|
|
1543
|
+
this.options.ProviderIdentifier = "AutoProviderID-".concat(this.fable.getUUID());
|
|
1544
|
+
}
|
|
1545
|
+
this.serviceType = 'PictProvider';
|
|
1546
|
+
/** @type {Record<string, any>} */
|
|
1547
|
+
this._Package = libPackage;
|
|
1548
|
+
|
|
1549
|
+
// Convenience and consistency naming
|
|
1550
|
+
this.pict = this.fable;
|
|
1551
|
+
|
|
1552
|
+
// Wire in the essential Pict application state
|
|
1553
|
+
/** @type {Record<string, any>} */
|
|
1554
|
+
this.AppData = this.pict.AppData;
|
|
1555
|
+
/** @type {Record<string, any>} */
|
|
1556
|
+
this.Bundle = this.pict.Bundle;
|
|
1557
|
+
this.initializeTimestamp = false;
|
|
1558
|
+
this.lastSolvedTimestamp = false;
|
|
1559
|
+
for (let i = 0; i < this.options.Templates.length; i++) {
|
|
1560
|
+
let tmpDefaultTemplate = this.options.Templates[i];
|
|
1561
|
+
if (!tmpDefaultTemplate.hasOwnProperty('Postfix') || !tmpDefaultTemplate.hasOwnProperty('Template')) {
|
|
1562
|
+
this.log.error("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " could not load Default Template ").concat(i, " in the options array."), tmpDefaultTemplate);
|
|
1563
|
+
} else {
|
|
1564
|
+
if (!tmpDefaultTemplate.Source) {
|
|
1565
|
+
tmpDefaultTemplate.Source = "PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " options object.");
|
|
1566
|
+
}
|
|
1567
|
+
this.pict.TemplateProvider.addDefaultTemplate(tmpDefaultTemplate.Prefix, tmpDefaultTemplate.Postfix, tmpDefaultTemplate.Template, tmpDefaultTemplate.Source);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
/* -------------------------------------------------------------------------- */
|
|
1573
|
+
/* Code Section: Initialization */
|
|
1574
|
+
/* -------------------------------------------------------------------------- */
|
|
1575
|
+
onBeforeInitialize() {
|
|
1576
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1577
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onBeforeInitialize:"));
|
|
1578
|
+
}
|
|
1579
|
+
return true;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after pre-pinitialization.
|
|
1584
|
+
*
|
|
1585
|
+
* @return {void}
|
|
1586
|
+
*/
|
|
1587
|
+
onBeforeInitializeAsync(fCallback) {
|
|
1588
|
+
this.onBeforeInitialize();
|
|
1589
|
+
return fCallback();
|
|
1590
|
+
}
|
|
1591
|
+
onInitialize() {
|
|
1592
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1593
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onInitialize:"));
|
|
1594
|
+
}
|
|
1595
|
+
return true;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after initialization.
|
|
1600
|
+
*
|
|
1601
|
+
* @return {void}
|
|
1602
|
+
*/
|
|
1603
|
+
onInitializeAsync(fCallback) {
|
|
1604
|
+
this.onInitialize();
|
|
1605
|
+
return fCallback();
|
|
1606
|
+
}
|
|
1607
|
+
initialize() {
|
|
1608
|
+
if (this.pict.LogControlFlow) {
|
|
1609
|
+
this.log.trace("PICT-ControlFlow PROVIDER [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " initialize:"));
|
|
1610
|
+
}
|
|
1611
|
+
if (!this.initializeTimestamp) {
|
|
1612
|
+
this.onBeforeInitialize();
|
|
1613
|
+
this.onInitialize();
|
|
1614
|
+
this.onAfterInitialize();
|
|
1615
|
+
this.initializeTimestamp = this.pict.log.getTimeStamp();
|
|
1616
|
+
return true;
|
|
1617
|
+
} else {
|
|
1618
|
+
this.log.warn("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " initialize called but initialization is already completed. Aborting."));
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after initialization.
|
|
1625
|
+
*
|
|
1626
|
+
* @return {void}
|
|
1627
|
+
*/
|
|
1628
|
+
initializeAsync(fCallback) {
|
|
1629
|
+
if (this.pict.LogControlFlow) {
|
|
1630
|
+
this.log.trace("PICT-ControlFlow PROVIDER [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " initializeAsync:"));
|
|
1631
|
+
}
|
|
1632
|
+
if (!this.initializeTimestamp) {
|
|
1633
|
+
let tmpAnticipate = this.pict.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
1634
|
+
if (this.pict.LogNoisiness > 0) {
|
|
1635
|
+
this.log.info("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " beginning initialization..."));
|
|
1636
|
+
}
|
|
1637
|
+
tmpAnticipate.anticipate(this.onBeforeInitializeAsync.bind(this));
|
|
1638
|
+
tmpAnticipate.anticipate(this.onInitializeAsync.bind(this));
|
|
1639
|
+
tmpAnticipate.anticipate(this.onAfterInitializeAsync.bind(this));
|
|
1640
|
+
tmpAnticipate.wait(pError => {
|
|
1641
|
+
this.initializeTimestamp = this.pict.log.getTimeStamp();
|
|
1642
|
+
if (pError) {
|
|
1643
|
+
this.log.error("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " initialization failed: ").concat(pError.message || pError), {
|
|
1644
|
+
Stack: pError.stack
|
|
1645
|
+
});
|
|
1646
|
+
} else if (this.pict.LogNoisiness > 0) {
|
|
1647
|
+
this.log.info("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " initialization complete."));
|
|
1648
|
+
}
|
|
1649
|
+
return fCallback();
|
|
1650
|
+
});
|
|
1651
|
+
} else {
|
|
1652
|
+
this.log.warn("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " async initialize called but initialization is already completed. Aborting."));
|
|
1653
|
+
// TODO: Should this be an error?
|
|
1654
|
+
return fCallback();
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
onAfterInitialize() {
|
|
1658
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1659
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onAfterInitialize:"));
|
|
1660
|
+
}
|
|
1661
|
+
return true;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
/**
|
|
1665
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after initialization.
|
|
1666
|
+
*
|
|
1667
|
+
* @return {void}
|
|
1668
|
+
*/
|
|
1669
|
+
onAfterInitializeAsync(fCallback) {
|
|
1670
|
+
this.onAfterInitialize();
|
|
1671
|
+
return fCallback();
|
|
1672
|
+
}
|
|
1673
|
+
onPreRender() {
|
|
1674
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1675
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onPreRender:"));
|
|
1676
|
+
}
|
|
1677
|
+
return true;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
/**
|
|
1681
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after pre-render.
|
|
1682
|
+
*
|
|
1683
|
+
* @return {void}
|
|
1684
|
+
*/
|
|
1685
|
+
onPreRenderAsync(fCallback) {
|
|
1686
|
+
this.onPreRender();
|
|
1687
|
+
return fCallback();
|
|
1688
|
+
}
|
|
1689
|
+
render() {
|
|
1690
|
+
return this.onPreRender();
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after render.
|
|
1695
|
+
*
|
|
1696
|
+
* @return {void}
|
|
1697
|
+
*/
|
|
1698
|
+
renderAsync(fCallback) {
|
|
1699
|
+
this.onPreRender();
|
|
1700
|
+
return fCallback();
|
|
1701
|
+
}
|
|
1702
|
+
onPreSolve() {
|
|
1703
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1704
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onPreSolve:"));
|
|
1705
|
+
}
|
|
1706
|
+
return true;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after pre-solve.
|
|
1711
|
+
*
|
|
1712
|
+
* @return {void}
|
|
1713
|
+
*/
|
|
1714
|
+
onPreSolveAsync(fCallback) {
|
|
1715
|
+
this.onPreSolve();
|
|
1716
|
+
return fCallback();
|
|
1717
|
+
}
|
|
1718
|
+
solve() {
|
|
1719
|
+
return this.onPreSolve();
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after solve.
|
|
1724
|
+
*
|
|
1725
|
+
* @return {void}
|
|
1726
|
+
*/
|
|
1727
|
+
solveAsync(fCallback) {
|
|
1728
|
+
this.onPreSolve();
|
|
1729
|
+
return fCallback();
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after the data pre-load.
|
|
1734
|
+
*/
|
|
1735
|
+
onBeforeLoadDataAsync(fCallback) {
|
|
1736
|
+
return fCallback();
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
/**
|
|
1740
|
+
* Hook to allow the provider to load data during application data load.
|
|
1741
|
+
*
|
|
1742
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after the data load.
|
|
1743
|
+
*/
|
|
1744
|
+
onLoadDataAsync(fCallback) {
|
|
1745
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1746
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onLoadDataAsync:"));
|
|
1747
|
+
}
|
|
1748
|
+
return fCallback();
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after the data post-load.
|
|
1753
|
+
*/
|
|
1754
|
+
onAfterLoadDataAsync(fCallback) {
|
|
1755
|
+
return fCallback();
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after the data pre-load.
|
|
1760
|
+
*
|
|
1761
|
+
* @return {void}
|
|
1762
|
+
*/
|
|
1763
|
+
onBeforeSaveDataAsync(fCallback) {
|
|
1764
|
+
return fCallback();
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
/**
|
|
1768
|
+
* Hook to allow the provider to load data during application data load.
|
|
1769
|
+
*
|
|
1770
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after the data load.
|
|
1771
|
+
*
|
|
1772
|
+
* @return {void}
|
|
1773
|
+
*/
|
|
1774
|
+
onSaveDataAsync(fCallback) {
|
|
1775
|
+
if (this.pict.LogNoisiness > 3) {
|
|
1776
|
+
this.log.trace("PictProvider [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ProviderIdentifier, " onSaveDataAsync:"));
|
|
1777
|
+
}
|
|
1778
|
+
return fCallback();
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
/**
|
|
1782
|
+
* @param {(pError?: Error) => void} fCallback - The callback to call after the data post-load.
|
|
1783
|
+
*
|
|
1784
|
+
* @return {void}
|
|
1785
|
+
*/
|
|
1786
|
+
onAfterSaveDataAsync(fCallback) {
|
|
1787
|
+
return fCallback();
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
module.exports = PictProvider;
|
|
1791
|
+
}, {
|
|
1792
|
+
"../package.json": 5,
|
|
1793
|
+
"fable-serviceproviderbase": 2
|
|
1794
|
+
}],
|
|
1795
|
+
7: [function (require, module, exports) {
|
|
1796
|
+
module.exports = {
|
|
1797
|
+
"name": "pict-view",
|
|
1798
|
+
"version": "1.0.64",
|
|
1799
|
+
"description": "Pict View Base Class",
|
|
1800
|
+
"main": "source/Pict-View.js",
|
|
1801
|
+
"scripts": {
|
|
1802
|
+
"test": "mocha -u tdd -R spec",
|
|
1803
|
+
"tests": "mocha -u tdd -R spec -g",
|
|
1804
|
+
"start": "node source/Pict-View.js",
|
|
1805
|
+
"coverage": "nyc --reporter=lcov --reporter=text-lcov npm test",
|
|
1806
|
+
"build": "npx quack build",
|
|
1807
|
+
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t pict-view-image:local",
|
|
1808
|
+
"docker-dev-run": "docker run -it -d --name pict-view-dev -p 30001:8080 -p 38086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/pict-view\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" pict-view-image:local",
|
|
1809
|
+
"docker-dev-shell": "docker exec -it pict-view-dev /bin/bash",
|
|
1810
|
+
"types": "tsc -p .",
|
|
1811
|
+
"lint": "eslint source/**"
|
|
1812
|
+
},
|
|
1813
|
+
"types": "types/source/Pict-View.d.ts",
|
|
1814
|
+
"repository": {
|
|
1815
|
+
"type": "git",
|
|
1816
|
+
"url": "git+https://github.com/stevenvelozo/pict-view.git"
|
|
1817
|
+
},
|
|
1818
|
+
"author": "steven velozo <steven@velozo.com>",
|
|
1819
|
+
"license": "MIT",
|
|
1820
|
+
"bugs": {
|
|
1821
|
+
"url": "https://github.com/stevenvelozo/pict-view/issues"
|
|
1822
|
+
},
|
|
1823
|
+
"homepage": "https://github.com/stevenvelozo/pict-view#readme",
|
|
1824
|
+
"devDependencies": {
|
|
1825
|
+
"@eslint/js": "^9.39.1",
|
|
1826
|
+
"browser-env": "^3.3.0",
|
|
1827
|
+
"eslint": "^9.39.1",
|
|
1828
|
+
"pict": "^1.0.337",
|
|
1829
|
+
"quackage": "^1.0.45",
|
|
1830
|
+
"typescript": "^5.9.3"
|
|
1831
|
+
},
|
|
1832
|
+
"mocha": {
|
|
1833
|
+
"diff": true,
|
|
1834
|
+
"extension": ["js"],
|
|
1835
|
+
"package": "./package.json",
|
|
1836
|
+
"reporter": "spec",
|
|
1837
|
+
"slow": "75",
|
|
1838
|
+
"timeout": "5000",
|
|
1839
|
+
"ui": "tdd",
|
|
1840
|
+
"watch-files": ["source/**/*.js", "test/**/*.js"],
|
|
1841
|
+
"watch-ignore": ["lib/vendor"]
|
|
1842
|
+
},
|
|
1843
|
+
"dependencies": {
|
|
1844
|
+
"fable": "^3.1.46",
|
|
1845
|
+
"fable-serviceproviderbase": "^3.0.15"
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
}, {}],
|
|
1849
|
+
8: [function (require, module, exports) {
|
|
1850
|
+
const libFableServiceBase = require('fable-serviceproviderbase');
|
|
1851
|
+
const libPackage = require('../package.json');
|
|
1852
|
+
const defaultPictViewSettings = {
|
|
1853
|
+
DefaultRenderable: false,
|
|
1854
|
+
DefaultDestinationAddress: false,
|
|
1855
|
+
DefaultTemplateRecordAddress: false,
|
|
1856
|
+
ViewIdentifier: false,
|
|
1857
|
+
// If this is set to true, when the App initializes this will.
|
|
1858
|
+
// After the App initializes, initialize will be called as soon as it's added.
|
|
1859
|
+
AutoInitialize: true,
|
|
1860
|
+
AutoInitializeOrdinal: 0,
|
|
1861
|
+
// If this is set to true, when the App autorenders (on load) this will.
|
|
1862
|
+
// After the App initializes, render will be called as soon as it's added.
|
|
1863
|
+
AutoRender: true,
|
|
1864
|
+
AutoRenderOrdinal: 0,
|
|
1865
|
+
AutoSolveWithApp: true,
|
|
1866
|
+
AutoSolveOrdinal: 0,
|
|
1867
|
+
CSSHash: false,
|
|
1868
|
+
CSS: false,
|
|
1869
|
+
CSSProvider: false,
|
|
1870
|
+
CSSPriority: 500,
|
|
1871
|
+
Templates: [],
|
|
1872
|
+
DefaultTemplates: [],
|
|
1873
|
+
Renderables: [],
|
|
1874
|
+
Manifests: {}
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1877
|
+
/** @typedef {(error?: Error) => void} ErrorCallback */
|
|
1878
|
+
/** @typedef {number | boolean} PictTimestamp */
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* @typedef {'replace' | 'append' | 'prepend' | 'append_once' | 'virtual-assignment'} RenderMethod
|
|
1882
|
+
*/
|
|
1883
|
+
/**
|
|
1884
|
+
* @typedef {Object} Renderable
|
|
1885
|
+
*
|
|
1886
|
+
* @property {string} RenderableHash - A unique hash for the renderable.
|
|
1887
|
+
* @property {string} TemplateHash - The hash of the template to use for rendering this renderable.
|
|
1888
|
+
* @property {string} [DefaultTemplateRecordAddress] - The default address for resolving the data record for this renderable.
|
|
1889
|
+
* @property {string} [ContentDestinationAddress] - The default address (DOM CSS selector) for rendering the content of this renderable.
|
|
1890
|
+
* @property {RenderMethod} [RenderMethod=replace] - The method to use when projecting the renderable to the DOM ('replace', 'append', 'prepend', 'append_once', 'virtual-assignment').
|
|
1891
|
+
* @property {string} [TestAddress] - The address to use for testing the renderable.
|
|
1892
|
+
* @property {string} [TransactionHash] - The transaction hash for the root renderable.
|
|
1893
|
+
* @property {string} [RootRenderableViewHash] - The hash of the root renderable.
|
|
1894
|
+
* @property {string} [Content] - The rendered content for this renderable, if applicable.
|
|
1895
|
+
*/
|
|
1896
|
+
|
|
1897
|
+
/**
|
|
1898
|
+
* Represents a view in the Pict ecosystem.
|
|
1899
|
+
*/
|
|
1900
|
+
class PictView extends libFableServiceBase {
|
|
1901
|
+
/**
|
|
1902
|
+
* @param {any} pFable - The Fable object that this service is attached to.
|
|
1903
|
+
* @param {any} [pOptions] - (optional) The options for this service.
|
|
1904
|
+
* @param {string} [pServiceHash] - (optional) The hash of the service.
|
|
1905
|
+
*/
|
|
1906
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
1907
|
+
// Intersect default options, parent constructor, service information
|
|
1908
|
+
let tmpOptions = Object.assign({}, JSON.parse(JSON.stringify(defaultPictViewSettings)), pOptions);
|
|
1909
|
+
super(pFable, tmpOptions, pServiceHash);
|
|
1910
|
+
//FIXME: add types to fable and ancillaries
|
|
1911
|
+
/** @type {any} */
|
|
1912
|
+
this.fable;
|
|
1913
|
+
/** @type {any} */
|
|
1914
|
+
this.options;
|
|
1915
|
+
/** @type {String} */
|
|
1916
|
+
this.UUID;
|
|
1917
|
+
/** @type {String} */
|
|
1918
|
+
this.Hash;
|
|
1919
|
+
/** @type {any} */
|
|
1920
|
+
this.log;
|
|
1921
|
+
const tmpHashIsUUID = this.Hash === this.UUID;
|
|
1922
|
+
//NOTE: since many places are using the view UUID as the HTML element ID, we prefix it to avoid starting with a number
|
|
1923
|
+
this.UUID = "V-".concat(this.UUID);
|
|
1924
|
+
if (tmpHashIsUUID) {
|
|
1925
|
+
this.Hash = this.UUID;
|
|
1926
|
+
}
|
|
1927
|
+
if (!this.options.ViewIdentifier) {
|
|
1928
|
+
this.options.ViewIdentifier = "AutoViewID-".concat(this.fable.getUUID());
|
|
1929
|
+
}
|
|
1930
|
+
this.serviceType = 'PictView';
|
|
1931
|
+
/** @type {Record<string, any>} */
|
|
1932
|
+
this._Package = libPackage;
|
|
1933
|
+
// Convenience and consistency naming
|
|
1934
|
+
/** @type {import('pict') & { log: any, instantiateServiceProviderWithoutRegistration: (hash: String) => any, instantiateServiceProviderIfNotExists: (hash: string) => any, TransactionTracking: import('pict/types/source/services/Fable-Service-TransactionTracking') }} */
|
|
1935
|
+
this.pict = this.fable;
|
|
1936
|
+
// Wire in the essential Pict application state
|
|
1937
|
+
this.AppData = this.pict.AppData;
|
|
1938
|
+
this.Bundle = this.pict.Bundle;
|
|
1939
|
+
|
|
1940
|
+
/** @type {PictTimestamp} */
|
|
1941
|
+
this.initializeTimestamp = false;
|
|
1942
|
+
/** @type {PictTimestamp} */
|
|
1943
|
+
this.lastSolvedTimestamp = false;
|
|
1944
|
+
/** @type {PictTimestamp} */
|
|
1945
|
+
this.lastRenderedTimestamp = false;
|
|
1946
|
+
/** @type {PictTimestamp} */
|
|
1947
|
+
this.lastMarshalFromViewTimestamp = false;
|
|
1948
|
+
/** @type {PictTimestamp} */
|
|
1949
|
+
this.lastMarshalToViewTimestamp = false;
|
|
1950
|
+
this.pict.instantiateServiceProviderIfNotExists('TransactionTracking');
|
|
1951
|
+
|
|
1952
|
+
// Load all templates from the array in the options
|
|
1953
|
+
// Templates are in the form of {Hash:'Some-Template-Hash',Template:'Template content',Source:'TemplateSource'}
|
|
1954
|
+
for (let i = 0; i < this.options.Templates.length; i++) {
|
|
1955
|
+
let tmpTemplate = this.options.Templates[i];
|
|
1956
|
+
if (!('Hash' in tmpTemplate) || !('Template' in tmpTemplate)) {
|
|
1957
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not load Template ").concat(i, " in the options array."), tmpTemplate);
|
|
1958
|
+
} else {
|
|
1959
|
+
if (!tmpTemplate.Source) {
|
|
1960
|
+
tmpTemplate.Source = "PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " options object.");
|
|
1961
|
+
}
|
|
1962
|
+
this.pict.TemplateProvider.addTemplate(tmpTemplate.Hash, tmpTemplate.Template, tmpTemplate.Source);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
// Load all default templates from the array in the options
|
|
1967
|
+
// Templates are in the form of {Prefix:'',Postfix:'-List-Row',Template:'Template content',Source:'TemplateSourceString'}
|
|
1968
|
+
for (let i = 0; i < this.options.DefaultTemplates.length; i++) {
|
|
1969
|
+
let tmpDefaultTemplate = this.options.DefaultTemplates[i];
|
|
1970
|
+
if (!('Postfix' in tmpDefaultTemplate) || !('Template' in tmpDefaultTemplate)) {
|
|
1971
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not load Default Template ").concat(i, " in the options array."), tmpDefaultTemplate);
|
|
1972
|
+
} else {
|
|
1973
|
+
if (!tmpDefaultTemplate.Source) {
|
|
1974
|
+
tmpDefaultTemplate.Source = "PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " options object.");
|
|
1975
|
+
}
|
|
1976
|
+
this.pict.TemplateProvider.addDefaultTemplate(tmpDefaultTemplate.Prefix, tmpDefaultTemplate.Postfix, tmpDefaultTemplate.Template, tmpDefaultTemplate.Source);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
// Load the CSS if it's available
|
|
1981
|
+
if (this.options.CSS) {
|
|
1982
|
+
let tmpCSSHash = this.options.CSSHash ? this.options.CSSHash : "View-".concat(this.options.ViewIdentifier);
|
|
1983
|
+
let tmpCSSProvider = this.options.CSSProvider ? this.options.CSSProvider : tmpCSSHash;
|
|
1984
|
+
this.pict.CSSMap.addCSS(tmpCSSHash, this.options.CSS, tmpCSSProvider, this.options.CSSPriority);
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
// Load all renderables
|
|
1988
|
+
// Renderables are launchable renderable instructions with templates
|
|
1989
|
+
// They look as such: {Identifier:'ContentEntry', TemplateHash:'Content-Entry-Section-Main', ContentDestinationAddress:'#ContentSection', RecordAddress:'AppData.Content.DefaultText', ManifestTransformation:'ManyfestHash', ManifestDestinationAddress:'AppData.Content.DataToTransformContent'}
|
|
1990
|
+
// The only parts that are necessary are Identifier and Template
|
|
1991
|
+
// A developer can then do render('ContentEntry') and it just kinda works. Or they can override the ContentDestinationAddress
|
|
1992
|
+
/** @type {Record<String, Renderable>} */
|
|
1993
|
+
this.renderables = {};
|
|
1994
|
+
for (let i = 0; i < this.options.Renderables.length; i++) {
|
|
1995
|
+
/** @type {Renderable} */
|
|
1996
|
+
let tmpRenderable = this.options.Renderables[i];
|
|
1997
|
+
this.addRenderable(tmpRenderable);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
/**
|
|
2002
|
+
* Adds a renderable to the view.
|
|
2003
|
+
*
|
|
2004
|
+
* @param {string | Renderable} pRenderableHash - The hash of the renderable, or a renderable object.
|
|
2005
|
+
* @param {string} [pTemplateHash] - (optional) The hash of the template for the renderable.
|
|
2006
|
+
* @param {string} [pDefaultTemplateRecordAddress] - (optional) The default data address for the template.
|
|
2007
|
+
* @param {string} [pDefaultDestinationAddress] - (optional) The default destination address for the renderable.
|
|
2008
|
+
* @param {RenderMethod} [pRenderMethod=replace] - (optional) The method to use when rendering the renderable (ex. 'replace').
|
|
2009
|
+
*/
|
|
2010
|
+
addRenderable(pRenderableHash, pTemplateHash, pDefaultTemplateRecordAddress, pDefaultDestinationAddress, pRenderMethod) {
|
|
2011
|
+
/** @type {Renderable} */
|
|
2012
|
+
let tmpRenderable;
|
|
2013
|
+
if (typeof pRenderableHash == 'object') {
|
|
2014
|
+
// The developer passed in the renderable as an object.
|
|
2015
|
+
// Use theirs instead!
|
|
2016
|
+
tmpRenderable = pRenderableHash;
|
|
2017
|
+
} else {
|
|
2018
|
+
/** @type {RenderMethod} */
|
|
2019
|
+
let tmpRenderMethod = typeof pRenderMethod !== 'string' ? pRenderMethod : 'replace';
|
|
2020
|
+
tmpRenderable = {
|
|
2021
|
+
RenderableHash: pRenderableHash,
|
|
2022
|
+
TemplateHash: pTemplateHash,
|
|
2023
|
+
DefaultTemplateRecordAddress: pDefaultTemplateRecordAddress,
|
|
2024
|
+
ContentDestinationAddress: pDefaultDestinationAddress,
|
|
2025
|
+
RenderMethod: tmpRenderMethod
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
if (typeof tmpRenderable.RenderableHash != 'string' || typeof tmpRenderable.TemplateHash != 'string') {
|
|
2029
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not load Renderable; RenderableHash or TemplateHash are invalid."), tmpRenderable);
|
|
2030
|
+
} else {
|
|
2031
|
+
if (this.pict.LogNoisiness > 0) {
|
|
2032
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " adding renderable [").concat(tmpRenderable.RenderableHash, "] pointed to template ").concat(tmpRenderable.TemplateHash, "."));
|
|
2033
|
+
}
|
|
2034
|
+
this.renderables[tmpRenderable.RenderableHash] = tmpRenderable;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
/* -------------------------------------------------------------------------- */
|
|
2039
|
+
/* Code Section: Initialization */
|
|
2040
|
+
/* -------------------------------------------------------------------------- */
|
|
2041
|
+
/**
|
|
2042
|
+
* Lifecycle hook that triggers before the view is initialized.
|
|
2043
|
+
*/
|
|
2044
|
+
onBeforeInitialize() {
|
|
2045
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2046
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onBeforeInitialize:"));
|
|
2047
|
+
}
|
|
2048
|
+
return true;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
/**
|
|
2052
|
+
* Lifecycle hook that triggers before the view is initialized (async flow).
|
|
2053
|
+
*
|
|
2054
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2055
|
+
*/
|
|
2056
|
+
onBeforeInitializeAsync(fCallback) {
|
|
2057
|
+
this.onBeforeInitialize();
|
|
2058
|
+
return fCallback();
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
/**
|
|
2062
|
+
* Lifecycle hook that triggers when the view is initialized.
|
|
2063
|
+
*/
|
|
2064
|
+
onInitialize() {
|
|
2065
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2066
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onInitialize:"));
|
|
2067
|
+
}
|
|
2068
|
+
return true;
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
/**
|
|
2072
|
+
* Lifecycle hook that triggers when the view is initialized (async flow).
|
|
2073
|
+
*
|
|
2074
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2075
|
+
*/
|
|
2076
|
+
onInitializeAsync(fCallback) {
|
|
2077
|
+
this.onInitialize();
|
|
2078
|
+
return fCallback();
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/**
|
|
2082
|
+
* Performs view initialization.
|
|
2083
|
+
*/
|
|
2084
|
+
initialize() {
|
|
2085
|
+
if (this.pict.LogControlFlow) {
|
|
2086
|
+
this.log.trace("PICT-ControlFlow VIEW [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " initialize:"));
|
|
2087
|
+
}
|
|
2088
|
+
if (!this.initializeTimestamp) {
|
|
2089
|
+
this.onBeforeInitialize();
|
|
2090
|
+
this.onInitialize();
|
|
2091
|
+
this.onAfterInitialize();
|
|
2092
|
+
this.initializeTimestamp = this.pict.log.getTimeStamp();
|
|
2093
|
+
return true;
|
|
2094
|
+
} else {
|
|
2095
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " initialize called but initialization is already completed. Aborting."));
|
|
2096
|
+
return false;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
/**
|
|
2101
|
+
* Performs view initialization (async flow).
|
|
2102
|
+
*
|
|
2103
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2104
|
+
*/
|
|
2105
|
+
initializeAsync(fCallback) {
|
|
2106
|
+
if (this.pict.LogControlFlow) {
|
|
2107
|
+
this.log.trace("PICT-ControlFlow VIEW [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " initializeAsync:"));
|
|
2108
|
+
}
|
|
2109
|
+
if (!this.initializeTimestamp) {
|
|
2110
|
+
let tmpAnticipate = this.pict.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
2111
|
+
if (this.pict.LogNoisiness > 0) {
|
|
2112
|
+
this.log.info("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " beginning initialization..."));
|
|
2113
|
+
}
|
|
2114
|
+
tmpAnticipate.anticipate(this.onBeforeInitializeAsync.bind(this));
|
|
2115
|
+
tmpAnticipate.anticipate(this.onInitializeAsync.bind(this));
|
|
2116
|
+
tmpAnticipate.anticipate(this.onAfterInitializeAsync.bind(this));
|
|
2117
|
+
tmpAnticipate.wait(/** @param {Error} pError */
|
|
2118
|
+
pError => {
|
|
2119
|
+
if (pError) {
|
|
2120
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " initialization failed: ").concat(pError.message || pError), {
|
|
2121
|
+
stack: pError.stack
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
this.initializeTimestamp = this.pict.log.getTimeStamp();
|
|
2125
|
+
if (this.pict.LogNoisiness > 0) {
|
|
2126
|
+
this.log.info("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " initialization complete."));
|
|
2127
|
+
}
|
|
2128
|
+
return fCallback();
|
|
2129
|
+
});
|
|
2130
|
+
} else {
|
|
2131
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " async initialize called but initialization is already completed. Aborting."));
|
|
2132
|
+
// TODO: Should this be an error?
|
|
2133
|
+
return fCallback();
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
onAfterInitialize() {
|
|
2137
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2138
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterInitialize:"));
|
|
2139
|
+
}
|
|
2140
|
+
return true;
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
/**
|
|
2144
|
+
* Lifecycle hook that triggers after the view is initialized (async flow).
|
|
2145
|
+
*
|
|
2146
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2147
|
+
*/
|
|
2148
|
+
onAfterInitializeAsync(fCallback) {
|
|
2149
|
+
this.onAfterInitialize();
|
|
2150
|
+
return fCallback();
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/* -------------------------------------------------------------------------- */
|
|
2154
|
+
/* Code Section: Render */
|
|
2155
|
+
/* -------------------------------------------------------------------------- */
|
|
2156
|
+
/**
|
|
2157
|
+
* Lifecycle hook that triggers before the view is rendered.
|
|
2158
|
+
*
|
|
2159
|
+
* @param {Renderable} pRenderable - The renderable that will be rendered.
|
|
2160
|
+
*/
|
|
2161
|
+
onBeforeRender(pRenderable) {
|
|
2162
|
+
// Overload this to mess with stuff before the content gets generated from the template
|
|
2163
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2164
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onBeforeRender:"));
|
|
2165
|
+
}
|
|
2166
|
+
return true;
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
/**
|
|
2170
|
+
* Lifecycle hook that triggers before the view is rendered (async flow).
|
|
2171
|
+
*
|
|
2172
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2173
|
+
* @param {Renderable} pRenderable - The renderable that will be rendered.
|
|
2174
|
+
*/
|
|
2175
|
+
onBeforeRenderAsync(fCallback, pRenderable) {
|
|
2176
|
+
this.onBeforeRender(pRenderable);
|
|
2177
|
+
return fCallback();
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
/**
|
|
2181
|
+
* Lifecycle hook that triggers before the view is projected into the DOM.
|
|
2182
|
+
*
|
|
2183
|
+
* @param {Renderable} pRenderable - The renderable that will be projected.
|
|
2184
|
+
*/
|
|
2185
|
+
onBeforeProject(pRenderable) {
|
|
2186
|
+
// Overload this to mess with stuff before the content gets generated from the template
|
|
2187
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2188
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onBeforeProject:"));
|
|
2189
|
+
}
|
|
2190
|
+
return true;
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
/**
|
|
2194
|
+
* Lifecycle hook that triggers before the view is projected into the DOM (async flow).
|
|
2195
|
+
*
|
|
2196
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2197
|
+
* @param {Renderable} pRenderable - The renderable that will be projected.
|
|
2198
|
+
*/
|
|
2199
|
+
onBeforeProjectAsync(fCallback, pRenderable) {
|
|
2200
|
+
this.onBeforeProject(pRenderable);
|
|
2201
|
+
return fCallback();
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
/**
|
|
2205
|
+
* Builds the render options for a renderable.
|
|
2206
|
+
*
|
|
2207
|
+
* For DRY purposes on the three flavors of render.
|
|
2208
|
+
*
|
|
2209
|
+
* @param {string|ErrorCallback} [pRenderableHash] - The hash of the renderable to render.
|
|
2210
|
+
* @param {string|ErrorCallback} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2211
|
+
* @param {string|object|ErrorCallback} [pTemplateRecordAddress] - The address of (or actual obejct) where the data for the template is stored.
|
|
2212
|
+
*/
|
|
2213
|
+
buildRenderOptions(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress) {
|
|
2214
|
+
let tmpRenderOptions = {
|
|
2215
|
+
Valid: true
|
|
2216
|
+
};
|
|
2217
|
+
tmpRenderOptions.RenderableHash = typeof pRenderableHash === 'string' ? pRenderableHash : typeof this.options.DefaultRenderable == 'string' ? this.options.DefaultRenderable : false;
|
|
2218
|
+
if (!tmpRenderOptions.RenderableHash) {
|
|
2219
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not find a suitable RenderableHash ").concat(tmpRenderOptions.RenderableHash, " (param ").concat(pRenderableHash, "because it is not a valid renderable."));
|
|
2220
|
+
tmpRenderOptions.Valid = false;
|
|
2221
|
+
}
|
|
2222
|
+
tmpRenderOptions.Renderable = this.renderables[tmpRenderOptions.RenderableHash];
|
|
2223
|
+
if (!tmpRenderOptions.Renderable) {
|
|
2224
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderOptions.RenderableHash, " (param ").concat(pRenderableHash, ") because it does not exist."));
|
|
2225
|
+
tmpRenderOptions.Valid = false;
|
|
2226
|
+
}
|
|
2227
|
+
tmpRenderOptions.DestinationAddress = typeof pRenderDestinationAddress === 'string' ? pRenderDestinationAddress : typeof tmpRenderOptions.Renderable.ContentDestinationAddress === 'string' ? tmpRenderOptions.Renderable.ContentDestinationAddress : typeof this.options.DefaultDestinationAddress === 'string' ? this.options.DefaultDestinationAddress : false;
|
|
2228
|
+
if (!tmpRenderOptions.DestinationAddress) {
|
|
2229
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderOptions.RenderableHash, " (param ").concat(pRenderableHash, ") because it does not have a valid destination address (param ").concat(pRenderDestinationAddress, ")."));
|
|
2230
|
+
tmpRenderOptions.Valid = false;
|
|
2231
|
+
}
|
|
2232
|
+
if (typeof pTemplateRecordAddress === 'object') {
|
|
2233
|
+
tmpRenderOptions.RecordAddress = 'Passed in as object';
|
|
2234
|
+
tmpRenderOptions.Record = pTemplateRecordAddress;
|
|
2235
|
+
} else {
|
|
2236
|
+
tmpRenderOptions.RecordAddress = typeof pTemplateRecordAddress === 'string' ? pTemplateRecordAddress : typeof tmpRenderOptions.Renderable.DefaultTemplateRecordAddress === 'string' ? tmpRenderOptions.Renderable.DefaultTemplateRecordAddress : typeof this.options.DefaultTemplateRecordAddress === 'string' ? this.options.DefaultTemplateRecordAddress : false;
|
|
2237
|
+
tmpRenderOptions.Record = typeof tmpRenderOptions.RecordAddress === 'string' ? this.pict.DataProvider.getDataByAddress(tmpRenderOptions.RecordAddress) : undefined;
|
|
2238
|
+
}
|
|
2239
|
+
return tmpRenderOptions;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* Assigns the content to the destination address.
|
|
2244
|
+
*
|
|
2245
|
+
* For DRY purposes on the three flavors of render.
|
|
2246
|
+
*
|
|
2247
|
+
* @param {Renderable} pRenderable - The renderable to render.
|
|
2248
|
+
* @param {string} pRenderDestinationAddress - The address where the renderable will be rendered.
|
|
2249
|
+
* @param {string} pContent - The content to render.
|
|
2250
|
+
* @returns {boolean} - Returns true if the content was assigned successfully.
|
|
2251
|
+
* @memberof PictView
|
|
2252
|
+
*/
|
|
2253
|
+
assignRenderContent(pRenderable, pRenderDestinationAddress, pContent) {
|
|
2254
|
+
return this.pict.ContentAssignment.projectContent(pRenderable.RenderMethod, pRenderDestinationAddress, pContent, pRenderable.TestAddress);
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
/**
|
|
2258
|
+
* Render a renderable from this view.
|
|
2259
|
+
*
|
|
2260
|
+
* @param {string} [pRenderableHash] - The hash of the renderable to render.
|
|
2261
|
+
* @param {string} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2262
|
+
* @param {string|object} [pTemplateRecordAddress] - The address where the data for the template is stored.
|
|
2263
|
+
* @param {Renderable} [pRootRenderable] - The root renderable for the render operation, if applicable.
|
|
2264
|
+
* @return {boolean}
|
|
2265
|
+
*/
|
|
2266
|
+
render(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, pRootRenderable) {
|
|
2267
|
+
return this.renderWithScope(this, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, pRootRenderable);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* Render a renderable from this view, providing a specifici scope for the template.
|
|
2272
|
+
*
|
|
2273
|
+
* @param {any} pScope - The scope to use for the template rendering.
|
|
2274
|
+
* @param {string} [pRenderableHash] - The hash of the renderable to render.
|
|
2275
|
+
* @param {string} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2276
|
+
* @param {string|object} [pTemplateRecordAddress] - The address where the data for the template is stored.
|
|
2277
|
+
* @param {Renderable} [pRootRenderable] - The root renderable for the render operation, if applicable.
|
|
2278
|
+
* @return {boolean}
|
|
2279
|
+
*/
|
|
2280
|
+
renderWithScope(pScope, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, pRootRenderable) {
|
|
2281
|
+
let tmpRenderableHash = typeof pRenderableHash === 'string' ? pRenderableHash : typeof this.options.DefaultRenderable == 'string' ? this.options.DefaultRenderable : false;
|
|
2282
|
+
if (!tmpRenderableHash) {
|
|
2283
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it is not a valid renderable."));
|
|
2284
|
+
return false;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
/** @type {Renderable} */
|
|
2288
|
+
let tmpRenderable;
|
|
2289
|
+
if (tmpRenderableHash == '__Virtual') {
|
|
2290
|
+
tmpRenderable = {
|
|
2291
|
+
RenderableHash: '__Virtual',
|
|
2292
|
+
TemplateHash: this.renderables[this.options.DefaultRenderable].TemplateHash,
|
|
2293
|
+
ContentDestinationAddress: typeof pRenderDestinationAddress === 'string' ? pRenderDestinationAddress : typeof tmpRenderable.ContentDestinationAddress === 'string' ? tmpRenderable.ContentDestinationAddress : typeof this.options.DefaultDestinationAddress === 'string' ? this.options.DefaultDestinationAddress : null,
|
|
2294
|
+
RenderMethod: 'virtual-assignment',
|
|
2295
|
+
TransactionHash: pRootRenderable && pRootRenderable.TransactionHash,
|
|
2296
|
+
RootRenderableViewHash: pRootRenderable && pRootRenderable.RootRenderableViewHash
|
|
2297
|
+
};
|
|
2298
|
+
} else {
|
|
2299
|
+
tmpRenderable = Object.assign({}, this.renderables[tmpRenderableHash]);
|
|
2300
|
+
tmpRenderable.ContentDestinationAddress = typeof pRenderDestinationAddress === 'string' ? pRenderDestinationAddress : typeof tmpRenderable.ContentDestinationAddress === 'string' ? tmpRenderable.ContentDestinationAddress : typeof this.options.DefaultDestinationAddress === 'string' ? this.options.DefaultDestinationAddress : null;
|
|
2301
|
+
}
|
|
2302
|
+
if (!tmpRenderable.TransactionHash) {
|
|
2303
|
+
tmpRenderable.TransactionHash = "ViewRender-V-".concat(this.options.ViewIdentifier, "-R-").concat(tmpRenderableHash, "-U-").concat(this.pict.getUUID());
|
|
2304
|
+
tmpRenderable.RootRenderableViewHash = this.Hash;
|
|
2305
|
+
this.pict.TransactionTracking.registerTransaction(tmpRenderable.TransactionHash);
|
|
2306
|
+
}
|
|
2307
|
+
if (!tmpRenderable) {
|
|
2308
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it does not exist."));
|
|
2309
|
+
return false;
|
|
2310
|
+
}
|
|
2311
|
+
if (!tmpRenderable.ContentDestinationAddress) {
|
|
2312
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it does not have a valid destination address."));
|
|
2313
|
+
return false;
|
|
2314
|
+
}
|
|
2315
|
+
let tmpRecordAddress;
|
|
2316
|
+
let tmpRecord;
|
|
2317
|
+
if (typeof pTemplateRecordAddress === 'object') {
|
|
2318
|
+
tmpRecord = pTemplateRecordAddress;
|
|
2319
|
+
tmpRecordAddress = 'Passed in as object';
|
|
2320
|
+
} else {
|
|
2321
|
+
tmpRecordAddress = typeof pTemplateRecordAddress === 'string' ? pTemplateRecordAddress : typeof tmpRenderable.DefaultTemplateRecordAddress === 'string' ? tmpRenderable.DefaultTemplateRecordAddress : typeof this.options.DefaultTemplateRecordAddress === 'string' ? this.options.DefaultTemplateRecordAddress : false;
|
|
2322
|
+
tmpRecord = typeof tmpRecordAddress === 'string' ? this.pict.DataProvider.getDataByAddress(tmpRecordAddress) : undefined;
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
// Execute the developer-overridable pre-render behavior
|
|
2326
|
+
this.onBeforeRender(tmpRenderable);
|
|
2327
|
+
if (this.pict.LogControlFlow) {
|
|
2328
|
+
this.log.trace("PICT-ControlFlow VIEW [".concat(this.UUID, "]::[").concat(this.Hash, "] Renderable[").concat(tmpRenderableHash, "] Destination[").concat(tmpRenderable.ContentDestinationAddress, "] TemplateRecordAddress[").concat(tmpRecordAddress, "] render:"));
|
|
2329
|
+
}
|
|
2330
|
+
if (this.pict.LogNoisiness > 0) {
|
|
2331
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " Beginning Render of Renderable[").concat(tmpRenderableHash, "] to Destination [").concat(tmpRenderable.ContentDestinationAddress, "]..."));
|
|
2332
|
+
}
|
|
2333
|
+
// Generate the content output from the template and data
|
|
2334
|
+
tmpRenderable.Content = this.pict.parseTemplateByHash(tmpRenderable.TemplateHash, tmpRecord, null, [this], pScope, {
|
|
2335
|
+
RootRenderable: typeof pRootRenderable === 'object' ? pRootRenderable : tmpRenderable
|
|
2336
|
+
});
|
|
2337
|
+
if (this.pict.LogNoisiness > 0) {
|
|
2338
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " Assigning Renderable[").concat(tmpRenderableHash, "] content length ").concat(tmpRenderable.Content.length, " to Destination [").concat(tmpRenderable.ContentDestinationAddress, "] using render method [").concat(tmpRenderable.RenderMethod, "]."));
|
|
2339
|
+
}
|
|
2340
|
+
this.onBeforeProject(tmpRenderable);
|
|
2341
|
+
this.onProject(tmpRenderable);
|
|
2342
|
+
if (tmpRenderable.RenderMethod !== 'virtual-assignment') {
|
|
2343
|
+
this.onAfterProject(tmpRenderable);
|
|
2344
|
+
|
|
2345
|
+
// Execute the developer-overridable post-render behavior
|
|
2346
|
+
this.onAfterRender(tmpRenderable);
|
|
2347
|
+
}
|
|
2348
|
+
return true;
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Render a renderable from this view.
|
|
2353
|
+
*
|
|
2354
|
+
* @param {string|ErrorCallback} [pRenderableHash] - The hash of the renderable to render.
|
|
2355
|
+
* @param {string|ErrorCallback} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2356
|
+
* @param {string|object|ErrorCallback} [pTemplateRecordAddress] - The address where the data for the template is stored.
|
|
2357
|
+
* @param {Renderable|ErrorCallback} [pRootRenderable] - The root renderable for the render operation, if applicable.
|
|
2358
|
+
* @param {ErrorCallback} [fCallback] - The callback to call when the async operation is complete.
|
|
2359
|
+
*
|
|
2360
|
+
* @return {void}
|
|
2361
|
+
*/
|
|
2362
|
+
renderAsync(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, pRootRenderable, fCallback) {
|
|
2363
|
+
return this.renderWithScopeAsync(this, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, pRootRenderable, fCallback);
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
/**
|
|
2367
|
+
* Render a renderable from this view.
|
|
2368
|
+
*
|
|
2369
|
+
* @param {any} pScope - The scope to use for the template rendering.
|
|
2370
|
+
* @param {string|ErrorCallback} [pRenderableHash] - The hash of the renderable to render.
|
|
2371
|
+
* @param {string|ErrorCallback} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2372
|
+
* @param {string|object|ErrorCallback} [pTemplateRecordAddress] - The address where the data for the template is stored.
|
|
2373
|
+
* @param {Renderable|ErrorCallback} [pRootRenderable] - The root renderable for the render operation, if applicable.
|
|
2374
|
+
* @param {ErrorCallback} [fCallback] - The callback to call when the async operation is complete.
|
|
2375
|
+
*
|
|
2376
|
+
* @return {void}
|
|
2377
|
+
*/
|
|
2378
|
+
renderWithScopeAsync(pScope, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, pRootRenderable, fCallback) {
|
|
2379
|
+
let tmpRenderableHash = typeof pRenderableHash === 'string' ? pRenderableHash : typeof this.options.DefaultRenderable == 'string' ? this.options.DefaultRenderable : false;
|
|
2380
|
+
|
|
2381
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
2382
|
+
/** @type {ErrorCallback} */
|
|
2383
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : typeof pTemplateRecordAddress === 'function' ? pTemplateRecordAddress : typeof pRenderDestinationAddress === 'function' ? pRenderDestinationAddress : typeof pRenderableHash === 'function' ? pRenderableHash : typeof pRootRenderable === 'function' ? pRootRenderable : null;
|
|
2384
|
+
if (!tmpCallback) {
|
|
2385
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
2386
|
+
tmpCallback = pError => {
|
|
2387
|
+
if (pError) {
|
|
2388
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " renderAsync Auto Callback Error: ").concat(pError), pError);
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
if (!tmpRenderableHash) {
|
|
2393
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not asynchronously render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, "because it is not a valid renderable."));
|
|
2394
|
+
return tmpCallback(new Error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not asynchronously render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, "because it is not a valid renderable.")));
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
/** @type {Renderable} */
|
|
2398
|
+
let tmpRenderable;
|
|
2399
|
+
if (tmpRenderableHash == '__Virtual') {
|
|
2400
|
+
tmpRenderable = {
|
|
2401
|
+
RenderableHash: '__Virtual',
|
|
2402
|
+
TemplateHash: this.renderables[this.options.DefaultRenderable].TemplateHash,
|
|
2403
|
+
ContentDestinationAddress: typeof pRenderDestinationAddress === 'string' ? pRenderDestinationAddress : typeof this.options.DefaultDestinationAddress === 'string' ? this.options.DefaultDestinationAddress : null,
|
|
2404
|
+
RenderMethod: 'virtual-assignment',
|
|
2405
|
+
TransactionHash: pRootRenderable && typeof pRootRenderable !== 'function' && pRootRenderable.TransactionHash,
|
|
2406
|
+
RootRenderableViewHash: pRootRenderable && typeof pRootRenderable !== 'function' && pRootRenderable.RootRenderableViewHash
|
|
2407
|
+
};
|
|
2408
|
+
} else {
|
|
2409
|
+
tmpRenderable = Object.assign({}, this.renderables[tmpRenderableHash]);
|
|
2410
|
+
tmpRenderable.ContentDestinationAddress = typeof pRenderDestinationAddress === 'string' ? pRenderDestinationAddress : typeof tmpRenderable.ContentDestinationAddress === 'string' ? tmpRenderable.ContentDestinationAddress : typeof this.options.DefaultDestinationAddress === 'string' ? this.options.DefaultDestinationAddress : null;
|
|
2411
|
+
}
|
|
2412
|
+
if (!tmpRenderable.TransactionHash) {
|
|
2413
|
+
tmpRenderable.TransactionHash = "ViewRender-V-".concat(this.options.ViewIdentifier, "-R-").concat(tmpRenderableHash, "-U-").concat(this.pict.getUUID());
|
|
2414
|
+
tmpRenderable.RootRenderableViewHash = this.Hash;
|
|
2415
|
+
this.pict.TransactionTracking.registerTransaction(tmpRenderable.TransactionHash);
|
|
2416
|
+
}
|
|
2417
|
+
if (!tmpRenderable) {
|
|
2418
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it does not exist."));
|
|
2419
|
+
return tmpCallback(new Error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it does not exist.")));
|
|
2420
|
+
}
|
|
2421
|
+
if (!tmpRenderable.ContentDestinationAddress) {
|
|
2422
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it does not have a valid destination address."));
|
|
2423
|
+
return tmpCallback(new Error("Could not render ".concat(tmpRenderableHash)));
|
|
2424
|
+
}
|
|
2425
|
+
let tmpRecordAddress;
|
|
2426
|
+
let tmpRecord;
|
|
2427
|
+
if (typeof pTemplateRecordAddress === 'object') {
|
|
2428
|
+
tmpRecord = pTemplateRecordAddress;
|
|
2429
|
+
tmpRecordAddress = 'Passed in as object';
|
|
2430
|
+
} else {
|
|
2431
|
+
tmpRecordAddress = typeof pTemplateRecordAddress === 'string' ? pTemplateRecordAddress : typeof tmpRenderable.DefaultTemplateRecordAddress === 'string' ? tmpRenderable.DefaultTemplateRecordAddress : typeof this.options.DefaultTemplateRecordAddress === 'string' ? this.options.DefaultTemplateRecordAddress : false;
|
|
2432
|
+
tmpRecord = typeof tmpRecordAddress === 'string' ? this.pict.DataProvider.getDataByAddress(tmpRecordAddress) : undefined;
|
|
2433
|
+
}
|
|
2434
|
+
if (this.pict.LogControlFlow) {
|
|
2435
|
+
this.log.trace("PICT-ControlFlow VIEW [".concat(this.UUID, "]::[").concat(this.Hash, "] Renderable[").concat(tmpRenderableHash, "] Destination[").concat(tmpRenderable.ContentDestinationAddress, "] TemplateRecordAddress[").concat(tmpRecordAddress, "] renderAsync:"));
|
|
2436
|
+
}
|
|
2437
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2438
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " Beginning Asynchronous Render (callback-style)..."));
|
|
2439
|
+
}
|
|
2440
|
+
let tmpAnticipate = this.fable.newAnticipate();
|
|
2441
|
+
tmpAnticipate.anticipate(fOnBeforeRenderCallback => {
|
|
2442
|
+
this.onBeforeRenderAsync(fOnBeforeRenderCallback, tmpRenderable);
|
|
2443
|
+
});
|
|
2444
|
+
tmpAnticipate.anticipate(fAsyncTemplateCallback => {
|
|
2445
|
+
// Render the template (asynchronously)
|
|
2446
|
+
this.pict.parseTemplateByHash(tmpRenderable.TemplateHash, tmpRecord, (pError, pContent) => {
|
|
2447
|
+
if (pError) {
|
|
2448
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render (asynchronously) ").concat(tmpRenderableHash, " (param ").concat(pRenderableHash, ") because it did not parse the template."), pError);
|
|
2449
|
+
return fAsyncTemplateCallback(pError);
|
|
2450
|
+
}
|
|
2451
|
+
tmpRenderable.Content = pContent;
|
|
2452
|
+
return fAsyncTemplateCallback();
|
|
2453
|
+
}, [this], pScope, {
|
|
2454
|
+
RootRenderable: typeof pRootRenderable === 'object' ? pRootRenderable : tmpRenderable
|
|
2455
|
+
});
|
|
2456
|
+
});
|
|
2457
|
+
tmpAnticipate.anticipate(fNext => {
|
|
2458
|
+
this.onBeforeProjectAsync(fNext, tmpRenderable);
|
|
2459
|
+
});
|
|
2460
|
+
tmpAnticipate.anticipate(fNext => {
|
|
2461
|
+
this.onProjectAsync(fNext, tmpRenderable);
|
|
2462
|
+
});
|
|
2463
|
+
if (tmpRenderable.RenderMethod !== 'virtual-assignment') {
|
|
2464
|
+
tmpAnticipate.anticipate(fNext => {
|
|
2465
|
+
this.onAfterProjectAsync(fNext, tmpRenderable);
|
|
2466
|
+
});
|
|
2467
|
+
|
|
2468
|
+
// Execute the developer-overridable post-render behavior
|
|
2469
|
+
tmpAnticipate.anticipate(fNext => {
|
|
2470
|
+
this.onAfterRenderAsync(fNext, tmpRenderable);
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
tmpAnticipate.wait(tmpCallback);
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
/**
|
|
2477
|
+
* Renders the default renderable.
|
|
2478
|
+
*
|
|
2479
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2480
|
+
*/
|
|
2481
|
+
renderDefaultAsync(fCallback) {
|
|
2482
|
+
// Render the default renderable
|
|
2483
|
+
this.renderAsync(fCallback);
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
/**
|
|
2487
|
+
* @param {string} [pRenderableHash] - The hash of the renderable to render.
|
|
2488
|
+
* @param {string} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2489
|
+
* @param {string|object} [pTemplateRecordAddress] - The address of (or actual obejct) where the data for the template is stored.
|
|
2490
|
+
*/
|
|
2491
|
+
basicRender(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress) {
|
|
2492
|
+
return this.basicRenderWithScope(this, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress);
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
/**
|
|
2496
|
+
* @param {any} pScope - The scope to use for the template rendering.
|
|
2497
|
+
* @param {string} [pRenderableHash] - The hash of the renderable to render.
|
|
2498
|
+
* @param {string} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2499
|
+
* @param {string|object} [pTemplateRecordAddress] - The address of (or actual obejct) where the data for the template is stored.
|
|
2500
|
+
*/
|
|
2501
|
+
basicRenderWithScope(pScope, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress) {
|
|
2502
|
+
let tmpRenderOptions = this.buildRenderOptions(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress);
|
|
2503
|
+
if (tmpRenderOptions.Valid) {
|
|
2504
|
+
this.assignRenderContent(tmpRenderOptions.Renderable, tmpRenderOptions.DestinationAddress, this.pict.parseTemplateByHash(tmpRenderOptions.Renderable.TemplateHash, tmpRenderOptions.Record, null, [this], pScope, {
|
|
2505
|
+
RootRenderable: tmpRenderOptions.Renderable
|
|
2506
|
+
}));
|
|
2507
|
+
return true;
|
|
2508
|
+
} else {
|
|
2509
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not perform a basic render of ").concat(tmpRenderOptions.RenderableHash, " because it is not valid."));
|
|
2510
|
+
return false;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
/**
|
|
2515
|
+
* @param {string|ErrorCallback} [pRenderableHash] - The hash of the renderable to render.
|
|
2516
|
+
* @param {string|ErrorCallback} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2517
|
+
* @param {string|Object|ErrorCallback} [pTemplateRecordAddress] - The address of (or actual obejct) where the data for the template is stored.
|
|
2518
|
+
* @param {ErrorCallback} [fCallback] - The callback to call when the async operation is complete.
|
|
2519
|
+
*/
|
|
2520
|
+
basicRenderAsync(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, fCallback) {
|
|
2521
|
+
return this.basicRenderWithScopeAsync(this, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, fCallback);
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
/**
|
|
2525
|
+
* @param {any} pScope - The scope to use for the template rendering.
|
|
2526
|
+
* @param {string|ErrorCallback} [pRenderableHash] - The hash of the renderable to render.
|
|
2527
|
+
* @param {string|ErrorCallback} [pRenderDestinationAddress] - The address where the renderable will be rendered.
|
|
2528
|
+
* @param {string|Object|ErrorCallback} [pTemplateRecordAddress] - The address of (or actual obejct) where the data for the template is stored.
|
|
2529
|
+
* @param {ErrorCallback} [fCallback] - The callback to call when the async operation is complete.
|
|
2530
|
+
*/
|
|
2531
|
+
basicRenderWithScopeAsync(pScope, pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress, fCallback) {
|
|
2532
|
+
// Allow the callback to be passed in as the last parameter no matter what
|
|
2533
|
+
/** @type {ErrorCallback} */
|
|
2534
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : typeof pTemplateRecordAddress === 'function' ? pTemplateRecordAddress : typeof pRenderDestinationAddress === 'function' ? pRenderDestinationAddress : typeof pRenderableHash === 'function' ? pRenderableHash : null;
|
|
2535
|
+
if (!tmpCallback) {
|
|
2536
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " basicRenderAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
2537
|
+
tmpCallback = pError => {
|
|
2538
|
+
if (pError) {
|
|
2539
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " basicRenderAsync Auto Callback Error: ").concat(pError), pError);
|
|
2540
|
+
}
|
|
2541
|
+
};
|
|
2542
|
+
}
|
|
2543
|
+
const tmpRenderOptions = this.buildRenderOptions(pRenderableHash, pRenderDestinationAddress, pTemplateRecordAddress);
|
|
2544
|
+
if (tmpRenderOptions.Valid) {
|
|
2545
|
+
this.pict.parseTemplateByHash(tmpRenderOptions.Renderable.TemplateHash, tmpRenderOptions.Record,
|
|
2546
|
+
/**
|
|
2547
|
+
* @param {Error} [pError] - The error that occurred during template parsing.
|
|
2548
|
+
* @param {string} [pContent] - The content that was rendered from the template.
|
|
2549
|
+
*/
|
|
2550
|
+
(pError, pContent) => {
|
|
2551
|
+
if (pError) {
|
|
2552
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not render (asynchronously) ").concat(tmpRenderOptions.RenderableHash, " because it did not parse the template."), pError);
|
|
2553
|
+
return tmpCallback(pError);
|
|
2554
|
+
}
|
|
2555
|
+
this.assignRenderContent(tmpRenderOptions.Renderable, tmpRenderOptions.DestinationAddress, pContent);
|
|
2556
|
+
return tmpCallback();
|
|
2557
|
+
}, [this], pScope, {
|
|
2558
|
+
RootRenderable: tmpRenderOptions.Renderable
|
|
2559
|
+
});
|
|
2560
|
+
} else {
|
|
2561
|
+
let tmpErrorMessage = "PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " could not perform a basic render of ").concat(tmpRenderOptions.RenderableHash, " because it is not valid.");
|
|
2562
|
+
this.log.error(tmpErrorMessage);
|
|
2563
|
+
return tmpCallback(new Error(tmpErrorMessage));
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
/**
|
|
2568
|
+
* @param {Renderable} pRenderable - The renderable that was rendered.
|
|
2569
|
+
*/
|
|
2570
|
+
onProject(pRenderable) {
|
|
2571
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2572
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onProject:"));
|
|
2573
|
+
}
|
|
2574
|
+
if (pRenderable.RenderMethod === 'virtual-assignment') {
|
|
2575
|
+
this.pict.TransactionTracking.pushToTransactionQueue(pRenderable.TransactionHash, {
|
|
2576
|
+
ViewHash: this.Hash,
|
|
2577
|
+
Renderable: pRenderable
|
|
2578
|
+
}, 'Deferred-Post-Content-Assignment');
|
|
2579
|
+
}
|
|
2580
|
+
if (this.pict.LogNoisiness > 0) {
|
|
2581
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " Assigning Renderable[").concat(pRenderable.RenderableHash, "] content length ").concat(pRenderable.Content.length, " to Destination [").concat(pRenderable.ContentDestinationAddress, "] using Async render method ").concat(pRenderable.RenderMethod, "."));
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
// Assign the content to the destination address
|
|
2585
|
+
this.pict.ContentAssignment.projectContent(pRenderable.RenderMethod, pRenderable.ContentDestinationAddress, pRenderable.Content, pRenderable.TestAddress);
|
|
2586
|
+
this.lastRenderedTimestamp = this.pict.log.getTimeStamp();
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
/**
|
|
2590
|
+
* Lifecycle hook that triggers after the view is projected into the DOM (async flow).
|
|
2591
|
+
*
|
|
2592
|
+
* @param {(error?: Error, content?: string) => void} fCallback - The callback to call when the async operation is complete.
|
|
2593
|
+
* @param {Renderable} pRenderable - The renderable that is being projected.
|
|
2594
|
+
*/
|
|
2595
|
+
onProjectAsync(fCallback, pRenderable) {
|
|
2596
|
+
this.onProject(pRenderable);
|
|
2597
|
+
return fCallback();
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
/**
|
|
2601
|
+
* Lifecycle hook that triggers after the view is rendered.
|
|
2602
|
+
*
|
|
2603
|
+
* @param {Renderable} pRenderable - The renderable that was rendered.
|
|
2604
|
+
*/
|
|
2605
|
+
onAfterRender(pRenderable) {
|
|
2606
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2607
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterRender:"));
|
|
2608
|
+
}
|
|
2609
|
+
if (pRenderable && pRenderable.RootRenderableViewHash === this.Hash) {
|
|
2610
|
+
const tmpTransactionQueue = this.pict.TransactionTracking.clearTransactionQueue(pRenderable.TransactionHash) || [];
|
|
2611
|
+
for (const tmpEvent of tmpTransactionQueue) {
|
|
2612
|
+
const tmpView = this.pict.views[tmpEvent.Data.ViewHash];
|
|
2613
|
+
if (!tmpView) {
|
|
2614
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterRender: Could not find view for transaction hash ").concat(pRenderable.TransactionHash, " and ViewHash ").concat(tmpEvent.Data.ViewHash, "."));
|
|
2615
|
+
continue;
|
|
2616
|
+
}
|
|
2617
|
+
tmpView.onAfterProject();
|
|
2618
|
+
|
|
2619
|
+
// Execute the developer-overridable post-render behavior
|
|
2620
|
+
tmpView.onAfterRender(tmpEvent.Data.Renderable);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
return true;
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
/**
|
|
2627
|
+
* Lifecycle hook that triggers after the view is rendered (async flow).
|
|
2628
|
+
*
|
|
2629
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2630
|
+
* @param {Renderable} pRenderable - The renderable that was rendered.
|
|
2631
|
+
*/
|
|
2632
|
+
onAfterRenderAsync(fCallback, pRenderable) {
|
|
2633
|
+
this.onAfterRender(pRenderable);
|
|
2634
|
+
const tmpAnticipate = this.fable.newAnticipate();
|
|
2635
|
+
if (pRenderable && pRenderable.RootRenderableViewHash === this.Hash) {
|
|
2636
|
+
const queue = this.pict.TransactionTracking.clearTransactionQueue(pRenderable.TransactionHash) || [];
|
|
2637
|
+
for (const event of queue) {
|
|
2638
|
+
/** @type {PictView} */
|
|
2639
|
+
const tmpView = this.pict.views[event.Data.ViewHash];
|
|
2640
|
+
if (!tmpView) {
|
|
2641
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterRenderAsync: Could not find view for transaction hash ").concat(pRenderable.TransactionHash, " and ViewHash ").concat(event.Data.ViewHash, "."));
|
|
2642
|
+
continue;
|
|
2643
|
+
}
|
|
2644
|
+
tmpAnticipate.anticipate(tmpView.onAfterProjectAsync.bind(tmpView));
|
|
2645
|
+
tmpAnticipate.anticipate(fNext => {
|
|
2646
|
+
tmpView.onAfterRenderAsync(fNext, event.Data.Renderable);
|
|
2647
|
+
});
|
|
2648
|
+
|
|
2649
|
+
// Execute the developer-overridable post-render behavior
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
return tmpAnticipate.wait(fCallback);
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
/**
|
|
2656
|
+
* Lifecycle hook that triggers after the view is projected into the DOM.
|
|
2657
|
+
*
|
|
2658
|
+
* @param {Renderable} pRenderable - The renderable that was projected.
|
|
2659
|
+
*/
|
|
2660
|
+
onAfterProject(pRenderable) {
|
|
2661
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2662
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterProject:"));
|
|
2663
|
+
}
|
|
2664
|
+
return true;
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
/**
|
|
2668
|
+
* Lifecycle hook that triggers after the view is projected into the DOM (async flow).
|
|
2669
|
+
*
|
|
2670
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2671
|
+
* @param {Renderable} pRenderable - The renderable that was projected.
|
|
2672
|
+
*/
|
|
2673
|
+
onAfterProjectAsync(fCallback, pRenderable) {
|
|
2674
|
+
return fCallback();
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
/* -------------------------------------------------------------------------- */
|
|
2678
|
+
/* Code Section: Solver */
|
|
2679
|
+
/* -------------------------------------------------------------------------- */
|
|
2680
|
+
/**
|
|
2681
|
+
* Lifecycle hook that triggers before the view is solved.
|
|
2682
|
+
*/
|
|
2683
|
+
onBeforeSolve() {
|
|
2684
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2685
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onBeforeSolve:"));
|
|
2686
|
+
}
|
|
2687
|
+
return true;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* Lifecycle hook that triggers before the view is solved (async flow).
|
|
2692
|
+
*
|
|
2693
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2694
|
+
*/
|
|
2695
|
+
onBeforeSolveAsync(fCallback) {
|
|
2696
|
+
this.onBeforeSolve();
|
|
2697
|
+
return fCallback();
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
/**
|
|
2701
|
+
* Lifecycle hook that triggers when the view is solved.
|
|
2702
|
+
*/
|
|
2703
|
+
onSolve() {
|
|
2704
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2705
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onSolve:"));
|
|
2706
|
+
}
|
|
2707
|
+
return true;
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
/**
|
|
2711
|
+
* Lifecycle hook that triggers when the view is solved (async flow).
|
|
2712
|
+
*
|
|
2713
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2714
|
+
*/
|
|
2715
|
+
onSolveAsync(fCallback) {
|
|
2716
|
+
this.onSolve();
|
|
2717
|
+
return fCallback();
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
/**
|
|
2721
|
+
* Performs view solving and triggers lifecycle hooks.
|
|
2722
|
+
*
|
|
2723
|
+
* @return {boolean} - True if the view was solved successfully, false otherwise.
|
|
2724
|
+
*/
|
|
2725
|
+
solve() {
|
|
2726
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2727
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " executing solve() function..."));
|
|
2728
|
+
}
|
|
2729
|
+
this.onBeforeSolve();
|
|
2730
|
+
this.onSolve();
|
|
2731
|
+
this.onAfterSolve();
|
|
2732
|
+
this.lastSolvedTimestamp = this.pict.log.getTimeStamp();
|
|
2733
|
+
return true;
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
/**
|
|
2737
|
+
* Performs view solving and triggers lifecycle hooks (async flow).
|
|
2738
|
+
*
|
|
2739
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2740
|
+
*/
|
|
2741
|
+
solveAsync(fCallback) {
|
|
2742
|
+
let tmpAnticipate = this.pict.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
2743
|
+
|
|
2744
|
+
/** @type {ErrorCallback} */
|
|
2745
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : null;
|
|
2746
|
+
if (!tmpCallback) {
|
|
2747
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " solveAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
2748
|
+
tmpCallback = pError => {
|
|
2749
|
+
if (pError) {
|
|
2750
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " solveAsync Auto Callback Error: ").concat(pError), pError);
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
}
|
|
2754
|
+
tmpAnticipate.anticipate(this.onBeforeSolveAsync.bind(this));
|
|
2755
|
+
tmpAnticipate.anticipate(this.onSolveAsync.bind(this));
|
|
2756
|
+
tmpAnticipate.anticipate(this.onAfterSolveAsync.bind(this));
|
|
2757
|
+
tmpAnticipate.wait(pError => {
|
|
2758
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2759
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " solveAsync() complete."));
|
|
2760
|
+
}
|
|
2761
|
+
this.lastSolvedTimestamp = this.pict.log.getTimeStamp();
|
|
2762
|
+
return tmpCallback(pError);
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
/**
|
|
2767
|
+
* Lifecycle hook that triggers after the view is solved.
|
|
2768
|
+
*/
|
|
2769
|
+
onAfterSolve() {
|
|
2770
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2771
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterSolve:"));
|
|
2772
|
+
}
|
|
2773
|
+
return true;
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
/**
|
|
2777
|
+
* Lifecycle hook that triggers after the view is solved (async flow).
|
|
2778
|
+
*
|
|
2779
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2780
|
+
*/
|
|
2781
|
+
onAfterSolveAsync(fCallback) {
|
|
2782
|
+
this.onAfterSolve();
|
|
2783
|
+
return fCallback();
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
/* -------------------------------------------------------------------------- */
|
|
2787
|
+
/* Code Section: Marshal From View */
|
|
2788
|
+
/* -------------------------------------------------------------------------- */
|
|
2789
|
+
/**
|
|
2790
|
+
* Lifecycle hook that triggers before data is marshaled from the view.
|
|
2791
|
+
*
|
|
2792
|
+
* @return {boolean} - True if the operation was successful, false otherwise.
|
|
2793
|
+
*/
|
|
2794
|
+
onBeforeMarshalFromView() {
|
|
2795
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2796
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onBeforeMarshalFromView:"));
|
|
2797
|
+
}
|
|
2798
|
+
return true;
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
/**
|
|
2802
|
+
* Lifecycle hook that triggers before data is marshaled from the view (async flow).
|
|
2803
|
+
*
|
|
2804
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2805
|
+
*/
|
|
2806
|
+
onBeforeMarshalFromViewAsync(fCallback) {
|
|
2807
|
+
this.onBeforeMarshalFromView();
|
|
2808
|
+
return fCallback();
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
/**
|
|
2812
|
+
* Lifecycle hook that triggers when data is marshaled from the view.
|
|
2813
|
+
*/
|
|
2814
|
+
onMarshalFromView() {
|
|
2815
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2816
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onMarshalFromView:"));
|
|
2817
|
+
}
|
|
2818
|
+
return true;
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
/**
|
|
2822
|
+
* Lifecycle hook that triggers when data is marshaled from the view (async flow).
|
|
2823
|
+
*
|
|
2824
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2825
|
+
*/
|
|
2826
|
+
onMarshalFromViewAsync(fCallback) {
|
|
2827
|
+
this.onMarshalFromView();
|
|
2828
|
+
return fCallback();
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
/**
|
|
2832
|
+
* Marshals data from the view.
|
|
2833
|
+
*
|
|
2834
|
+
* @return {boolean} - True if the operation was successful, false otherwise.
|
|
2835
|
+
*/
|
|
2836
|
+
marshalFromView() {
|
|
2837
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2838
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " executing solve() function..."));
|
|
2839
|
+
}
|
|
2840
|
+
this.onBeforeMarshalFromView();
|
|
2841
|
+
this.onMarshalFromView();
|
|
2842
|
+
this.onAfterMarshalFromView();
|
|
2843
|
+
this.lastMarshalFromViewTimestamp = this.pict.log.getTimeStamp();
|
|
2844
|
+
return true;
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
/**
|
|
2848
|
+
* Marshals data from the view (async flow).
|
|
2849
|
+
*
|
|
2850
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2851
|
+
*/
|
|
2852
|
+
marshalFromViewAsync(fCallback) {
|
|
2853
|
+
let tmpAnticipate = this.pict.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
2854
|
+
|
|
2855
|
+
/** @type {ErrorCallback} */
|
|
2856
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : null;
|
|
2857
|
+
if (!tmpCallback) {
|
|
2858
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalFromViewAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
2859
|
+
tmpCallback = pError => {
|
|
2860
|
+
if (pError) {
|
|
2861
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalFromViewAsync Auto Callback Error: ").concat(pError), pError);
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
tmpAnticipate.anticipate(this.onBeforeMarshalFromViewAsync.bind(this));
|
|
2866
|
+
tmpAnticipate.anticipate(this.onMarshalFromViewAsync.bind(this));
|
|
2867
|
+
tmpAnticipate.anticipate(this.onAfterMarshalFromViewAsync.bind(this));
|
|
2868
|
+
tmpAnticipate.wait(pError => {
|
|
2869
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2870
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " marshalFromViewAsync() complete."));
|
|
2871
|
+
}
|
|
2872
|
+
this.lastMarshalFromViewTimestamp = this.pict.log.getTimeStamp();
|
|
2873
|
+
return tmpCallback(pError);
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
/**
|
|
2878
|
+
* Lifecycle hook that triggers after data is marshaled from the view.
|
|
2879
|
+
*/
|
|
2880
|
+
onAfterMarshalFromView() {
|
|
2881
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2882
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterMarshalFromView:"));
|
|
2883
|
+
}
|
|
2884
|
+
return true;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
/**
|
|
2888
|
+
* Lifecycle hook that triggers after data is marshaled from the view (async flow).
|
|
2889
|
+
*
|
|
2890
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2891
|
+
*/
|
|
2892
|
+
onAfterMarshalFromViewAsync(fCallback) {
|
|
2893
|
+
this.onAfterMarshalFromView();
|
|
2894
|
+
return fCallback();
|
|
2895
|
+
}
|
|
2896
|
+
|
|
2897
|
+
/* -------------------------------------------------------------------------- */
|
|
2898
|
+
/* Code Section: Marshal To View */
|
|
2899
|
+
/* -------------------------------------------------------------------------- */
|
|
2900
|
+
/**
|
|
2901
|
+
* Lifecycle hook that triggers before data is marshaled into the view.
|
|
2902
|
+
*/
|
|
2903
|
+
onBeforeMarshalToView() {
|
|
2904
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2905
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onBeforeMarshalToView:"));
|
|
2906
|
+
}
|
|
2907
|
+
return true;
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
/**
|
|
2911
|
+
* Lifecycle hook that triggers before data is marshaled into the view (async flow).
|
|
2912
|
+
*
|
|
2913
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2914
|
+
*/
|
|
2915
|
+
onBeforeMarshalToViewAsync(fCallback) {
|
|
2916
|
+
this.onBeforeMarshalToView();
|
|
2917
|
+
return fCallback();
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
/**
|
|
2921
|
+
* Lifecycle hook that triggers when data is marshaled into the view.
|
|
2922
|
+
*/
|
|
2923
|
+
onMarshalToView() {
|
|
2924
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2925
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onMarshalToView:"));
|
|
2926
|
+
}
|
|
2927
|
+
return true;
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
/**
|
|
2931
|
+
* Lifecycle hook that triggers when data is marshaled into the view (async flow).
|
|
2932
|
+
*
|
|
2933
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2934
|
+
*/
|
|
2935
|
+
onMarshalToViewAsync(fCallback) {
|
|
2936
|
+
this.onMarshalToView();
|
|
2937
|
+
return fCallback();
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
/**
|
|
2941
|
+
* Marshals data into the view.
|
|
2942
|
+
*
|
|
2943
|
+
* @return {boolean} - True if the operation was successful, false otherwise.
|
|
2944
|
+
*/
|
|
2945
|
+
marshalToView() {
|
|
2946
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2947
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " executing solve() function..."));
|
|
2948
|
+
}
|
|
2949
|
+
this.onBeforeMarshalToView();
|
|
2950
|
+
this.onMarshalToView();
|
|
2951
|
+
this.onAfterMarshalToView();
|
|
2952
|
+
this.lastMarshalToViewTimestamp = this.pict.log.getTimeStamp();
|
|
2953
|
+
return true;
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
/**
|
|
2957
|
+
* Marshals data into the view (async flow).
|
|
2958
|
+
*
|
|
2959
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
2960
|
+
*/
|
|
2961
|
+
marshalToViewAsync(fCallback) {
|
|
2962
|
+
let tmpAnticipate = this.pict.instantiateServiceProviderWithoutRegistration('Anticipate');
|
|
2963
|
+
|
|
2964
|
+
/** @type {ErrorCallback} */
|
|
2965
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : null;
|
|
2966
|
+
if (!tmpCallback) {
|
|
2967
|
+
this.log.warn("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalToViewAsync was called without a valid callback. A callback will be generated but this could lead to race conditions."));
|
|
2968
|
+
tmpCallback = pError => {
|
|
2969
|
+
if (pError) {
|
|
2970
|
+
this.log.error("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.Name, " marshalToViewAsync Auto Callback Error: ").concat(pError), pError);
|
|
2971
|
+
}
|
|
2972
|
+
};
|
|
2973
|
+
}
|
|
2974
|
+
tmpAnticipate.anticipate(this.onBeforeMarshalToViewAsync.bind(this));
|
|
2975
|
+
tmpAnticipate.anticipate(this.onMarshalToViewAsync.bind(this));
|
|
2976
|
+
tmpAnticipate.anticipate(this.onAfterMarshalToViewAsync.bind(this));
|
|
2977
|
+
tmpAnticipate.wait(pError => {
|
|
2978
|
+
if (this.pict.LogNoisiness > 2) {
|
|
2979
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " marshalToViewAsync() complete."));
|
|
2980
|
+
}
|
|
2981
|
+
this.lastMarshalToViewTimestamp = this.pict.log.getTimeStamp();
|
|
2982
|
+
return tmpCallback(pError);
|
|
2983
|
+
});
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2986
|
+
/**
|
|
2987
|
+
* Lifecycle hook that triggers after data is marshaled into the view.
|
|
2988
|
+
*/
|
|
2989
|
+
onAfterMarshalToView() {
|
|
2990
|
+
if (this.pict.LogNoisiness > 3) {
|
|
2991
|
+
this.log.trace("PictView [".concat(this.UUID, "]::[").concat(this.Hash, "] ").concat(this.options.ViewIdentifier, " onAfterMarshalToView:"));
|
|
2992
|
+
}
|
|
2993
|
+
return true;
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
/**
|
|
2997
|
+
* Lifecycle hook that triggers after data is marshaled into the view (async flow).
|
|
2998
|
+
*
|
|
2999
|
+
* @param {ErrorCallback} fCallback - The callback to call when the async operation is complete.
|
|
3000
|
+
*/
|
|
3001
|
+
onAfterMarshalToViewAsync(fCallback) {
|
|
3002
|
+
this.onAfterMarshalToView();
|
|
3003
|
+
return fCallback();
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
/** @return {boolean} - True if the object is a PictView. */
|
|
3007
|
+
get isPictView() {
|
|
3008
|
+
return true;
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
module.exports = PictView;
|
|
3012
|
+
}, {
|
|
3013
|
+
"../package.json": 7,
|
|
3014
|
+
"fable-serviceproviderbase": 2
|
|
3015
|
+
}],
|
|
3016
|
+
9: [function (require, module, exports) {
|
|
3017
|
+
module.exports = {
|
|
3018
|
+
"Name": "Pict Docuserve",
|
|
3019
|
+
"Hash": "Docuserve",
|
|
3020
|
+
"MainViewportViewIdentifier": "Docuserve-Layout",
|
|
3021
|
+
"AutoSolveAfterInitialize": true,
|
|
3022
|
+
"AutoRenderMainViewportViewAfterInitialize": false,
|
|
3023
|
+
"AutoRenderViewsAfterInitialize": false,
|
|
3024
|
+
"pict_configuration": {
|
|
3025
|
+
"Product": "Docuserve-Pict-Application"
|
|
3026
|
+
}
|
|
3027
|
+
};
|
|
3028
|
+
}, {}],
|
|
3029
|
+
10: [function (require, module, exports) {
|
|
3030
|
+
const libPictApplication = require('pict-application');
|
|
3031
|
+
|
|
3032
|
+
// Provider
|
|
3033
|
+
const libDocumentationProvider = require('./providers/Pict-Provider-Docuserve-Documentation.js');
|
|
3034
|
+
|
|
3035
|
+
// Views
|
|
3036
|
+
const libViewLayout = require('./views/PictView-Docuserve-Layout.js');
|
|
3037
|
+
const libViewTopBar = require('./views/PictView-Docuserve-TopBar.js');
|
|
3038
|
+
const libViewSidebar = require('./views/PictView-Docuserve-Sidebar.js');
|
|
3039
|
+
const libViewSplash = require('./views/PictView-Docuserve-Splash.js');
|
|
3040
|
+
const libViewContent = require('./views/PictView-Docuserve-Content.js');
|
|
3041
|
+
class DocuserveApplication extends libPictApplication {
|
|
3042
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
3043
|
+
super(pFable, pOptions, pServiceHash);
|
|
3044
|
+
|
|
3045
|
+
// Add the documentation provider
|
|
3046
|
+
this.pict.addProvider('Docuserve-Documentation', libDocumentationProvider.default_configuration, libDocumentationProvider);
|
|
3047
|
+
|
|
3048
|
+
// Add views
|
|
3049
|
+
this.pict.addView('Docuserve-Layout', libViewLayout.default_configuration, libViewLayout);
|
|
3050
|
+
this.pict.addView('Docuserve-TopBar', libViewTopBar.default_configuration, libViewTopBar);
|
|
3051
|
+
this.pict.addView('Docuserve-Sidebar', libViewSidebar.default_configuration, libViewSidebar);
|
|
3052
|
+
this.pict.addView('Docuserve-Splash', libViewSplash.default_configuration, libViewSplash);
|
|
3053
|
+
this.pict.addView('Docuserve-Content', libViewContent.default_configuration, libViewContent);
|
|
3054
|
+
}
|
|
3055
|
+
onAfterInitializeAsync(fCallback) {
|
|
3056
|
+
// Initialize application state
|
|
3057
|
+
this.pict.AppData.Docuserve = {
|
|
3058
|
+
CatalogLoaded: false,
|
|
3059
|
+
Catalog: null,
|
|
3060
|
+
CoverLoaded: false,
|
|
3061
|
+
Cover: null,
|
|
3062
|
+
SidebarLoaded: false,
|
|
3063
|
+
SidebarGroups: [],
|
|
3064
|
+
TopBarLoaded: false,
|
|
3065
|
+
TopBar: null,
|
|
3066
|
+
ErrorPageLoaded: false,
|
|
3067
|
+
ErrorPageHTML: null,
|
|
3068
|
+
CurrentGroup: '',
|
|
3069
|
+
CurrentModule: '',
|
|
3070
|
+
CurrentPath: '',
|
|
3071
|
+
// Whether the sidebar is currently visible
|
|
3072
|
+
SidebarVisible: true,
|
|
3073
|
+
// Base URL for local docs (relative to where the app is served)
|
|
3074
|
+
DocsBaseURL: '',
|
|
3075
|
+
// URL for the catalog JSON
|
|
3076
|
+
CatalogURL: 'retold-catalog.json'
|
|
3077
|
+
};
|
|
3078
|
+
|
|
3079
|
+
// Load the catalog, then render the layout
|
|
3080
|
+
let tmpDocProvider = this.pict.providers['Docuserve-Documentation'];
|
|
3081
|
+
tmpDocProvider.loadCatalog(() => {
|
|
3082
|
+
// Render the layout shell, which triggers child view rendering
|
|
3083
|
+
this.pict.views['Docuserve-Layout'].render();
|
|
3084
|
+
return super.onAfterInitializeAsync(fCallback);
|
|
3085
|
+
});
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
/**
|
|
3089
|
+
* Read the current window.location.hash and dispatch to the correct handler.
|
|
3090
|
+
*
|
|
3091
|
+
* Route patterns:
|
|
3092
|
+
* #/Home -> showView('Docuserve-Splash')
|
|
3093
|
+
* #/page/<docpath> -> navigateToPage(docpath)
|
|
3094
|
+
* #/doc/<group>/<module> -> navigateToModule(group, module)
|
|
3095
|
+
* #/doc/<group>/<module>/<path> -> navigateToModulePath(group, module, path)
|
|
3096
|
+
*/
|
|
3097
|
+
resolveHash() {
|
|
3098
|
+
let tmpHash = (window.location.hash || '').replace(/^#\/?/, '');
|
|
3099
|
+
if (!tmpHash || tmpHash === 'Home') {
|
|
3100
|
+
this.showView('Docuserve-Splash');
|
|
3101
|
+
return;
|
|
3102
|
+
}
|
|
3103
|
+
let tmpParts = tmpHash.split('/');
|
|
3104
|
+
if (tmpParts[0] === 'page' && tmpParts.length >= 2) {
|
|
3105
|
+
// Rejoin everything after 'page/' in case the path has slashes
|
|
3106
|
+
let tmpDocPath = tmpParts.slice(1).join('/');
|
|
3107
|
+
this.navigateToPage(tmpDocPath);
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3110
|
+
if (tmpParts[0] === 'doc' && tmpParts.length >= 3) {
|
|
3111
|
+
let tmpGroup = tmpParts[1];
|
|
3112
|
+
let tmpModule = tmpParts[2];
|
|
3113
|
+
if (tmpParts.length >= 4) {
|
|
3114
|
+
let tmpPath = tmpParts.slice(3).join('/');
|
|
3115
|
+
this.navigateToModulePath(tmpGroup, tmpModule, tmpPath);
|
|
3116
|
+
} else {
|
|
3117
|
+
this.navigateToModule(tmpGroup, tmpModule);
|
|
3118
|
+
}
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
// Unknown route — treat as a page
|
|
3123
|
+
this.navigateToPage(tmpHash);
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
/**
|
|
3127
|
+
* Navigate to a hash route.
|
|
3128
|
+
*
|
|
3129
|
+
* Sets window.location.hash, which triggers the hashchange listener in the
|
|
3130
|
+
* layout view, which calls resolveHash() automatically.
|
|
3131
|
+
*
|
|
3132
|
+
* @param {string} pRoute - The route path (e.g. '/Home', '/page/quick-start')
|
|
3133
|
+
*/
|
|
3134
|
+
navigateTo(pRoute) {
|
|
3135
|
+
window.location.hash = pRoute;
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
/**
|
|
3139
|
+
* Show a specific view in the content area.
|
|
3140
|
+
*
|
|
3141
|
+
* @param {string} pViewIdentifier - The view identifier to render
|
|
3142
|
+
*/
|
|
3143
|
+
showView(pViewIdentifier) {
|
|
3144
|
+
if (pViewIdentifier in this.pict.views) {
|
|
3145
|
+
this.pict.AppData.Docuserve.CurrentGroup = '';
|
|
3146
|
+
this.pict.AppData.Docuserve.CurrentModule = '';
|
|
3147
|
+
this.pict.AppData.Docuserve.CurrentPath = '';
|
|
3148
|
+
this.pict.views[pViewIdentifier].render();
|
|
3149
|
+
|
|
3150
|
+
// Update sidebar to clear module nav and refresh active states
|
|
3151
|
+
this.pict.views['Docuserve-Sidebar'].clearModuleNav();
|
|
3152
|
+
this.pict.views['Docuserve-Sidebar'].renderSidebarGroups();
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
/**
|
|
3157
|
+
* Navigate to a module's documentation.
|
|
3158
|
+
*
|
|
3159
|
+
* @param {string} pGroup - The group key
|
|
3160
|
+
* @param {string} pModule - The module name
|
|
3161
|
+
*/
|
|
3162
|
+
navigateToModule(pGroup, pModule) {
|
|
3163
|
+
this.navigateToModulePath(pGroup, pModule, 'README.md');
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
/**
|
|
3167
|
+
* Navigate to a specific path within a module's documentation.
|
|
3168
|
+
*
|
|
3169
|
+
* @param {string} pGroup - The group key
|
|
3170
|
+
* @param {string} pModule - The module name
|
|
3171
|
+
* @param {string} pPath - The document path
|
|
3172
|
+
*/
|
|
3173
|
+
navigateToModulePath(pGroup, pModule, pPath) {
|
|
3174
|
+
let tmpDocProvider = this.pict.providers['Docuserve-Documentation'];
|
|
3175
|
+
let tmpContentView = this.pict.views['Docuserve-Content'];
|
|
3176
|
+
let tmpSidebarView = this.pict.views['Docuserve-Sidebar'];
|
|
3177
|
+
|
|
3178
|
+
// Update current navigation state
|
|
3179
|
+
this.pict.AppData.Docuserve.CurrentGroup = pGroup;
|
|
3180
|
+
this.pict.AppData.Docuserve.CurrentModule = pModule;
|
|
3181
|
+
this.pict.AppData.Docuserve.CurrentPath = pPath;
|
|
3182
|
+
|
|
3183
|
+
// Render the content view shell and show loading
|
|
3184
|
+
tmpContentView.render();
|
|
3185
|
+
tmpContentView.showLoading();
|
|
3186
|
+
|
|
3187
|
+
// Update sidebar to show active module and module-specific nav
|
|
3188
|
+
tmpSidebarView.renderSidebarGroups();
|
|
3189
|
+
tmpSidebarView.renderModuleNav(pGroup, pModule);
|
|
3190
|
+
|
|
3191
|
+
// Resolve the document URL and fetch it
|
|
3192
|
+
let tmpURL = tmpDocProvider.resolveDocumentURL(pGroup, pModule, pPath || 'README.md');
|
|
3193
|
+
if (!tmpURL) {
|
|
3194
|
+
tmpContentView.displayContent(tmpDocProvider.getErrorPageHTML(pGroup + '/' + pModule));
|
|
3195
|
+
return;
|
|
3196
|
+
}
|
|
3197
|
+
tmpDocProvider.fetchDocument(tmpURL, (pError, pHTML) => {
|
|
3198
|
+
// fetchDocument always provides displayable HTML in pHTML,
|
|
3199
|
+
// even on error, so we can use it directly.
|
|
3200
|
+
tmpContentView.displayContent(pHTML);
|
|
3201
|
+
});
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
/**
|
|
3205
|
+
* Navigate to a local documentation page (e.g. architecture.md).
|
|
3206
|
+
*
|
|
3207
|
+
* @param {string} pDocPath - The doc path without extension
|
|
3208
|
+
*/
|
|
3209
|
+
navigateToPage(pDocPath) {
|
|
3210
|
+
let tmpDocProvider = this.pict.providers['Docuserve-Documentation'];
|
|
3211
|
+
let tmpContentView = this.pict.views['Docuserve-Content'];
|
|
3212
|
+
let tmpSidebarView = this.pict.views['Docuserve-Sidebar'];
|
|
3213
|
+
|
|
3214
|
+
// Update state
|
|
3215
|
+
this.pict.AppData.Docuserve.CurrentGroup = '';
|
|
3216
|
+
this.pict.AppData.Docuserve.CurrentModule = '';
|
|
3217
|
+
this.pict.AppData.Docuserve.CurrentPath = pDocPath;
|
|
3218
|
+
|
|
3219
|
+
// Render the content view shell and show loading
|
|
3220
|
+
tmpContentView.render();
|
|
3221
|
+
tmpContentView.showLoading();
|
|
3222
|
+
|
|
3223
|
+
// Clear module-specific sidebar nav
|
|
3224
|
+
tmpSidebarView.clearModuleNav();
|
|
3225
|
+
tmpSidebarView.renderSidebarGroups();
|
|
3226
|
+
|
|
3227
|
+
// Fetch the local document
|
|
3228
|
+
let tmpPath = pDocPath;
|
|
3229
|
+
if (!tmpPath.match(/\.md$/)) {
|
|
3230
|
+
tmpPath = tmpPath + '.md';
|
|
3231
|
+
}
|
|
3232
|
+
tmpDocProvider.fetchLocalDocument(tmpPath, (pError, pHTML) => {
|
|
3233
|
+
// fetchDocument always provides displayable HTML in pHTML,
|
|
3234
|
+
// even on error, so we can use it directly.
|
|
3235
|
+
tmpContentView.displayContent(pHTML);
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
module.exports = DocuserveApplication;
|
|
3240
|
+
module.exports.default_configuration = require('./Pict-Application-Docuserve-Configuration.json');
|
|
3241
|
+
}, {
|
|
3242
|
+
"./Pict-Application-Docuserve-Configuration.json": 9,
|
|
3243
|
+
"./providers/Pict-Provider-Docuserve-Documentation.js": 11,
|
|
3244
|
+
"./views/PictView-Docuserve-Content.js": 12,
|
|
3245
|
+
"./views/PictView-Docuserve-Layout.js": 13,
|
|
3246
|
+
"./views/PictView-Docuserve-Sidebar.js": 14,
|
|
3247
|
+
"./views/PictView-Docuserve-Splash.js": 15,
|
|
3248
|
+
"./views/PictView-Docuserve-TopBar.js": 16,
|
|
3249
|
+
"pict-application": 4
|
|
3250
|
+
}],
|
|
3251
|
+
11: [function (require, module, exports) {
|
|
3252
|
+
const libPictProvider = require('pict-provider');
|
|
3253
|
+
|
|
3254
|
+
/**
|
|
3255
|
+
* Documentation Provider for Docuserve
|
|
3256
|
+
*
|
|
3257
|
+
* Loads the Indoctrinate-generated catalog and keyword index,
|
|
3258
|
+
* fetches markdown documents from local paths or raw GitHub URLs,
|
|
3259
|
+
* and parses them into HTML for rendering.
|
|
3260
|
+
*/
|
|
3261
|
+
class DocuserveDocumentationProvider extends libPictProvider {
|
|
3262
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
3263
|
+
super(pFable, pOptions, pServiceHash);
|
|
3264
|
+
this._Catalog = null;
|
|
3265
|
+
this._ContentCache = {};
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
/**
|
|
3269
|
+
* Load all documentation data sources: catalog, cover.md, _sidebar.md.
|
|
3270
|
+
*
|
|
3271
|
+
* Loads the catalog first (it provides the fallback data), then attempts
|
|
3272
|
+
* to load cover.md and _sidebar.md in parallel. If those markdown files
|
|
3273
|
+
* exist they drive the splash and sidebar views; otherwise the catalog
|
|
3274
|
+
* data is used as a fallback.
|
|
3275
|
+
*
|
|
3276
|
+
* @param {Function} fCallback - Callback when all loading is complete
|
|
3277
|
+
*/
|
|
3278
|
+
loadCatalog(fCallback) {
|
|
3279
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : () => {};
|
|
3280
|
+
let tmpCatalogURL = this.pict.AppData.Docuserve.CatalogURL || 'retold-catalog.json';
|
|
3281
|
+
fetch(tmpCatalogURL).then(pResponse => {
|
|
3282
|
+
if (!pResponse.ok) {
|
|
3283
|
+
this.log.warn("Docuserve: Could not load catalog from [".concat(tmpCatalogURL, "]."));
|
|
3284
|
+
return null;
|
|
3285
|
+
}
|
|
3286
|
+
return pResponse.json();
|
|
3287
|
+
}).then(pCatalog => {
|
|
3288
|
+
if (pCatalog) {
|
|
3289
|
+
this._Catalog = pCatalog;
|
|
3290
|
+
this.pict.AppData.Docuserve.Catalog = pCatalog;
|
|
3291
|
+
this.pict.AppData.Docuserve.CatalogLoaded = true;
|
|
3292
|
+
|
|
3293
|
+
// Build sidebar navigation data from the catalog as default
|
|
3294
|
+
this.buildSidebarData(pCatalog);
|
|
3295
|
+
}
|
|
3296
|
+
|
|
3297
|
+
// Now try to load cover.md, _sidebar.md, _topbar.md, and errorpage.md in parallel
|
|
3298
|
+
let tmpPending = 4;
|
|
3299
|
+
let tmpFinish = () => {
|
|
3300
|
+
tmpPending--;
|
|
3301
|
+
if (tmpPending <= 0) {
|
|
3302
|
+
return tmpCallback();
|
|
3303
|
+
}
|
|
3304
|
+
};
|
|
3305
|
+
this.loadCover(tmpFinish);
|
|
3306
|
+
this.loadSidebar(tmpFinish);
|
|
3307
|
+
this.loadTopbar(tmpFinish);
|
|
3308
|
+
this.loadErrorPage(tmpFinish);
|
|
3309
|
+
}).catch(pError => {
|
|
3310
|
+
this.log.warn("Docuserve: Error loading catalog: ".concat(pError));
|
|
3311
|
+
return tmpCallback();
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
/**
|
|
3316
|
+
* Fetch and parse cover.md into structured data for the splash view.
|
|
3317
|
+
*
|
|
3318
|
+
* The expected cover.md format follows the docsify convention:
|
|
3319
|
+
* # Title
|
|
3320
|
+
* > Tagline
|
|
3321
|
+
* Description paragraph text.
|
|
3322
|
+
* - **Group** — description
|
|
3323
|
+
* [Link Text](url)
|
|
3324
|
+
*
|
|
3325
|
+
* Parsed result stored in this.pict.AppData.Docuserve.Cover:
|
|
3326
|
+
* { Title, Tagline, Description, Highlights: [{Label, Text}], Actions: [{Text, Href}] }
|
|
3327
|
+
*
|
|
3328
|
+
* @param {Function} fCallback - Callback when done
|
|
3329
|
+
*/
|
|
3330
|
+
loadCover(fCallback) {
|
|
3331
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : () => {};
|
|
3332
|
+
let tmpDocsBase = this.pict.AppData.Docuserve.DocsBaseURL || '';
|
|
3333
|
+
fetch(tmpDocsBase + 'cover.md').then(pResponse => {
|
|
3334
|
+
if (!pResponse.ok) {
|
|
3335
|
+
return null;
|
|
3336
|
+
}
|
|
3337
|
+
return pResponse.text();
|
|
3338
|
+
}).then(pMarkdown => {
|
|
3339
|
+
if (!pMarkdown) {
|
|
3340
|
+
this.log.info('Docuserve: No cover.md found; splash will use catalog data.');
|
|
3341
|
+
return tmpCallback();
|
|
3342
|
+
}
|
|
3343
|
+
this.pict.AppData.Docuserve.Cover = this.parseCover(pMarkdown);
|
|
3344
|
+
this.pict.AppData.Docuserve.CoverLoaded = true;
|
|
3345
|
+
return tmpCallback();
|
|
3346
|
+
}).catch(pError => {
|
|
3347
|
+
this.log.warn("Docuserve: Error loading cover.md: ".concat(pError));
|
|
3348
|
+
return tmpCallback();
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3352
|
+
/**
|
|
3353
|
+
* Parse cover.md markdown text into a structured object.
|
|
3354
|
+
*
|
|
3355
|
+
* @param {string} pMarkdown - Raw cover.md content
|
|
3356
|
+
* @returns {Object} Parsed cover data
|
|
3357
|
+
*/
|
|
3358
|
+
parseCover(pMarkdown) {
|
|
3359
|
+
let tmpCover = {
|
|
3360
|
+
Title: '',
|
|
3361
|
+
Tagline: '',
|
|
3362
|
+
Description: '',
|
|
3363
|
+
Highlights: [],
|
|
3364
|
+
Actions: []
|
|
3365
|
+
};
|
|
3366
|
+
let tmpLines = pMarkdown.split('\n');
|
|
3367
|
+
for (let i = 0; i < tmpLines.length; i++) {
|
|
3368
|
+
let tmpLine = tmpLines[i].trim();
|
|
3369
|
+
if (!tmpLine) {
|
|
3370
|
+
continue;
|
|
3371
|
+
}
|
|
3372
|
+
|
|
3373
|
+
// Heading — the title
|
|
3374
|
+
let tmpHeadingMatch = tmpLine.match(/^#+\s+(.+)/);
|
|
3375
|
+
if (tmpHeadingMatch) {
|
|
3376
|
+
tmpCover.Title = tmpHeadingMatch[1].trim();
|
|
3377
|
+
continue;
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
// Blockquote — the tagline
|
|
3381
|
+
let tmpBlockquoteMatch = tmpLine.match(/^>\s*(.*)/);
|
|
3382
|
+
if (tmpBlockquoteMatch) {
|
|
3383
|
+
tmpCover.Tagline = tmpBlockquoteMatch[1].trim();
|
|
3384
|
+
continue;
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
// Bullet list — highlights (e.g. "- **Fable** — Core ecosystem, DI, config")
|
|
3388
|
+
let tmpBulletMatch = tmpLine.match(/^[-*+]\s+(.*)/);
|
|
3389
|
+
if (tmpBulletMatch) {
|
|
3390
|
+
let tmpBulletContent = tmpBulletMatch[1];
|
|
3391
|
+
// Try to split on bold label: **Label** — rest
|
|
3392
|
+
let tmpLabelMatch = tmpBulletContent.match(/^\*\*([^*]+)\*\*\s*[-—:]\s*(.*)/);
|
|
3393
|
+
if (tmpLabelMatch) {
|
|
3394
|
+
tmpCover.Highlights.push({
|
|
3395
|
+
Label: tmpLabelMatch[1].trim(),
|
|
3396
|
+
Text: tmpLabelMatch[2].trim()
|
|
3397
|
+
});
|
|
3398
|
+
} else {
|
|
3399
|
+
tmpCover.Highlights.push({
|
|
3400
|
+
Label: '',
|
|
3401
|
+
Text: tmpBulletContent.trim()
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
3404
|
+
continue;
|
|
3405
|
+
}
|
|
3406
|
+
|
|
3407
|
+
// Bare link — action button (e.g. "[Get Started](getting-started.md)")
|
|
3408
|
+
let tmpLinkMatch = tmpLine.match(/^\[([^\]]+)\]\(([^)]+)\)\s*$/);
|
|
3409
|
+
if (tmpLinkMatch) {
|
|
3410
|
+
tmpCover.Actions.push({
|
|
3411
|
+
Text: tmpLinkMatch[1].trim(),
|
|
3412
|
+
Href: tmpLinkMatch[2].trim()
|
|
3413
|
+
});
|
|
3414
|
+
continue;
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
// Otherwise it's description text
|
|
3418
|
+
if (!tmpCover.Description) {
|
|
3419
|
+
tmpCover.Description = tmpLine;
|
|
3420
|
+
} else {
|
|
3421
|
+
tmpCover.Description += ' ' + tmpLine;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
return tmpCover;
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
/**
|
|
3428
|
+
* Fetch and parse _sidebar.md into structured navigation data.
|
|
3429
|
+
*
|
|
3430
|
+
* The expected _sidebar.md format follows the docsify convention:
|
|
3431
|
+
* - [Home](/)
|
|
3432
|
+
* - Group Title
|
|
3433
|
+
* - [module-name](/group/module/)
|
|
3434
|
+
* - [Group Title](group.md)
|
|
3435
|
+
* - [module-name](/group/module/)
|
|
3436
|
+
*
|
|
3437
|
+
* If _sidebar.md is successfully loaded and parsed, its data replaces
|
|
3438
|
+
* the catalog-inferred SidebarGroups in AppData.
|
|
3439
|
+
*
|
|
3440
|
+
* @param {Function} fCallback - Callback when done
|
|
3441
|
+
*/
|
|
3442
|
+
loadSidebar(fCallback) {
|
|
3443
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : () => {};
|
|
3444
|
+
let tmpDocsBase = this.pict.AppData.Docuserve.DocsBaseURL || '';
|
|
3445
|
+
fetch(tmpDocsBase + '_sidebar.md').then(pResponse => {
|
|
3446
|
+
if (!pResponse.ok) {
|
|
3447
|
+
return null;
|
|
3448
|
+
}
|
|
3449
|
+
return pResponse.text();
|
|
3450
|
+
}).then(pMarkdown => {
|
|
3451
|
+
if (!pMarkdown) {
|
|
3452
|
+
this.log.info('Docuserve: No _sidebar.md found; sidebar will use catalog data.');
|
|
3453
|
+
return tmpCallback();
|
|
3454
|
+
}
|
|
3455
|
+
let tmpSidebarData = this.parseSidebarMarkdown(pMarkdown);
|
|
3456
|
+
if (tmpSidebarData && tmpSidebarData.length > 0) {
|
|
3457
|
+
this.pict.AppData.Docuserve.SidebarGroups = tmpSidebarData;
|
|
3458
|
+
this.pict.AppData.Docuserve.SidebarLoaded = true;
|
|
3459
|
+
}
|
|
3460
|
+
return tmpCallback();
|
|
3461
|
+
}).catch(pError => {
|
|
3462
|
+
this.log.warn("Docuserve: Error loading _sidebar.md: ".concat(pError));
|
|
3463
|
+
return tmpCallback();
|
|
3464
|
+
});
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
/**
|
|
3468
|
+
* Fetch and parse _topbar.md into structured data for the top bar view.
|
|
3469
|
+
*
|
|
3470
|
+
* The expected _topbar.md format:
|
|
3471
|
+
* # Brand Name
|
|
3472
|
+
* - [Link Text](url)
|
|
3473
|
+
* - [Link Text](url)
|
|
3474
|
+
*
|
|
3475
|
+
* The heading becomes the brand/title shown on the left. List items become
|
|
3476
|
+
* navigation links. External links (starting with http) render on the
|
|
3477
|
+
* right side; internal links render in the centre nav area.
|
|
3478
|
+
*
|
|
3479
|
+
* Parsed result stored in this.pict.AppData.Docuserve.TopBar:
|
|
3480
|
+
* { Brand, NavLinks: [{Text, Href, External}], ExternalLinks: [{Text, Href}] }
|
|
3481
|
+
*
|
|
3482
|
+
* @param {Function} fCallback - Callback when done
|
|
3483
|
+
*/
|
|
3484
|
+
loadTopbar(fCallback) {
|
|
3485
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : () => {};
|
|
3486
|
+
let tmpDocsBase = this.pict.AppData.Docuserve.DocsBaseURL || '';
|
|
3487
|
+
fetch(tmpDocsBase + '_topbar.md').then(pResponse => {
|
|
3488
|
+
if (!pResponse.ok) {
|
|
3489
|
+
return null;
|
|
3490
|
+
}
|
|
3491
|
+
return pResponse.text();
|
|
3492
|
+
}).then(pMarkdown => {
|
|
3493
|
+
if (!pMarkdown) {
|
|
3494
|
+
this.log.info('Docuserve: No _topbar.md found; top bar will use defaults.');
|
|
3495
|
+
return tmpCallback();
|
|
3496
|
+
}
|
|
3497
|
+
this.pict.AppData.Docuserve.TopBar = this.parseTopbar(pMarkdown);
|
|
3498
|
+
this.pict.AppData.Docuserve.TopBarLoaded = true;
|
|
3499
|
+
return tmpCallback();
|
|
3500
|
+
}).catch(pError => {
|
|
3501
|
+
this.log.warn("Docuserve: Error loading _topbar.md: ".concat(pError));
|
|
3502
|
+
return tmpCallback();
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
|
|
3506
|
+
/**
|
|
3507
|
+
* Parse _topbar.md markdown text into a structured object.
|
|
3508
|
+
*
|
|
3509
|
+
* @param {string} pMarkdown - Raw _topbar.md content
|
|
3510
|
+
* @returns {Object} Parsed top bar data { Brand, NavLinks, ExternalLinks }
|
|
3511
|
+
*/
|
|
3512
|
+
parseTopbar(pMarkdown) {
|
|
3513
|
+
let tmpTopBar = {
|
|
3514
|
+
Brand: '',
|
|
3515
|
+
NavLinks: [],
|
|
3516
|
+
ExternalLinks: []
|
|
3517
|
+
};
|
|
3518
|
+
let tmpLines = pMarkdown.split('\n');
|
|
3519
|
+
for (let i = 0; i < tmpLines.length; i++) {
|
|
3520
|
+
let tmpLine = tmpLines[i].trim();
|
|
3521
|
+
if (!tmpLine) {
|
|
3522
|
+
continue;
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
// Heading — the brand name
|
|
3526
|
+
let tmpHeadingMatch = tmpLine.match(/^#+\s+(.+)/);
|
|
3527
|
+
if (tmpHeadingMatch) {
|
|
3528
|
+
tmpTopBar.Brand = tmpHeadingMatch[1].trim();
|
|
3529
|
+
continue;
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
// Bullet list item with link
|
|
3533
|
+
let tmpBulletMatch = tmpLine.match(/^[-*+]\s+(.*)/);
|
|
3534
|
+
if (tmpBulletMatch) {
|
|
3535
|
+
let tmpContent = tmpBulletMatch[1].trim();
|
|
3536
|
+
let tmpLinkMatch = tmpContent.match(/^\[([^\]]+)\]\(([^)]+)\)/);
|
|
3537
|
+
if (tmpLinkMatch) {
|
|
3538
|
+
let tmpText = tmpLinkMatch[1].trim();
|
|
3539
|
+
let tmpHref = tmpLinkMatch[2].trim();
|
|
3540
|
+
|
|
3541
|
+
// External links (http/https) go to the right side
|
|
3542
|
+
if (tmpHref.match(/^https?:\/\//)) {
|
|
3543
|
+
tmpTopBar.ExternalLinks.push({
|
|
3544
|
+
Text: tmpText,
|
|
3545
|
+
Href: tmpHref
|
|
3546
|
+
});
|
|
3547
|
+
} else {
|
|
3548
|
+
// Internal link — convert to hash route
|
|
3549
|
+
let tmpRoute = this.convertSidebarLink(tmpHref);
|
|
3550
|
+
tmpTopBar.NavLinks.push({
|
|
3551
|
+
Text: tmpText,
|
|
3552
|
+
Href: tmpRoute
|
|
3553
|
+
});
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
continue;
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
return tmpTopBar;
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3562
|
+
/**
|
|
3563
|
+
* Fetch and parse errorpage.md into HTML for use as a custom error page.
|
|
3564
|
+
*
|
|
3565
|
+
* The errorpage.md is a standard markdown file. If it contains the
|
|
3566
|
+
* placeholder `{{path}}` anywhere in its source, that token will be
|
|
3567
|
+
* replaced with the actual requested path at display time (via
|
|
3568
|
+
* getErrorPageHTML).
|
|
3569
|
+
*
|
|
3570
|
+
* @param {Function} fCallback - Callback when done
|
|
3571
|
+
*/
|
|
3572
|
+
loadErrorPage(fCallback) {
|
|
3573
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : () => {};
|
|
3574
|
+
let tmpDocsBase = this.pict.AppData.Docuserve.DocsBaseURL || '';
|
|
3575
|
+
fetch(tmpDocsBase + 'errorpage.md').then(pResponse => {
|
|
3576
|
+
if (!pResponse.ok) {
|
|
3577
|
+
return null;
|
|
3578
|
+
}
|
|
3579
|
+
return pResponse.text();
|
|
3580
|
+
}).then(pMarkdown => {
|
|
3581
|
+
if (!pMarkdown) {
|
|
3582
|
+
this.log.info('Docuserve: No errorpage.md found; errors will use default page.');
|
|
3583
|
+
return tmpCallback();
|
|
3584
|
+
}
|
|
3585
|
+
this.pict.AppData.Docuserve.ErrorPageHTML = this.parseMarkdown(pMarkdown);
|
|
3586
|
+
this.pict.AppData.Docuserve.ErrorPageLoaded = true;
|
|
3587
|
+
return tmpCallback();
|
|
3588
|
+
}).catch(pError => {
|
|
3589
|
+
this.log.warn("Docuserve: Error loading errorpage.md: ".concat(pError));
|
|
3590
|
+
return tmpCallback();
|
|
3591
|
+
});
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
/**
|
|
3595
|
+
* Get the error page HTML for a given requested path.
|
|
3596
|
+
*
|
|
3597
|
+
* If a custom errorpage.md was loaded, its parsed HTML is returned with
|
|
3598
|
+
* the `{{path}}` placeholder replaced by the actual requested path.
|
|
3599
|
+
* Otherwise a default not-found HTML block is returned.
|
|
3600
|
+
*
|
|
3601
|
+
* @param {string} pRequestedPath - The path that was not found
|
|
3602
|
+
* @returns {string} HTML to display
|
|
3603
|
+
*/
|
|
3604
|
+
getErrorPageHTML(pRequestedPath) {
|
|
3605
|
+
let tmpPath = pRequestedPath || 'unknown';
|
|
3606
|
+
if (this.pict.AppData.Docuserve.ErrorPageLoaded && this.pict.AppData.Docuserve.ErrorPageHTML) {
|
|
3607
|
+
// Replace the {{path}} placeholder with the actual requested path
|
|
3608
|
+
return this.pict.AppData.Docuserve.ErrorPageHTML.replace(/\{\{path\}\}/g, this.escapeHTML(tmpPath));
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
// Default fallback
|
|
3612
|
+
return '<div class="docuserve-not-found">' + '<h2>Page Not Found</h2>' + '<p>The document <code>' + this.escapeHTML(tmpPath) + '</code> could not be loaded.</p>' + '<p><a href="#/Home">Return to the home page</a></p>' + '</div>';
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
/**
|
|
3616
|
+
* Parse _sidebar.md into the SidebarGroups format the sidebar view consumes.
|
|
3617
|
+
*
|
|
3618
|
+
* Returns an array of group objects:
|
|
3619
|
+
* [{ Name, Key, Route, Modules: [{ Name, HasDocs, Group, Route }] }]
|
|
3620
|
+
*
|
|
3621
|
+
* Top-level items (no indent) become groups. Indented child items become
|
|
3622
|
+
* modules within the preceding group. The special "Home" entry is stored
|
|
3623
|
+
* as a group with no modules.
|
|
3624
|
+
*
|
|
3625
|
+
* @param {string} pMarkdown - Raw _sidebar.md content
|
|
3626
|
+
* @returns {Array} Parsed sidebar groups
|
|
3627
|
+
*/
|
|
3628
|
+
parseSidebarMarkdown(pMarkdown) {
|
|
3629
|
+
let tmpGroups = [];
|
|
3630
|
+
let tmpCurrentGroup = null;
|
|
3631
|
+
let tmpLines = pMarkdown.split('\n');
|
|
3632
|
+
for (let i = 0; i < tmpLines.length; i++) {
|
|
3633
|
+
let tmpLine = tmpLines[i];
|
|
3634
|
+
if (!tmpLine.trim()) {
|
|
3635
|
+
continue;
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
// Detect indent level: child items have 2+ leading spaces
|
|
3639
|
+
let tmpIndentMatch = tmpLine.match(/^(\s*)/);
|
|
3640
|
+
let tmpIndent = tmpIndentMatch ? tmpIndentMatch[1].length : 0;
|
|
3641
|
+
let tmpContent = tmpLine.trim();
|
|
3642
|
+
|
|
3643
|
+
// Must start with a list marker
|
|
3644
|
+
let tmpListMatch = tmpContent.match(/^[-*+]\s+(.*)/);
|
|
3645
|
+
if (!tmpListMatch) {
|
|
3646
|
+
continue;
|
|
3647
|
+
}
|
|
3648
|
+
let tmpItemContent = tmpListMatch[1].trim();
|
|
3649
|
+
|
|
3650
|
+
// Parse link if present: [Text](href)
|
|
3651
|
+
let tmpLinkMatch = tmpItemContent.match(/^\[([^\]]+)\]\(([^)]+)\)/);
|
|
3652
|
+
if (tmpIndent < 2) {
|
|
3653
|
+
// Top-level item — this is a group header or standalone link
|
|
3654
|
+
if (tmpLinkMatch) {
|
|
3655
|
+
let tmpName = tmpLinkMatch[1].trim();
|
|
3656
|
+
let tmpHref = tmpLinkMatch[2].trim();
|
|
3657
|
+
|
|
3658
|
+
// Derive a group key from the href or name
|
|
3659
|
+
let tmpKey = this.deriveGroupKey(tmpName, tmpHref);
|
|
3660
|
+
let tmpRoute = this.convertSidebarLink(tmpHref);
|
|
3661
|
+
tmpCurrentGroup = {
|
|
3662
|
+
Name: tmpName,
|
|
3663
|
+
Key: tmpKey,
|
|
3664
|
+
Route: tmpRoute,
|
|
3665
|
+
Modules: []
|
|
3666
|
+
};
|
|
3667
|
+
tmpGroups.push(tmpCurrentGroup);
|
|
3668
|
+
} else {
|
|
3669
|
+
// Plain text group header (no link)
|
|
3670
|
+
let tmpName = tmpItemContent;
|
|
3671
|
+
let tmpKey = tmpName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
3672
|
+
tmpCurrentGroup = {
|
|
3673
|
+
Name: tmpName,
|
|
3674
|
+
Key: tmpKey,
|
|
3675
|
+
Route: '',
|
|
3676
|
+
Modules: []
|
|
3677
|
+
};
|
|
3678
|
+
tmpGroups.push(tmpCurrentGroup);
|
|
3679
|
+
}
|
|
3680
|
+
} else if (tmpCurrentGroup) {
|
|
3681
|
+
// Indented item — this is a module within the current group
|
|
3682
|
+
if (tmpLinkMatch) {
|
|
3683
|
+
let tmpModuleName = tmpLinkMatch[1].trim();
|
|
3684
|
+
let tmpModuleHref = tmpLinkMatch[2].trim();
|
|
3685
|
+
let tmpModuleRoute = this.convertSidebarLink(tmpModuleHref);
|
|
3686
|
+
tmpCurrentGroup.Modules.push({
|
|
3687
|
+
Name: tmpModuleName,
|
|
3688
|
+
HasDocs: true,
|
|
3689
|
+
Group: tmpCurrentGroup.Key,
|
|
3690
|
+
Route: tmpModuleRoute
|
|
3691
|
+
});
|
|
3692
|
+
} else {
|
|
3693
|
+
// Plain text child entry (no docs link)
|
|
3694
|
+
tmpCurrentGroup.Modules.push({
|
|
3695
|
+
Name: tmpItemContent,
|
|
3696
|
+
HasDocs: false,
|
|
3697
|
+
Group: tmpCurrentGroup.Key,
|
|
3698
|
+
Route: ''
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
return tmpGroups;
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3706
|
+
/**
|
|
3707
|
+
* Convert a docsify-style sidebar link href into a docuserve hash route.
|
|
3708
|
+
*
|
|
3709
|
+
* Handles these forms:
|
|
3710
|
+
* / -> #/Home
|
|
3711
|
+
* /group/module/ -> #/doc/group/module
|
|
3712
|
+
* /group/module/path.md -> #/doc/group/module/path.md
|
|
3713
|
+
* something.md -> #/page/something
|
|
3714
|
+
*
|
|
3715
|
+
* @param {string} pHref - The original sidebar link href
|
|
3716
|
+
* @returns {string} The converted hash route
|
|
3717
|
+
*/
|
|
3718
|
+
convertSidebarLink(pHref) {
|
|
3719
|
+
if (!pHref) {
|
|
3720
|
+
return '';
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
// Root home link
|
|
3724
|
+
if (pHref === '/') {
|
|
3725
|
+
return '#/Home';
|
|
3726
|
+
}
|
|
3727
|
+
|
|
3728
|
+
// Strip leading/trailing slashes for parsing
|
|
3729
|
+
let tmpPath = pHref.replace(/^\//, '').replace(/\/$/, '');
|
|
3730
|
+
if (!tmpPath) {
|
|
3731
|
+
return '#/Home';
|
|
3732
|
+
}
|
|
3733
|
+
let tmpParts = tmpPath.split('/');
|
|
3734
|
+
|
|
3735
|
+
// Check if it's a module path (group/module)
|
|
3736
|
+
if (tmpParts.length >= 2) {
|
|
3737
|
+
let tmpGroupKeys = ['fable', 'meadow', 'orator', 'pict', 'utility'];
|
|
3738
|
+
if (tmpGroupKeys.indexOf(tmpParts[0]) >= 0) {
|
|
3739
|
+
return '#/doc/' + tmpPath;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3743
|
+
// Local page reference
|
|
3744
|
+
if (tmpPath.match(/\.md$/)) {
|
|
3745
|
+
return '#/page/' + tmpPath.replace(/\.md$/, '');
|
|
3746
|
+
}
|
|
3747
|
+
return '#/page/' + tmpPath;
|
|
3748
|
+
}
|
|
3749
|
+
|
|
3750
|
+
/**
|
|
3751
|
+
* Derive a short group key from a sidebar group name or href.
|
|
3752
|
+
*
|
|
3753
|
+
* @param {string} pName - The display name (e.g. "Fable — Core Ecosystem")
|
|
3754
|
+
* @param {string} pHref - The link href (e.g. "fable.md")
|
|
3755
|
+
* @returns {string} A short key (e.g. "fable")
|
|
3756
|
+
*/
|
|
3757
|
+
deriveGroupKey(pName, pHref) {
|
|
3758
|
+
// Try href first — "fable.md" -> "fable"
|
|
3759
|
+
if (pHref && pHref !== '/') {
|
|
3760
|
+
let tmpFromHref = pHref.replace(/^\//, '').replace(/\.md$/, '').replace(/\/$/, '');
|
|
3761
|
+
if (tmpFromHref && !tmpFromHref.includes('/')) {
|
|
3762
|
+
return tmpFromHref.toLowerCase();
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
|
|
3766
|
+
// Fall back to first word of name lowercased
|
|
3767
|
+
let tmpFirstWord = pName.split(/[\s—\-:]+/)[0];
|
|
3768
|
+
return tmpFirstWord.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
/**
|
|
3772
|
+
* Build structured sidebar data from the catalog for the sidebar view.
|
|
3773
|
+
*
|
|
3774
|
+
* @param {Object} pCatalog - The parsed retold-catalog.json
|
|
3775
|
+
*/
|
|
3776
|
+
buildSidebarData(pCatalog) {
|
|
3777
|
+
let tmpSidebarGroups = [];
|
|
3778
|
+
for (let i = 0; i < pCatalog.Groups.length; i++) {
|
|
3779
|
+
let tmpGroup = pCatalog.Groups[i];
|
|
3780
|
+
let tmpGroupEntry = {
|
|
3781
|
+
Name: tmpGroup.Name,
|
|
3782
|
+
Key: tmpGroup.Key,
|
|
3783
|
+
Description: tmpGroup.Description,
|
|
3784
|
+
Modules: []
|
|
3785
|
+
};
|
|
3786
|
+
for (let j = 0; j < tmpGroup.Modules.length; j++) {
|
|
3787
|
+
let tmpModule = tmpGroup.Modules[j];
|
|
3788
|
+
tmpGroupEntry.Modules.push({
|
|
3789
|
+
Name: tmpModule.Name,
|
|
3790
|
+
HasDocs: tmpModule.HasDocs,
|
|
3791
|
+
Group: tmpGroup.Key,
|
|
3792
|
+
Route: '#/doc/' + tmpGroup.Key + '/' + tmpModule.Name
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
tmpSidebarGroups.push(tmpGroupEntry);
|
|
3796
|
+
}
|
|
3797
|
+
this.pict.AppData.Docuserve.SidebarGroups = tmpSidebarGroups;
|
|
3798
|
+
}
|
|
3799
|
+
|
|
3800
|
+
/**
|
|
3801
|
+
* Resolve a document URL from group/module/path to a fetchable URL.
|
|
3802
|
+
*
|
|
3803
|
+
* @param {string} pGroup - The group key (e.g. 'fable')
|
|
3804
|
+
* @param {string} pModule - The module name (e.g. 'fable')
|
|
3805
|
+
* @param {string} pPath - The document path within the module docs (e.g. 'README.md')
|
|
3806
|
+
* @returns {string} The resolved URL
|
|
3807
|
+
*/
|
|
3808
|
+
resolveDocumentURL(pGroup, pModule, pPath) {
|
|
3809
|
+
if (!this._Catalog) {
|
|
3810
|
+
return null;
|
|
3811
|
+
}
|
|
3812
|
+
let tmpOrg = this._Catalog.GitHubOrg || 'stevenvelozo';
|
|
3813
|
+
let tmpDefaultBranch = this._Catalog.DefaultBranch || 'master';
|
|
3814
|
+
|
|
3815
|
+
// Find the module in the catalog
|
|
3816
|
+
for (let i = 0; i < this._Catalog.Groups.length; i++) {
|
|
3817
|
+
let tmpGroup = this._Catalog.Groups[i];
|
|
3818
|
+
if (tmpGroup.Key !== pGroup) {
|
|
3819
|
+
continue;
|
|
3820
|
+
}
|
|
3821
|
+
for (let j = 0; j < tmpGroup.Modules.length; j++) {
|
|
3822
|
+
let tmpModule = tmpGroup.Modules[j];
|
|
3823
|
+
if (tmpModule.Name !== pModule) {
|
|
3824
|
+
continue;
|
|
3825
|
+
}
|
|
3826
|
+
let tmpBranch = tmpModule.Branch || tmpDefaultBranch;
|
|
3827
|
+
let tmpDocPath = pPath || 'README.md';
|
|
3828
|
+
return 'https://raw.githubusercontent.com/' + tmpOrg + '/' + tmpModule.Repo + '/' + tmpBranch + '/docs/' + tmpDocPath;
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
return null;
|
|
3832
|
+
}
|
|
3833
|
+
|
|
3834
|
+
/**
|
|
3835
|
+
* Get the module-specific sidebar entries for a given group/module.
|
|
3836
|
+
*
|
|
3837
|
+
* @param {string} pGroup - The group key
|
|
3838
|
+
* @param {string} pModule - The module name
|
|
3839
|
+
* @returns {Array|null} The sidebar entries or null
|
|
3840
|
+
*/
|
|
3841
|
+
getModuleSidebar(pGroup, pModule) {
|
|
3842
|
+
if (!this._Catalog) {
|
|
3843
|
+
return null;
|
|
3844
|
+
}
|
|
3845
|
+
for (let i = 0; i < this._Catalog.Groups.length; i++) {
|
|
3846
|
+
let tmpGroup = this._Catalog.Groups[i];
|
|
3847
|
+
if (tmpGroup.Key !== pGroup) {
|
|
3848
|
+
continue;
|
|
3849
|
+
}
|
|
3850
|
+
for (let j = 0; j < tmpGroup.Modules.length; j++) {
|
|
3851
|
+
let tmpModule = tmpGroup.Modules[j];
|
|
3852
|
+
if (tmpModule.Name !== pModule) {
|
|
3853
|
+
continue;
|
|
3854
|
+
}
|
|
3855
|
+
return tmpModule.Sidebar || null;
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
return null;
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
/**
|
|
3862
|
+
* Fetch a markdown document and convert it to HTML.
|
|
3863
|
+
*
|
|
3864
|
+
* @param {string} pURL - The URL to fetch
|
|
3865
|
+
* @param {Function} fCallback - Callback receiving (error, htmlContent)
|
|
3866
|
+
*/
|
|
3867
|
+
fetchDocument(pURL, fCallback) {
|
|
3868
|
+
let tmpCallback = typeof fCallback === 'function' ? fCallback : () => {};
|
|
3869
|
+
if (!pURL) {
|
|
3870
|
+
return tmpCallback('No URL provided', '');
|
|
3871
|
+
}
|
|
3872
|
+
|
|
3873
|
+
// Check cache
|
|
3874
|
+
if (this._ContentCache[pURL]) {
|
|
3875
|
+
return tmpCallback(null, this._ContentCache[pURL]);
|
|
3876
|
+
}
|
|
3877
|
+
fetch(pURL).then(pResponse => {
|
|
3878
|
+
if (!pResponse.ok) {
|
|
3879
|
+
return null;
|
|
3880
|
+
}
|
|
3881
|
+
return pResponse.text();
|
|
3882
|
+
}).then(pMarkdown => {
|
|
3883
|
+
if (!pMarkdown) {
|
|
3884
|
+
return tmpCallback('Document not found', this.getErrorPageHTML(pURL));
|
|
3885
|
+
}
|
|
3886
|
+
let tmpHTML = this.parseMarkdown(pMarkdown);
|
|
3887
|
+
this._ContentCache[pURL] = tmpHTML;
|
|
3888
|
+
return tmpCallback(null, tmpHTML);
|
|
3889
|
+
}).catch(pError => {
|
|
3890
|
+
this.log.warn("Docuserve: Error fetching document [".concat(pURL, "]: ").concat(pError));
|
|
3891
|
+
return tmpCallback(pError, this.getErrorPageHTML(pURL));
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
|
|
3895
|
+
/**
|
|
3896
|
+
* Fetch a local document relative to the docs folder.
|
|
3897
|
+
*
|
|
3898
|
+
* @param {string} pPath - The relative path (e.g. 'architecture.md')
|
|
3899
|
+
* @param {Function} fCallback - Callback receiving (error, htmlContent)
|
|
3900
|
+
*/
|
|
3901
|
+
fetchLocalDocument(pPath, fCallback) {
|
|
3902
|
+
let tmpDocsBase = this.pict.AppData.Docuserve.DocsBaseURL || '';
|
|
3903
|
+
let tmpURL = tmpDocsBase + pPath;
|
|
3904
|
+
this.fetchDocument(tmpURL, fCallback);
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
/**
|
|
3908
|
+
* Parse a markdown string into HTML.
|
|
3909
|
+
*
|
|
3910
|
+
* This is a basic markdown parser that handles the most common constructs:
|
|
3911
|
+
* headings, paragraphs, code blocks, inline code, links, bold, italic,
|
|
3912
|
+
* lists, blockquotes, and horizontal rules.
|
|
3913
|
+
*
|
|
3914
|
+
* @param {string} pMarkdown - The raw markdown text
|
|
3915
|
+
* @returns {string} The parsed HTML
|
|
3916
|
+
*/
|
|
3917
|
+
parseMarkdown(pMarkdown) {
|
|
3918
|
+
if (!pMarkdown) {
|
|
3919
|
+
return '';
|
|
3920
|
+
}
|
|
3921
|
+
let tmpLines = pMarkdown.split('\n');
|
|
3922
|
+
let tmpHTML = [];
|
|
3923
|
+
let tmpInCodeBlock = false;
|
|
3924
|
+
let tmpCodeLang = '';
|
|
3925
|
+
let tmpCodeLines = [];
|
|
3926
|
+
let tmpInList = false;
|
|
3927
|
+
let tmpListType = '';
|
|
3928
|
+
let tmpInBlockquote = false;
|
|
3929
|
+
let tmpBlockquoteLines = [];
|
|
3930
|
+
for (let i = 0; i < tmpLines.length; i++) {
|
|
3931
|
+
let tmpLine = tmpLines[i];
|
|
3932
|
+
|
|
3933
|
+
// Code blocks (fenced)
|
|
3934
|
+
if (tmpLine.match(/^```/)) {
|
|
3935
|
+
if (tmpInCodeBlock) {
|
|
3936
|
+
// End code block
|
|
3937
|
+
tmpHTML.push('<pre><code class="language-' + this.escapeHTML(tmpCodeLang) + '">' + this.escapeHTML(tmpCodeLines.join('\n')) + '</code></pre>');
|
|
3938
|
+
tmpInCodeBlock = false;
|
|
3939
|
+
tmpCodeLang = '';
|
|
3940
|
+
tmpCodeLines = [];
|
|
3941
|
+
} else {
|
|
3942
|
+
// Close any open list or blockquote
|
|
3943
|
+
if (tmpInList) {
|
|
3944
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
3945
|
+
tmpInList = false;
|
|
3946
|
+
}
|
|
3947
|
+
if (tmpInBlockquote) {
|
|
3948
|
+
tmpHTML.push('<blockquote>' + this.parseMarkdown(tmpBlockquoteLines.join('\n')) + '</blockquote>');
|
|
3949
|
+
tmpInBlockquote = false;
|
|
3950
|
+
tmpBlockquoteLines = [];
|
|
3951
|
+
}
|
|
3952
|
+
// Start code block
|
|
3953
|
+
tmpCodeLang = tmpLine.replace(/^```/, '').trim();
|
|
3954
|
+
tmpInCodeBlock = true;
|
|
3955
|
+
}
|
|
3956
|
+
continue;
|
|
3957
|
+
}
|
|
3958
|
+
if (tmpInCodeBlock) {
|
|
3959
|
+
tmpCodeLines.push(tmpLine);
|
|
3960
|
+
continue;
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
// Blockquotes
|
|
3964
|
+
if (tmpLine.match(/^>\s?/)) {
|
|
3965
|
+
if (!tmpInBlockquote) {
|
|
3966
|
+
// Close any open list
|
|
3967
|
+
if (tmpInList) {
|
|
3968
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
3969
|
+
tmpInList = false;
|
|
3970
|
+
}
|
|
3971
|
+
tmpInBlockquote = true;
|
|
3972
|
+
tmpBlockquoteLines = [];
|
|
3973
|
+
}
|
|
3974
|
+
tmpBlockquoteLines.push(tmpLine.replace(/^>\s?/, ''));
|
|
3975
|
+
continue;
|
|
3976
|
+
} else if (tmpInBlockquote) {
|
|
3977
|
+
tmpHTML.push('<blockquote>' + this.parseMarkdown(tmpBlockquoteLines.join('\n')) + '</blockquote>');
|
|
3978
|
+
tmpInBlockquote = false;
|
|
3979
|
+
tmpBlockquoteLines = [];
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
// Horizontal rule
|
|
3983
|
+
if (tmpLine.match(/^(-{3,}|\*{3,}|_{3,})\s*$/)) {
|
|
3984
|
+
if (tmpInList) {
|
|
3985
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
3986
|
+
tmpInList = false;
|
|
3987
|
+
}
|
|
3988
|
+
tmpHTML.push('<hr>');
|
|
3989
|
+
continue;
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
// Headings
|
|
3993
|
+
let tmpHeadingMatch = tmpLine.match(/^(#{1,6})\s+(.+)/);
|
|
3994
|
+
if (tmpHeadingMatch) {
|
|
3995
|
+
if (tmpInList) {
|
|
3996
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
3997
|
+
tmpInList = false;
|
|
3998
|
+
}
|
|
3999
|
+
let tmpLevel = tmpHeadingMatch[1].length;
|
|
4000
|
+
let tmpText = this.parseInline(tmpHeadingMatch[2]);
|
|
4001
|
+
let tmpID = tmpHeadingMatch[2].toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-');
|
|
4002
|
+
tmpHTML.push('<h' + tmpLevel + ' id="' + tmpID + '">' + tmpText + '</h' + tmpLevel + '>');
|
|
4003
|
+
continue;
|
|
4004
|
+
}
|
|
4005
|
+
|
|
4006
|
+
// Unordered list items
|
|
4007
|
+
let tmpULMatch = tmpLine.match(/^(\s*)[-*+]\s+(.*)/);
|
|
4008
|
+
if (tmpULMatch) {
|
|
4009
|
+
if (!tmpInList || tmpListType !== 'ul') {
|
|
4010
|
+
if (tmpInList) {
|
|
4011
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
4012
|
+
}
|
|
4013
|
+
tmpHTML.push('<ul>');
|
|
4014
|
+
tmpInList = true;
|
|
4015
|
+
tmpListType = 'ul';
|
|
4016
|
+
}
|
|
4017
|
+
tmpHTML.push('<li>' + this.parseInline(tmpULMatch[2]) + '</li>');
|
|
4018
|
+
continue;
|
|
4019
|
+
}
|
|
4020
|
+
|
|
4021
|
+
// Ordered list items
|
|
4022
|
+
let tmpOLMatch = tmpLine.match(/^(\s*)\d+\.\s+(.*)/);
|
|
4023
|
+
if (tmpOLMatch) {
|
|
4024
|
+
if (!tmpInList || tmpListType !== 'ol') {
|
|
4025
|
+
if (tmpInList) {
|
|
4026
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
4027
|
+
}
|
|
4028
|
+
tmpHTML.push('<ol>');
|
|
4029
|
+
tmpInList = true;
|
|
4030
|
+
tmpListType = 'ol';
|
|
4031
|
+
}
|
|
4032
|
+
tmpHTML.push('<li>' + this.parseInline(tmpOLMatch[2]) + '</li>');
|
|
4033
|
+
continue;
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
// Close list if we've left list items
|
|
4037
|
+
if (tmpInList && tmpLine.trim() !== '') {
|
|
4038
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
4039
|
+
tmpInList = false;
|
|
4040
|
+
}
|
|
4041
|
+
|
|
4042
|
+
// Empty line
|
|
4043
|
+
if (tmpLine.trim() === '') {
|
|
4044
|
+
continue;
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
// Table detection
|
|
4048
|
+
if (tmpLine.match(/^\|/) && i + 1 < tmpLines.length && tmpLines[i + 1].match(/^\|[\s-:|]+\|/)) {
|
|
4049
|
+
// Close any open list
|
|
4050
|
+
if (tmpInList) {
|
|
4051
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
4052
|
+
tmpInList = false;
|
|
4053
|
+
}
|
|
4054
|
+
let tmpTableHTML = '<table>';
|
|
4055
|
+
|
|
4056
|
+
// Header row
|
|
4057
|
+
let tmpHeaders = tmpLine.split('|').filter(pCell => {
|
|
4058
|
+
return pCell.trim() !== '';
|
|
4059
|
+
});
|
|
4060
|
+
tmpTableHTML += '<thead><tr>';
|
|
4061
|
+
for (let h = 0; h < tmpHeaders.length; h++) {
|
|
4062
|
+
tmpTableHTML += '<th>' + this.parseInline(tmpHeaders[h].trim()) + '</th>';
|
|
4063
|
+
}
|
|
4064
|
+
tmpTableHTML += '</tr></thead>';
|
|
4065
|
+
|
|
4066
|
+
// Skip separator row
|
|
4067
|
+
i++;
|
|
4068
|
+
|
|
4069
|
+
// Body rows
|
|
4070
|
+
tmpTableHTML += '<tbody>';
|
|
4071
|
+
while (i + 1 < tmpLines.length && tmpLines[i + 1].match(/^\|/)) {
|
|
4072
|
+
i++;
|
|
4073
|
+
let tmpCells = tmpLines[i].split('|').filter(pCell => {
|
|
4074
|
+
return pCell.trim() !== '';
|
|
4075
|
+
});
|
|
4076
|
+
tmpTableHTML += '<tr>';
|
|
4077
|
+
for (let c = 0; c < tmpCells.length; c++) {
|
|
4078
|
+
tmpTableHTML += '<td>' + this.parseInline(tmpCells[c].trim()) + '</td>';
|
|
4079
|
+
}
|
|
4080
|
+
tmpTableHTML += '</tr>';
|
|
4081
|
+
}
|
|
4082
|
+
tmpTableHTML += '</tbody></table>';
|
|
4083
|
+
tmpHTML.push(tmpTableHTML);
|
|
4084
|
+
continue;
|
|
4085
|
+
}
|
|
4086
|
+
|
|
4087
|
+
// Regular paragraph
|
|
4088
|
+
tmpHTML.push('<p>' + this.parseInline(tmpLine) + '</p>');
|
|
4089
|
+
}
|
|
4090
|
+
|
|
4091
|
+
// Close any trailing open elements
|
|
4092
|
+
if (tmpInList) {
|
|
4093
|
+
tmpHTML.push(tmpListType === 'ul' ? '</ul>' : '</ol>');
|
|
4094
|
+
}
|
|
4095
|
+
if (tmpInBlockquote) {
|
|
4096
|
+
tmpHTML.push('<blockquote>' + this.parseMarkdown(tmpBlockquoteLines.join('\n')) + '</blockquote>');
|
|
4097
|
+
}
|
|
4098
|
+
if (tmpInCodeBlock) {
|
|
4099
|
+
tmpHTML.push('<pre><code>' + this.escapeHTML(tmpCodeLines.join('\n')) + '</code></pre>');
|
|
4100
|
+
}
|
|
4101
|
+
return tmpHTML.join('\n');
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
/**
|
|
4105
|
+
* Parse inline markdown elements (bold, italic, code, links, images).
|
|
4106
|
+
*
|
|
4107
|
+
* @param {string} pText - The text to parse
|
|
4108
|
+
* @returns {string} HTML with inline elements
|
|
4109
|
+
*/
|
|
4110
|
+
parseInline(pText) {
|
|
4111
|
+
if (!pText) {
|
|
4112
|
+
return '';
|
|
4113
|
+
}
|
|
4114
|
+
let tmpResult = pText;
|
|
4115
|
+
|
|
4116
|
+
// Inline code (backticks) - handle first to avoid interfering with other patterns
|
|
4117
|
+
tmpResult = tmpResult.replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
4118
|
+
|
|
4119
|
+
// Images
|
|
4120
|
+
tmpResult = tmpResult.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1">');
|
|
4121
|
+
|
|
4122
|
+
// Links
|
|
4123
|
+
tmpResult = tmpResult.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (pMatch, pLinkText, pHref) => {
|
|
4124
|
+
// Convert internal doc links to hash routes
|
|
4125
|
+
if (pHref.match(/^\//) || pHref.match(/^[^:]+\.md/)) {
|
|
4126
|
+
let tmpRoute = this.convertDocLink(pHref);
|
|
4127
|
+
return '<a href="' + tmpRoute + '">' + pLinkText + '</a>';
|
|
4128
|
+
}
|
|
4129
|
+
return '<a href="' + pHref + '" target="_blank" rel="noopener">' + pLinkText + '</a>';
|
|
4130
|
+
});
|
|
4131
|
+
|
|
4132
|
+
// Bold
|
|
4133
|
+
tmpResult = tmpResult.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
|
4134
|
+
tmpResult = tmpResult.replace(/__([^_]+)__/g, '<strong>$1</strong>');
|
|
4135
|
+
|
|
4136
|
+
// Italic
|
|
4137
|
+
tmpResult = tmpResult.replace(/\*([^*]+)\*/g, '<em>$1</em>');
|
|
4138
|
+
tmpResult = tmpResult.replace(/_([^_]+)_/g, '<em>$1</em>');
|
|
4139
|
+
return tmpResult;
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
/**
|
|
4143
|
+
* Convert a docsify-style internal link to a hash route for docuserve.
|
|
4144
|
+
*
|
|
4145
|
+
* @param {string} pHref - The original link href
|
|
4146
|
+
* @returns {string} The converted hash route
|
|
4147
|
+
*/
|
|
4148
|
+
convertDocLink(pHref) {
|
|
4149
|
+
// Remove leading slash
|
|
4150
|
+
let tmpPath = pHref.replace(/^\//, '');
|
|
4151
|
+
|
|
4152
|
+
// If it looks like a module path (group/module/), convert to our route format
|
|
4153
|
+
let tmpParts = tmpPath.split('/');
|
|
4154
|
+
if (tmpParts.length >= 2) {
|
|
4155
|
+
// Check if first segment matches a known group key
|
|
4156
|
+
let tmpGroupKeys = ['fable', 'meadow', 'orator', 'pict', 'utility'];
|
|
4157
|
+
if (tmpGroupKeys.indexOf(tmpParts[0]) >= 0) {
|
|
4158
|
+
return '#/doc/' + tmpPath;
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
// Local doc page
|
|
4163
|
+
if (tmpPath.match(/\.md$/)) {
|
|
4164
|
+
let tmpPageKey = tmpPath.replace(/\.md$/, '');
|
|
4165
|
+
return '#/page/' + tmpPageKey;
|
|
4166
|
+
}
|
|
4167
|
+
return '#/page/' + tmpPath;
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
/**
|
|
4171
|
+
* Escape HTML special characters.
|
|
4172
|
+
*
|
|
4173
|
+
* @param {string} pText - The text to escape
|
|
4174
|
+
* @returns {string} The escaped text
|
|
4175
|
+
*/
|
|
4176
|
+
escapeHTML(pText) {
|
|
4177
|
+
if (!pText) {
|
|
4178
|
+
return '';
|
|
4179
|
+
}
|
|
4180
|
+
return pText.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
module.exports = DocuserveDocumentationProvider;
|
|
4184
|
+
module.exports.default_configuration = {
|
|
4185
|
+
ProviderIdentifier: "Docuserve-Documentation",
|
|
4186
|
+
AutoInitialize: true,
|
|
4187
|
+
AutoInitializeOrdinal: 0
|
|
4188
|
+
};
|
|
4189
|
+
}, {
|
|
4190
|
+
"pict-provider": 6
|
|
4191
|
+
}],
|
|
4192
|
+
12: [function (require, module, exports) {
|
|
4193
|
+
const libPictView = require('pict-view');
|
|
4194
|
+
const _ViewConfiguration = {
|
|
4195
|
+
ViewIdentifier: "Docuserve-Content",
|
|
4196
|
+
DefaultRenderable: "Docuserve-Content-Display",
|
|
4197
|
+
DefaultDestinationAddress: "#Docuserve-Content-Container",
|
|
4198
|
+
AutoRender: false,
|
|
4199
|
+
CSS: /*css*/"\n\t\t.docuserve-content {\n\t\t\tpadding: 2em 3em;\n\t\t\tmax-width: 900px;\n\t\t\tmargin: 0 auto;\n\t\t}\n\t\t.docuserve-content-loading {\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t\tjustify-content: center;\n\t\t\tmin-height: 200px;\n\t\t\tcolor: #999;\n\t\t\tfont-size: 1em;\n\t\t}\n\t\t.docuserve-content h1 {\n\t\t\tfont-size: 2em;\n\t\t\tcolor: #2c3e50;\n\t\t\tborder-bottom: 1px solid #eee;\n\t\t\tpadding-bottom: 0.3em;\n\t\t\tmargin-top: 0;\n\t\t}\n\t\t.docuserve-content h2 {\n\t\t\tfont-size: 1.5em;\n\t\t\tcolor: #2c3e50;\n\t\t\tborder-bottom: 1px solid #f0f0f0;\n\t\t\tpadding-bottom: 0.25em;\n\t\t\tmargin-top: 1.5em;\n\t\t}\n\t\t.docuserve-content h3 {\n\t\t\tfont-size: 1.25em;\n\t\t\tcolor: #333;\n\t\t\tmargin-top: 1.25em;\n\t\t}\n\t\t.docuserve-content h4, .docuserve-content h5, .docuserve-content h6 {\n\t\t\tcolor: #555;\n\t\t\tmargin-top: 1em;\n\t\t}\n\t\t.docuserve-content p {\n\t\t\tline-height: 1.7;\n\t\t\tcolor: #444;\n\t\t\tmargin: 0.75em 0;\n\t\t}\n\t\t.docuserve-content a {\n\t\t\tcolor: #42b983;\n\t\t\ttext-decoration: none;\n\t\t}\n\t\t.docuserve-content a:hover {\n\t\t\ttext-decoration: underline;\n\t\t}\n\t\t.docuserve-content pre {\n\t\t\tbackground: #2c3e50;\n\t\t\tcolor: #ecf0f1;\n\t\t\tpadding: 1.25em;\n\t\t\tborder-radius: 6px;\n\t\t\toverflow-x: auto;\n\t\t\tline-height: 1.5;\n\t\t\tfont-size: 0.9em;\n\t\t}\n\t\t.docuserve-content code {\n\t\t\tbackground: #f4f4f5;\n\t\t\tpadding: 0.15em 0.4em;\n\t\t\tborder-radius: 3px;\n\t\t\tfont-size: 0.9em;\n\t\t\tcolor: #e74c3c;\n\t\t}\n\t\t.docuserve-content pre code {\n\t\t\tbackground: none;\n\t\t\tpadding: 0;\n\t\t\tcolor: inherit;\n\t\t\tfont-size: inherit;\n\t\t}\n\t\t.docuserve-content blockquote {\n\t\t\tborder-left: 4px solid #42b983;\n\t\t\tmargin: 1em 0;\n\t\t\tpadding: 0.5em 1em;\n\t\t\tbackground: #f9f9f9;\n\t\t\tcolor: #666;\n\t\t}\n\t\t.docuserve-content blockquote p {\n\t\t\tmargin: 0.25em 0;\n\t\t}\n\t\t.docuserve-content ul, .docuserve-content ol {\n\t\t\tpadding-left: 2em;\n\t\t\tline-height: 1.8;\n\t\t}\n\t\t.docuserve-content li {\n\t\t\tmargin: 0.25em 0;\n\t\t\tcolor: #444;\n\t\t}\n\t\t.docuserve-content hr {\n\t\t\tborder: none;\n\t\t\tborder-top: 1px solid #eee;\n\t\t\tmargin: 2em 0;\n\t\t}\n\t\t.docuserve-content table {\n\t\t\twidth: 100%;\n\t\t\tborder-collapse: collapse;\n\t\t\tmargin: 1em 0;\n\t\t}\n\t\t.docuserve-content table th {\n\t\t\tbackground: #f5f7fa;\n\t\t\tborder: 1px solid #e0e0e0;\n\t\t\tpadding: 0.6em 0.8em;\n\t\t\ttext-align: left;\n\t\t\tfont-weight: 600;\n\t\t\tcolor: #2c3e50;\n\t\t}\n\t\t.docuserve-content table td {\n\t\t\tborder: 1px solid #e0e0e0;\n\t\t\tpadding: 0.5em 0.8em;\n\t\t\tcolor: #444;\n\t\t}\n\t\t.docuserve-content table tr:nth-child(even) {\n\t\t\tbackground: #fafafa;\n\t\t}\n\t\t.docuserve-content img {\n\t\t\tmax-width: 100%;\n\t\t\theight: auto;\n\t\t}\n\t\t.docuserve-not-found {\n\t\t\ttext-align: center;\n\t\t\tpadding: 3em 1em;\n\t\t\tcolor: #666;\n\t\t}\n\t\t.docuserve-not-found h2 {\n\t\t\tcolor: #999;\n\t\t\tfont-size: 1.5em;\n\t\t\tborder-bottom: none;\n\t\t}\n\t\t.docuserve-not-found code {\n\t\t\tbackground: #f4f4f5;\n\t\t\tpadding: 0.15em 0.4em;\n\t\t\tborder-radius: 3px;\n\t\t\tfont-size: 0.9em;\n\t\t\tcolor: #e74c3c;\n\t\t}\n\t",
|
|
4200
|
+
Templates: [{
|
|
4201
|
+
Hash: "Docuserve-Content-Template",
|
|
4202
|
+
Template: /*html*/"\n<div class=\"docuserve-content\" id=\"Docuserve-Content-Body\">\n\t<div class=\"docuserve-content-loading\">Loading documentation...</div>\n</div>\n"
|
|
4203
|
+
}],
|
|
4204
|
+
Renderables: [{
|
|
4205
|
+
RenderableHash: "Docuserve-Content-Display",
|
|
4206
|
+
TemplateHash: "Docuserve-Content-Template",
|
|
4207
|
+
DestinationAddress: "#Docuserve-Content-Container",
|
|
4208
|
+
RenderMethod: "replace"
|
|
4209
|
+
}]
|
|
4210
|
+
};
|
|
4211
|
+
class DocuserveContentView extends libPictView {
|
|
4212
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
4213
|
+
super(pFable, pOptions, pServiceHash);
|
|
4214
|
+
}
|
|
4215
|
+
|
|
4216
|
+
/**
|
|
4217
|
+
* Display parsed HTML content in the content area.
|
|
4218
|
+
*
|
|
4219
|
+
* @param {string} pHTMLContent - The HTML to display
|
|
4220
|
+
*/
|
|
4221
|
+
displayContent(pHTMLContent) {
|
|
4222
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Content-Body', pHTMLContent);
|
|
4223
|
+
|
|
4224
|
+
// Scroll to top of content area
|
|
4225
|
+
let tmpContentContainer = document.getElementById('Docuserve-Content-Container');
|
|
4226
|
+
if (tmpContentContainer) {
|
|
4227
|
+
tmpContentContainer.scrollTop = 0;
|
|
4228
|
+
}
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
/**
|
|
4232
|
+
* Show a loading indicator.
|
|
4233
|
+
*/
|
|
4234
|
+
showLoading() {
|
|
4235
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Content-Body', '<div class="docuserve-content-loading">Loading documentation...</div>');
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
module.exports = DocuserveContentView;
|
|
4239
|
+
module.exports.default_configuration = _ViewConfiguration;
|
|
4240
|
+
}, {
|
|
4241
|
+
"pict-view": 8
|
|
4242
|
+
}],
|
|
4243
|
+
13: [function (require, module, exports) {
|
|
4244
|
+
const libPictView = require('pict-view');
|
|
4245
|
+
const _ViewConfiguration = {
|
|
4246
|
+
ViewIdentifier: "Docuserve-Layout",
|
|
4247
|
+
DefaultRenderable: "Docuserve-Layout-Shell",
|
|
4248
|
+
DefaultDestinationAddress: "#Docuserve-Application-Container",
|
|
4249
|
+
AutoRender: false,
|
|
4250
|
+
CSS: /*css*/"\n\t\t#Docuserve-Application-Container {\n\t\t\tdisplay: flex;\n\t\t\tflex-direction: column;\n\t\t\theight: 100vh;\n\t\t\toverflow: hidden;\n\t\t}\n\t\t#Docuserve-TopBar-Container {\n\t\t\tflex-shrink: 0;\n\t\t}\n\t\t.docuserve-body {\n\t\t\tdisplay: flex;\n\t\t\tflex: 1;\n\t\t\tmin-height: 0;\n\t\t}\n\t\t#Docuserve-Sidebar-Container {\n\t\t\tflex-shrink: 0;\n\t\t\twidth: 280px;\n\t\t\toverflow-y: auto;\n\t\t}\n\t\t#Docuserve-Content-Container {\n\t\t\tflex: 1;\n\t\t\tmin-width: 0;\n\t\t\toverflow-y: auto;\n\t\t}\n\t",
|
|
4251
|
+
Templates: [{
|
|
4252
|
+
Hash: "Docuserve-Layout-Shell-Template",
|
|
4253
|
+
Template: /*html*/"\n<div id=\"Docuserve-TopBar-Container\"></div>\n<div class=\"docuserve-body\">\n\t<div id=\"Docuserve-Sidebar-Container\"></div>\n\t<div id=\"Docuserve-Content-Container\"></div>\n</div>\n"
|
|
4254
|
+
}],
|
|
4255
|
+
Renderables: [{
|
|
4256
|
+
RenderableHash: "Docuserve-Layout-Shell",
|
|
4257
|
+
TemplateHash: "Docuserve-Layout-Shell-Template",
|
|
4258
|
+
DestinationAddress: "#Docuserve-Application-Container",
|
|
4259
|
+
RenderMethod: "replace"
|
|
4260
|
+
}]
|
|
4261
|
+
};
|
|
4262
|
+
class DocuserveLayoutView extends libPictView {
|
|
4263
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
4264
|
+
super(pFable, pOptions, pServiceHash);
|
|
4265
|
+
}
|
|
4266
|
+
onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent) {
|
|
4267
|
+
// After the layout shell is rendered, render the child views into their containers
|
|
4268
|
+
this.pict.views['Docuserve-TopBar'].render();
|
|
4269
|
+
this.pict.views['Docuserve-Sidebar'].render();
|
|
4270
|
+
|
|
4271
|
+
// Show the splash screen initially
|
|
4272
|
+
this.pict.views['Docuserve-Splash'].render();
|
|
4273
|
+
|
|
4274
|
+
// Inject all view CSS into the PICT-CSS style element
|
|
4275
|
+
this.pict.CSSMap.injectCSS();
|
|
4276
|
+
|
|
4277
|
+
// Resolve the current hash on initial load
|
|
4278
|
+
this.pict.PictApplication.resolveHash();
|
|
4279
|
+
|
|
4280
|
+
// Listen for hash changes so that plain <a href="#/..."> links trigger
|
|
4281
|
+
// navigation. This covers sidebar links, splash action buttons,
|
|
4282
|
+
// in-content links, and browser back/forward navigation.
|
|
4283
|
+
if (!this._HashChangeListenerBound) {
|
|
4284
|
+
this._HashChangeListenerBound = true;
|
|
4285
|
+
let tmpSelf = this;
|
|
4286
|
+
window.addEventListener('hashchange', () => {
|
|
4287
|
+
tmpSelf.pict.PictApplication.resolveHash();
|
|
4288
|
+
});
|
|
4289
|
+
}
|
|
4290
|
+
return super.onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent);
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
module.exports = DocuserveLayoutView;
|
|
4294
|
+
module.exports.default_configuration = _ViewConfiguration;
|
|
4295
|
+
}, {
|
|
4296
|
+
"pict-view": 8
|
|
4297
|
+
}],
|
|
4298
|
+
14: [function (require, module, exports) {
|
|
4299
|
+
const libPictView = require('pict-view');
|
|
4300
|
+
const _ViewConfiguration = {
|
|
4301
|
+
ViewIdentifier: "Docuserve-Sidebar",
|
|
4302
|
+
DefaultRenderable: "Docuserve-Sidebar-Content",
|
|
4303
|
+
DefaultDestinationAddress: "#Docuserve-Sidebar-Container",
|
|
4304
|
+
AutoRender: false,
|
|
4305
|
+
CSS: /*css*/"\n\t\t.docuserve-sidebar {\n\t\t\tbackground-color: #f8f9fa;\n\t\t\tborder-right: 1px solid #e0e0e0;\n\t\t\tpadding: 1em 0;\n\t\t\theight: 100%;\n\t\t\tposition: relative;\n\t\t}\n\t\t.docuserve-sidebar-close {\n\t\t\tposition: absolute;\n\t\t\ttop: 0.5em;\n\t\t\tright: 0.5em;\n\t\t\tbackground: none;\n\t\t\tborder: none;\n\t\t\tcolor: #999;\n\t\t\tfont-size: 1.2em;\n\t\t\tcursor: pointer;\n\t\t\tpadding: 0.2em 0.4em;\n\t\t\tline-height: 1;\n\t\t}\n\t\t.docuserve-sidebar-close:hover {\n\t\t\tcolor: #42b983;\n\t\t}\n\t\t.docuserve-sidebar-search {\n\t\t\tpadding: 0 1em 1em 1em;\n\t\t\tborder-bottom: 1px solid #e9ecef;\n\t\t\tmargin-bottom: 0.5em;\n\t\t}\n\t\t.docuserve-sidebar-search input {\n\t\t\twidth: 100%;\n\t\t\tpadding: 0.5em 0.75em;\n\t\t\tborder: 1px solid #ddd;\n\t\t\tborder-radius: 4px;\n\t\t\tfont-size: 0.85em;\n\t\t\toutline: none;\n\t\t\tbox-sizing: border-box;\n\t\t}\n\t\t.docuserve-sidebar-search input:focus {\n\t\t\tborder-color: #42b983;\n\t\t}\n\t\t.docuserve-sidebar-home {\n\t\t\tpadding: 0.5em 1.25em;\n\t\t\tfont-weight: 600;\n\t\t\tfont-size: 0.85em;\n\t\t\ttext-transform: uppercase;\n\t\t\tletter-spacing: 0.03em;\n\t\t}\n\t\t.docuserve-sidebar-home a {\n\t\t\tcolor: #666;\n\t\t\ttext-decoration: none;\n\t\t\tcursor: pointer;\n\t\t\tuser-select: none;\n\t\t}\n\t\t.docuserve-sidebar-home a:hover {\n\t\t\tcolor: #42b983;\n\t\t}\n\t\t.docuserve-sidebar-group {\n\t\t\tmargin-top: 0.25em;\n\t\t}\n\t\t.docuserve-sidebar-group-title {\n\t\t\tdisplay: block;\n\t\t\tpadding: 0.5em 1.25em;\n\t\t\tfont-weight: 600;\n\t\t\tfont-size: 0.85em;\n\t\t\tcolor: #666;\n\t\t\ttext-decoration: none;\n\t\t\ttext-transform: uppercase;\n\t\t\tletter-spacing: 0.03em;\n\t\t\tcursor: pointer;\n\t\t\tuser-select: none;\n\t\t}\n\t\t.docuserve-sidebar-group-title:hover {\n\t\t\tcolor: #42b983;\n\t\t}\n\t\t.docuserve-sidebar-modules {\n\t\t\tlist-style: none;\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\t\t.docuserve-sidebar-modules li {\n\t\t\tpadding: 0;\n\t\t}\n\t\t.docuserve-sidebar-modules a {\n\t\t\tdisplay: block;\n\t\t\tpadding: 0.3em 1.25em 0.3em 2em;\n\t\t\tcolor: #555;\n\t\t\ttext-decoration: none;\n\t\t\tfont-size: 0.85em;\n\t\t\ttransition: background-color 0.1s, color 0.1s;\n\t\t\tcursor: pointer;\n\t\t}\n\t\t.docuserve-sidebar-modules a:hover {\n\t\t\tbackground-color: #e9ecef;\n\t\t\tcolor: #42b983;\n\t\t}\n\t\t.docuserve-sidebar-modules a.active {\n\t\t\tcolor: #42b983;\n\t\t\tfont-weight: 600;\n\t\t\tbackground-color: #e8f5e9;\n\t\t}\n\t\t.docuserve-sidebar-modules .no-docs {\n\t\t\tdisplay: block;\n\t\t\tpadding: 0.3em 1.25em 0.3em 2em;\n\t\t\tcolor: #bbb;\n\t\t\tfont-size: 0.85em;\n\t\t}\n\t\t.docuserve-sidebar-module-nav {\n\t\t\tborder-top: 1px solid #e9ecef;\n\t\t\tmargin-top: 0.5em;\n\t\t\tpadding-top: 0.5em;\n\t\t}\n\t\t.docuserve-sidebar-module-nav-section {\n\t\t\tpadding: 0.4em 1.25em;\n\t\t\tfont-weight: 600;\n\t\t\tfont-size: 0.8em;\n\t\t\tcolor: #888;\n\t\t\ttext-transform: uppercase;\n\t\t\tletter-spacing: 0.02em;\n\t\t}\n\t\t.docuserve-sidebar-module-nav a {\n\t\t\tdisplay: block;\n\t\t\tpadding: 0.25em 1.25em 0.25em 2.25em;\n\t\t\tcolor: #555;\n\t\t\ttext-decoration: none;\n\t\t\tfont-size: 0.82em;\n\t\t\ttransition: background-color 0.1s, color 0.1s;\n\t\t\tcursor: pointer;\n\t\t}\n\t\t.docuserve-sidebar-module-nav a:hover {\n\t\t\tbackground-color: #e9ecef;\n\t\t\tcolor: #42b983;\n\t\t}\n\t",
|
|
4306
|
+
Templates: [{
|
|
4307
|
+
Hash: "Docuserve-Sidebar-Template",
|
|
4308
|
+
Template: /*html*/"\n<div class=\"docuserve-sidebar\">\n\t<button class=\"docuserve-sidebar-close\" onclick=\"{~P~}.views['Docuserve-Sidebar'].toggleSidebar()\">×</button>\n\t<div class=\"docuserve-sidebar-home\">\n\t\t<a onclick=\"{~P~}.PictApplication.navigateTo('/Home')\">Home</a>\n\t</div>\n\t<div id=\"Docuserve-Sidebar-Groups\"></div>\n\t<div id=\"Docuserve-Sidebar-ModuleNav\"></div>\n</div>\n"
|
|
4309
|
+
}],
|
|
4310
|
+
Renderables: [{
|
|
4311
|
+
RenderableHash: "Docuserve-Sidebar-Content",
|
|
4312
|
+
TemplateHash: "Docuserve-Sidebar-Template",
|
|
4313
|
+
DestinationAddress: "#Docuserve-Sidebar-Container",
|
|
4314
|
+
RenderMethod: "replace"
|
|
4315
|
+
}]
|
|
4316
|
+
};
|
|
4317
|
+
class DocusserveSidebarView extends libPictView {
|
|
4318
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
4319
|
+
super(pFable, pOptions, pServiceHash);
|
|
4320
|
+
}
|
|
4321
|
+
onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent) {
|
|
4322
|
+
this.renderSidebarGroups();
|
|
4323
|
+
return super.onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent);
|
|
4324
|
+
}
|
|
4325
|
+
|
|
4326
|
+
/**
|
|
4327
|
+
* Render the sidebar group navigation from catalog data.
|
|
4328
|
+
*/
|
|
4329
|
+
renderSidebarGroups() {
|
|
4330
|
+
let tmpGroups = this.pict.AppData.Docuserve.SidebarGroups;
|
|
4331
|
+
if (!tmpGroups || tmpGroups.length < 1) {
|
|
4332
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Sidebar-Groups', '<p style="padding: 1em; color: #999; font-size: 0.85em;">Loading catalog...</p>');
|
|
4333
|
+
return;
|
|
4334
|
+
}
|
|
4335
|
+
let tmpHTML = '';
|
|
4336
|
+
for (let i = 0; i < tmpGroups.length; i++) {
|
|
4337
|
+
let tmpGroup = tmpGroups[i];
|
|
4338
|
+
tmpHTML += '<div class="docuserve-sidebar-group">';
|
|
4339
|
+
|
|
4340
|
+
// Determine the route for the group title: use the group's own route,
|
|
4341
|
+
// or fall back to the first module with docs.
|
|
4342
|
+
let tmpGroupRoute = tmpGroup.Route || '';
|
|
4343
|
+
if (!tmpGroupRoute) {
|
|
4344
|
+
for (let k = 0; k < tmpGroup.Modules.length; k++) {
|
|
4345
|
+
if (tmpGroup.Modules[k].HasDocs && tmpGroup.Modules[k].Route) {
|
|
4346
|
+
tmpGroupRoute = tmpGroup.Modules[k].Route;
|
|
4347
|
+
break;
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4351
|
+
if (tmpGroupRoute) {
|
|
4352
|
+
tmpHTML += '<a class="docuserve-sidebar-group-title" href="' + tmpGroupRoute + '">' + this.escapeHTML(tmpGroup.Name) + '</a>';
|
|
4353
|
+
} else {
|
|
4354
|
+
tmpHTML += '<div class="docuserve-sidebar-group-title">' + this.escapeHTML(tmpGroup.Name) + '</div>';
|
|
4355
|
+
}
|
|
4356
|
+
tmpHTML += '<ul class="docuserve-sidebar-modules">';
|
|
4357
|
+
for (let j = 0; j < tmpGroup.Modules.length; j++) {
|
|
4358
|
+
let tmpModule = tmpGroup.Modules[j];
|
|
4359
|
+
if (tmpModule.HasDocs) {
|
|
4360
|
+
let tmpActiveClass = '';
|
|
4361
|
+
if (this.pict.AppData.Docuserve.CurrentGroup === tmpModule.Group && this.pict.AppData.Docuserve.CurrentModule === tmpModule.Name) {
|
|
4362
|
+
tmpActiveClass = ' class="active"';
|
|
4363
|
+
}
|
|
4364
|
+
tmpHTML += '<li><a' + tmpActiveClass + ' href="' + tmpModule.Route + '">' + this.escapeHTML(tmpModule.Name) + '</a></li>';
|
|
4365
|
+
} else {
|
|
4366
|
+
tmpHTML += '<li><span class="no-docs">' + this.escapeHTML(tmpModule.Name) + '</span></li>';
|
|
4367
|
+
}
|
|
4368
|
+
}
|
|
4369
|
+
tmpHTML += '</ul>';
|
|
4370
|
+
tmpHTML += '</div>';
|
|
4371
|
+
}
|
|
4372
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Sidebar-Groups', tmpHTML);
|
|
4373
|
+
}
|
|
4374
|
+
|
|
4375
|
+
/**
|
|
4376
|
+
* Render module-specific sub-navigation when viewing a module.
|
|
4377
|
+
*
|
|
4378
|
+
* @param {string} pGroup - The group key
|
|
4379
|
+
* @param {string} pModule - The module name
|
|
4380
|
+
*/
|
|
4381
|
+
renderModuleNav(pGroup, pModule) {
|
|
4382
|
+
let tmpDocProvider = this.pict.providers['Docuserve-Documentation'];
|
|
4383
|
+
if (!tmpDocProvider) {
|
|
4384
|
+
return;
|
|
4385
|
+
}
|
|
4386
|
+
let tmpSidebar = tmpDocProvider.getModuleSidebar(pGroup, pModule);
|
|
4387
|
+
if (!tmpSidebar) {
|
|
4388
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Sidebar-ModuleNav', '');
|
|
4389
|
+
return;
|
|
4390
|
+
}
|
|
4391
|
+
let tmpRoutePrefix = '#/doc/' + pGroup + '/' + pModule + '/';
|
|
4392
|
+
let tmpHTML = '<div class="docuserve-sidebar-module-nav">';
|
|
4393
|
+
for (let i = 0; i < tmpSidebar.length; i++) {
|
|
4394
|
+
let tmpEntry = tmpSidebar[i];
|
|
4395
|
+
if (tmpEntry.Children) {
|
|
4396
|
+
tmpHTML += '<div class="docuserve-sidebar-module-nav-section">' + this.escapeHTML(tmpEntry.Title) + '</div>';
|
|
4397
|
+
for (let j = 0; j < tmpEntry.Children.length; j++) {
|
|
4398
|
+
let tmpChild = tmpEntry.Children[j];
|
|
4399
|
+
if (tmpChild.Path) {
|
|
4400
|
+
tmpHTML += '<a href="' + tmpRoutePrefix + tmpChild.Path + '">' + this.escapeHTML(tmpChild.Title) + '</a>';
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4403
|
+
} else if (tmpEntry.Path) {
|
|
4404
|
+
tmpHTML += '<a href="' + tmpRoutePrefix + tmpEntry.Path + '">' + this.escapeHTML(tmpEntry.Title) + '</a>';
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
tmpHTML += '</div>';
|
|
4408
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Sidebar-ModuleNav', tmpHTML);
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4411
|
+
/**
|
|
4412
|
+
* Toggle the sidebar visibility and update the top bar hamburger button.
|
|
4413
|
+
*/
|
|
4414
|
+
toggleSidebar() {
|
|
4415
|
+
this.pict.AppData.Docuserve.SidebarVisible = !this.pict.AppData.Docuserve.SidebarVisible;
|
|
4416
|
+
let tmpContainer = document.getElementById('Docuserve-Sidebar-Container');
|
|
4417
|
+
let tmpToggle = document.getElementById('Docuserve-TopBar-Toggle');
|
|
4418
|
+
if (this.pict.AppData.Docuserve.SidebarVisible) {
|
|
4419
|
+
if (tmpContainer) tmpContainer.style.display = '';
|
|
4420
|
+
if (tmpToggle) tmpToggle.style.display = 'none';
|
|
4421
|
+
} else {
|
|
4422
|
+
if (tmpContainer) tmpContainer.style.display = 'none';
|
|
4423
|
+
if (tmpToggle) tmpToggle.style.display = 'inline-block';
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
|
|
4427
|
+
/**
|
|
4428
|
+
* Clear the module-specific sub-navigation.
|
|
4429
|
+
*/
|
|
4430
|
+
clearModuleNav() {
|
|
4431
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Sidebar-ModuleNav', '');
|
|
4432
|
+
}
|
|
4433
|
+
|
|
4434
|
+
/**
|
|
4435
|
+
* Escape HTML special characters.
|
|
4436
|
+
*
|
|
4437
|
+
* @param {string} pText - The text to escape
|
|
4438
|
+
* @returns {string} The escaped text
|
|
4439
|
+
*/
|
|
4440
|
+
escapeHTML(pText) {
|
|
4441
|
+
if (!pText) {
|
|
4442
|
+
return '';
|
|
4443
|
+
}
|
|
4444
|
+
return pText.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
module.exports = DocusserveSidebarView;
|
|
4448
|
+
module.exports.default_configuration = _ViewConfiguration;
|
|
4449
|
+
}, {
|
|
4450
|
+
"pict-view": 8
|
|
4451
|
+
}],
|
|
4452
|
+
15: [function (require, module, exports) {
|
|
4453
|
+
const libPictView = require('pict-view');
|
|
4454
|
+
const _ViewConfiguration = {
|
|
4455
|
+
ViewIdentifier: "Docuserve-Splash",
|
|
4456
|
+
DefaultRenderable: "Docuserve-Splash-Content",
|
|
4457
|
+
DefaultDestinationAddress: "#Docuserve-Content-Container",
|
|
4458
|
+
AutoRender: false,
|
|
4459
|
+
CSS: /*css*/"\n\t\t.docuserve-splash {\n\t\t\tdisplay: flex;\n\t\t\tflex-direction: column;\n\t\t\talign-items: center;\n\t\t\tjustify-content: center;\n\t\t\tmin-height: calc(100vh - 56px);\n\t\t\tpadding: 3em 2em;\n\t\t\ttext-align: center;\n\t\t\tbackground: linear-gradient(135deg, #f5f7fa 0%, #e8f5e9 100%);\n\t\t}\n\t\t.docuserve-splash h1 {\n\t\t\tfont-size: 3em;\n\t\t\tfont-weight: 700;\n\t\t\tcolor: #2c3e50;\n\t\t\tmargin: 0 0 0.25em 0;\n\t\t}\n\t\t.docuserve-splash-tagline {\n\t\t\tfont-size: 1.25em;\n\t\t\tcolor: #666;\n\t\t\tmargin-bottom: 1.5em;\n\t\t\tfont-style: italic;\n\t\t}\n\t\t.docuserve-splash-description {\n\t\t\tfont-size: 1em;\n\t\t\tcolor: #555;\n\t\t\tmax-width: 600px;\n\t\t\tline-height: 1.7;\n\t\t\tmargin-bottom: 2em;\n\t\t}\n\t\t.docuserve-splash-highlights {\n\t\t\tdisplay: grid;\n\t\t\tgrid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n\t\t\tgap: 1.25em;\n\t\t\tmax-width: 900px;\n\t\t\twidth: 100%;\n\t\t\tmargin-bottom: 2.5em;\n\t\t}\n\t\t.docuserve-splash-highlight-card {\n\t\t\tbackground: #fff;\n\t\t\tborder: 1px solid #e0e0e0;\n\t\t\tborder-radius: 8px;\n\t\t\tpadding: 1.25em;\n\t\t\ttext-align: left;\n\t\t\ttransition: box-shadow 0.2s, border-color 0.2s;\n\t\t}\n\t\t.docuserve-splash-highlight-card:hover {\n\t\t\tbox-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n\t\t\tborder-color: #42b983;\n\t\t}\n\t\t.docuserve-splash-highlight-card h3 {\n\t\t\tmargin: 0 0 0.5em 0;\n\t\t\tcolor: #2c3e50;\n\t\t\tfont-size: 1em;\n\t\t}\n\t\t.docuserve-splash-highlight-card p {\n\t\t\tmargin: 0;\n\t\t\tcolor: #777;\n\t\t\tfont-size: 0.85em;\n\t\t\tline-height: 1.5;\n\t\t}\n\t\t.docuserve-splash-actions {\n\t\t\tdisplay: flex;\n\t\t\tgap: 1em;\n\t\t\tflex-wrap: wrap;\n\t\t\tjustify-content: center;\n\t\t}\n\t\t.docuserve-splash-actions a {\n\t\t\tdisplay: inline-block;\n\t\t\tpadding: 0.7em 1.5em;\n\t\t\tborder-radius: 6px;\n\t\t\tfont-size: 0.95em;\n\t\t\tfont-weight: 600;\n\t\t\ttext-decoration: none;\n\t\t\ttransition: background-color 0.15s, color 0.15s;\n\t\t\tcursor: pointer;\n\t\t}\n\t\t.docuserve-splash-actions .primary {\n\t\t\tbackground-color: #42b983;\n\t\t\tcolor: #fff;\n\t\t}\n\t\t.docuserve-splash-actions .primary:hover {\n\t\t\tbackground-color: #38a373;\n\t\t}\n\t\t.docuserve-splash-actions .secondary {\n\t\t\tbackground-color: #fff;\n\t\t\tcolor: #2c3e50;\n\t\t\tborder: 1px solid #ddd;\n\t\t}\n\t\t.docuserve-splash-actions .secondary:hover {\n\t\t\tborder-color: #42b983;\n\t\t\tcolor: #42b983;\n\t\t}\n\t",
|
|
4460
|
+
Templates: [{
|
|
4461
|
+
Hash: "Docuserve-Splash-Template",
|
|
4462
|
+
Template: /*html*/"\n<div class=\"docuserve-splash\">\n\t<h1 id=\"Docuserve-Splash-Title\"></h1>\n\t<div class=\"docuserve-splash-tagline\" id=\"Docuserve-Splash-Tagline\"></div>\n\t<div class=\"docuserve-splash-description\" id=\"Docuserve-Splash-Description\"></div>\n\t<div class=\"docuserve-splash-highlights\" id=\"Docuserve-Splash-Highlights\"></div>\n\t<div class=\"docuserve-splash-actions\" id=\"Docuserve-Splash-Actions\"></div>\n</div>\n"
|
|
4463
|
+
}],
|
|
4464
|
+
Renderables: [{
|
|
4465
|
+
RenderableHash: "Docuserve-Splash-Content",
|
|
4466
|
+
TemplateHash: "Docuserve-Splash-Template",
|
|
4467
|
+
DestinationAddress: "#Docuserve-Content-Container",
|
|
4468
|
+
RenderMethod: "replace"
|
|
4469
|
+
}]
|
|
4470
|
+
};
|
|
4471
|
+
class DocusserveSplashView extends libPictView {
|
|
4472
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
4473
|
+
super(pFable, pOptions, pServiceHash);
|
|
4474
|
+
}
|
|
4475
|
+
onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent) {
|
|
4476
|
+
let tmpDocuserve = this.pict.AppData.Docuserve;
|
|
4477
|
+
if (tmpDocuserve.CoverLoaded && tmpDocuserve.Cover) {
|
|
4478
|
+
this.renderFromCover(tmpDocuserve.Cover);
|
|
4479
|
+
} else {
|
|
4480
|
+
this.renderFromCatalog(tmpDocuserve);
|
|
4481
|
+
}
|
|
4482
|
+
return super.onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent);
|
|
4483
|
+
}
|
|
4484
|
+
|
|
4485
|
+
/**
|
|
4486
|
+
* Render the splash screen from parsed cover.md data.
|
|
4487
|
+
*
|
|
4488
|
+
* @param {Object} pCover - The parsed cover data { Title, Tagline, Description, Highlights, Actions }
|
|
4489
|
+
*/
|
|
4490
|
+
renderFromCover(pCover) {
|
|
4491
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Title', this.escapeHTML(pCover.Title));
|
|
4492
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Tagline', this.escapeHTML(pCover.Tagline));
|
|
4493
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Description', this.escapeHTML(pCover.Description));
|
|
4494
|
+
|
|
4495
|
+
// Render highlight cards
|
|
4496
|
+
let tmpHighlightsHTML = '';
|
|
4497
|
+
for (let i = 0; i < pCover.Highlights.length; i++) {
|
|
4498
|
+
let tmpHighlight = pCover.Highlights[i];
|
|
4499
|
+
tmpHighlightsHTML += '<div class="docuserve-splash-highlight-card">';
|
|
4500
|
+
if (tmpHighlight.Label) {
|
|
4501
|
+
tmpHighlightsHTML += '<h3>' + this.escapeHTML(tmpHighlight.Label) + '</h3>';
|
|
4502
|
+
}
|
|
4503
|
+
tmpHighlightsHTML += '<p>' + this.escapeHTML(tmpHighlight.Text) + '</p>';
|
|
4504
|
+
tmpHighlightsHTML += '</div>';
|
|
4505
|
+
}
|
|
4506
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Highlights', tmpHighlightsHTML);
|
|
4507
|
+
|
|
4508
|
+
// Render action buttons
|
|
4509
|
+
let tmpActionsHTML = '';
|
|
4510
|
+
let tmpDocProvider = this.pict.providers['Docuserve-Documentation'];
|
|
4511
|
+
for (let i = 0; i < pCover.Actions.length; i++) {
|
|
4512
|
+
let tmpAction = pCover.Actions[i];
|
|
4513
|
+
let tmpClass = i === 0 ? 'primary' : 'secondary';
|
|
4514
|
+
let tmpHref = tmpAction.Href;
|
|
4515
|
+
|
|
4516
|
+
// External links open in new tab
|
|
4517
|
+
if (tmpHref.match(/^https?:\/\//)) {
|
|
4518
|
+
tmpActionsHTML += '<a class="' + tmpClass + '" href="' + this.escapeHTML(tmpHref) + '" target="_blank" rel="noopener">' + this.escapeHTML(tmpAction.Text) + '</a>';
|
|
4519
|
+
} else {
|
|
4520
|
+
// Internal links go through the app router
|
|
4521
|
+
let tmpRoute = tmpDocProvider.convertSidebarLink(tmpHref);
|
|
4522
|
+
tmpActionsHTML += '<a class="' + tmpClass + '" href="' + this.escapeHTML(tmpRoute) + '">' + this.escapeHTML(tmpAction.Text) + '</a>';
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Actions', tmpActionsHTML);
|
|
4526
|
+
}
|
|
4527
|
+
|
|
4528
|
+
/**
|
|
4529
|
+
* Render the splash screen from catalog data as a fallback when cover.md
|
|
4530
|
+
* is not available.
|
|
4531
|
+
*
|
|
4532
|
+
* @param {Object} pDocuserve - The AppData.Docuserve state
|
|
4533
|
+
*/
|
|
4534
|
+
renderFromCatalog(pDocuserve) {
|
|
4535
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Title', 'Retold');
|
|
4536
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Tagline', 'Documentation');
|
|
4537
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Description', '');
|
|
4538
|
+
|
|
4539
|
+
// Build highlight cards from catalog groups
|
|
4540
|
+
let tmpHighlightsHTML = '';
|
|
4541
|
+
let tmpGroups = pDocuserve.SidebarGroups || [];
|
|
4542
|
+
for (let i = 0; i < tmpGroups.length; i++) {
|
|
4543
|
+
let tmpGroup = tmpGroups[i];
|
|
4544
|
+
// Skip groups with no modules (like "Home" or "Getting Started")
|
|
4545
|
+
if (!tmpGroup.Modules || tmpGroup.Modules.length < 1) {
|
|
4546
|
+
continue;
|
|
4547
|
+
}
|
|
4548
|
+
let tmpDescription = tmpGroup.Description || tmpGroup.Modules.length + ' modules';
|
|
4549
|
+
tmpHighlightsHTML += '<div class="docuserve-splash-highlight-card">';
|
|
4550
|
+
tmpHighlightsHTML += '<h3>' + this.escapeHTML(tmpGroup.Name) + '</h3>';
|
|
4551
|
+
tmpHighlightsHTML += '<p>' + this.escapeHTML(tmpDescription) + '</p>';
|
|
4552
|
+
tmpHighlightsHTML += '</div>';
|
|
4553
|
+
}
|
|
4554
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Highlights', tmpHighlightsHTML);
|
|
4555
|
+
|
|
4556
|
+
// Default action buttons
|
|
4557
|
+
this.pict.ContentAssignment.assignContent('#Docuserve-Splash-Actions', '');
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4560
|
+
/**
|
|
4561
|
+
* Escape HTML special characters.
|
|
4562
|
+
*
|
|
4563
|
+
* @param {string} pText - The text to escape
|
|
4564
|
+
* @returns {string} The escaped text
|
|
4565
|
+
*/
|
|
4566
|
+
escapeHTML(pText) {
|
|
4567
|
+
if (!pText) {
|
|
4568
|
+
return '';
|
|
4569
|
+
}
|
|
4570
|
+
return pText.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
4571
|
+
}
|
|
4572
|
+
}
|
|
4573
|
+
module.exports = DocusserveSplashView;
|
|
4574
|
+
module.exports.default_configuration = _ViewConfiguration;
|
|
4575
|
+
}, {
|
|
4576
|
+
"pict-view": 8
|
|
4577
|
+
}],
|
|
4578
|
+
16: [function (require, module, exports) {
|
|
4579
|
+
const libPictView = require('pict-view');
|
|
4580
|
+
const _ViewConfiguration = {
|
|
4581
|
+
ViewIdentifier: "Docuserve-TopBar",
|
|
4582
|
+
DefaultRenderable: "Docuserve-TopBar-Content",
|
|
4583
|
+
DefaultDestinationAddress: "#Docuserve-TopBar-Container",
|
|
4584
|
+
AutoRender: false,
|
|
4585
|
+
CSS: /*css*/"\n\t\t.docuserve-topbar {\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t\tjustify-content: space-between;\n\t\t\tbackground-color: #2c3e50;\n\t\t\tcolor: #ecf0f1;\n\t\t\tpadding: 0 1.5em;\n\t\t\theight: 56px;\n\t\t\tbox-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);\n\t\t\tposition: sticky;\n\t\t\ttop: 0;\n\t\t\tz-index: 100;\n\t\t}\n\t\t.docuserve-topbar-brand {\n\t\t\tfont-size: 1.25em;\n\t\t\tfont-weight: 600;\n\t\t\tletter-spacing: 0.02em;\n\t\t\tcolor: #ecf0f1;\n\t\t\ttext-decoration: none;\n\t\t\tcursor: pointer;\n\t\t}\n\t\t.docuserve-topbar-brand:hover {\n\t\t\tcolor: #fff;\n\t\t}\n\t\t.docuserve-topbar-nav {\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t\tgap: 0.25em;\n\t\t}\n\t\t.docuserve-topbar-nav a {\n\t\t\tcolor: #bdc3c7;\n\t\t\ttext-decoration: none;\n\t\t\tpadding: 0.5em 0.75em;\n\t\t\tborder-radius: 4px;\n\t\t\tfont-size: 0.9em;\n\t\t\ttransition: background-color 0.15s, color 0.15s;\n\t\t\tcursor: pointer;\n\t\t}\n\t\t.docuserve-topbar-nav a:hover {\n\t\t\tbackground-color: #34495e;\n\t\t\tcolor: #fff;\n\t\t}\n\t\t.docuserve-topbar-links {\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t\tgap: 0.5em;\n\t\t}\n\t\t.docuserve-topbar-links a {\n\t\t\tcolor: #95a5a6;\n\t\t\ttext-decoration: none;\n\t\t\tfont-size: 0.85em;\n\t\t\tpadding: 0.4em 0.6em;\n\t\t\tborder-radius: 4px;\n\t\t\ttransition: background-color 0.15s, color 0.15s;\n\t\t}\n\t\t.docuserve-topbar-links a:hover {\n\t\t\tbackground-color: #34495e;\n\t\t\tcolor: #ecf0f1;\n\t\t}\n\t\t.docuserve-topbar-toggle {\n\t\t\tdisplay: none;\n\t\t\tbackground: none;\n\t\t\tborder: none;\n\t\t\tcolor: #bdc3c7;\n\t\t\tfont-size: 1.3em;\n\t\t\tcursor: pointer;\n\t\t\tpadding: 0.3em 0.5em;\n\t\t\tmargin-left: 0.5em;\n\t\t\tline-height: 1;\n\t\t}\n\t\t.docuserve-topbar-toggle:hover {\n\t\t\tcolor: #fff;\n\t\t}\n\t\t.docuserve-topbar-right {\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t}\n\t",
|
|
4586
|
+
Templates: [{
|
|
4587
|
+
Hash: "Docuserve-TopBar-Template",
|
|
4588
|
+
Template: /*html*/"\n<div class=\"docuserve-topbar\">\n\t<a id=\"Docuserve-TopBar-Brand\" class=\"docuserve-topbar-brand\" href=\"#/Home\"></a>\n\t<div id=\"Docuserve-TopBar-Nav\" class=\"docuserve-topbar-nav\"></div>\n\t<div class=\"docuserve-topbar-right\">\n\t\t<div id=\"Docuserve-TopBar-Links\" class=\"docuserve-topbar-links\"></div>\n\t\t<button id=\"Docuserve-TopBar-Toggle\" class=\"docuserve-topbar-toggle\" onclick=\"{~P~}.views['Docuserve-Sidebar'].toggleSidebar()\">☰</button>\n\t</div>\n</div>\n"
|
|
4589
|
+
}],
|
|
4590
|
+
Renderables: [{
|
|
4591
|
+
RenderableHash: "Docuserve-TopBar-Content",
|
|
4592
|
+
TemplateHash: "Docuserve-TopBar-Template",
|
|
4593
|
+
DestinationAddress: "#Docuserve-TopBar-Container",
|
|
4594
|
+
RenderMethod: "replace"
|
|
4595
|
+
}]
|
|
4596
|
+
};
|
|
4597
|
+
class DocuserveTopBarView extends libPictView {
|
|
4598
|
+
constructor(pFable, pOptions, pServiceHash) {
|
|
4599
|
+
super(pFable, pOptions, pServiceHash);
|
|
4600
|
+
}
|
|
4601
|
+
onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent) {
|
|
4602
|
+
this.renderTopBarContent();
|
|
4603
|
+
return super.onAfterRender(pRenderable, pRenderDestinationAddress, pRecord, pContent);
|
|
4604
|
+
}
|
|
4605
|
+
|
|
4606
|
+
/**
|
|
4607
|
+
* Populate the top bar from _topbar.md data or fall back to defaults.
|
|
4608
|
+
*/
|
|
4609
|
+
renderTopBarContent() {
|
|
4610
|
+
let tmpDocuserve = this.pict.AppData.Docuserve;
|
|
4611
|
+
let tmpBrandEl = document.getElementById('Docuserve-TopBar-Brand');
|
|
4612
|
+
let tmpNavEl = document.getElementById('Docuserve-TopBar-Nav');
|
|
4613
|
+
let tmpLinksEl = document.getElementById('Docuserve-TopBar-Links');
|
|
4614
|
+
if (!tmpBrandEl || !tmpNavEl || !tmpLinksEl) {
|
|
4615
|
+
return;
|
|
4616
|
+
}
|
|
4617
|
+
if (tmpDocuserve.TopBarLoaded && tmpDocuserve.TopBar) {
|
|
4618
|
+
// Data-driven from _topbar.md
|
|
4619
|
+
let tmpTopBar = tmpDocuserve.TopBar;
|
|
4620
|
+
|
|
4621
|
+
// Brand
|
|
4622
|
+
tmpBrandEl.textContent = tmpTopBar.Brand || 'Documentation';
|
|
4623
|
+
|
|
4624
|
+
// Navigation links (centre)
|
|
4625
|
+
let tmpNavHTML = '<a href="#/Home">Home</a>';
|
|
4626
|
+
for (let i = 0; i < tmpTopBar.NavLinks.length; i++) {
|
|
4627
|
+
let tmpLink = tmpTopBar.NavLinks[i];
|
|
4628
|
+
tmpNavHTML += '<a href="' + tmpLink.Href + '">' + this.escapeHTML(tmpLink.Text) + '</a>';
|
|
4629
|
+
}
|
|
4630
|
+
tmpNavEl.innerHTML = tmpNavHTML;
|
|
4631
|
+
|
|
4632
|
+
// External links (right side)
|
|
4633
|
+
let tmpLinksHTML = '';
|
|
4634
|
+
for (let i = 0; i < tmpTopBar.ExternalLinks.length; i++) {
|
|
4635
|
+
let tmpLink = tmpTopBar.ExternalLinks[i];
|
|
4636
|
+
tmpLinksHTML += '<a href="' + this.escapeHTML(tmpLink.Href) + '" target="_blank" rel="noopener">' + this.escapeHTML(tmpLink.Text) + '</a>';
|
|
4637
|
+
}
|
|
4638
|
+
tmpLinksEl.innerHTML = tmpLinksHTML;
|
|
4639
|
+
} else {
|
|
4640
|
+
// Fallback: use brand from cover or a default, and just show Home
|
|
4641
|
+
let tmpBrand = 'Documentation';
|
|
4642
|
+
if (tmpDocuserve.CoverLoaded && tmpDocuserve.Cover && tmpDocuserve.Cover.Title) {
|
|
4643
|
+
tmpBrand = tmpDocuserve.Cover.Title;
|
|
4644
|
+
} else if (tmpDocuserve.CatalogLoaded && tmpDocuserve.Catalog && tmpDocuserve.Catalog.Name) {
|
|
4645
|
+
tmpBrand = tmpDocuserve.Catalog.Name;
|
|
4646
|
+
}
|
|
4647
|
+
tmpBrandEl.textContent = tmpBrand;
|
|
4648
|
+
tmpNavEl.innerHTML = '<a href="#/Home">Home</a>';
|
|
4649
|
+
tmpLinksEl.innerHTML = '';
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
|
|
4653
|
+
/**
|
|
4654
|
+
* Escape HTML special characters.
|
|
4655
|
+
*/
|
|
4656
|
+
escapeHTML(pText) {
|
|
4657
|
+
if (!pText) {
|
|
4658
|
+
return '';
|
|
4659
|
+
}
|
|
4660
|
+
return pText.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
4661
|
+
}
|
|
4662
|
+
}
|
|
4663
|
+
module.exports = DocuserveTopBarView;
|
|
4664
|
+
module.exports.default_configuration = _ViewConfiguration;
|
|
4665
|
+
}, {
|
|
4666
|
+
"pict-view": 8
|
|
4667
|
+
}]
|
|
4668
|
+
}, {}, [10])(10);
|
|
4669
|
+
});
|
|
4670
|
+
//# sourceMappingURL=pict-docuserve.js.map
|