@qikdev/sdk 0.1.16 → 0.1.17

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.
@@ -0,0 +1,88 @@
1
+ export default function(qik) {
2
+
3
+
4
+ ///////////////////////
5
+
6
+ var service = {};
7
+
8
+ ///////////////////////
9
+
10
+ service.downloadUrl = function(type, id, params) {
11
+ params = params || {}
12
+ params.download = true;
13
+ id = qik.utils.id(id);
14
+ return qik.api.generateEndpointURL(`/${type}/${id}`, params);
15
+ }
16
+
17
+ service.mediaUrl = function(type, id, params) {
18
+ params = params || {}
19
+ id = qik.utils.id(id);
20
+ return qik.api.generateEndpointURL(`/${type}/${id}`, params);
21
+ }
22
+
23
+ ///////////////////////
24
+
25
+ service.filesize = function(bytes) {
26
+ var sizes = ['b', 'kb', 'mb', 'gb', 'tb'];
27
+ if (bytes == 0) return '0 Byte';
28
+ var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
29
+ return Math.round(bytes / Math.pow(1024, i), 2) + '' + sizes[i];
30
+ }
31
+
32
+ ///////////////////////
33
+
34
+ service.getBinaryTypeFromMime = function(fileMime) {
35
+
36
+ if (!fileMime) {
37
+ return 'file';
38
+ }
39
+
40
+ ////////////////////////////////
41
+
42
+ switch (fileMime) {
43
+ case 'image/jpeg':
44
+ case 'image/png':
45
+ case 'image/gif':
46
+ case 'image/bmp':
47
+ case 'image/tiff':
48
+ case 'image/svg+xml':
49
+ return 'image';
50
+ break;
51
+ case 'video/mp4':
52
+ case 'video/quicktime':
53
+ case 'video/ogg':
54
+ case 'video/webm':
55
+ return 'video'
56
+ break;
57
+ case 'audio/aac':
58
+ case 'audio/aiff':
59
+ case 'audio/mp3':
60
+ case 'audio/x-m4a':
61
+ case 'audio/mpeg':
62
+ case 'audio/ogg':
63
+ case 'audio/wav':
64
+ case 'audio/webm':
65
+ return 'audio'
66
+ break;
67
+ default:
68
+ //See if we can guess it from the first part of the mimetype
69
+ var prefix = fileMime.split('/')[0];
70
+ switch (prefix) {
71
+ case 'image':
72
+ case 'video':
73
+ case 'audio':
74
+ return prefix;
75
+ break;
76
+ default:
77
+ return 'file';
78
+ break;
79
+ }
80
+ break;
81
+ }
82
+ }
83
+
84
+ ////////////////////////////////
85
+
86
+ return service;
87
+
88
+ }
@@ -0,0 +1,255 @@
1
+ ///////////////////////
2
+
3
+ var service = {};
4
+
5
+
6
+ ///////////////////////
7
+
8
+
9
+ function isEmpty(value) {
10
+ if(value === 0) {
11
+ return false;
12
+ }
13
+
14
+ var empty = typeof value === 'undefined' || value === null || String(value).trim() === '';
15
+
16
+ if (empty) {
17
+ return true;
18
+ }
19
+
20
+ //If it's a string of undefined or null then treat it as empty also
21
+ if (value === 'undefined' || value === 'null') {
22
+ return true;
23
+ }
24
+
25
+ return false;
26
+ }
27
+
28
+ function compactFunction(val) {
29
+ return !isEmpty(val)
30
+ }
31
+
32
+
33
+ ///////////////////////
34
+
35
+ service.cleanKey = function(key) {
36
+ key = String(key).split('|')[0];
37
+
38
+ if (key[0] == '.') {
39
+ key = key.slice(1);
40
+ }
41
+
42
+ return key;
43
+ }
44
+
45
+ ///////////////////////
46
+
47
+ service.isValidFilter = function(filter) {
48
+ if (!filter) {
49
+ return false;
50
+ }
51
+
52
+ ///////////////////////////
53
+
54
+ //If the filter has nested filters consider it valid
55
+ //if it has valid child filters
56
+ if (filter.operator) {
57
+ if (!filter.filters || !filter.filters.length) {
58
+ return false;
59
+ }
60
+
61
+ return filter.filters.some(service.isValidFilter);
62
+ }
63
+
64
+ // ///////////////////////////
65
+
66
+ // //Get the comparator for the filter
67
+ // var comparator = hash[filter.comparator];
68
+ // if (!comparator) {
69
+ // //No comparator was specified for the filter
70
+ // return false;
71
+ // }
72
+
73
+ ///////////////////////////
74
+
75
+ var key = service.cleanKey(filter.key);
76
+ if (!key) {
77
+ //No key has been specified for the filter
78
+ return false;
79
+ }
80
+
81
+ if(filter.comparator == 'empty' || filter.comparator == 'notempty') {
82
+ return true;
83
+ }
84
+
85
+
86
+ var multiValues = (filter.values || []).filter(compactFunction);
87
+
88
+
89
+
90
+ return !isEmpty(filter.value) || !isEmpty(filter.value2) || multiValues.length;
91
+ // ///////////////////////////
92
+
93
+ // switch (filter.inputType) {
94
+ // case 'none':
95
+ // //If we are checking empty/notempty
96
+ // //the filter is always valid without any extra parameters
97
+ // return true;
98
+ // break;
99
+ // case 'range':
100
+ // //If we are filtering a number range
101
+ // //we need the start and end of the range
102
+ // if (!filter.value || isNaN(filter.value)) {
103
+ // return false;
104
+ // }
105
+
106
+ // if (!filter.value2 || isNaN(filter.value2)) {
107
+ // return false;
108
+ // }
109
+ // break;
110
+ // case 'daterange':
111
+ // if (!filter.value || !parseDate(filter.value)) {
112
+ // return false;
113
+ // }
114
+
115
+ // if (!filter.value2 || !parseDate(filter.value2)) {
116
+ // return false;
117
+ // }
118
+ // break;
119
+ // case 'array':
120
+ // if (!filter.values || !filter.values.length) {
121
+ // return false;
122
+ // }
123
+ // break;
124
+ // default:
125
+ // // if (filter.dataType == 'boolean') {
126
+ // // //Check if they provided a valid boolean value to the filter
127
+ // // return validBooleans[String(filter.value).toLowerCase()];
128
+ // // } else {
129
+ // // //The filter has not been provided with a value
130
+ // if (isEmpty(filter.value)) {
131
+ // return false;
132
+ // }
133
+ // // }
134
+ // break;
135
+ // }
136
+
137
+ ///////////////////////////
138
+
139
+ //If we got this far then the information
140
+ //provided to the filter is enough to run it
141
+ return true;
142
+
143
+ }
144
+
145
+ ////////////////////////////////////////////////
146
+
147
+ service.activeFilters = function(filterConfiguration) {
148
+ var memo = [];
149
+
150
+ retrieveActiveFilter(filterConfiguration, memo);
151
+
152
+ return memo;
153
+
154
+ ////////////////////////////
155
+
156
+ function retrieveActiveFilter(filterBlock, memo) {
157
+ if (!filterBlock) {
158
+ return;
159
+ }
160
+
161
+ var isValid = service.isValidFilter(filterBlock);
162
+
163
+ if (isValid) {
164
+ memo.push(filterBlock);
165
+ }
166
+
167
+ if (filterBlock.filters && filterBlock.filters.length) {
168
+ filterBlock.filters.forEach(function(b) {
169
+ retrieveActiveFilter(b, memo);
170
+ })
171
+ }
172
+ }
173
+ }
174
+
175
+ ////////////////////////////////////////////////
176
+
177
+ service.activeFilterKeys = function(filterConfiguration) {
178
+ var value = service.activeFilters(filterConfiguration)
179
+ .filter(function(entry) {
180
+ //Ignore all the wrapping entries
181
+ return !entry.operator;
182
+ })
183
+ .reduce(function(set, filter) {
184
+ var rootKey = service.cleanKey(filter.key);
185
+ set[rootKey] = true;
186
+ return set;
187
+ }, {})
188
+
189
+ return Object.keys(value);
190
+ }
191
+
192
+ service.activeFilterComparators = function(filterConfiguration) {
193
+ var comparators = service.activeFilters(filterConfiguration)
194
+ .filter(function(entry) {
195
+ //Ignore all the wrapping entries
196
+ return !entry.operator;
197
+ })
198
+ .reduce(function(set, filter) {
199
+ set[filter.comparator] = true;
200
+ return set;
201
+ }, {})
202
+
203
+ return Object.keys(comparators);
204
+ }
205
+
206
+
207
+ service.activeFilterOperators = function(filterConfiguration) {
208
+ var operators = service.activeFilters(filterConfiguration)
209
+ .filter(function(entry) {
210
+ return entry.operator;
211
+ })
212
+ .reduce(function(set, filter) {
213
+ set[filter.operator] = true;
214
+ return set;
215
+ }, {})
216
+
217
+ return Object.keys(operators);
218
+ }
219
+
220
+
221
+
222
+ service.activeFilterValues = function(filterConfiguration, options) {
223
+
224
+ options = options || {};
225
+
226
+ var activeFilters = service.activeFilters(filterConfiguration);
227
+
228
+ var values = activeFilters
229
+ .filter(function(entry) {
230
+ //Ignore all the wrapping entries
231
+ return !entry.operator;
232
+ })
233
+ .reduce(function(set, filter) {
234
+ set = [...set, ...(filter.values || []), filter.value, filter.value2];
235
+ return set;
236
+ }, [])
237
+ .filter(compactFunction);
238
+
239
+
240
+
241
+ return values;
242
+ }
243
+ service.filterChangeString = function(config) {
244
+ var string = [
245
+ service.activeFilterKeys(config).join(', '),
246
+ service.activeFilterValues(config).join(', '),
247
+ service.activeFilterComparators(config).join(', '),
248
+ service.activeFilterOperators(config).join(', '),
249
+ ]
250
+ return string.filter(compactFunction).join(', ');
251
+ };
252
+
253
+ ///////////////////////
254
+
255
+ export default service;
@@ -0,0 +1,42 @@
1
+ ///////////////////////////////////////////////////
2
+
3
+ /**
4
+ * Creates a new QikSystem instance.
5
+ * This module provides a number of helper functions for the system
6
+ * @alias content
7
+ * @constructor
8
+ * @hideconstructor
9
+ * @param {QikCore} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
10
+ */
11
+ export default function(qik) {
12
+
13
+ ///////////////////////////////////////////////////
14
+
15
+ var service = {}
16
+
17
+
18
+ ///////////////////////////////////////////////////////////////////////////////
19
+
20
+ var inflightCountries;
21
+
22
+ service.countries = async function() {
23
+
24
+ if (!inflightCountries) {
25
+
26
+ inflightCountries = new Promise(async function(resolve, reject) {
27
+ qik.api.get(`/system/countries`)
28
+ .then(function(res) {
29
+ return resolve(res.data);
30
+ })
31
+ .catch(reject);
32
+ })
33
+ }
34
+
35
+ return inflightCountries;
36
+ }
37
+
38
+ ///////////////////////////////////////////////////
39
+
40
+ return service;
41
+
42
+ }