@vgip/meta-ui 2.1.3 → 2.1.5
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/fesm2022/vgip-meta-ui.mjs +6092 -0
- package/fesm2022/vgip-meta-ui.mjs.map +1 -0
- package/index.d.ts +709 -0
- package/package.json +15 -3
- package/.eslintrc.json +0 -57
- package/karma.conf.js +0 -35
- package/ng-package.json +0 -10
- package/src/lib/common/fieldNormalizer/boolean.ts +0 -11
- package/src/lib/common/fieldNormalizer/datetime.ts +0 -8
- package/src/lib/common/fieldNormalizer/index.ts +0 -171
- package/src/lib/common/fieldNormalizer/number.ts +0 -13
- package/src/lib/common/fieldNormalizer/options.ts +0 -48
- package/src/lib/common/fieldNormalizer/radio.ts +0 -29
- package/src/lib/common/fieldNormalizer/reference.ts +0 -32
- package/src/lib/common/fieldNormalizer/richtext.ts +0 -15
- package/src/lib/common/fieldNormalizer/string.ts +0 -23
- package/src/lib/common/fieldNormalizer/text.ts +0 -17
- package/src/lib/common/fieldNormalizer/uniqueNameFilter.ts +0 -21
- package/src/lib/common/metaAutofocus.directive.ts +0 -31
- package/src/lib/common/metaContext.resolver.ts +0 -25
- package/src/lib/common/metaIcons.pipe.spec.ts +0 -15
- package/src/lib/common/metaIcons.pipe.ts +0 -29
- package/src/lib/common/metaModel.pipe.ts +0 -19
- package/src/lib/common/metaNormalizer.ts +0 -366
- package/src/lib/common/metaStripHtml.pipe.ts +0 -18
- package/src/lib/common/utils/colorThemes.ts +0 -86
- package/src/lib/common/utils/indexedDbStore/index.ts +0 -244
- package/src/lib/common/utils/indexedDbStore/indexedDbStore.spec.ts +0 -149
- package/src/lib/common/utils/relativeTimeBuilder.ts +0 -49
- package/src/lib/common/utils/resourceCardLabel.ts +0 -25
- package/src/lib/common/utils/smartProp.spec.ts +0 -24
- package/src/lib/common/utils/smartProp.ts +0 -28
- package/src/lib/common/utils/templateBuilder.ts +0 -99
- package/src/lib/field.scss +0 -207
- package/src/lib/fieldAbstract.ts +0 -327
- package/src/lib/fieldBoolean/index.ts +0 -55
- package/src/lib/fieldBoolean/style.scss +0 -22
- package/src/lib/fieldBoolean/test.spec.ts +0 -43
- package/src/lib/fieldBoolean/view.html +0 -30
- package/src/lib/fieldComposite/index.ts +0 -86
- package/src/lib/fieldComposite/style.scss +0 -6
- package/src/lib/fieldComposite/test.spec.ts +0 -43
- package/src/lib/fieldComposite/view.html +0 -9
- package/src/lib/fieldDatetime/index.ts +0 -359
- package/src/lib/fieldDatetime/style.scss +0 -81
- package/src/lib/fieldDatetime/test.spec.ts +0 -43
- package/src/lib/fieldDatetime/view.html +0 -26
- package/src/lib/fieldHidden/index.ts +0 -15
- package/src/lib/fieldHidden/view.html +0 -0
- package/src/lib/fieldInput/index.ts +0 -477
- package/src/lib/fieldInput/style.scss +0 -128
- package/src/lib/fieldInput/test.spec.ts +0 -43
- package/src/lib/fieldInput/view.html +0 -81
- package/src/lib/fieldList/index.ts +0 -73
- package/src/lib/fieldList/style.scss +0 -26
- package/src/lib/fieldList/test.spec.ts +0 -43
- package/src/lib/fieldList/view.html +0 -25
- package/src/lib/fieldRadio/index.ts +0 -93
- package/src/lib/fieldRadio/style.scss +0 -32
- package/src/lib/fieldRadio/test.spec.ts +0 -43
- package/src/lib/fieldRadio/view.html +0 -24
- package/src/lib/fieldReference/index.ts +0 -871
- package/src/lib/fieldReference/style.scss +0 -273
- package/src/lib/fieldReference/test.spec.ts +0 -44
- package/src/lib/fieldReference/view.html +0 -163
- package/src/lib/fieldRichtext/index.ts +0 -98
- package/src/lib/fieldRichtext/quill.scss +0 -6
- package/src/lib/fieldRichtext/style.scss +0 -87
- package/src/lib/fieldRichtext/test.spec.ts +0 -43
- package/src/lib/fieldRichtext/view.html +0 -17
- package/src/lib/fieldSelect/index.ts +0 -597
- package/src/lib/fieldSelect/style.scss +0 -165
- package/src/lib/fieldSelect/test.spec.ts +0 -44
- package/src/lib/fieldSelect/view.html +0 -128
- package/src/lib/fieldText/index.ts +0 -86
- package/src/lib/fieldText/style.scss +0 -24
- package/src/lib/fieldText/test.spec.ts +0 -43
- package/src/lib/fieldText/view.html +0 -23
- package/src/lib/fieldUnknown/index.ts +0 -15
- package/src/lib/fieldUnknown/test.spec.ts +0 -34
- package/src/lib/fieldUnknown/view.html +0 -9
- package/src/lib/index.ts +0 -127
- package/src/lib/layout/index.ts +0 -255
- package/src/lib/layout/style.scss +0 -67
- package/src/lib/layout/view.html +0 -45
- package/src/lib/metaField/index.ts +0 -133
- package/src/lib/metaField/test.spec.ts +0 -32
- package/src/lib/refDialog/index.ts +0 -157
- package/src/lib/refDialog/style.scss +0 -154
- package/src/lib/refDialog/view.html +0 -24
- package/src/lib/resource/index.ts +0 -559
- package/src/lib/resource/style.scss +0 -132
- package/src/lib/resource/view.html +0 -70
- package/src/lib/resourceCard/index.ts +0 -44
- package/src/lib/resourceCard/style.scss +0 -7
- package/src/lib/resourceCard/view.html +0 -14
- package/src/lib/services/metaContext/index.ts +0 -61
- package/src/lib/services/metaMsg/index.ts +0 -84
- package/src/lib/services/metaReference/index.ts +0 -98
- package/src/lib/services/metaResource/index.ts +0 -163
- package/src/lib/services/metaResource/metaHttpClient.ts +0 -76
- package/src/lib/services/metaResource/metaResource.spec.ts +0 -24
- package/src/lib/services/metaTracker/index.ts +0 -38
- package/src/lib/services/resourceDrafts/index.ts +0 -81
- package/src/lib/services/resourceDrafts/resourceDrafts.spec.ts +0 -24
- package/src/lib/styles.scss +0 -13
- package/src/public-api.ts +0 -5
- package/src/test.ts +0 -17
- package/tsconfig.lib.json +0 -25
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -17
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: Alexander.Vangelov@vonage.com
|
|
3
|
-
* @Date: 2020-02-10 18:47:45
|
|
4
|
-
* @Last Modified by: Alexander.Vangelov@vonage.com
|
|
5
|
-
* @Last Modified time: 2020-02-28 13:29:23
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface IStoreRecord {
|
|
9
|
-
id?: string | number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IStore {
|
|
13
|
-
initCollection(collectionName: string, callback?: (err, result?) => void): any;
|
|
14
|
-
findById(collectionName, id: number | string, callback?: (err, result?) => void): any;
|
|
15
|
-
save(collectionName: string, record: any, callback?: (err, result?) => void): any;
|
|
16
|
-
find(collectionName: string, conditions: any, options: any, callback: (err, result?) => void);
|
|
17
|
-
findOne(collectionName: string, conditions: any, options: any, callback?: (err, result?) => void);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class IndexedDbStore implements IStore {
|
|
21
|
-
indxDb: IDBFactory;
|
|
22
|
-
db: IDBDatabase;
|
|
23
|
-
dbName: string;
|
|
24
|
-
|
|
25
|
-
constructor(dbName: string = 'vgip') {
|
|
26
|
-
this.dbName = dbName;
|
|
27
|
-
this.indxDb = window.indexedDB || (window as any).mozIndexedDB || (window as any).webkitIndexedDB || (window as any).msIndexedDB;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
_getDb(callback: (err, result?) => void) {
|
|
31
|
-
const self = this;
|
|
32
|
-
if (this.db) {
|
|
33
|
-
return callback(null, this.db);
|
|
34
|
-
}
|
|
35
|
-
const req = this.indxDb.open(this.dbName, 3);
|
|
36
|
-
req.onupgradeneeded = (ev: any) => {
|
|
37
|
-
self.db = ev.target.result;
|
|
38
|
-
if (!self.db.objectStoreNames.contains('Draft')) {
|
|
39
|
-
this.createDraftStore();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
if (callback) {
|
|
43
|
-
req.onsuccess = (ev: any) => {
|
|
44
|
-
self.db = ev.target.result;
|
|
45
|
-
callback(null, self.db);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
req.onerror = (ev: any) => {
|
|
49
|
-
if (callback) {
|
|
50
|
-
callback(ev.error);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
initCollection(collectionName: string, callback: (err, result?) => void) {
|
|
56
|
-
const self = this;
|
|
57
|
-
this._getDb((err) => { // eslint-disable-line no-underscore-dangle
|
|
58
|
-
if (typeof(callback) === 'function') {
|
|
59
|
-
if (err) {
|
|
60
|
-
return callback(err);
|
|
61
|
-
} else if (!self.db.objectStoreNames.contains(collectionName)) {
|
|
62
|
-
return callback(new Error(`IDBDatabase store ${collectionName} does not exist!`));
|
|
63
|
-
} else {
|
|
64
|
-
callback(null, self.db);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
reset(callback: (err, result?) => void) {
|
|
71
|
-
this._getDb((err) => { // eslint-disable-line no-underscore-dangle
|
|
72
|
-
if (err) {
|
|
73
|
-
return callback(err);
|
|
74
|
-
}
|
|
75
|
-
this.db.close();
|
|
76
|
-
this.indxDb.deleteDatabase(this.dbName);
|
|
77
|
-
delete this.db;
|
|
78
|
-
this._getDb(callback); // eslint-disable-line no-underscore-dangle
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
findById(collectionName: string, id: number | string, callback: (err, result?) => void): any {
|
|
83
|
-
const tx = this.db.transaction([collectionName]);
|
|
84
|
-
const store = tx.objectStore(collectionName);
|
|
85
|
-
const request = store.get(parseInt(`${id}`, 10));
|
|
86
|
-
if (callback) {
|
|
87
|
-
request.onerror = () => {
|
|
88
|
-
callback(request.error);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
request.onsuccess = () => {
|
|
92
|
-
if (!request.result) {
|
|
93
|
-
callback({ message: 'Not Found' });
|
|
94
|
-
} else if (callback) {
|
|
95
|
-
callback(null, request.result);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
destroyById(collectionName: string, id: number | string, callback: (err, result?) => void): any {
|
|
101
|
-
const tx = this.db.transaction([collectionName], 'readwrite');
|
|
102
|
-
const store = tx.objectStore(collectionName);
|
|
103
|
-
const request = store.delete(parseInt(`${id}`, 10));
|
|
104
|
-
if (callback) {
|
|
105
|
-
request.onerror = () => {
|
|
106
|
-
callback(request.error);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
request.onsuccess = () => {
|
|
110
|
-
if (callback) {
|
|
111
|
-
callback(null, request.result);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
findOne(collectionName: string, conditions: any, options: any, callback?: (err, result?) => void): any {
|
|
117
|
-
const tx = this.db.transaction([collectionName]);
|
|
118
|
-
const store = tx.objectStore(collectionName);
|
|
119
|
-
const conditionsKeys = Object.keys(conditions);
|
|
120
|
-
let idx: IDBIndex;
|
|
121
|
-
let req: IDBRequest;
|
|
122
|
-
if (conditionsKeys.length > 1) {
|
|
123
|
-
const vals = [];
|
|
124
|
-
conditionsKeys.forEach((key) => vals.push(conditions[key]));
|
|
125
|
-
idx = store.index(`${conditionsKeys.join('')}Index`);
|
|
126
|
-
req = idx.get(vals);
|
|
127
|
-
} else {
|
|
128
|
-
idx = store.index(`${conditionsKeys[0]}Index`);
|
|
129
|
-
req = idx.get(conditions[conditionsKeys[0]]);
|
|
130
|
-
}
|
|
131
|
-
if (callback) {
|
|
132
|
-
req.onerror = () => {
|
|
133
|
-
callback(req.error);
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
req.onsuccess = (ev: any) => {
|
|
137
|
-
if (!ev.target.result) {
|
|
138
|
-
callback({ message: 'Not Found' });
|
|
139
|
-
} else if (callback) {
|
|
140
|
-
callback(null, ev.target.result);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
find(collectionName: string, conditions: any, options: any, callback?: (err, result?) => void): Array<IStoreRecord> | any {
|
|
146
|
-
const tx = this.db.transaction([collectionName]);
|
|
147
|
-
const store = tx.objectStore(collectionName);
|
|
148
|
-
const conditionsKeys = Object.keys(conditions);
|
|
149
|
-
let idx: IDBIndex;
|
|
150
|
-
let req: IDBRequest;
|
|
151
|
-
if (conditionsKeys.length > 1) {
|
|
152
|
-
const vals = [];
|
|
153
|
-
conditionsKeys.forEach((key) => vals.push(conditions[key]));
|
|
154
|
-
idx = store.index(`${conditionsKeys.join('')}Index`);
|
|
155
|
-
req = idx.openCursor(vals);
|
|
156
|
-
} else {
|
|
157
|
-
idx = store.index(`${conditionsKeys[0]}Index`);
|
|
158
|
-
req = idx.openCursor(conditions[conditionsKeys[0]]);
|
|
159
|
-
}
|
|
160
|
-
req.onerror = () => {
|
|
161
|
-
if (callback) {
|
|
162
|
-
callback(req.error);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
const items = [];
|
|
166
|
-
req.onsuccess = (ev: any) => {
|
|
167
|
-
const cursor = ev.target.result;
|
|
168
|
-
if (cursor) {
|
|
169
|
-
items.push(cursor.value);
|
|
170
|
-
cursor.continue();
|
|
171
|
-
} else if (callback) {
|
|
172
|
-
callback(null, items);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
save(collectionName: string, model: any, callback?: (err, result?) => void) {
|
|
178
|
-
const record = model; // model.toJson(true, false);
|
|
179
|
-
const createNew = () => {
|
|
180
|
-
const txN = this.db.transaction([collectionName], 'readwrite');
|
|
181
|
-
const request = txN.objectStore(collectionName).add(record);
|
|
182
|
-
if (callback) {
|
|
183
|
-
request.onerror = () => callback(request.error);
|
|
184
|
-
}
|
|
185
|
-
request.onsuccess = () => {
|
|
186
|
-
record.id = request.result;
|
|
187
|
-
if (callback) {
|
|
188
|
-
callback(null, record);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const updateOldById = (id) => {
|
|
194
|
-
const txO = this.db.transaction([collectionName], 'readwrite');
|
|
195
|
-
const storeW = txO.objectStore(collectionName);
|
|
196
|
-
const getRequest = storeW.get(id);
|
|
197
|
-
if (callback) {
|
|
198
|
-
getRequest.onerror = () => callback(getRequest.error);
|
|
199
|
-
}
|
|
200
|
-
getRequest.onsuccess = () => {
|
|
201
|
-
const existing = getRequest.result;
|
|
202
|
-
if (!existing) {
|
|
203
|
-
callback({ message: 'Not Found' });
|
|
204
|
-
} else {
|
|
205
|
-
for (const p of Object.keys(record)) {
|
|
206
|
-
existing[p] = record[p];
|
|
207
|
-
}
|
|
208
|
-
const updateRequest = storeW.put(existing);
|
|
209
|
-
updateRequest.onerror = () => callback(updateRequest.error);
|
|
210
|
-
updateRequest.onsuccess = () => {
|
|
211
|
-
if (typeof (callback) === 'function') {
|
|
212
|
-
callback(null, existing);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
if (record.id) {
|
|
220
|
-
updateOldById(record.id);
|
|
221
|
-
} else if (record.integration && record.resource) {
|
|
222
|
-
this.findOne(collectionName, {
|
|
223
|
-
context: record.context || '',
|
|
224
|
-
integration: record.integration || '',
|
|
225
|
-
resource: record.resource || ''
|
|
226
|
-
}, null, (err, existing) => {
|
|
227
|
-
if (!existing) {
|
|
228
|
-
createNew();
|
|
229
|
-
} else {
|
|
230
|
-
updateOldById(existing.id);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
} else {
|
|
234
|
-
createNew();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private createDraftStore() {
|
|
239
|
-
const objectStore = this.db.createObjectStore('Draft', { keyPath: 'id', autoIncrement: true });
|
|
240
|
-
objectStore.createIndex('contextIndex', 'context', { unique: false });
|
|
241
|
-
objectStore.createIndex('contextintegrationIndex', ['context', 'integration'], { unique: false });
|
|
242
|
-
objectStore.createIndex('contextintegrationresourceIndex', ['context', 'integration', 'resource'], { unique: true });
|
|
243
|
-
}
|
|
244
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: Alexander.Vangelov@vonage.com
|
|
3
|
-
* @Date: 2020-02-10 18:47:45
|
|
4
|
-
* @Last Modified by: Alexander.Vangelov@vonage.com
|
|
5
|
-
* @Last Modified time: 2020-02-10 21:07:14
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { IndexedDbStore } from './index';
|
|
9
|
-
|
|
10
|
-
describe('IndexedDbStore', () => {
|
|
11
|
-
let store: IndexedDbStore;
|
|
12
|
-
const collectionName = 'Draft';
|
|
13
|
-
const mockModel = (record) => record;
|
|
14
|
-
|
|
15
|
-
beforeAll((done) => {
|
|
16
|
-
store = new IndexedDbStore('items');
|
|
17
|
-
store.reset(() => {
|
|
18
|
-
done();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('init', (done) => {
|
|
23
|
-
store.reset((e1) => {
|
|
24
|
-
expect(e1).toBeNull();
|
|
25
|
-
store.initCollection(collectionName, (err) => {
|
|
26
|
-
expect(err).toBeNull();
|
|
27
|
-
done();
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('findById', (done) => {
|
|
33
|
-
store.findById(collectionName, 10000, (err) => {
|
|
34
|
-
expect(err.message).toEqual('Not Found');
|
|
35
|
-
done();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('save (create)', (done) => {
|
|
40
|
-
store.save(collectionName, mockModel({}), (err, record) => {
|
|
41
|
-
expect(record.id).toBeDefined();
|
|
42
|
-
done();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('create - increment id', (done) => {
|
|
47
|
-
store.save(collectionName, mockModel({}), (e1, record1) => {
|
|
48
|
-
expect(record1.id).toBeDefined();
|
|
49
|
-
store.save(collectionName, mockModel({}), (e2, record2) => {
|
|
50
|
-
expect(record2.id).toEqual(record1.id + 1);
|
|
51
|
-
store.save(collectionName, mockModel({}), (e3, record3) => {
|
|
52
|
-
expect(record3.id).toEqual(record2.id + 1);
|
|
53
|
-
done();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('create - search', (done) => {
|
|
60
|
-
store.save('Draft', mockModel({ context: 'ccc', integration: 'mocks1', resource: 'Demo1' }), (e1, r1) => {
|
|
61
|
-
expect(r1.id).toBeDefined();
|
|
62
|
-
store.save('Draft', mockModel({ context: 'ddd', integration: 'mocks2', resource: 'Demo2' }), (e2, r2) => {
|
|
63
|
-
expect(r2.id).toEqual(r1.id + 1);
|
|
64
|
-
store.save('Draft', mockModel({ context: 'ddd', integration: 'mocks3', resource: 'Demo3' }), (e3, record3) => {
|
|
65
|
-
expect(record3.id).toEqual(r2.id + 1);
|
|
66
|
-
store.find('Draft', { context: 'ddd' }, {}, (err, records) => {
|
|
67
|
-
expect(records.length).toEqual(2);
|
|
68
|
-
done();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('save (update)', (done) => {
|
|
76
|
-
store.save(collectionName, mockModel({ context: '', integration: 'mocks', resource: 'Demo', data: 'aaa' }), (e1, r1) => {
|
|
77
|
-
r1.data = 'bbb';
|
|
78
|
-
expect(r1.id).toBeDefined();
|
|
79
|
-
store.save(collectionName, mockModel({ id: r1.id, data: 'bbb' }), (err, updatedRecord) => {
|
|
80
|
-
expect(updatedRecord.id).toEqual(r1.id);
|
|
81
|
-
expect(updatedRecord.data).toEqual('bbb');
|
|
82
|
-
done();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('find', (done) => {
|
|
88
|
-
store.save('Draft', mockModel({ context: 'zzz', integration: 'mocks', resource: 'Demo1' }), (e1) => {
|
|
89
|
-
expect(e1).toBeNull();
|
|
90
|
-
store.save('Draft', mockModel({ context: 'zzz', integration: 'mocks', resource: 'Demo2' }), () => {
|
|
91
|
-
store.find('Draft', { context: 'zzz' }, null, (err, records) => {
|
|
92
|
-
expect(err).toBeNull();
|
|
93
|
-
expect(records).toBeDefined();
|
|
94
|
-
expect(records.length).toEqual(2);
|
|
95
|
-
if (records.length) {
|
|
96
|
-
expect(records[0].resource).toEqual('Demo1');
|
|
97
|
-
expect(records[1].resource).toEqual('Demo2');
|
|
98
|
-
}
|
|
99
|
-
done();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('findOne', (done) => {
|
|
106
|
-
store.save('Draft', mockModel({ context: 'eee', integration: 'mocks', resource: 'Demo1' }), () => {
|
|
107
|
-
store.save('Draft', mockModel({ context: 'eee', integration: 'mocks', resource: 'Demo2' }), () => {
|
|
108
|
-
store.findOne('Draft', { context: 'eee' }, null, (err, record) => {
|
|
109
|
-
expect(err).toBeNull();
|
|
110
|
-
expect(record.id).toBeDefined();
|
|
111
|
-
expect(record.integration).toEqual('mocks');
|
|
112
|
-
expect(record.resource).toEqual('Demo1');
|
|
113
|
-
done();
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('findOne (multi index)', (done) => {
|
|
120
|
-
store.save('Draft', mockModel({ context: 'aaa', integration: 'mocks', resource: 'Demo', data: '{}' }), (err1) => {
|
|
121
|
-
expect(err1).toBeNull();
|
|
122
|
-
store.save('Draft', mockModel({ context: 'bbb', integration: 'mocks', resource: 'Demo', data: '{}' }), () => {
|
|
123
|
-
store.findOne('Draft', { context: 'bbb', integration: 'mocks', resource: 'Demo' }, null, (err, record) => {
|
|
124
|
-
expect(err).toBeNull();
|
|
125
|
-
expect(record).toBeDefined();
|
|
126
|
-
expect(record.context).toEqual('bbb');
|
|
127
|
-
expect(record.integration).toEqual('mocks');
|
|
128
|
-
expect(record.resource).toEqual('Demo');
|
|
129
|
-
expect(record.data).toEqual('{}');
|
|
130
|
-
done();
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('destroy', (done) => {
|
|
137
|
-
store.save(collectionName, mockModel({ context: 'yyy', integration: 'mocks', resource: 'Demo', data: '{}' }), (err1, r1) => {
|
|
138
|
-
expect(err1).toBeNull();
|
|
139
|
-
expect(r1.id).toBeDefined();
|
|
140
|
-
store.destroyById(collectionName, r1.id, (err, record) => {
|
|
141
|
-
expect(record).toBeUndefined();
|
|
142
|
-
store.findById(collectionName, r1.id, (err2) => {
|
|
143
|
-
expect(err2.message).toEqual('Not Found');
|
|
144
|
-
done();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: Alexander.Vangelov@vonage.com
|
|
3
|
-
* @Date: 2019-09-19 17:35:19
|
|
4
|
-
* @Last Modified by: Alexander.Vangelov@vonage.com
|
|
5
|
-
* @Last Modified time: 2020-02-18 15:41:17
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const wordToMilliseconds = {
|
|
9
|
-
now: 0,
|
|
10
|
-
seconds: 1000,
|
|
11
|
-
minutes: 1000 * 60,
|
|
12
|
-
hours: 1000 * 60 * 60,
|
|
13
|
-
days: 1000 * 60 * 60 * 24
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const protoTime = (text) => { // protocol is: 30.minutes, -4.hours, 3.days, etc...
|
|
17
|
-
const protoMatch = (text || '').match(/^(-?)((\d+).)?(\S+)$/);
|
|
18
|
-
if (protoMatch) {
|
|
19
|
-
const negative = protoMatch[1] === '-';
|
|
20
|
-
const units = parseInt(protoMatch[3], 10) * (wordToMilliseconds[protoMatch[4]] || 0);
|
|
21
|
-
if (negative) {
|
|
22
|
-
return -units;
|
|
23
|
-
} else {
|
|
24
|
-
return units;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const relativeTimeBuilder = (type: 'date' | 'datetime' | 'datetime-local' | 'time', value: string, step = 0, base?: number) => {
|
|
30
|
-
let timestamp = base || new Date().getTime();
|
|
31
|
-
const offset = protoTime(value);
|
|
32
|
-
if (offset) {
|
|
33
|
-
timestamp = timestamp + offset;
|
|
34
|
-
}
|
|
35
|
-
if (step) {
|
|
36
|
-
if (type === 'date') { // step is days
|
|
37
|
-
const mod = timestamp % (step * 1000 * 60 * 60 * 24);
|
|
38
|
-
if (mod) {
|
|
39
|
-
timestamp = timestamp - mod + (step * 1000 * 60 * 60 * 24);
|
|
40
|
-
}
|
|
41
|
-
} else { // step is seconds
|
|
42
|
-
const mod = timestamp % (step * 1000);
|
|
43
|
-
if (mod) {
|
|
44
|
-
timestamp = timestamp - mod + (step * 1000);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return timestamp;
|
|
49
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: Alexander.Vangelov@vonage.com
|
|
3
|
-
* @Date: 2023-02-08 12:41:56
|
|
4
|
-
* @Last Modified by: Alexander.Vangelov@vonage.com
|
|
5
|
-
* @Last Modified time: 2023-02-08 14:04:46
|
|
6
|
-
*/
|
|
7
|
-
const pad2Digit = (t) => t < 10 ? '0' + t : t;
|
|
8
|
-
|
|
9
|
-
export const resourceCardLabel = (r: any) => { // TODO make pipe to ask integration worker for this in abstract
|
|
10
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
11
|
-
if (r._vgis && r._vgis.connector === 'CLIO' && r._vgis.resourceType === 'PhoneCommunicationTimer') {
|
|
12
|
-
const duration = r.quantity || 0; // in seconds
|
|
13
|
-
let durationText = '00:00';
|
|
14
|
-
if (duration > 0) {
|
|
15
|
-
const hours = Math.floor(duration / 3600);
|
|
16
|
-
const minutes = Math.floor((duration % 3600) / 60);
|
|
17
|
-
const seconds = Math.round(duration % 60);
|
|
18
|
-
const checkHours = hours ? pad2Digit(hours) + ':' : '';
|
|
19
|
-
|
|
20
|
-
durationText = checkHours + pad2Digit(minutes) + ':' + pad2Digit(seconds);
|
|
21
|
-
}
|
|
22
|
-
return `⏱ ${ durationText } | $${ (Math.round(r.price) * 100 ) / 100} | ${ r.non_billable ? 'Non-billable' : 'Billable' }`;
|
|
23
|
-
}
|
|
24
|
-
return r.Subject || r.subject || r.summary || r.title || r.CaseNumber || r.comment || r.body || r.name || r.topic || r.content || '...';
|
|
25
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { extractValueBySmartProp } from './smartProp';
|
|
2
|
-
|
|
3
|
-
describe('SmartProp', () => {
|
|
4
|
-
it('extract undefined', () => {
|
|
5
|
-
const rootObj = { whoId: { id: 1, type: 'Lead', label: 'Test' } };
|
|
6
|
-
expect(extractValueBySmartProp(rootObj, 'nonExisting')).toBeUndefined();
|
|
7
|
-
expect(extractValueBySmartProp(rootObj, 'whoId.nonExisting')).toBeUndefined();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('extract root property', () => {
|
|
11
|
-
const rootObj = { a: 1 };
|
|
12
|
-
expect(extractValueBySmartProp(rootObj, 'a')).toEqual(1);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('extract nested property', () => {
|
|
16
|
-
const rootObj = { whoId: { id: 1, type: 'Lead', label: 'Test' } };
|
|
17
|
-
expect(extractValueBySmartProp(rootObj, 'whoId.type')).toEqual('Lead');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('extract deep nested property', () => {
|
|
21
|
-
const rootObj = { children: { whoId: { id: 1, type: 'Lead', label: 'Test' } } };
|
|
22
|
-
expect(extractValueBySmartProp(rootObj, 'children.whoId.type')).toEqual('Lead');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const extractValueBySmartProp = (rootObj, prop) => {
|
|
2
|
-
// { WhoId: { id: 1, type: 'Contact' } } // "WhoId.type" -> 'Contact'
|
|
3
|
-
if (rootObj.hasOwnProperty(prop)) {
|
|
4
|
-
return rootObj[prop];
|
|
5
|
-
} else {
|
|
6
|
-
const parts = prop.split('.');
|
|
7
|
-
if (parts.length > 1) {
|
|
8
|
-
if (rootObj.hasOwnProperty(parts[0])) {
|
|
9
|
-
if (typeof (rootObj[parts[0]]) === 'object' && rootObj[parts[0]][parts[1]]) {
|
|
10
|
-
return extractValueBySmartProp(rootObj[parts[0]], prop.substring(parts[0].length + 1));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const extractBooleanValueBySmartProp = (rootValue, visibleObj) => {
|
|
18
|
-
if (rootValue) {
|
|
19
|
-
if(typeof(rootValue) === 'boolean') {
|
|
20
|
-
return visibleObj !== rootValue;
|
|
21
|
-
}else{
|
|
22
|
-
return rootValue !== '' ? visibleObj !== true : visibleObj !== false;
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
// rootValue is undefined
|
|
26
|
-
return visibleObj !== false;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
export const templateBuilder = (metaContext, pattern) => {
|
|
2
|
-
const context = (metaContext || {}).context;
|
|
3
|
-
if (!context) {
|
|
4
|
-
if (!pattern || typeof(pattern) !== 'string') {
|
|
5
|
-
return;
|
|
6
|
-
} else {
|
|
7
|
-
return (pattern || '').replace(/\${\s*([\w.]+)\s*}/g, 'N/A');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const padTime = (t) => t < 10 ? '0' + t : t;
|
|
12
|
-
|
|
13
|
-
const patternBuilder = (pattern || '').replace(/\${\s*([\w.]+)\s*}/g, (match, value) => {
|
|
14
|
-
switch (value) {
|
|
15
|
-
case 'direction': {
|
|
16
|
-
return (context[value] || '').toUpperCase() === 'INBOUND' ? 'Inbound' : 'Outbound';
|
|
17
|
-
}
|
|
18
|
-
case 'name': {
|
|
19
|
-
return context.contact ? context.contact.name : (context.callerId || 'Unknown');
|
|
20
|
-
}
|
|
21
|
-
case 'contact': { // (FE-BE contract violation)
|
|
22
|
-
return context.contact ? context.contact.name : (context.callerId || 'Unknown');
|
|
23
|
-
}
|
|
24
|
-
case 'type': {
|
|
25
|
-
return context.type ? context.type : '';
|
|
26
|
-
}
|
|
27
|
-
case 'phoneNumber': {
|
|
28
|
-
return context[value];
|
|
29
|
-
}
|
|
30
|
-
case 'directionArrow': {
|
|
31
|
-
return (context.direction || '').toUpperCase() === 'INBOUND' ? '⬇' : '⬆';
|
|
32
|
-
}
|
|
33
|
-
case 'timestamp': {
|
|
34
|
-
try {
|
|
35
|
-
const callTime = new Date(context.answerTime || context.startTime || Date.now());
|
|
36
|
-
const date = callTime.toDateString();
|
|
37
|
-
const time = callTime.toLocaleTimeString();
|
|
38
|
-
return date + ', ' + time;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
console.error('context without startTime', e);
|
|
41
|
-
}
|
|
42
|
-
return '';
|
|
43
|
-
}
|
|
44
|
-
case 'duration': {
|
|
45
|
-
try {
|
|
46
|
-
if (typeof (context[value]) === 'number' && context.endTime) {
|
|
47
|
-
return '(' + (context[value]).toFixed() + 'ms)';
|
|
48
|
-
}
|
|
49
|
-
} catch (e) {
|
|
50
|
-
console.error('context without duration', e);
|
|
51
|
-
}
|
|
52
|
-
return '(0ms)';
|
|
53
|
-
}
|
|
54
|
-
case 'durationSec': {
|
|
55
|
-
try {
|
|
56
|
-
if (typeof (context.duration) === 'number' && context.endTime) {
|
|
57
|
-
return '(' + (context.duration / 1000).toFixed() + 's)';
|
|
58
|
-
}
|
|
59
|
-
} catch (e) {
|
|
60
|
-
console.error('call without duration', e);
|
|
61
|
-
}
|
|
62
|
-
return '(0s)';
|
|
63
|
-
}
|
|
64
|
-
case 'durationTime': {
|
|
65
|
-
try {
|
|
66
|
-
if (typeof (context.duration) === 'number' && context.endTime) {
|
|
67
|
-
const duration = context.duration / 1000; // convert it to seconds
|
|
68
|
-
if (duration < 0) {
|
|
69
|
-
return '00:00';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const hours = Math.floor(duration / 3600);
|
|
73
|
-
const minutes = Math.floor((duration % 3600) / 60);
|
|
74
|
-
const seconds = Math.floor(duration % 60);
|
|
75
|
-
|
|
76
|
-
const checkHours = hours ? padTime(hours) + ':' : '';
|
|
77
|
-
return checkHours + padTime(minutes) + ':' + padTime(seconds);
|
|
78
|
-
}
|
|
79
|
-
} catch (e) {
|
|
80
|
-
console.error('context without duration', e);
|
|
81
|
-
}
|
|
82
|
-
return '00:00';
|
|
83
|
-
}
|
|
84
|
-
default: {
|
|
85
|
-
const nestedTagMatch = value.match(/(\S+)\.(\S+)/);
|
|
86
|
-
if (nestedTagMatch) {
|
|
87
|
-
if (typeof(context[nestedTagMatch[1]]) === 'object') {
|
|
88
|
-
return context[nestedTagMatch[1]][nestedTagMatch[2]] || '';
|
|
89
|
-
} else {
|
|
90
|
-
return '';
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
return context[value] || '';
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return /^\s+$/.test(patternBuilder) ? '' : patternBuilder;
|
|
99
|
-
};
|