sdc_client 0.57.11 → 0.57.14

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.
@@ -71,7 +71,6 @@ const ModelProxyHandler = {
71
71
  }
72
72
 
73
73
 
74
-
75
74
  function parse_hidden_inputs(value) {
76
75
 
77
76
  let isFloatReg = /^-?\d+\.?\d+$/;
@@ -97,7 +96,6 @@ function parse_hidden_inputs(value) {
97
96
  }
98
97
 
99
98
 
100
-
101
99
  export class Model {
102
100
  /**
103
101
  *
@@ -105,6 +103,7 @@ export class Model {
105
103
  * @param model_query {json}
106
104
  */
107
105
  constructor(model_name, model_query = {}) {
106
+ this._onNoOpenRequests = [];
108
107
  this.values_list = [];
109
108
  this.values = {};
110
109
  this.model_name = model_name;
@@ -180,7 +179,7 @@ export class Model {
180
179
  });
181
180
  }
182
181
 
183
- listView(filter = {}, cb_resolve = null, cb_reject = null) {
182
+ listView(filter = {}, cb_resolve = null, cb_reject = null, template_context = {}) {
184
183
  let $div_list = $('<div class="container-fluid">');
185
184
  this.isConnected().then(() => {
186
185
  const id = uuidv4();
@@ -191,7 +190,8 @@ export class Model {
191
190
  args: {
192
191
  model_name: this.model_name,
193
192
  model_query: this.model_query,
194
- filter: filter
193
+ filter,
194
+ template_context
195
195
  }
196
196
  }));
197
197
 
@@ -208,7 +208,8 @@ export class Model {
208
208
  return $div_list;
209
209
  }
210
210
 
211
- detailView(pk = -1, cb_resolve = null, cb_reject = null) {
211
+ detailView(pk = null, cb_resolve = null, cb_reject = null, template_context = {}) {
212
+ pk = pk ?? -1;
212
213
  pk = parseInt(pk);
213
214
  if (isNaN(pk)) {
214
215
  pk = -1;
@@ -234,7 +235,8 @@ export class Model {
234
235
  args: {
235
236
  model_name: this.model_name,
236
237
  model_query: this.model_query,
237
- pk: pk
238
+ pk,
239
+ template_context
238
240
  }
239
241
  }));
240
242
 
@@ -623,7 +625,7 @@ export class Model {
623
625
  if (data.is_error) {
624
626
  if (this.open_request.hasOwnProperty(data.event_id)) {
625
627
  this.open_request[data.event_id][1](data);
626
- delete this.open_request[data.event_id];
628
+ this._closeOpenRequest(data.event_id);
627
629
  }
628
630
  if (data.msg || data.header) {
629
631
  trigger('pushErrorMsg', data.header || '', data.msg || '');
@@ -631,7 +633,7 @@ export class Model {
631
633
 
632
634
  if (data.type === 'connect') {
633
635
  this.open_request['_connecting_process'][1](data);
634
- delete this.open_request['_connecting_process'];
636
+ this._closeOpenRequest('_connecting_process');
635
637
  this._auto_reconnect = false;
636
638
  this.socket.close();
637
639
  }
@@ -645,7 +647,7 @@ export class Model {
645
647
  this._is_connected = true;
646
648
  this._is_conneting_process = false;
647
649
  this.open_request['_connecting_process'][0](data);
648
- delete this.open_request['_connecting_process'];
650
+ this._closeOpenRequest('_connecting_process');
649
651
  } else if (data.type === 'load') {
650
652
  const json_res = JSON.parse(data.args.data);
651
653
  this.values_list = [];
@@ -675,11 +677,30 @@ export class Model {
675
677
 
676
678
  if (this.open_request.hasOwnProperty(data.event_id)) {
677
679
  this.open_request[data.event_id][0](data);
678
- delete this.open_request[data.event_id];
680
+ this._closeOpenRequest(data.event_id);
679
681
  }
680
682
  }
681
683
  }
682
684
 
685
+ noOpenRequests() {
686
+ return new Promise(resolve => {
687
+ if (Object.keys(this.open_request).length === 0) {
688
+ return resolve();
689
+ }
690
+
691
+ this._onNoOpenRequests.push(resolve);
692
+ });
693
+ }
694
+
695
+ _closeOpenRequest(event_id) {
696
+ delete this.open_request[event_id];
697
+ if (Object.keys(this.open_request).length === 0) {
698
+ this._onNoOpenRequests.forEach(x => x());
699
+ this._onNoOpenRequests = [];
700
+ }
701
+
702
+ }
703
+
683
704
  _connectToServer() {
684
705
  return new Promise((resolve) => {
685
706
 
@@ -1,20 +1,22 @@
1
1
  /**
2
2
  * @jest-environment jsdom
3
3
  */
4
+ ;
4
5
 
5
- import {app} from './sdc_main.js';
6
- let spy, _originAjax;
6
+ import {app} from './sdc_main.js'
7
+
8
+ let spy = [], _originAjax;
7
9
 
8
10
  function setDefaults() {
9
- if(!jest) throw new Error("JEST is not defined");
10
- if(!spy) {
11
+ if (!jest) throw new Error("JEST is not defined");
12
+ if (spy.length === 0) {
11
13
  _originAjax = $.ajax.bind($);
12
14
 
13
- spy = jest.spyOn(
15
+ spy.push(jest.spyOn(
14
16
  $,
15
17
  'ajax'
16
- );
17
- spy.mockImplementation(function (a) {
18
+ ));
19
+ spy[0].mockImplementation(function (a) {
18
20
  return _originAjax(a).then((html) => {
19
21
  return html;
20
22
  }).catch((html) => {
@@ -50,9 +52,10 @@ export function getCsrfToken() {
50
52
  /**
51
53
  *
52
54
  * @param html{string} HTML: .
55
+ * @param afterLifecycle{bool} Lifecycle Methode -> Reruns the controller after the root controller has run the "onRefresh" methode. This is optional.
53
56
  * @returns {Promise<Array<{AbstractSDC}>>}
54
57
  */
55
- export async function controllerFromTestHtml(html) {
58
+ export async function controllerFromTestHtml(html, afterLifecycle = null) {
56
59
  setDefaults();
57
60
  const $body = $('body');
58
61
  app.updateJquery();
@@ -61,7 +64,28 @@ export async function controllerFromTestHtml(html) {
61
64
  app.cleanCache();
62
65
  await app.init_sdc();
63
66
 
64
- return app.rootController.iterateAllChildren();
67
+
68
+ let children = app.rootController.iterateAllChildren();
69
+
70
+ if (!afterLifecycle) {
71
+ return children
72
+ }
73
+
74
+ const origenRefresh = children[0].onRefresh;
75
+
76
+ const refreshSpy = jest.spyOn(
77
+ children[0],
78
+ 'onRefresh'
79
+ );
80
+
81
+ return new Promise((resolve) => {
82
+ refreshSpy.mockImplementation(function () {
83
+ refreshSpy.mockRestore();
84
+ const res = origenRefresh.apply(children[0], arguments);
85
+ resolve(children);
86
+ return res;
87
+ });
88
+ });
65
89
  }
66
90
 
67
91
  /**
@@ -72,7 +96,7 @@ export async function controllerFromTestHtml(html) {
72
96
  * @param origen_html{string} HTML: Mocked content of the content in your target HTML container.
73
97
  * @returns {Promise<{AbstractSDC}>}
74
98
  */
75
- export async function get_controller( tag_name, init_arguments = {}, origen_html = '') {
99
+ export async function get_controller(tag_name, init_arguments = {}, origen_html = '') {
76
100
  setDefaults();
77
101
  const $body = $('body');
78
102
  app.updateJquery();
@@ -56,6 +56,7 @@ export function tagNameToCamelCase(str) {
56
56
  str = str.replace(/-./g, letter => `${letter[1].toUpperCase()}`);
57
57
  return str;
58
58
  }
59
+
59
60
  export function tagNameToReadableName(str) {
60
61
  str = str.replace(/-./g, letter => ` ${letter[1].toUpperCase()}`).replace(/^./g, letter => `${letter.toUpperCase()}`);
61
62
  return str;
@@ -83,31 +84,42 @@ const copyProps = (targetClass, sourceClass) => {
83
84
 
84
85
  /**
85
86
  *
86
- * @param {AbstractSDC} baseClass
87
- * @param {AbstractSDC} mixins
88
- * @returns {AbstractSDC}
87
+ * @param {typeof AbstractSDC} baseClass
88
+ * @param {typeof AbstractSDC} mixins
89
+ * @returns {typeof AbstractSDC}
89
90
  */
90
91
  export function agileAggregation(baseClass, ...mixins) {
91
92
 
92
- let base = class _Combined {
93
- constructor(..._args) {
94
- let _mixins = {};
95
- mixins.forEach((mixin) => {
96
- let newMixin;
97
- Object.assign(this, (newMixin = new mixin()));
98
- newMixin._tagName = mixin.prototype._tagName;
99
- newMixin._isMixin = true;
100
- _mixins[mixin.name] = newMixin;
101
- });
93
+ let base = {
94
+ [baseClass.name]: class {
95
+ constructor(..._args) {
96
+ let _mixins = {};
97
+ mixins.forEach((mixin) => {
98
+ let newMixin;
99
+ Object.assign(this, (newMixin = new mixin()));
100
+ newMixin._tagName = mixin.prototype._tagName;
101
+ newMixin._isMixin = true;
102
+ _mixins[mixin.name] = newMixin;
103
+ });
104
+
105
+ Object.assign(this, new baseClass());
106
+ this._mixins = _mixins;
107
+ }
102
108
 
103
- Object.assign(this, new baseClass());
104
- this._mixins = _mixins;
105
- }
106
109
 
107
- get mixins() {
108
- return this._mixins;
110
+ static get name() {
111
+ return baseClass.name;
112
+ }
113
+
114
+ static className() {
115
+ return this.name
116
+ }
117
+
118
+ get mixins() {
119
+ return this._mixins;
120
+ }
109
121
  }
110
- };
122
+ }[baseClass.name];
111
123
 
112
124
  copyProps(base, baseClass);
113
125
 
@@ -141,7 +153,7 @@ export function uploadFileFormData(formData, url, method) {
141
153
  cache: false,
142
154
  contentType: false,
143
155
  processData: false,
144
- beforeSend: function(xhr, settings) {
156
+ beforeSend: function (xhr, settings) {
145
157
  if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
146
158
  xhr.setRequestHeader("X-CSRFToken", window.CSRF_TOKEN);
147
159
  }
@@ -171,8 +183,8 @@ export function checkIfParamNumberBoolOrString(paramElement, controller = null)
171
183
  return paramElement;
172
184
  }
173
185
 
174
- if(controller && typeof controller[paramElement] !== 'undefined') {
175
- if(typeof controller[paramElement] === 'function') {
186
+ if (controller && typeof controller[paramElement] !== 'undefined') {
187
+ if (typeof controller[paramElement] === 'function') {
176
188
  return controller[paramElement].bind(controller);
177
189
  }
178
190
  return controller[paramElement];
@@ -213,7 +225,7 @@ export function clearErrorsInForm($form) {
213
225
  }
214
226
 
215
227
  export function setErrorsInForm($form, $resForm) {
216
- $resForm = $('<div>').append($resForm);
228
+ $resForm = $('<div>').append($resForm);
217
229
 
218
230
  $form.find('.has-error').removeClass('has-error').find('.alert-danger').safeRemove();
219
231
  $form.find('.non-field-errors').safeRemove();
@@ -233,4 +245,14 @@ export function setErrorsInForm($form, $resForm) {
233
245
  });
234
246
 
235
247
  return hasNoError;
236
- }
248
+ }
249
+
250
+ export function jqueryInsertAt($container, index, $newElement) {
251
+ let lastIndex = $container.children().size();
252
+ if (index < lastIndex) {
253
+ $container.children().eq(index).before($newElement);
254
+ } else {
255
+ $container.append($newElement);
256
+ }
257
+ return this;
258
+ }