sdc_client 0.58.6 → 0.158.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.
Files changed (39) hide show
  1. package/.github/workflows/node.js.yml +2 -2
  2. package/.idea/inspectionProfiles/Project_Default.xml +17 -0
  3. package/.idea/workspace.xml +122 -23
  4. package/.readthedocs.yaml +13 -0
  5. package/dist/index.js +70 -51
  6. package/dist/ugly.index.js +1 -1
  7. package/docs/api-reference.rst +225 -0
  8. package/docs/conf.py +11 -0
  9. package/docs/controllers.rst +228 -0
  10. package/docs/events-and-dom.rst +120 -0
  11. package/docs/getting-started.rst +143 -0
  12. package/docs/index.rst +22 -0
  13. package/docs/models.rst +351 -0
  14. package/docs/overview.rst +66 -0
  15. package/docs/requirements.txt +1 -0
  16. package/eslint.config.js +60 -0
  17. package/gulp/gulp.jsx +15 -13
  18. package/package.json +13 -3
  19. package/src/index.js +44 -11
  20. package/src/simpleDomControl/AbstractSDC.js +287 -286
  21. package/src/simpleDomControl/sdc_controller.js +157 -132
  22. package/src/simpleDomControl/sdc_dom_events.js +99 -88
  23. package/src/simpleDomControl/sdc_events.js +39 -40
  24. package/src/simpleDomControl/sdc_main.js +88 -67
  25. package/src/simpleDomControl/sdc_model.js +1513 -0
  26. package/src/simpleDomControl/sdc_params.js +44 -29
  27. package/src/simpleDomControl/sdc_server_call.js +153 -154
  28. package/src/simpleDomControl/sdc_socket.js +8 -829
  29. package/src/simpleDomControl/sdc_test_utils.js +77 -80
  30. package/src/simpleDomControl/sdc_utils.js +295 -176
  31. package/src/simpleDomControl/sdc_view.js +245 -177
  32. package/test/model.test.js +332 -0
  33. package/test/models/Author.js +145 -0
  34. package/test/models/Book.js +112 -0
  35. package/test/models/BookContent.js +114 -0
  36. package/test/models/SdcUser.js +75 -0
  37. package/test/models/src.js +8 -0
  38. package/test/sdc_model_dates.ai.test.js +57 -0
  39. package/test/sdc_server_call.ai.test.js +267 -0
@@ -1,337 +1,338 @@
1
1
  import {allOff} from "./sdc_events.js";
2
2
  import {app} from "./sdc_main.js";
3
- import {Model} from "./sdc_socket.js";
3
+ import {SdcQuerySet} from "./sdc_model.js";
4
4
  import {callServer} from "./sdc_server_call.js";
5
- import {uuidv4, setErrorsInForm, clearErrorsInForm, tagNameToCamelCase, tagNameToReadableName} from "./sdc_utils.js";
5
+ import {
6
+ uuidv4,
7
+ clearErrorsInForm,
8
+ tagNameToCamelCase,
9
+ tagNameToReadableName,
10
+ } from "./sdc_utils.js";
6
11
 
7
12
  export class AbstractSDC {
8
- constructor() {
9
- this._uuid = uuidv4();
10
- this.contentUrl = '';
11
- this.contentReload = false;
12
- this.parsedContentUrl = null;
13
- this.events = [];
14
- this.load_async = false;
15
- this._isEventsSet = false;
16
- this._allEvents = null;
17
-
18
- this._urlParams = [];
19
- this._models = [];
20
-
21
- // ------------------ Old deprecated properties ----------------------
22
- this._cssUrls = [];
23
- this.afterShow = () => {
24
- console.warn('afterShow is deprecated!!')
25
- };
26
- // -------------- End old deprecated properties ----------------------
27
-
28
-
29
- /**
30
- *
31
- * @type {{string: AbstractSDC}}
32
- */
33
- this._mixins = {};
34
-
35
- /**
36
- * @type {string}
37
- */
38
- this._tagName = Object.getPrototypeOf(this)._tagName ?? '';
39
-
40
- /**
41
- * @type {{string:AbstractSDC}}
42
- */
43
- this._childController = {};
44
-
45
- /**
46
- * @type {AbstractSDC}
47
- */
48
- this._parentController = null;
49
-
50
- /**
51
- * @type {boolean}
52
- */
53
- this._onLoadDone = false;
54
-
55
- /**
56
- * @type {jquery}
57
- */
58
- this.$container = null;
59
-
60
- /**
61
- *
62
- * @type {boolean}
63
- */
64
- this._isMixin = false;
65
- }
13
+ constructor() {
14
+ this._uuid = uuidv4();
15
+ this.contentUrl = "";
16
+ this.contentReload = false;
17
+ this.parsedContentUrl = null;
18
+ this.events = [];
19
+ this.load_async = false;
20
+ this._isEventsSet = false;
21
+ this._allEvents = null;
22
+
23
+ this._urlParams = [];
24
+ this._models = [];
25
+
26
+ // ------------------ Old deprecated properties ----------------------
27
+ this._cssUrls = [];
28
+ this.afterShow = () => {
29
+ console.warn("afterShow is deprecated!!");
30
+ };
31
+ // -------------- End old deprecated properties ----------------------
66
32
 
67
33
  /**
68
34
  *
69
- * @param {string} method must be in {}
70
- * @param {Array} args in arguments of
71
- *
35
+ * @type {{string: AbstractSDC}}
72
36
  */
73
- _runLifecycle(method, args) {
74
- if (app.DEBUG && !this._isMixin) {
75
- console.debug(method, this._tagName);
76
- }
77
-
78
- let returnPromisses = [];
79
- if (this._isMixin) {
80
- return;
81
- }
82
- this._isMixin = true;
83
- for (let mixinKey in this._mixins) {
84
- let mixin = this._mixins[mixinKey];
85
- if (typeof mixin[method] === 'function') {
37
+ this._mixins = {};
86
38
 
87
- returnPromisses.push(mixin[method].apply(this, args));
88
- }
89
- }
90
-
91
- return Promise.all(returnPromisses).then(() => {
92
- this._isMixin = false;
93
- });
94
- }
95
-
96
- onInit() {
97
- if (app.DEBUG && !this._isMixin) {
98
- console.DEBUG(Array.apply(null, arguments), this._tagName);
99
- }
100
- }
39
+ /**
40
+ * @type {string}
41
+ */
42
+ this._tagName = Object.getPrototypeOf(this)._tagName ?? "";
101
43
 
102
- get parentController() {
103
- return this._parentController;
104
- }
44
+ /**
45
+ * @type {{string:AbstractSDC}}
46
+ */
47
+ this._childController = {};
105
48
 
106
- get childController() {
107
- return this._childController;
108
- }
49
+ /**
50
+ * @type {AbstractSDC}
51
+ */
52
+ this._parentController = null;
109
53
 
110
- onLoad() {
111
- return this._runLifecycle('onLoad', arguments);
112
- }
54
+ /**
55
+ * @type {boolean}
56
+ */
57
+ this._onLoadDone = false;
113
58
 
114
- willShow() {
115
- return this._runLifecycle('willShow', arguments);
116
- }
59
+ /**
60
+ * @type {jquery}
61
+ */
62
+ this.$container = null;
117
63
 
118
- onRefresh() {
119
- return this._runLifecycle('onRefresh', arguments);
64
+ /**
65
+ *
66
+ * @type {boolean}
67
+ */
68
+ this._isMixin = false;
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @param {string} method must be in {}
74
+ * @param {Array} args in arguments of
75
+ *
76
+ */
77
+ _runLifecycle(method, args) {
78
+ if (app.DEBUG && !this._isMixin) {
79
+ console.debug(method, this._tagName);
120
80
  }
121
81
 
122
- onRemove() {
123
- this._runLifecycle('onRemove', arguments)
124
- return true;
82
+ let returnPromisses = [];
83
+ if (this._isMixin) {
84
+ return;
125
85
  }
126
-
127
- noOpenModelRequests( ) {
128
- return Promise.all(this._models.map(x => x.noOpenRequests()));
86
+ this._isMixin = true;
87
+ for (let mixinKey in this._mixins) {
88
+ let mixin = this._mixins[mixinKey];
89
+ if (typeof mixin[method] === "function") {
90
+ returnPromisses.push(mixin[method].apply(this, args));
91
+ }
129
92
  }
130
93
 
131
- remove() {
132
- for (const model of this._models) {
133
- model.close();
134
- }
135
- let _childController = this._childController;
136
- for (let i in _childController) {
137
- if (_childController.hasOwnProperty(i)) {
138
- for (let cc of _childController[i]) {
139
- if (!cc.remove()) {
140
- return false;
141
- }
142
- }
143
- }
144
- }
145
-
146
- if (!this.onRemove || this.onRemove()) {
147
- allOff(this);
148
- const c_name = tagNameToCamelCase(this._tagName);
149
- if (this._parentController._childController[c_name]) {
150
- let arr = this._parentController._childController[c_name];
151
- for (let i = 0; i < arr.length; i++) {
152
- if (arr[i] === this) {
153
- arr.splice(i, 1);
154
- }
155
- }
156
- }
157
-
158
- this.$container.remove();
159
- delete this;
160
- return true;
161
- }
162
-
163
- return false;
94
+ return Promise.all(returnPromisses).then(() => {
95
+ this._isMixin = false;
96
+ });
97
+ }
98
+
99
+ /**
100
+ *
101
+ * @return {Promise<*>|*}
102
+ */
103
+ onInit() {
104
+ if (app.DEBUG && !this._isMixin) {
105
+ console.debug(Array.apply(null, arguments), this._tagName);
164
106
  }
107
+ }
165
108
 
166
- controller_name() {
167
- return tagNameToReadableName(this._tagName);
168
- }
109
+ get parentController() {
110
+ return this._parentController;
111
+ }
169
112
 
170
- addEvent(event, selector, handler) {
171
- this.getEvents();
172
- this._allEvents[event] = this._allEvents[event] || {};
173
- this._allEvents[event][selector] = handler;
174
- }
113
+ get childController() {
114
+ return this._childController;
115
+ }
175
116
 
176
- getEvents() {
177
- if (this._allEvents) return this._allEvents;
178
- let allEvents = [];
179
- allEvents = allEvents.concat(this.events);
180
- for (let mixinKey in this._mixins) {
181
- let mixin = this._mixins[mixinKey];
182
- if (Array.isArray(mixin.events)) {
183
- allEvents = allEvents.concat(mixin.events)
184
- }
185
- }
117
+ onLoad() {
118
+ return this._runLifecycle("onLoad", arguments);
119
+ }
186
120
 
121
+ willShow() {
122
+ return this._runLifecycle("willShow", arguments);
123
+ }
187
124
 
188
- return (this._allEvents = _.merge(...allEvents));
189
- }
125
+ onRefresh() {
126
+ return this._runLifecycle("onRefresh", arguments);
127
+ }
190
128
 
191
- post(url, args) {
192
- return app.post(this, url, args);
193
- }
129
+ onRemove() {
130
+ this._runLifecycle("onRemove", arguments);
131
+ return true;
132
+ }
194
133
 
195
- get(url, args) {
196
- return app.get(this, url, args);
197
- }
134
+ noOpenModelRequests() {
135
+ return Promise.all(this._models.map((x) => x.noOpenRequests()));
136
+ }
198
137
 
199
- submitForm(form, url, method) {
200
- return app.submitFormAndUpdateView(this, form, url, method);
138
+ remove() {
139
+ for (const model of this._models) {
140
+ model.close();
201
141
  }
202
-
203
- serverCall(methode, args) {
204
- let re = /sdc_view\/([^/]+)/i;
205
- let app = this.contentUrl.match(re);
206
- if (!app || app.length < 2) {
207
- console.error('To use the serverCall function the contentUrl must be set: ' + this.name);
208
- return;
142
+ let _childController = this._childController;
143
+ for (let i in _childController) {
144
+ if (_childController.hasOwnProperty(i)) {
145
+ for (let cc of _childController[i]) {
146
+ if (!cc.remove()) {
147
+ return false;
148
+ }
209
149
  }
210
-
211
- return callServer(app[1], this._tagName, this.parsedContentUrl ?? this.contentUrl, methode, args);
150
+ }
212
151
  }
213
152
 
214
- /**
215
- *
216
- * @param model_name {string | Number}
217
- * @param model_query {Object}
218
- * @constructor
219
- */
220
- newModel(model_name, model_query = {}) {
221
- if(model_name instanceof Number && model_name.hasOwnProperty('load')) {
222
- return model_name.load(this);
223
- }
224
- if (model_name instanceof Model) {
225
- return model_name;
153
+ if (!this.onRemove || this.onRemove()) {
154
+ allOff(this);
155
+ const c_name = tagNameToCamelCase(this._tagName);
156
+ if (this._parentController._childController[c_name]) {
157
+ let arr = this._parentController._childController[c_name];
158
+ for (let i = 0; i < arr.length; i++) {
159
+ if (arr[i] === this) {
160
+ arr.splice(i, 1);
161
+ }
226
162
  }
163
+ }
227
164
 
228
- const model = new Model(model_name, model_query);
229
- this._models.push(model);
230
- return model;
165
+ this.$container.remove();
166
+ delete this;
167
+ return true;
231
168
  }
232
169
 
233
- /**
234
- *
235
- * @param model_name {string}
236
- * @param model_query {Object}
237
- * @param values {Object}
238
- * @constructor
239
- */
240
- updateModel(model_name, model_query = {}, values) {
241
- let model = new Model(model_name, model_query);
242
- return model.load().then(()=>{
243
- model.values |= values;
244
- model.save().then(()=> {
245
- model.close();
246
- return model.values
247
- });
248
- });
170
+ return false;
171
+ }
172
+
173
+ controller_name() {
174
+ return tagNameToReadableName(this._tagName);
175
+ }
176
+
177
+ addEvent(event, selector, handler) {
178
+ this.getEvents();
179
+ this._allEvents[event] = this._allEvents[event] || {};
180
+ this._allEvents[event][selector] = handler;
181
+ }
182
+
183
+ getEvents() {
184
+ if (this._allEvents) return this._allEvents;
185
+ let allEvents = [];
186
+ allEvents = allEvents.concat(this.events);
187
+ for (let mixinKey in this._mixins) {
188
+ let mixin = this._mixins[mixinKey];
189
+ if (Array.isArray(mixin.events)) {
190
+ allEvents = allEvents.concat(mixin.events);
191
+ }
249
192
  }
250
193
 
251
- /**
252
- * Adapter to this.$container.find
253
- * @param {string} domSelector
254
- */
255
- find(domSelector) {
256
- return this.$container.find(domSelector);
194
+ return (this._allEvents = _.merge(...allEvents));
195
+ }
196
+
197
+ post(url, args) {
198
+ return app.post(this, url, args);
199
+ }
200
+
201
+ get(url, args) {
202
+ return app.get(this, url, args);
203
+ }
204
+
205
+ submitForm(form, url, method) {
206
+ return app.submitFormAndUpdateView(this, form, url, method);
207
+ }
208
+
209
+ serverCall(methode, args) {
210
+ let re = /sdc_view\/([^/]+)/i;
211
+ let app = this.contentUrl.match(re);
212
+ if (!app || app.length < 2) {
213
+ console.error(
214
+ "To use the serverCall function the contentUrl must be set: " +
215
+ this.name,
216
+ );
217
+ return;
257
218
  }
258
219
 
259
- refresh() {
260
- return app.refresh(this.$container, this);
220
+ return callServer(
221
+ app[1],
222
+ this._tagName,
223
+ this.parsedContentUrl ?? this.contentUrl,
224
+ methode,
225
+ args,
226
+ );
227
+ }
228
+
229
+ /**
230
+ *
231
+ * @param {string} modelName
232
+ * @param {object?} modelQuery
233
+ * @returns {SdcQuerySet}
234
+ */
235
+ querySet(modelName, modelQuery = {}) {
236
+ const newQuerySet = new SdcQuerySet(modelName, modelQuery);
237
+ this._models.push(newQuerySet);
238
+ return newQuerySet;
239
+ }
240
+
241
+ newModel(modelName, modelQuery = {}) {
242
+ console.warn("newModel is deprecated and will soon be removed");
243
+ return this.querySet(modelName, modelQuery);
244
+ }
245
+
246
+ /**
247
+ * Adapter to this.$container.find
248
+ * @param {string} domSelector
249
+ */
250
+ find(domSelector) {
251
+ return this.$container.find(domSelector);
252
+ }
253
+
254
+ refresh() {
255
+ return app.refresh(this.$container, this);
256
+ }
257
+
258
+ reload() {
259
+ return app.reloadController(this);
260
+ }
261
+
262
+ reconcile($virtualNode, $realNode = null) {
263
+ return app.reconcile(this, $virtualNode, $realNode);
264
+ }
265
+
266
+ submitModelFormDistributor($form, e) {
267
+ if (typeof this._submitModelForm === "function") {
268
+ return this._submitModelForm($form, e);
261
269
  }
262
-
263
- reload() {
264
- return app.reloadController(this);
265
- }
266
-
267
- reconcile($virtualNode, $realNode = null) {
268
- return app.reconcile(this, $virtualNode, $realNode);
270
+ if (typeof this.submitModelForm === "function") {
271
+ return this.submitModelForm($form, e);
269
272
  }
270
-
271
- submitModelFormDistributor($form, e) {
272
- if (typeof this._submitModelForm === 'function') {
273
- return this._submitModelForm($form, e);
273
+ return this.defaultSubmitModelForm($form, e);
274
+ }
275
+
276
+ iterateAllChildren() {
277
+ let _childController = this._childController;
278
+ let res = [];
279
+ for (let i in _childController) {
280
+ if (_childController.hasOwnProperty(i)) {
281
+ for (let cc of _childController[i]) {
282
+ res.push(cc);
283
+ res.push(...cc.iterateAllChildren());
274
284
  }
275
- if (typeof this.submitModelForm === 'function') {
276
- return this.submitModelForm($form, e);
277
- }
278
- return this.defaultSubmitModelForm($form, e);
285
+ }
279
286
  }
287
+ return res;
288
+ }
289
+
290
+ /**
291
+ * Model Form Events
292
+ */
293
+ defaultSubmitModelForm($form, e) {
294
+ if (!this._isMixin) {
295
+ e.stopPropagation();
296
+ e.preventDefault();
297
+ let {model, form_name} = $form.data();
298
+ let data = model.syncForm($form);
299
+ return new Promise((resolve, reject) => {
300
+ let prom;
301
+ if (model.id !== null && model.id >= 0) {
302
+ prom = model.save({formName: form_name, data});
303
+ } else {
304
+ prom = model.create({data});
305
+ }
280
306
 
281
- iterateAllChildren() {
282
- let _childController = this._childController;
283
- let res = [];
284
- for (let i in _childController) {
285
- if (_childController.hasOwnProperty(i)) {
286
- for (let cc of _childController[i]) {
287
- res.push(cc);
288
- res.push(...cc.iterateAllChildren());
289
- }
307
+ prom
308
+ .then((res) => {
309
+ clearErrorsInForm($form);
310
+ this.submit_model_form_success &&
311
+ this.submit_model_form_success(res[0]);
312
+ for (const controller of this.iterateAllChildren()) {
313
+ controller.submit_model_form_success &&
314
+ controller.submit_model_form_success(res[0]);
290
315
  }
291
- }
292
- return res;
293
- }
294
316
 
295
- /**
296
- * Model Form Events
297
- */
298
- defaultSubmitModelForm($form, e) {
299
- let p_list = [];
300
- if (!this._isMixin) {
301
- e.stopPropagation();
302
- e.preventDefault();
303
- let {model, form_name} = $form.data();
304
- const values = model.syncForm($form);
305
- for (let instance_value of values) {
306
- p_list.push(new Promise((resolve, reject) => {
307
- let prom;
308
- if (instance_value.pk !== null && instance_value.pk >= 0) {
309
- prom = model.save(instance_value.pk, form_name);
310
- } else {
311
- prom = model.create(instance_value);
312
- }
313
-
314
- prom.then((res) => {
315
- clearErrorsInForm($form);
316
- this.submit_model_form_success && this.submit_model_form_success(res[0]);
317
- for(const controller of this.iterateAllChildren()) {
318
- controller.submit_model_form_success && controller.submit_model_form_success(res[0]);
319
- }
320
- resolve(res);
321
- }).catch((data) => {
322
- this.reconcile($(`<div class="container-fluid">${data.html}</div>`), $form.find('.container-fluid').first());
323
- this.submit_model_form_error && this.submit_model_form_error(data);
324
- for(const controller of this.iterateAllChildren()) {
325
- controller.submit_model_form_error && controller.submit_model_form_error(data);
326
- }
327
- reject(data);
328
- });
329
- }));
317
+ resolve(res);
318
+ })
319
+ .catch((data) => {
320
+ this.reconcile(
321
+ $(`<div class="container-fluid">${data.html}</div>`),
322
+ $form.find(".container-fluid").first(),
323
+ );
324
+ this.submit_model_form_error &&
325
+ this.submit_model_form_error(data);
326
+ for (const controller of this.iterateAllChildren()) {
327
+ controller.submit_model_form_error &&
328
+ controller.submit_model_form_error(data);
330
329
  }
331
- }
332
330
 
333
- return Promise.all(p_list).then((res) => {
334
- return Object.assign({}, ...res.flat());
335
- });
331
+ reject(data);
332
+ });
333
+ });
336
334
  }
337
- }
335
+
336
+ return Promise.resolve();
337
+ }
338
+ }