fng-ui-select 0.12.0-beta.34 → 0.12.0-beta.340
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/README.md +1 -1
- package/package.json +8 -8
- package/playwright.config.js +81 -0
- package/playwright.config.ts +77 -0
- package/src/fng-ui-select.js +304 -110
- package/styles/fng-ui-select.css +13 -4
- package/test/playwright/select.spec.js +75 -0
- package/test/playwright/select.spec.ts +69 -0
- package/test/playwright/tsconfig.json +10 -0
- package/test/e2e/multi-control.spec.js +0 -94
- package/test/e2e/multiple-control.spec.js +0 -175
- package/test/e2e/protractor-chrome.conf.js +0 -10
- package/test/e2e/protractor-firefox.conf.js +0 -38
- package/test/e2e/protractor-phantom.conf.js +0 -10
- package/test/e2e/protractor-wip.conf.js +0 -10
- package/test/e2e/single-control.spec.js +0 -86
- package/test/e2e/single-within-array.spec.js +0 -95
- package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should convert multi ajax lookups into multiple controls.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should handle inside cached lookups.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should handle outside cached lookups.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should handle simple enum.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets ajax lookup.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets cached table lookups.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets ajax lookup.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets cached table lookups.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle simple enums.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle Ajax lookup.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle cached table lookup.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle filtered Ajax lookup.png +0 -0
- package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle simple enum.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multi control-should convert multi ajax lookups into multiple controls.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multi control-should handle inside cached lookups.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multi control-should handle outside cached lookups.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multi control-should handle simple enum.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets ajax lookup.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets cached table lookups.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets ajax lookup.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets cached table lookups.png +0 -0
- package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle simple enums.png +0 -0
- package/test/screen_tests/screenshots/firefox-Single control-should handle Ajax lookup.png +0 -0
- package/test/screen_tests/screenshots/firefox-Single control-should handle cached table lookup.png +0 -0
- package/test/screen_tests/screenshots/firefox-Single control-should handle filtered Ajax lookup.png +0 -0
- package/test/screen_tests/screenshots/firefox-Single control-should handle simple enum.png +0 -0
package/src/fng-ui-select.js
CHANGED
|
@@ -3,9 +3,44 @@
|
|
|
3
3
|
|
|
4
4
|
var uiSelectModule = angular.module('fng.uiSelect', ['ui.select']);
|
|
5
5
|
|
|
6
|
-
uiSelectModule.factory('
|
|
6
|
+
uiSelectModule.factory('FngUISelectHelperService', ['$rootScope', '$q', 'RecordHandlerService', 'SubmissionsService', function ($rootScope, $q, RecordHandlerService, SubmissionsService) {
|
|
7
7
|
var lastW, lastH;
|
|
8
|
-
|
|
8
|
+
const localLookups = {};
|
|
9
|
+
// this ultra-simple cache stores { [id: string]: stringValue } as a means of avoiding unnecessary network round-trips, and the UI refresh
|
|
10
|
+
// lagging caused by the promises used to make them.
|
|
11
|
+
// there is no cache life-span because all we're storing here is the concatenation of records' list fields, and the chances of those
|
|
12
|
+
// changing while present in this cache is miniscule. even if they did change, displaying a stale record description in a picklist
|
|
13
|
+
// would surely not cause any great concern.
|
|
14
|
+
// there is no cache size limit because we're storing tiny amounts of data.
|
|
15
|
+
// NB: this cache assumes that record ids are unique across all resources (as is the case with a standard MongoDB back-end).
|
|
16
|
+
// TODO: provide an alternative implementation that includes the resourceName in the cache ids to avoid this limitation.
|
|
17
|
+
let valueCache = {};
|
|
18
|
+
// we're going to populate the select with this value whenever a SubmissionsService.getListAttributes(...) call is rejected. because we're
|
|
19
|
+
// only asking for list fields, permissions should not be the cause of failures, making "record not found" (where the foreign key
|
|
20
|
+
// reference has been broken) by far the most likely explanation.
|
|
21
|
+
// TODO: interpret the actual error condition and translate this into a user-friendly message
|
|
22
|
+
const RECORD_NOT_FOUND = "record not found";
|
|
23
|
+
|
|
24
|
+
function useCacheOrLookItUp(resourceName, id, cb) {
|
|
25
|
+
if (valueCache[id]) {
|
|
26
|
+
cb(valueCache[id]);
|
|
27
|
+
} else {
|
|
28
|
+
var text;
|
|
29
|
+
SubmissionsService.getListAttributes(resourceName, id)
|
|
30
|
+
.then((response) => {
|
|
31
|
+
text = response.data.list;
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
text = RECORD_NOT_FOUND; // cache this as well as there's no point in repeatedly performing a failing lookup
|
|
35
|
+
})
|
|
36
|
+
.finally(() => {
|
|
37
|
+
cb(text);
|
|
38
|
+
valueCache[id] = text;
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// NB: the type defs for this service (IFngUISelectHelperService) are in the forms-angular's index.d.ts
|
|
9
44
|
return {
|
|
10
45
|
windowChanged: function (w, h) {
|
|
11
46
|
var result = false;
|
|
@@ -19,53 +54,112 @@
|
|
|
19
54
|
addClientLookup: function (lkpName, lkpData) {
|
|
20
55
|
localLookups[lkpName] = lkpData;
|
|
21
56
|
},
|
|
57
|
+
clearCache: function () {
|
|
58
|
+
valueCache = {};
|
|
59
|
+
},
|
|
60
|
+
// Builds a lookupFunc closure bound to a specific localLookups key. Used for the deriveOptions case
|
|
61
|
+
// instead of the generic lookupFunc below, because deriveOptions can resolve to a different scope
|
|
62
|
+
// array per row (e.g. one "Also willing to work for" picklist per contract row, each with its own
|
|
63
|
+
// leafNodes_N array) - the shared lookupFunc/localLookups keyed by the (row-shared) deriveOptions
|
|
64
|
+
// function name can't distinguish between rows, causing lookups to hit the wrong row's data.
|
|
65
|
+
makeDeriveOptionsLookupFunc: function (lkpName) {
|
|
66
|
+
return function (value, formSchema, cb) {
|
|
67
|
+
if (formSchema.array) {
|
|
68
|
+
const results = value.map((value) => {
|
|
69
|
+
// a value can already have been converted to { id, text } by an earlier run of this same
|
|
70
|
+
// conversion function (forms-angular can re-run conversions - see the comment on
|
|
71
|
+
// $watchCollection("conversions", ...) - so this isn't necessarily the first pass over this
|
|
72
|
+
// field). converting it again would wrap it a second time ({ id: { id, text }, text: "" }),
|
|
73
|
+
// silently corrupting the value, so pass already-converted entries through unchanged.
|
|
74
|
+
if (value && typeof value === "object") {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
const obj = localLookups[lkpName].find((test) => test.id === value);
|
|
78
|
+
return { id: value, text: obj ? obj.text : "" };
|
|
79
|
+
});
|
|
80
|
+
cb(formSchema, results);
|
|
81
|
+
if (results.length > 0) {
|
|
82
|
+
setTimeout(function () {
|
|
83
|
+
$rootScope.$digest();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
} else if (typeof value !== "string") {
|
|
87
|
+
cb(formSchema, value); // already converted
|
|
88
|
+
} else {
|
|
89
|
+
const obj = localLookups[lkpName].find((test) => test.id === value);
|
|
90
|
+
cb(formSchema, { id: value, text: obj ? obj.text : "" });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
},
|
|
22
94
|
lookupFunc: function (value, formSchema, cb) {
|
|
23
95
|
if (formSchema.array) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
angular.forEach(value, function (obj) {
|
|
29
|
-
promises.push(SubmissionsService.getListAttributes(formSchema.ref, obj.x));
|
|
30
|
-
});
|
|
31
|
-
$q.all(promises).then(function (responses) {
|
|
32
|
-
angular.forEach(responses, function (response) {
|
|
33
|
-
results.push({x: {id: value.shift().x, text: response.data.list}});
|
|
96
|
+
if (formSchema.fngUiSelect.deriveOptions) {
|
|
97
|
+
const results = value.map((value) => {
|
|
98
|
+
const obj = localLookups[formSchema.fngUiSelect.deriveOptions].find((test) => test.id === value);
|
|
99
|
+
return { id: value, text: obj ? obj.text : "" };
|
|
34
100
|
});
|
|
35
101
|
cb(formSchema, results);
|
|
36
|
-
|
|
37
|
-
|
|
102
|
+
if (results.length > 0) {
|
|
103
|
+
setTimeout(function () {
|
|
104
|
+
$rootScope.$digest();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
const promises = value.map((value) => {
|
|
109
|
+
const id = value.x ? (value.x.id || value.x) : value; // if it's already been converted, throw away the result of the previous conversion
|
|
110
|
+
if (!id) {
|
|
111
|
+
return $q.resolve({ data: { list: "" } }); // nothing to convert
|
|
112
|
+
} else if (valueCache[id]) {
|
|
113
|
+
return $q.resolve({ data: { list: valueCache[id] } }); // already cached
|
|
114
|
+
} else {
|
|
115
|
+
return SubmissionsService.getListAttributes(formSchema.ref, id); // need to look it up
|
|
116
|
+
}
|
|
38
117
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
118
|
+
// TODO: no error handling here
|
|
119
|
+
// TODO: perform lookups of cache misses using a single round-trip
|
|
120
|
+
$q.all(promises).then((responses) => {
|
|
121
|
+
const results = responses.map((response) => {
|
|
122
|
+
let id = value.shift().x;
|
|
123
|
+
id = id.id || id; // in case it's already been converted
|
|
124
|
+
const text = response.data.list
|
|
125
|
+
valueCache[id] = text; // cache it for next time
|
|
126
|
+
return { id, text }
|
|
127
|
+
});
|
|
128
|
+
cb(formSchema, results);
|
|
129
|
+
setTimeout(function () {
|
|
130
|
+
$rootScope.$digest();
|
|
131
|
+
});
|
|
45
132
|
});
|
|
46
|
-
retVal = {id: value, text: obj ? obj.text : ''}
|
|
47
|
-
} else {
|
|
48
|
-
retVal = value;
|
|
49
133
|
}
|
|
50
|
-
|
|
134
|
+
} else if (typeof value !== "string") {
|
|
135
|
+
cb(formSchema, value); // already converted
|
|
136
|
+
} else if (formSchema.fngUiSelect && formSchema.fngUiSelect.deriveOptions) {
|
|
137
|
+
const obj = localLookups[formSchema.fngUiSelect.deriveOptions].find((test) => test.id === value);
|
|
138
|
+
cb(formSchema, { id: value, text: obj ? obj.text : "" });
|
|
51
139
|
} else {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
140
|
+
useCacheOrLookItUp(formSchema.ref, value, (text) => { cb(formSchema, { id: value, text }) });
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
doOwnConversion: function (scope, processedAttrs, ref) {
|
|
144
|
+
var id = RecordHandlerService.getData(scope.record, processedAttrs.info.name, scope.$index);
|
|
145
|
+
if (id) {
|
|
146
|
+
id = id.id || id; // in case it's already been converted
|
|
147
|
+
useCacheOrLookItUp(ref, id, (text) => { RecordHandlerService.setData(scope.record, processedAttrs.info.name, scope.$index, { id, text }) });
|
|
55
148
|
}
|
|
56
149
|
}
|
|
57
150
|
};
|
|
58
151
|
}]);
|
|
59
152
|
|
|
60
153
|
|
|
61
|
-
uiSelectModule.controller('FngUISelectCtrl', ['$scope', '$window', '$timeout', '$http', '
|
|
154
|
+
uiSelectModule.controller('FngUISelectCtrl', ['$scope', '$window', '$timeout', '$http', 'FngUISelectHelperService', function ($scope, $window, $timeout, $http, FngUISelectHelperService) {
|
|
62
155
|
|
|
63
156
|
$scope.uiSelect = $scope.uiSelect || [];
|
|
64
157
|
|
|
65
158
|
$scope.windowResizeUiSelect = function (checkResize) {
|
|
66
|
-
// This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable
|
|
159
|
+
// This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable
|
|
160
|
+
// design choices which will be factored out later
|
|
67
161
|
// Actually not choices - just not knowing any better
|
|
68
|
-
if (!checkResize ||
|
|
162
|
+
if (!checkResize || FngUISelectHelperService.windowChanged($window.innerWidth, $window.innerHeight)) {
|
|
69
163
|
for (var i = 0; i < $scope.uiSelect.length; i++) {
|
|
70
164
|
var selectId = $scope.uiSelect[i].selectId;
|
|
71
165
|
var select = document.getElementById(selectId);
|
|
@@ -94,14 +188,23 @@
|
|
|
94
188
|
$scope[id + '_options'] = [];
|
|
95
189
|
} else {
|
|
96
190
|
var promise;
|
|
97
|
-
if (elem.filter && elem.filter[0] ===
|
|
191
|
+
if (elem.filter && typeof elem.filter === "string" && elem.filter[0] === "/") {
|
|
192
|
+
if (elem.filter.startsWith("/api/")) {
|
|
193
|
+
console.log("WARNING! fng-ui-select is using an /api/ endpoint to refresh options - this is likely to cause security authorisation problems");
|
|
194
|
+
}
|
|
195
|
+
// HACK We want to pass the existing record in e, but we can fall foul of 431 errors if it is large, so we test for that
|
|
196
|
+
// using an arbitrary number and if so just send the _id (on the assumption that large records won't be new so will have an _id).
|
|
197
|
+
// According to https://stackoverflow.com/questions/57431355/how-to-fix-431-request-header-fields-too-large-in-react-redux-app the limit is 8KB
|
|
198
|
+
// but I have seen it fail at about 5k...
|
|
199
|
+
var record = JSON.stringify($scope.record).length >= (4 * 1024) ? { _id: $scope.record._id } : $scope.record;
|
|
98
200
|
// Custom URL
|
|
99
201
|
promise = $http({
|
|
100
202
|
method: 'GET',
|
|
101
203
|
url: elem.filter,
|
|
102
204
|
params: {
|
|
103
205
|
q: searchString,
|
|
104
|
-
e:
|
|
206
|
+
e: record,
|
|
207
|
+
i: $scope.$index
|
|
105
208
|
},
|
|
106
209
|
cache: false
|
|
107
210
|
});
|
|
@@ -122,9 +225,15 @@
|
|
|
122
225
|
}
|
|
123
226
|
}
|
|
124
227
|
})
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
228
|
+
.catch(function (err) {
|
|
229
|
+
var msg;
|
|
230
|
+
if (err && err.data && err.data.message) {
|
|
231
|
+
msg = err.data.message;
|
|
232
|
+
} else {
|
|
233
|
+
msg = 'Error ' + err.status + ': ' + err.statusText + ' - ' + err.data;
|
|
234
|
+
}
|
|
235
|
+
$scope.showError(msg);
|
|
236
|
+
});
|
|
128
237
|
}
|
|
129
238
|
} else {
|
|
130
239
|
throw new Error('Could not find uiSelect element for ' + id);
|
|
@@ -139,50 +248,71 @@
|
|
|
139
248
|
$timeout($scope.windowResizeUiSelect);
|
|
140
249
|
}]);
|
|
141
250
|
|
|
142
|
-
uiSelectModule.directive('fngUiSelect', ['$compile', '
|
|
143
|
-
function ($compile,
|
|
251
|
+
uiSelectModule.directive('fngUiSelect', ['$compile', 'PluginHelperService', 'CssFrameworkService', 'FngUISelectHelperService', '$timeout',
|
|
252
|
+
function ($compile, PluginHelperService, CssFrameworkService, FngUISelectHelperService, $timeout) {
|
|
144
253
|
return {
|
|
145
254
|
restrict: 'E',
|
|
146
255
|
controller: 'FngUISelectCtrl',
|
|
147
|
-
link: function (scope, element,
|
|
256
|
+
link: function (scope, element, attrs) {
|
|
148
257
|
|
|
149
258
|
function addToConversions(path, options) {
|
|
150
259
|
if (Object.keys(options).length > 0) {
|
|
151
260
|
var keys = path.split('.');
|
|
152
|
-
|
|
153
|
-
|
|
261
|
+
|
|
262
|
+
// Find the scope that owns the form (where the watcher is)
|
|
263
|
+
var conversionScope = scope;
|
|
264
|
+
while (conversionScope.$parent && !conversionScope.hasOwnProperty('topLevelFormName')) {
|
|
265
|
+
conversionScope = conversionScope.$parent;
|
|
154
266
|
}
|
|
155
|
-
|
|
267
|
+
|
|
268
|
+
if (!conversionScope.conversions) {
|
|
269
|
+
conversionScope.conversions = {};
|
|
270
|
+
}
|
|
271
|
+
var target = conversionScope.conversions;
|
|
156
272
|
for (var i = 0; i < keys.length; i++) {
|
|
157
273
|
var thisKey = keys[i];
|
|
158
274
|
target[thisKey] = target[thisKey] || {};
|
|
159
275
|
target = target[thisKey];
|
|
160
276
|
}
|
|
161
277
|
angular.extend(target, options);
|
|
278
|
+
conversionScope.conversionsModified = true;
|
|
162
279
|
}
|
|
163
280
|
}
|
|
164
281
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
282
|
+
const processedAttrs = PluginHelperService.extractFromAttr(attrs, 'fngUiSelect', scope);
|
|
283
|
+
const id = processedAttrs.info.id;
|
|
284
|
+
const uniqueId = scope.$index !== undefined ? processedAttrs.info.id + "_" + scope.$index : id;
|
|
285
|
+
const elemScope = angular.extend({ selectId: uniqueId }, processedAttrs.directiveOptions);
|
|
286
|
+
const multi = processedAttrs.info.array;
|
|
287
|
+
let elementHtml;
|
|
288
|
+
let input = '';
|
|
170
289
|
|
|
171
290
|
scope.uiSelect.push(elemScope);
|
|
172
|
-
addToConversions(
|
|
291
|
+
addToConversions(processedAttrs.info.name, processedAttrs.directiveOptions);
|
|
173
292
|
|
|
174
293
|
// Sort out the theme, defaulting to select2 (so old users won't see the change). Bootstrap theme only works with Bootstrap 3
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
294
|
+
// and not with animate (see https://github.com/angular-ui/ui-select/issues/1731 and others)
|
|
295
|
+
var theme = processedAttrs.directiveOptions.theme || 'select2';
|
|
296
|
+
if (theme === 'bootstrap') {
|
|
297
|
+
if (CssFrameworkService.framework() !== 'bs3') {
|
|
298
|
+
theme = 'select2';
|
|
299
|
+
} else {
|
|
300
|
+
try {
|
|
301
|
+
if (angular.module('ngAnimate')) {
|
|
302
|
+
theme = 'select2';
|
|
303
|
+
}
|
|
304
|
+
} catch (e) {
|
|
305
|
+
; // module not present, so bootstrap theme will work
|
|
306
|
+
}
|
|
307
|
+
}
|
|
178
308
|
}
|
|
179
309
|
|
|
180
310
|
var multiControl = false;
|
|
181
311
|
var multiStr = '';
|
|
182
|
-
if (multi && (
|
|
312
|
+
if (multi && (processedAttrs.directiveOptions.fngajax || processedAttrs.directiveOptions.forcemultiple)) {
|
|
183
313
|
// We need the array to be an array of objects with a x property. This tells forms-angular to convert it by
|
|
184
314
|
// adding an attribute to the schema.
|
|
185
|
-
|
|
315
|
+
PluginHelperService.findIdInSchemaAndFlagNeedX(scope.baseSchema(), id);
|
|
186
316
|
multiControl = true;
|
|
187
317
|
} else {
|
|
188
318
|
multiStr = multi ? 'multiple close-on-select reset-search-input ' : '';
|
|
@@ -190,36 +320,57 @@
|
|
|
190
320
|
|
|
191
321
|
var requiredStr = '';
|
|
192
322
|
var allowClearStr = '';
|
|
193
|
-
if (
|
|
323
|
+
if (processedAttrs.info.required) {
|
|
194
324
|
requiredStr = ' ng-required="true"';
|
|
325
|
+
} else if (processedAttrs.directiveOptions.ngrequired) {
|
|
326
|
+
requiredStr = ` ng-required="${processedAttrs.directiveOptions.ngrequired}"`;
|
|
195
327
|
} else {
|
|
196
328
|
allowClearStr = ' allow-clear';
|
|
197
329
|
}
|
|
330
|
+
let disabledStr = PluginHelperService.genIdAndDisabledStr(scope, processedAttrs, "", { forceNg: true });
|
|
198
331
|
|
|
199
332
|
// First of all add a hidden input field which we will use to set the width of the select
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
333
|
+
if (!angular.element(`#${uniqueId}_width-helper`).length > 0) {
|
|
334
|
+
var hiddenInputInfo = {
|
|
335
|
+
id: `${uniqueId}_width-helper`,
|
|
336
|
+
name: processedAttrs.info.name + '_width-helper',
|
|
337
|
+
label: ''
|
|
338
|
+
};
|
|
339
|
+
if (processedAttrs.info.size) {
|
|
340
|
+
hiddenInputInfo.size = processedAttrs.info.size;
|
|
341
|
+
}
|
|
342
|
+
input = PluginHelperService.buildInputMarkup(
|
|
343
|
+
scope,
|
|
344
|
+
attrs,
|
|
345
|
+
{
|
|
346
|
+
processedAttrs,
|
|
347
|
+
fieldInfoOverrides: hiddenInputInfo,
|
|
348
|
+
ignoreFieldInfoFromAttrs: true,
|
|
349
|
+
needsX: multiControl
|
|
350
|
+
},
|
|
351
|
+
function () {
|
|
352
|
+
return '<input id="' + hiddenInputInfo.id + '" type="text" class="form-control" disabled="" aria-label="unused input" style="position: absolute; left: -4200px;">';
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
input = input.replace('class="row', 'class="hidden-row row')
|
|
207
356
|
}
|
|
208
|
-
input = pluginHelper.buildInputMarkup(scope, attr.model, hiddenInputInfo, processedAttr.options, false, multiControl, function (buildingBlocks) {
|
|
209
|
-
return '<input id="' + hiddenInputInfo.id + '" type="text" class="form-control" disabled="" style="position: absolute; left: -4200px;">';
|
|
210
|
-
});
|
|
211
357
|
|
|
212
358
|
function optionsFromArray(multiControl, multi, array, arrayGetter) {
|
|
213
359
|
var isObjects = scope[array] && (scope[array].isObjects || typeof scope[array][0] === "object");
|
|
214
360
|
if (isObjects) {
|
|
215
|
-
|
|
216
|
-
|
|
361
|
+
// Key the lookup by the resolved scope array name (e.g. "leafNodes_0"), not by arrayGetter
|
|
362
|
+
// (the deriveOptions function name, which is shared/identical across every row when the same
|
|
363
|
+
// deriveOptions function is used for multiple rows, e.g. one per ng-repeat contract). Using
|
|
364
|
+
// arrayGetter as the key would make every row's conversion overwrite the same cache entry,
|
|
365
|
+
// leaving other rows' lookups resolving against the wrong array and rendering blank text.
|
|
366
|
+
addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.makeDeriveOptionsLookupFunc(array) });
|
|
367
|
+
FngUISelectHelperService.addClientLookup(array, scope[array]);
|
|
217
368
|
}
|
|
218
369
|
var select = '';
|
|
219
370
|
if (multiControl) {
|
|
220
371
|
select += '{{$select.selected' + (isObjects ? '.text' : '') + '}}';
|
|
221
372
|
} else {
|
|
222
|
-
select += multi ? '{{$item}}' : ('{{$select.selected' + (isObjects ? '.text' : '') + '}}');
|
|
373
|
+
select += multi ? '{{$item' + (isObjects ? '.text' : '') + '}}' : ('{{$select.selected' + (isObjects ? '.text' : '') + '}}');
|
|
223
374
|
}
|
|
224
375
|
select += '</ui-select-match>';
|
|
225
376
|
select += '<ui-select-choices repeat="option in ' + array + ' | filter:$select.search">';
|
|
@@ -227,55 +378,98 @@
|
|
|
227
378
|
return select;
|
|
228
379
|
}
|
|
229
380
|
|
|
230
|
-
elementHtml =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (processedAttr.directiveOptions.fngajax !== true) {
|
|
243
|
-
elemScope.filter = processedAttr.directiveOptions.fngajax;
|
|
381
|
+
elementHtml = PluginHelperService.buildInputMarkup(
|
|
382
|
+
scope,
|
|
383
|
+
attrs,
|
|
384
|
+
{
|
|
385
|
+
processedAttrs,
|
|
386
|
+
addButtons: multiControl,
|
|
387
|
+
needsX: multiControl,
|
|
388
|
+
},
|
|
389
|
+
function (buildingBlocks) {
|
|
390
|
+
var defaultPlaceholder = 'Select an option...';
|
|
391
|
+
if (processedAttrs.directiveOptions.fngajax) {
|
|
392
|
+
defaultPlaceholder = 'Start typing...'
|
|
244
393
|
}
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
394
|
+
// set up the ui-select directives
|
|
395
|
+
// hack here. buildingBlocks.common will almost certainly contain 'id="xxxx"', but we don't want this because the
|
|
396
|
+
// id will already be in disabledStr. remove it.
|
|
397
|
+
// the right solution here would be to include an option in the params that are passed to buildInputMarkup which
|
|
398
|
+
// specifies whether or not the buildingBlocks that it creates should include the id or not.
|
|
399
|
+
const idIdx = buildingBlocks.common.indexOf('id="');
|
|
400
|
+
if (idIdx > -1) {
|
|
401
|
+
const endIdIdx = buildingBlocks.common.indexOf('"', idIdx + 4);
|
|
402
|
+
if (endIdIdx > -1) {
|
|
403
|
+
buildingBlocks.common = buildingBlocks.common.substring(0, idIdx) + buildingBlocks.common.substring(endIdIdx + 1);
|
|
404
|
+
}
|
|
256
405
|
}
|
|
257
|
-
select
|
|
258
|
-
select += '<ui-select-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
406
|
+
var select = '<ui-select ' + multiStr + buildingBlocks.common + requiredStr + disabledStr + ' theme="' + theme + '" style="min-width:18em;">'
|
|
407
|
+
select += '<ui-select-match' + allowClearStr + ' placeholder="' + (processedAttrs.info.placeholder || defaultPlaceholder) + '">';
|
|
408
|
+
|
|
409
|
+
if (processedAttrs.directiveOptions.fngajax) {
|
|
410
|
+
// Stash any filters
|
|
411
|
+
if (processedAttrs.directiveOptions.fngajax !== true) {
|
|
412
|
+
elemScope.filter = processedAttrs.directiveOptions.fngajax;
|
|
413
|
+
}
|
|
414
|
+
// if we have a hard-coded ref (processedAttrs.info.ref), forms-angular can perform the lookup conversion for us.
|
|
415
|
+
// where processedAttrs.directiveOptions.refprop is being used instead, the ref is 'variable' - it comes from a property of scope.record, and
|
|
416
|
+
// in this case, we'll need to handle the conversions ourselves.
|
|
417
|
+
addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.lookupFunc, noconvert: !!processedAttrs.directiveOptions.refprop });
|
|
418
|
+
if (processedAttrs.directiveOptions.refprop) {
|
|
419
|
+
// the property that we'll be getting the ref from may not be populated yet, and might conceivably change at any time, so we
|
|
420
|
+
// need to $watch it. buildingBlocks.modelString will be something like "record.<array>[$index].<field>". replacing <field>
|
|
421
|
+
// with the value of refprop will give us a suitable watch expression.
|
|
422
|
+
const watchStr = buildingBlocks.modelString.substring(0, buildingBlocks.modelString.lastIndexOf(".") + 1) + processedAttrs.directiveOptions.refprop;
|
|
423
|
+
scope.$watch(watchStr, (newValue) => {
|
|
424
|
+
if (newValue && elemScope.ref !== newValue) {
|
|
425
|
+
elemScope.ref = newValue;
|
|
426
|
+
FngUISelectHelperService.doOwnConversion(scope, processedAttrs, elemScope.ref);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
// we also need to re-do the conversion if the user cancels changes. this event does fire on more than just user cancellation,
|
|
430
|
+
// so this is slightly wasteful. but with the caching implemented by uiSelectHelper, this is no big deal.
|
|
431
|
+
scope.$on("fngCancel", () => {
|
|
432
|
+
$timeout(() => {
|
|
433
|
+
if (elemScope.ref) {
|
|
434
|
+
FngUISelectHelperService.doOwnConversion(scope, processedAttrs, elemScope.ref);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
} else {
|
|
439
|
+
elemScope.ref = processedAttrs.info.ref;
|
|
440
|
+
}
|
|
441
|
+
scope[`${uniqueId}_options`] = [];
|
|
442
|
+
if (multiControl) {
|
|
443
|
+
select += '{{$select.selected.text}}';
|
|
444
|
+
} else {
|
|
445
|
+
// buildingBlocks.modelString already addresses the field correctly at every nesting
|
|
446
|
+
// level, including inside a sub-schema array. It used to be special cased here to
|
|
447
|
+
// build an absolute "<root>[$index].<field>" path, which cannot reach a field in an
|
|
448
|
+
// array nested within a sub-schema array - $index there belongs to the inner repeat.
|
|
449
|
+
select += '{{' + buildingBlocks.modelString + '.text}}';
|
|
450
|
+
}
|
|
451
|
+
select += '</ui-select-match>';
|
|
452
|
+
select += `<ui-select-choices repeat="option in (${uniqueId}_options) track by $index" `;
|
|
453
|
+
select += `refresh="refreshOptions($select.search, '${uniqueId}')" `;
|
|
454
|
+
select += 'refresh-delay="400"> ';
|
|
455
|
+
select += '<div ng-bind-html="option.text" ng-attr-title="{{ option.text }}"></div>';
|
|
456
|
+
} else if (processedAttrs.directiveOptions.deriveoptions) {
|
|
457
|
+
if (typeof scope[processedAttrs.directiveOptions.deriveoptions] === "function") {
|
|
458
|
+
select += optionsFromArray(multiControl, multi, scope[processedAttrs.directiveOptions.deriveoptions](), processedAttrs.directiveOptions.deriveoptions);
|
|
459
|
+
} else {
|
|
460
|
+
throw new Error("In fng-ui-select " + processedAttrs.directiveOptions.deriveoptions + " is not a function on the scope");
|
|
461
|
+
}
|
|
462
|
+
} else if (processedAttrs.info.options) {
|
|
463
|
+
// Simple case - enumerated options on the form scope
|
|
464
|
+
select += optionsFromArray(multiControl, multi, processedAttrs.info.options);
|
|
265
465
|
} else {
|
|
266
|
-
throw new Error(
|
|
466
|
+
throw new Error('fng-ui-select has no means of populating select');
|
|
267
467
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
select
|
|
271
|
-
} else {
|
|
272
|
-
throw new Error('fng-ui-select has no means of populating select');
|
|
468
|
+
select += '</ui-select-choices>';
|
|
469
|
+
select += '</ui-select>';
|
|
470
|
+
return select;
|
|
273
471
|
}
|
|
274
|
-
|
|
275
|
-
select += '</ui-select>';
|
|
276
|
-
return select;
|
|
277
|
-
});
|
|
278
|
-
scope.content = input + elementHtml;
|
|
472
|
+
);
|
|
279
473
|
element.append($compile(input + elementHtml)(scope));
|
|
280
474
|
}
|
|
281
475
|
}
|
package/styles/fng-ui-select.css
CHANGED
|
@@ -14,10 +14,19 @@
|
|
|
14
14
|
background-color: rgba(255, 0, 0, 0.10);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
fng-ui-select div[id*="width-helper"] {
|
|
18
|
+
margin-bottom: 0px!important;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
fng-ui-select
|
|
22
|
-
|
|
21
|
+
fng-ui-select div[id*="width-helper"] div {
|
|
22
|
+
min-height: 0px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fng-ui-select div[id*="width-helper"] label.control-label {
|
|
26
|
+
padding-top: 0px!important;
|
|
27
|
+
min-height: 0px!important;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.hidden-row {
|
|
31
|
+
display: none;
|
|
23
32
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const test_1 = require("@playwright/test");
|
|
13
|
+
const unique = new Date().valueOf();
|
|
14
|
+
(0, test_1.test)('Creates a new record with multiple shelves', ({ page }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
yield page.goto('http://localhost:9000/#/k_referencing_self_collection/new');
|
|
16
|
+
yield page.getByLabel('Warehouse Name').fill(`M${unique} Warehouse`);
|
|
17
|
+
yield page.locator('#add_f_shelves_btn').click();
|
|
18
|
+
yield page.locator('#add_f_shelves_btn').click();
|
|
19
|
+
yield page.locator('#add_f_shelves_btn').click();
|
|
20
|
+
yield page.locator('#f_shelves_location_0').click();
|
|
21
|
+
yield page.locator('#f_shelves_location_0').fill('Top');
|
|
22
|
+
yield page.locator('#f_shelves_location_1').click();
|
|
23
|
+
yield page.locator('#f_shelves_location_1').fill('Middle');
|
|
24
|
+
yield page.locator('#f_shelves_location_2').click();
|
|
25
|
+
yield page.locator('#f_shelves_location_2').fill('Bottom');
|
|
26
|
+
yield page.locator('#add_f_items_btn').click();
|
|
27
|
+
yield page.getByLabel('Items Description').click();
|
|
28
|
+
yield page.getByLabel('Items Description').fill('Item 1');
|
|
29
|
+
yield page.getByLabel('Shelf', { exact: true }).selectOption('Middle');
|
|
30
|
+
yield page.locator('#add_f_cleanedShelves').click();
|
|
31
|
+
yield page.locator('#add_f_cleanedShelves').click();
|
|
32
|
+
yield page.locator('#f_cleanedShelves_0').selectOption('Middle');
|
|
33
|
+
yield page.locator('#f_cleanedShelves_1').selectOption('Top');
|
|
34
|
+
yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toContainText('Middle');
|
|
35
|
+
yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toHaveClass(/ng-valid-required/);
|
|
36
|
+
yield page.getByLabel('Favourite Shelf').selectOption('Bottom');
|
|
37
|
+
yield (0, test_1.expect)(page.getByLabel('Favourite Shelf')).toContainText('Bottom');
|
|
38
|
+
yield page.getByRole('button', { name: ' Save' }).click();
|
|
39
|
+
yield (0, test_1.expect)(page.getByRole('button', { name: ' Save' })).toBeDisabled();
|
|
40
|
+
yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toContainText('Middle');
|
|
41
|
+
// await expect(page.locator('#f_cleanedShelves_0')).toHaveClass(/ng-valid-required/); // This currently fails, but has done I think for ages...
|
|
42
|
+
yield (0, test_1.expect)(page.getByLabel('Favourite Shelf')).toContainText('Bottom');
|
|
43
|
+
yield page.goto('http://localhost:9000/#/l_referencing_list_in_other_document/new');
|
|
44
|
+
yield page.getByLabel('Description').click();
|
|
45
|
+
yield page.getByLabel('Description').fill('An item in multi');
|
|
46
|
+
yield page.getByLabel('Select box select').click();
|
|
47
|
+
yield page.getByLabel('Select box', { exact: true }).click();
|
|
48
|
+
yield page.getByLabel('Select box', { exact: true }).fill(`M${unique}`);
|
|
49
|
+
yield page.getByText(`M${unique} Warehouse`).click();
|
|
50
|
+
yield page.getByLabel('Shelf').selectOption('Top');
|
|
51
|
+
}));
|
|
52
|
+
(0, test_1.test)('Creates a new record with a single shelf', ({ page }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
yield page.goto('http://localhost:9000/#/k_referencing_self_collection/new');
|
|
54
|
+
yield page.getByLabel('Warehouse Name').fill(`S${unique} Warehouse`);
|
|
55
|
+
yield page.locator('#add_f_shelves_btn').click();
|
|
56
|
+
yield page.getByLabel('Shelves Location').click();
|
|
57
|
+
yield page.getByLabel('Shelves Location').fill('Only');
|
|
58
|
+
yield page.locator('#add_f_items_btn').click();
|
|
59
|
+
yield page.getByLabel('Items Description').click();
|
|
60
|
+
yield page.getByLabel('Items Description').fill('Item 1');
|
|
61
|
+
yield page.getByLabel('Shelf', { exact: true }).selectOption('Only');
|
|
62
|
+
yield page.locator('#add_f_cleanedShelves').click();
|
|
63
|
+
yield page.getByLabel('Cleaned Shelves').selectOption('Only');
|
|
64
|
+
yield page.getByLabel('Favourite Shelf').selectOption('Only');
|
|
65
|
+
yield page.getByRole('button', { name: ' Save' }).click();
|
|
66
|
+
yield (0, test_1.expect)(page.getByRole('button', { name: ' Save' })).toBeDisabled();
|
|
67
|
+
yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toContainText('Only');
|
|
68
|
+
yield page.goto('http://localhost:9000/#/l_referencing_list_in_other_document/new');
|
|
69
|
+
yield page.getByLabel('Description').fill('Single');
|
|
70
|
+
yield page.getByLabel('Select box select').click();
|
|
71
|
+
yield page.getByLabel('Select box', { exact: true }).click();
|
|
72
|
+
yield page.getByLabel('Select box', { exact: true }).fill(`S${unique}`);
|
|
73
|
+
yield page.getByText(`S${unique} Warehouse`).click();
|
|
74
|
+
yield page.getByLabel('Shelf').selectOption('Only');
|
|
75
|
+
}));
|