@onehat/data 1.18.13 → 1.19.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.
|
@@ -127,6 +127,94 @@ describe('Property', function() {
|
|
|
127
127
|
expect(property.isTempId).to.be.true;
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
+
it('getModel', function() {
|
|
131
|
+
|
|
132
|
+
// fails when name is incorrect
|
|
133
|
+
let error = null;
|
|
134
|
+
try {
|
|
135
|
+
this.property.modelName;
|
|
136
|
+
} catch(err) {
|
|
137
|
+
error = err.message;
|
|
138
|
+
}
|
|
139
|
+
expect(error).to.eq('this.name is not in the correct format for modelName.');
|
|
140
|
+
|
|
141
|
+
const
|
|
142
|
+
schema = new Schema({
|
|
143
|
+
name: 'foo',
|
|
144
|
+
model: {
|
|
145
|
+
idProperty: 'model__field',
|
|
146
|
+
displayProperty: 'model__field',
|
|
147
|
+
properties: [
|
|
148
|
+
{ name: 'model__field', },
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
entity = new Entity(schema);
|
|
153
|
+
|
|
154
|
+
entity.initialize();
|
|
155
|
+
const property = entity.getProperty('model__field');
|
|
156
|
+
|
|
157
|
+
expect(property.modelName).to.be.eq('model');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('OneBuild properties', function() {
|
|
161
|
+
|
|
162
|
+
expect(this.property.isVirtual).to.be.false;
|
|
163
|
+
expect(this.property.title).to.be.null;
|
|
164
|
+
expect(this.property.tooltip).to.be.null;
|
|
165
|
+
expect(this.property.fieldGroup).to.be.null;
|
|
166
|
+
expect(this.property.isForeignModel).to.be.false;
|
|
167
|
+
expect(this.property.filterType).to.be.null;
|
|
168
|
+
expect(this.property.isFilteringDisabled).to.be.false;
|
|
169
|
+
expect(this.property.editorType).to.be.null;
|
|
170
|
+
expect(this.property.isEditingDisabled).to.be.false;
|
|
171
|
+
|
|
172
|
+
const
|
|
173
|
+
filterType = {
|
|
174
|
+
type: 'Combo',
|
|
175
|
+
loadAfterRender: false,
|
|
176
|
+
},
|
|
177
|
+
editorType = {
|
|
178
|
+
type: 'Input',
|
|
179
|
+
},
|
|
180
|
+
schema = new Schema({
|
|
181
|
+
name: 'foo',
|
|
182
|
+
model: {
|
|
183
|
+
idProperty: 'model__field',
|
|
184
|
+
displayProperty: 'model__field',
|
|
185
|
+
properties: [
|
|
186
|
+
{
|
|
187
|
+
name: 'model__field',
|
|
188
|
+
isVirtual: true,
|
|
189
|
+
title: 'title',
|
|
190
|
+
tooltip: 'tooltip',
|
|
191
|
+
fieldGroup: 'fieldGroup',
|
|
192
|
+
isForeignModel: true,
|
|
193
|
+
filterType,
|
|
194
|
+
isFilteringDisabled: true,
|
|
195
|
+
editorType,
|
|
196
|
+
isEditingDisabled: true,
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
entity = new Entity(schema);
|
|
202
|
+
|
|
203
|
+
entity.initialize();
|
|
204
|
+
const property = entity.getProperty('model__field');
|
|
205
|
+
|
|
206
|
+
expect(property.isVirtual).to.be.true;
|
|
207
|
+
expect(property.title).to.be.eq('title');
|
|
208
|
+
expect(property.tooltip).to.be.eq('tooltip');
|
|
209
|
+
expect(property.fieldGroup).to.be.eq('fieldGroup');
|
|
210
|
+
expect(property.isForeignModel).to.be.true;
|
|
211
|
+
expect(property.filterType).to.be.eql(filterType);
|
|
212
|
+
expect(property.isFilteringDisabled).to.be.true;
|
|
213
|
+
expect(property.editorType).to.be.eql(editorType);
|
|
214
|
+
expect(property.isEditingDisabled).to.be.true;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
|
|
130
218
|
});
|
|
131
219
|
|
|
132
220
|
describe('setters', function() {
|
|
@@ -63,7 +63,83 @@ describe('OneBuildRepository', function() {
|
|
|
63
63
|
expect(p.conditions.key2).to.be.eq('2');
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
it('
|
|
66
|
+
it.only('getTitles, getVirtualdPropertyNames, getIsFilteringDisabledPropertyNames, getIsEditingDisabledPropertyNames, getFieldGroupNames, getFilterTypes', function() {
|
|
67
|
+
let repository;
|
|
68
|
+
(async () => {
|
|
69
|
+
repository = await this.oneHatData.createRepository({
|
|
70
|
+
schema: {
|
|
71
|
+
id: 'foo',
|
|
72
|
+
name: 'foo',
|
|
73
|
+
model: {
|
|
74
|
+
idProperty: 'model__field1',
|
|
75
|
+
displayProperty: 'model__field2',
|
|
76
|
+
properties: [
|
|
77
|
+
{
|
|
78
|
+
name: 'model__field1',
|
|
79
|
+
isVirtual: true,
|
|
80
|
+
isFilteringDisabled: false,
|
|
81
|
+
filterType: {
|
|
82
|
+
type: 'Combo',
|
|
83
|
+
loadAfterRender: false,
|
|
84
|
+
},
|
|
85
|
+
isEditingDisabled: true,
|
|
86
|
+
fieldGroup: 'group1',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'model__field2',
|
|
90
|
+
isVirtual: true,
|
|
91
|
+
isFilteringDisabled: true,
|
|
92
|
+
isEditingDisabled: false,
|
|
93
|
+
fieldGroup: 'group1',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'model__field3',
|
|
97
|
+
isVirtual: false,
|
|
98
|
+
isFilteringDisabled: true,
|
|
99
|
+
isEditingDisabled: true,
|
|
100
|
+
fieldGroup: 'group2',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
repository: {
|
|
105
|
+
type: 'onebuild',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const
|
|
111
|
+
virtualPropertyNames = [
|
|
112
|
+
'model__field1',
|
|
113
|
+
'model__field2',
|
|
114
|
+
],
|
|
115
|
+
isFilteringDisabledPropertyNames = [
|
|
116
|
+
'model__field2',
|
|
117
|
+
'model__field3',
|
|
118
|
+
],
|
|
119
|
+
isEditingDisabledPropertyNames = [
|
|
120
|
+
'model__field1',
|
|
121
|
+
'model__field3',
|
|
122
|
+
],
|
|
123
|
+
fieldGroupNames = [
|
|
124
|
+
'group1',
|
|
125
|
+
'group2',
|
|
126
|
+
],
|
|
127
|
+
filterTypes = [
|
|
128
|
+
{
|
|
129
|
+
type: 'Combo',
|
|
130
|
+
loadAfterRender: false,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
expect(repository.getVirtualPropertyNames()).to.be.eql(virtualPropertyNames);
|
|
134
|
+
expect(repository.getIsFilteringDisabledPropertyNames()).to.be.eql(isFilteringDisabledPropertyNames);
|
|
135
|
+
expect(repository.getIsEditingDisabledPropertyNames()).to.be.eql(isEditingDisabledPropertyNames);
|
|
136
|
+
expect(repository.getFieldGroupNames()).to.be.eql(fieldGroupNames);
|
|
137
|
+
expect(repository.getFilterTypes()).to.be.eql(filterTypes);
|
|
138
|
+
|
|
139
|
+
})();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it.skip('401', function() {
|
|
67
143
|
cy.wrap((async () => {
|
|
68
144
|
|
|
69
145
|
let loggedOut = false,
|
package/package.json
CHANGED
package/src/Property/Property.js
CHANGED
|
@@ -89,45 +89,55 @@ export default class Property extends EventEmitter {
|
|
|
89
89
|
*/
|
|
90
90
|
isTempId: false,
|
|
91
91
|
|
|
92
|
+
// ##################################################################
|
|
93
|
+
// #### These next properties are only for OneBuild repositories ####
|
|
94
|
+
// ##################################################################
|
|
92
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @member {boolean} isVirtual - Whether this property represents a virtual field on server
|
|
98
|
+
*/
|
|
99
|
+
isVirtual: false,
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @member {string} title - The human-readable title for this property
|
|
103
|
+
*/
|
|
104
|
+
title: null,
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @member {string} tooltip - The human-readable tooltip for this property
|
|
108
|
+
*/
|
|
109
|
+
tooltip: null,
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @member {string} fieldGroup - The field group for this property
|
|
113
|
+
*/
|
|
114
|
+
fieldGroup: null,
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @member {boolean} isForeignModel - Whether this property belongs to a foreign model
|
|
118
|
+
*/
|
|
119
|
+
isForeignModel: false,
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @member {object} filterType - The UI filter type of this property
|
|
123
|
+
*/
|
|
124
|
+
filterType: null,
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @member {boolean} isFilteringDisabled - Whether this property is disabled for UI filtering
|
|
128
|
+
*/
|
|
129
|
+
isFilteringDisabled: false,
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @member {object} editorType - The UI editor type of this property
|
|
133
|
+
*/
|
|
134
|
+
editorType: null,
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @member {boolean} isEditingDisabled - Whether this property is disabled for UI editing
|
|
138
|
+
*/
|
|
139
|
+
isEditingDisabled: false,
|
|
93
140
|
|
|
94
|
-
// OneBuild META attributes, just bring these over wholesale for now
|
|
95
|
-
// id: null,
|
|
96
|
-
// table_id: null,
|
|
97
|
-
// field_name: null,
|
|
98
|
-
// client_name: null,
|
|
99
|
-
// title: null,
|
|
100
|
-
// is_id_field: null,
|
|
101
|
-
// is_display_field: null,
|
|
102
|
-
// is_virtual: null,
|
|
103
|
-
// pk: null,
|
|
104
|
-
// fk: null,
|
|
105
|
-
// exclude: null,
|
|
106
|
-
// is_editable: null,
|
|
107
|
-
// date_format: null,
|
|
108
|
-
// field_group_id: null,
|
|
109
|
-
// field_type_id: null,
|
|
110
|
-
// field_data_type_id: null,
|
|
111
|
-
// sort_order: null,
|
|
112
|
-
// o_length: null,
|
|
113
|
-
// o_unsigned: null,
|
|
114
|
-
// allow_null: true,
|
|
115
|
-
// o_default: null,
|
|
116
|
-
// extra: null,
|
|
117
|
-
// o_zerofill: null,
|
|
118
|
-
// o_binary: null,
|
|
119
|
-
// o_encoding: null,
|
|
120
|
-
// o_collation: null,
|
|
121
|
-
// comment: null,
|
|
122
|
-
// xtype: null,
|
|
123
|
-
// options: null,
|
|
124
|
-
// tooltip: null,
|
|
125
|
-
// help_text: null,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// TODO: Room for future development of Property
|
|
129
|
-
// unique: false, // Boolean
|
|
130
|
-
// validators: null, // Object[]
|
|
131
141
|
};
|
|
132
142
|
|
|
133
143
|
_.merge(this, defaults, config);
|
|
@@ -318,6 +328,25 @@ export default class Property extends EventEmitter {
|
|
|
318
328
|
return entity.getDisplayProperty() === this;
|
|
319
329
|
}
|
|
320
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Gets the model name from this property
|
|
333
|
+
* NOTE: Only for OneBuild repositories!
|
|
334
|
+
* @return {any} submitValue
|
|
335
|
+
*/
|
|
336
|
+
get modelName() {
|
|
337
|
+
if (this.isDestroyed) {
|
|
338
|
+
throw Error('this.modelName is no longer valid. Property has been destroyed.');
|
|
339
|
+
}
|
|
340
|
+
if (!this.name.match(/__/)) {
|
|
341
|
+
throw Error('this.name is not in the correct format for modelName.');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const
|
|
345
|
+
matches = this.name.match(/^([\w_]+)__/),
|
|
346
|
+
modelName = matches[1];
|
|
347
|
+
return modelName;
|
|
348
|
+
}
|
|
349
|
+
|
|
321
350
|
|
|
322
351
|
|
|
323
352
|
|
|
@@ -425,6 +425,81 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
425
425
|
return response;
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
+
|
|
429
|
+
getVirtualPropertyNames = () => {
|
|
430
|
+
if (this.isDestroyed) {
|
|
431
|
+
this.throwError('this.getVirtualPropertyNames is no longer valid. Repository has been destroyed.');
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const found = [];
|
|
436
|
+
_.each(this.schema.model.properties, (property) => {
|
|
437
|
+
if (property.isVirtual) {
|
|
438
|
+
found.push(property.name);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
return found;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
getIsFilteringDisabledPropertyNames = () => {
|
|
445
|
+
if (this.isDestroyed) {
|
|
446
|
+
this.throwError('this.getIsFilteringDisabledPropertyNames is no longer valid. Repository has been destroyed.');
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const found = [];
|
|
451
|
+
_.each(this.schema.model.properties, (property) => {
|
|
452
|
+
if (property.isFilteringDisabled) {
|
|
453
|
+
found.push(property.name);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
return found;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
getIsEditingDisabledPropertyNames = () => {
|
|
460
|
+
if (this.isDestroyed) {
|
|
461
|
+
this.throwError('this.getIsEditingDisabledPropertyNames is no longer valid. Repository has been destroyed.');
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const found = [];
|
|
466
|
+
_.each(this.schema.model.properties, (property) => {
|
|
467
|
+
if (property.isEditingDisabled) {
|
|
468
|
+
found.push(property.name);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
return found;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
getFieldGroupNames = () => {
|
|
475
|
+
if (this.isDestroyed) {
|
|
476
|
+
this.throwError('this.getFieldGroupNames is no longer valid. Repository has been destroyed.');
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const found = [];
|
|
481
|
+
_.each(this.schema.model.properties, (property) => {
|
|
482
|
+
if (!_.isNil(property.fieldGroup) && !found.includes(property.fieldGroup)) {
|
|
483
|
+
found.push(property.fieldGroup);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return found;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
getFilterTypes = () => {
|
|
490
|
+
if (this.isDestroyed) {
|
|
491
|
+
this.throwError('this.getFilterTypes is no longer valid. Repository has been destroyed.');
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const found = [];
|
|
496
|
+
_.each(this.schema.model.properties, (property) => {
|
|
497
|
+
if (!_.isNil(property.filterType) && !found.includes(property.filterType)) {
|
|
498
|
+
found.push(property.filterType);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
return found;
|
|
502
|
+
}
|
|
428
503
|
|
|
429
504
|
|
|
430
505
|
// ______
|
package/src/Schema/Schema.js
CHANGED
|
@@ -235,13 +235,9 @@ export default class Schema extends EventEmitter {
|
|
|
235
235
|
if (this.isDestroyed) {
|
|
236
236
|
throw Error('this.getPropertyDefinition is no longer valid. Schema has been destroyed.');
|
|
237
237
|
}
|
|
238
|
-
|
|
238
|
+
return _.find(this.model.properties, (propertyDefinition) => {
|
|
239
239
|
return propertyDefinition.name === propertyName;
|
|
240
240
|
});
|
|
241
|
-
if (!propertyDefinition) {
|
|
242
|
-
throw new Error('Property definition ' + propertyName + ' not found.');
|
|
243
|
-
}
|
|
244
|
-
return propertyDefinition;
|
|
245
241
|
}
|
|
246
242
|
|
|
247
243
|
/**
|