@vgip/meta-ui 2.1.1 → 2.1.3
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/.eslintrc.json +57 -0
- package/karma.conf.js +35 -0
- package/ng-package.json +10 -0
- package/package.json +4 -16
- package/src/lib/common/fieldNormalizer/boolean.ts +11 -0
- package/src/lib/common/fieldNormalizer/datetime.ts +8 -0
- package/src/lib/common/fieldNormalizer/index.ts +171 -0
- package/src/lib/common/fieldNormalizer/number.ts +13 -0
- package/src/lib/common/fieldNormalizer/options.ts +48 -0
- package/src/lib/common/fieldNormalizer/radio.ts +29 -0
- package/src/lib/common/fieldNormalizer/reference.ts +32 -0
- package/src/lib/common/fieldNormalizer/richtext.ts +15 -0
- package/src/lib/common/fieldNormalizer/string.ts +23 -0
- package/src/lib/common/fieldNormalizer/text.ts +17 -0
- package/src/lib/common/fieldNormalizer/uniqueNameFilter.ts +21 -0
- package/src/lib/common/metaAutofocus.directive.ts +31 -0
- package/src/lib/common/metaContext.resolver.ts +25 -0
- package/src/lib/common/metaIcons.pipe.spec.ts +15 -0
- package/src/lib/common/metaIcons.pipe.ts +29 -0
- package/src/lib/common/metaModel.pipe.ts +19 -0
- package/src/lib/common/metaNormalizer.ts +366 -0
- package/src/lib/common/metaStripHtml.pipe.ts +18 -0
- package/src/lib/common/utils/colorThemes.ts +86 -0
- package/src/lib/common/utils/indexedDbStore/index.ts +244 -0
- package/src/lib/common/utils/indexedDbStore/indexedDbStore.spec.ts +149 -0
- package/src/lib/common/utils/relativeTimeBuilder.ts +49 -0
- package/src/lib/common/utils/resourceCardLabel.ts +25 -0
- package/src/lib/common/utils/smartProp.spec.ts +24 -0
- package/src/lib/common/utils/smartProp.ts +28 -0
- package/src/lib/common/utils/templateBuilder.ts +99 -0
- package/src/lib/field.scss +207 -0
- package/src/lib/fieldAbstract.ts +327 -0
- package/src/lib/fieldBoolean/index.ts +55 -0
- package/src/lib/fieldBoolean/style.scss +22 -0
- package/src/lib/fieldBoolean/test.spec.ts +43 -0
- package/src/lib/fieldBoolean/view.html +30 -0
- package/src/lib/fieldComposite/index.ts +86 -0
- package/src/lib/fieldComposite/style.scss +6 -0
- package/src/lib/fieldComposite/test.spec.ts +43 -0
- package/src/lib/fieldComposite/view.html +9 -0
- package/src/lib/fieldDatetime/index.ts +359 -0
- package/src/lib/fieldDatetime/style.scss +81 -0
- package/src/lib/fieldDatetime/test.spec.ts +43 -0
- package/src/lib/fieldDatetime/view.html +26 -0
- package/src/lib/fieldHidden/index.ts +15 -0
- package/src/lib/fieldHidden/view.html +0 -0
- package/src/lib/fieldInput/index.ts +477 -0
- package/src/lib/fieldInput/style.scss +128 -0
- package/src/lib/fieldInput/test.spec.ts +43 -0
- package/src/lib/fieldInput/view.html +81 -0
- package/src/lib/fieldList/index.ts +73 -0
- package/src/lib/fieldList/style.scss +26 -0
- package/src/lib/fieldList/test.spec.ts +43 -0
- package/src/lib/fieldList/view.html +25 -0
- package/src/lib/fieldRadio/index.ts +93 -0
- package/src/lib/fieldRadio/style.scss +32 -0
- package/src/lib/fieldRadio/test.spec.ts +43 -0
- package/src/lib/fieldRadio/view.html +24 -0
- package/src/lib/fieldReference/index.ts +871 -0
- package/src/lib/fieldReference/style.scss +273 -0
- package/src/lib/fieldReference/test.spec.ts +44 -0
- package/src/lib/fieldReference/view.html +163 -0
- package/src/lib/fieldRichtext/index.ts +98 -0
- package/src/lib/fieldRichtext/quill.scss +6 -0
- package/src/lib/fieldRichtext/style.scss +87 -0
- package/src/lib/fieldRichtext/test.spec.ts +43 -0
- package/src/lib/fieldRichtext/view.html +17 -0
- package/src/lib/fieldSelect/index.ts +597 -0
- package/src/lib/fieldSelect/style.scss +165 -0
- package/src/lib/fieldSelect/test.spec.ts +44 -0
- package/src/lib/fieldSelect/view.html +128 -0
- package/src/lib/fieldText/index.ts +86 -0
- package/src/lib/fieldText/style.scss +24 -0
- package/src/lib/fieldText/test.spec.ts +43 -0
- package/src/lib/fieldText/view.html +23 -0
- package/src/lib/fieldUnknown/index.ts +15 -0
- package/src/lib/fieldUnknown/test.spec.ts +34 -0
- package/src/lib/fieldUnknown/view.html +9 -0
- package/src/lib/index.ts +127 -0
- package/src/lib/layout/index.ts +255 -0
- package/src/lib/layout/style.scss +67 -0
- package/src/lib/layout/view.html +45 -0
- package/src/lib/metaField/index.ts +133 -0
- package/src/lib/metaField/test.spec.ts +32 -0
- package/src/lib/refDialog/index.ts +157 -0
- package/src/lib/refDialog/style.scss +154 -0
- package/src/lib/refDialog/view.html +24 -0
- package/src/lib/resource/index.ts +559 -0
- package/src/lib/resource/style.scss +132 -0
- package/src/lib/resource/view.html +70 -0
- package/src/lib/resourceCard/index.ts +44 -0
- package/src/lib/resourceCard/style.scss +7 -0
- package/src/lib/resourceCard/view.html +14 -0
- package/src/lib/services/metaContext/index.ts +61 -0
- package/src/lib/services/metaMsg/index.ts +84 -0
- package/src/lib/services/metaReference/index.ts +98 -0
- package/src/lib/services/metaResource/index.ts +163 -0
- package/src/lib/services/metaResource/metaHttpClient.ts +76 -0
- package/src/lib/services/metaResource/metaResource.spec.ts +24 -0
- package/src/lib/services/metaTracker/index.ts +38 -0
- package/src/lib/services/resourceDrafts/index.ts +81 -0
- package/src/lib/services/resourceDrafts/resourceDrafts.spec.ts +24 -0
- package/src/lib/styles.scss +13 -0
- package/src/public-api.ts +5 -0
- package/src/test.ts +17 -0
- package/tsconfig.lib.json +25 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +17 -0
- package/vendor/volta3/scss/components/_accordions.scss +5 -1
- package/vendor/volta3/scss/components/_callouts.scss +6 -2
- package/vendor/volta3/scss/components/_card.scss +1 -1
- package/vendor/volta3/scss/components/_form-elements.scss +1 -1
- package/vendor/volta3/scss/components/_modals.scss +1 -1
- package/vendor/volta3/scss/components/_tables.scss +1 -1
- package/vendor/volta3/scss/lib/_variables.scss +1 -1
- package/fesm2022/vgip-meta-ui.mjs +0 -6076
- package/fesm2022/vgip-meta-ui.mjs.map +0 -1
- package/index.d.ts +0 -709
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
};
|