ru.coon 3.0.59 → 3.0.60

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/.husky/pre-commit CHANGED
File without changes
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # Version 3.0.60, [link](http://gitlab-dbr.sigma-it.local/dbr/ru.coon/-/commit/b3ba3aeb89954b8e1650cb40e052a4509b4809fb)
2
+ * ## Fixes
3
+ * <span style='color:red'>fix validator, util.getByPath</span> ([608e70], [link](http://gitlab-dbr.sigma-it.local/dbr/ru.coon/-/commit/608e7096603a0ed31656b0f45686bab7a4ee302b))
4
+
5
+ * update: CHANGELOG.md ([e42a2a], [link](http://gitlab-dbr.sigma-it.local/dbr/ru.coon/-/commit/e42a2a6fb8b511ba174ab5060fc84c683a046945))
6
+
1
7
  # Version 3.0.59, [link](http://gitlab-dbr.sigma-it.local/dbr/ru.coon/-/commit/065a134b1f6c6211d56ef758b127778d5e104faa)
2
8
  * Копирование в буфер обмена без использования дополнительного окна prompt. Related to NEVA-990 ([41cd4e], [link](http://gitlab-dbr.sigma-it.local/dbr/ru.coon/-/commit/41cd4ed4fdb7088d10df1eac44964c5aadae4646))
3
9
  * add Coon.validator singleton class ([a402d0], [link](http://gitlab-dbr.sigma-it.local/dbr/ru.coon/-/commit/a402d0829e81d7f4297fba2af9b628a4528533c1))
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "ru.coon"
5
5
  },
6
6
  "description": "",
7
- "version": "3.0.59",
7
+ "version": "3.0.60",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+http://gitlab-dbr.sigma-it.local/dbr/ru.coon"
@@ -0,0 +1,17 @@
1
+ Ext.define('Coon.common.AbstractPlugin', {
2
+ extend: 'Ext.AbstractPlugin',
3
+
4
+ constructor(config) {
5
+ Ext.apply(this, config || {});
6
+
7
+ if (Array.isArray(this.validConfig)) {
8
+ const state = Coon.validator.isObjectValid(this.pluginConfig.properties, this.validConfig);
9
+ if (!state.valid) {
10
+ console.error(`Invalid configuration for plugin ${this.pluginConfig.name}:\n${state.errors}`);
11
+ }
12
+ this.pluginConfig.validity = state;
13
+ }
14
+
15
+ this.callParent([config]);
16
+ },
17
+ });
File without changes
File without changes
@@ -868,6 +868,11 @@ Ext.define('Coon.report.component.ReportPanel', {
868
868
  }
869
869
  config[prefix + 'type'] = plugin[ns.$uiElement].xtype || plugin[ns.$xtype];
870
870
  config[ns.$sortSequence] = plugin[ns.$sortSequence] || null;
871
+ config.pluginConfig = {
872
+ properties: Object.assign({}, config),
873
+ type,
874
+ name: prefix + 'type',
875
+ };
871
876
  return config;
872
877
  });
873
878
  },
@@ -57,6 +57,7 @@ Ext.define('Coon.report.component.reportpanel.ReportGrid', {
57
57
  try {
58
58
  this.addPlugin(plugin);
59
59
  } catch (e) {
60
+ console.error('plugin error', e);
60
61
  pluginErrors.push(e.message);
61
62
  }
62
63
  });
@@ -10,17 +10,17 @@ Ext.define('Coon.report.util', {
10
10
  path: 'fields',
11
11
  valid: 'array',
12
12
  rules: [
13
- {path: '[].description', valid: 'string, required'},
14
- {path: '[].reportFieldCd', valid: 'string, required'},
15
- {path: '[].visibleSwitch', valid: 'boolean'},
16
- {path: '[].reportFieldTypeLookup', valid: 'uppercase, required'},
13
+ {path: 'description', valid: 'string, required'},
14
+ {path: 'reportFieldCd', valid: 'string, required'},
15
+ {path: 'visibleSwitch', valid: 'boolean'},
16
+ {path: 'reportFieldTypeLookup', valid: 'uppercase, required'},
17
17
  {
18
- path: '[].properties',
18
+ path: 'properties',
19
19
  valid: 'array',
20
20
  rules: [
21
- {path: '[].sequenceNumber', valid: 'number'},
22
- {path: '[].key', valid: 'type.string'},
23
- {path: '[].value', valid: '!type.undefined'}
21
+ {path: 'sequenceNumber', valid: 'number'},
22
+ {path: 'key', valid: 'type.string'},
23
+ {path: 'value', valid: '!type.undefined'}
24
24
  ],
25
25
  }
26
26
  ],
@@ -29,40 +29,40 @@ Ext.define('Coon.report.util', {
29
29
  path: 'plugins',
30
30
  valid: 'array',
31
31
  rules: [
32
- {path: '[].xtype', valid: 'string, required'},
33
- {path: '[].type', valid: 'string, required'},
34
- {path: '[].uiElement', valid: 'string, required'},
35
- {path: '[].jsonProperties', valid: 'string, required'},
36
- {path: '[].sequenceNumber', valid: 'number, required'},
37
- {path: '[].sortSequence', valid: 'number, required'}
32
+ {path: 'xtype', valid: 'string, required'},
33
+ {path: 'type', valid: 'string, required'},
34
+ {path: 'uiElement', valid: 'string, required'},
35
+ {path: 'jsonProperties', valid: 'string, required'},
36
+ {path: 'sequenceNumber', valid: 'number, required'},
37
+ {path: 'sortSequence', valid: 'number, required'}
38
38
  ],
39
39
  },
40
40
  {
41
41
  path: 'properties',
42
42
  valid: 'array',
43
43
  rules: [
44
- {path: '[].key', valid: 'string, required'},
45
- {path: '[].value', valid: 'string, required'},
46
- {path: '[].sequenceNumber', valid: 'string, required'}
44
+ {path: 'key', valid: 'string, required'},
45
+ {path: 'value', valid: 'string, required'},
46
+ {path: 'sequenceNumber', valid: 'string, required'}
47
47
  ],
48
48
  },
49
49
  {
50
50
  path: 'parameters',
51
51
  valid: 'array',
52
52
  rules: [
53
- {path: '[].requiredSwitch', valid: 'boolean'},
54
- {path: '[].visibleSwitch', valid: 'boolean'},
55
- {path: '[].notUsedInSQLSwitch', valid: 'boolean'},
56
- {path: '[].description', valid: 'string, required'},
57
- {path: '[].reportParameterCd', valid: 'string, required'},
58
- {path: '[].reportParameterTypeLookup', valid: 'string, required, uppercase'},
53
+ {path: 'requiredSwitch', valid: 'boolean'},
54
+ {path: 'visibleSwitch', valid: 'boolean'},
55
+ {path: 'notUsedInSQLSwitch', valid: 'boolean'},
56
+ {path: 'description', valid: 'string, required'},
57
+ {path: 'reportParameterCd', valid: 'string, required'},
58
+ {path: 'reportParameterTypeLookup', valid: 'string, required, uppercase'},
59
59
  {
60
- path: '[].properties',
60
+ path: 'properties',
61
61
  valid: 'array',
62
62
  rules: [
63
- {path: '[].key', valid: 'string, required'},
64
- {path: '[].value', valid: 'string, required'},
65
- {path: '[].sequenceNumber', valid: 'number'}
63
+ {path: 'key', valid: 'string, required'},
64
+ {path: 'value', valid: 'string, required'},
65
+ {path: 'sequenceNumber', valid: 'number'}
66
66
  ],
67
67
  }
68
68
  ],
package/src/util.js CHANGED
@@ -73,19 +73,17 @@ Ext.define('Coon.util', {
73
73
  }
74
74
  return path.reduce((acc, pathProp) => {
75
75
  if (acc) {
76
+ if (pathProp.startsWith('[') && pathProp.endsWith(']')) {
77
+ pathProp = pathProp.slice(1, -1) || 0;
78
+ if (Number.isInteger(parseInt(pathProp))) {
79
+ acc = acc[parseInt(pathProp)];
80
+ return acc;
81
+ }
82
+ }
76
83
  if (Ext.isObject(acc)) {
77
84
  acc = acc[pathProp];
78
85
  return acc;
79
86
  }
80
- if (Array.isArray(acc)) {
81
- if (pathProp.startsWith('[') && pathProp.endsWith(']')) {
82
- pathProp = pathProp.slice(1, -1) || 0;
83
- if (Number.isInteger(parseInt(pathProp))) {
84
- acc = acc[parseInt(pathProp)];
85
- return acc;
86
- }
87
- }
88
- }
89
87
  } else {
90
88
  path = [];
91
89
  acc = defaultValue;
package/src/validator.js CHANGED
@@ -58,6 +58,12 @@ Ext.define('Coon.validator', {
58
58
  * ]
59
59
  */
60
60
  isObjectValid(obj, rules) {
61
+ if (!Ext.isObject(obj)) {
62
+ return {
63
+ valid: false,
64
+ errors: ['object is not valid'],
65
+ };
66
+ }
61
67
  const getValid = (valid) => {
62
68
  if (typeof valid === 'string') {
63
69
  return valid.split(',').map((el) => el.trim());
@@ -69,42 +75,47 @@ Ext.define('Coon.validator', {
69
75
  const checkValidity = (validProps, value) => validProps.find((prop) => {
70
76
  const [name, ...args] = prop.split('.');
71
77
  if (typeof validators[name] === 'function') {
72
- return !(
73
- validators[name](value, ...args)
74
- );
78
+ return validators[name](value, ...args);
79
+ } else {
80
+ console.error(`validator [${name}] is not exist!`);
81
+ return false;
75
82
  }
76
83
  });
77
84
  const validators = this.getValidators();
78
- const getErrors = (obj, rules) => {
85
+ const getErrors = (src, rules) => {
86
+ if (Array.isArray(src)) {
87
+ for (const el of src) {
88
+ const state = getErrors(el, rules);
89
+ if (!state.valid) {
90
+ return state;
91
+ }
92
+ }
93
+ return {valid: true, errors: []};
94
+ }
79
95
  const errors = Coon.util.filterMap(rules, (rule) => {
96
+ let errorMessage = '';
80
97
  if (!rule.path) {
81
98
  return;
82
99
  }
83
- const value = Coon.util.getByPath(obj, rule.path);
100
+ const value = Coon.util.getByPath(src, rule.path);
84
101
  const validTags = getValid(rule.valid) || [];
85
- let subErrors;
86
- let isInvalid = typeof valid === 'function' ?
87
- validTags(value) :
88
- checkValidity(validTags, value);
102
+ let subResult;
103
+ const isValid = checkValidity(validTags, value);
89
104
  if (
90
- !Ext.isEmpty(value) &&
91
- !isInvalid &&
105
+ isValid &&
92
106
  Array.isArray(rule.rules) &&
93
107
  rule.rules.length
94
108
  ) {
95
- const subResult = getErrors(value, rule.rules);
96
- if (!subResult.valid) {
97
- isInvalid = false;
98
- subErrors = subResult.errors.join('\n');
99
- }
109
+ subResult = getErrors(value, rule.rules);
100
110
  }
101
- if (isInvalid) {
102
- rule.msg = rule.msg || `[by path: ${rule.path}], value [${value}] is invalid`;
103
- if (subErrors) {
104
- rule.msg = rule.msg + '\n' + subErrors;
105
- }
106
- return rule.msg;
111
+ if (!isValid) {
112
+ errorMessage += rule.msg ||
113
+ `The property on the path "${rule.path}" with the value ${value} is invalid, validity check: ${rule.valid}`;
114
+ }
115
+ if (subResult && !subResult.valid) {
116
+ errorMessage += '\n---\n ' + subResult.errors.join('\n ');
107
117
  }
118
+ return errorMessage || false;
108
119
  });
109
120
  return {
110
121
  valid: !errors.length,
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  Ext.define('Coon.version', {
2
2
  singleton: true,
3
- number: '3.0.59',
3
+ number: '3.0.60',
4
4
  });