Skip to content

Commit 38899a3

Browse files
committed
Fix/Rework Multi-select removal
* The bitwiseToArray was not firing because the array reference was not getting tickled and it was being completely removed instead of removing one entry. * Fixed version displayed on splash screen * Added some tests for select-picker Fixes #181
1 parent 081fe3f commit 38899a3

File tree

8 files changed

+214
-45
lines changed

8 files changed

+214
-45
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ Webdriver for NodeJS is used for the integration tests. This project has been mo
9393
The following is a list of test statistics for the project for date
9494

9595
| Date | Commit | Number of Tests | Code Coverage |
96-
| --- | --- | --- | --- |
97-
| 2022-01-15 | [8ac447f](https://github.com/stamp-web/stamp-web-aurelia/commit/8ac447f580f29d1f0f8dd23e284c6f25448cf1d7) | 83 | 12% |
98-
96+
| --- | --- | --- |---------------|
97+
| 2022-01-15 | [8ac447f](https://github.com/stamp-web/stamp-web-aurelia/commit/8ac447f580f29d1f0f8dd23e284c6f25448cf1d7) | 83 | 12.05% |
98+
| 2022-01-15 | [081fe3f](https://github.com/stamp-web/stamp-web-aurelia/commit/081fe3f31d5962c10777f4017e2c7a5dbe26e12e) | 86 | 12.20% |
9999

100100
## Optimizing for Browsers
101101

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</div>
1717
<div class="content">
1818
<div class="message">Stamp Web</div>
19-
<div class="version">Version 6.0.0</div>
19+
<div class="version">Version 6.2.0</div>
2020
<div class="sw-icon-progress splash-spin"></div>
2121
<div class="build-version"></div>
2222
</div>

src/resources/elements/ownerships/ownership-cert.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@import "../../../theme/_semantic.scss";
22

33
ownership-cert {
4+
z-index: 10;
5+
46
.sw-icon-ribbon {
57
color: $theme-success-color;
68
}

src/resources/elements/ownerships/ownership-editor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<div class="form-group row">
4040
<label for="owner-defects" class="col-3 col-form-label">${'editor.defects'|t}</label>
4141
<div class="col-9">
42-
<select-picker items.bind="defects" value.two-way="model.defects | bitwiseToArray:defects.length"
42+
<select-picker items.bind="defects" value.bind="model.defects | bitwiseToArray:defects.length"
4343
config.bind="{ id: 'owner-defects', tabIndex: 104, name: 'defects', labelProperty: 'description', valueProperty: 'ordinal', filterSearch: false, multiple: true, caption: 'editor.defects-select' }">
4444
</select-picker>
4545
</div>
@@ -48,7 +48,7 @@
4848
<label for="owner-deceptions" class="col-3 col-form-label">${'editor.deceptions'|t}</label>
4949
<div class="col-9">
5050
<select-picker items.bind="deceptions"
51-
value.two-way="model.deception | bitwiseToArray:deceptions.length"
51+
value.bind="model.deception | bitwiseToArray:deceptions.length"
5252
config.bind="{ id: 'owner-deceptions', tabIndex: 107, name: 'deceptions', labelProperty: 'description', valueProperty: 'ordinal', filterSearch: false, multiple: true, caption: 'editor.deceptions-select' }">
5353
</select-picker>
5454
</div>

src/resources/elements/ownerships/ownership-notes.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@import "../../../theme/_semantic.scss";
22

33
ownership-notes {
4+
z-index: 10;
5+
46
.sw-icon-info {
57
color: $theme-link-color;
68
}

src/resources/elements/select-picker/select-picker.js

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import select2 from 'select2'; //eslint-disable-line no-unused-vars
2424
@customElement('select-picker')
2525
export class Select2Picker {
2626

27-
@bindable({defaultBindingMode : bindingMode.twoWay}) value;
27+
@bindable({defaultBindingMode: bindingMode.twoWay}) value;
2828
@bindable valueType = 'Number';
2929
@bindable valueProperty = 'id';
3030
@bindable labelProperty = 'name';
@@ -51,37 +51,37 @@ export class Select2Picker {
5151

5252
let options = {
5353
placeholder: caption,
54-
allowClear: true
55-
};
54+
allowClear: true
55+
};
5656

57-
if( typeof this.config.filterSearch !== 'undefined' && this.config.filterSearch === false ) {
57+
if (typeof this.config.filterSearch !== 'undefined' && this.config.filterSearch === false) {
5858
options.minimumResultsForSearch = Infinity;
5959
}
6060

61-
if( this.config.valueProperty ) {
61+
if (this.config.valueProperty) {
6262
this.valueProperty = this.config.valueProperty;
6363
}
64-
if( this.config.labelProperty ) {
64+
if (this.config.labelProperty) {
6565
this.labelProperty = this.config.labelProperty;
6666
}
67-
if( this.config.valueType ) {
67+
if (this.config.valueType) {
6868
this.valueType = this.config.valueType;
6969
}
70-
if( typeof this.config.allowClear !== 'undefined') {
70+
if (typeof this.config.allowClear !== 'undefined') {
7171
options.allowClear = this.config.allowClear;
7272
}
7373

74-
if( typeof this.config.noSearch !== 'undefined') {
74+
if (typeof this.config.noSearch !== 'undefined') {
7575
options.minimumResultsForSearch = Infinity;
7676
}
7777

78-
if( this.config.id ) {
78+
if (this.config.id) {
7979
this.id = this.config.id;
8080
} else {
81-
this.id = 'select-' + parseInt(Math.random() * 16384, 10);
81+
this.id = `select-${parseInt(Math.random() * 16384, 10)}`;
8282
}
8383

84-
if( this.config.multiple === true || this.multiple === 'true' ) {
84+
if (_.get(this, 'config.multiple') === true || _.get(this, 'multiple') === 'true') {
8585
options.multiple = true;
8686
this.multiple = true;
8787
}
@@ -96,7 +96,7 @@ export class Select2Picker {
9696
this.select2 = $select.select2(options);
9797

9898
let tabIndex = this.config.tabIndex;
99-
if( typeof tabIndex === 'undefined' ) {
99+
if (typeof tabIndex === 'undefined') {
100100
tabIndex = -1;
101101
}
102102

@@ -109,9 +109,9 @@ export class Select2Picker {
109109

110110
unbind() {
111111
let select = this.element.firstElementChild;
112-
if( select ) {
112+
if (select) {
113113
const $select = $(select);
114-
if( $select.data('select2')) { // depending on the destory state need to check whether it still thinks it is a select2
114+
if ($select.data('select2')) { // depending on the destroyed state need to check whether it still thinks it is a select2
115115
$select.select2('destroy');
116116
}
117117
}
@@ -122,28 +122,29 @@ export class Select2Picker {
122122
* @param e selection event.
123123
*/
124124
onSelect(e) {
125-
if( e.params && e.params.data ) {
126-
let data = e.params.data.id;
127-
if( this.multiple === true ) {
128-
let val = data;
129-
data = (this.value) ? _.clone(this.value) : this._getClearedValue();
130-
data.push(val);
131-
this.value = _.uniq(data); // prevent duplicates
132-
} else if ( this.valueType === 'Number') {
133-
this.value = data ? Number.parseInt(data) : this._getClearedValue();
125+
if (e.params && e.params.data) {
126+
let data = _.get(e, 'params.data.id');
127+
let originValue = this.value;
128+
if (this.multiple === true) {
129+
originValue.push(data);
130+
this.value = this._getClearedValue();
131+
} else if (this.valueType === 'Number') {
132+
originValue = data ? Number.parseInt(data) : this._getClearedValue();
134133
} else {
135-
this.value = data;
134+
originValue = data;
136135
}
137-
let changeEvent = EventHelper.changeEvent(data);
138-
this.element.dispatchEvent(changeEvent);
136+
_.defer(() => { // need to tickle the array
137+
this.value = originValue;
138+
this.element.dispatchEvent(EventHelper.changeEvent(this.value));
139+
});
139140
}
140141
}
141142

142143
_getClearedValue() {
143144
let value = '';
144-
if( this.multiple === true ) {
145+
if (this.multiple === true) {
145146
value = [];
146-
} else if ( this.valueType === 'Number') {
147+
} else if (this.valueType === 'Number') {
147148
value = -1;
148149
}
149150
return value;
@@ -157,15 +158,27 @@ export class Select2Picker {
157158
return item[this.labelProperty];
158159
}
159160

160-
onUnselect(e) {
161+
onUnselect() {
161162
_.defer(() => {
162163
$(this.select2).off('select2:opening');
163164
});
164165
}
165166

166167
onUnselecting(e) {
167-
this.value = this._getClearedValue();
168-
this.element.dispatchEvent(EventHelper.changeEvent(this.value));
168+
let removalValue = _.get(e, 'params.args.data');
169+
let origValue = this.value;
170+
if (removalValue) {
171+
if (this.multiple) {
172+
this.value = this._getClearedValue();
173+
_.pull(origValue, _.get(removalValue, 'id'));
174+
} else {
175+
origValue = this._getClearedValue();
176+
}
177+
}
178+
_.defer(() => {
179+
this.value = origValue;
180+
this.element.dispatchEvent(EventHelper.changeEvent(origValue));
181+
});
169182

170183
$(this.select2).on('select2:opening', e => {
171184
e.preventDefault();
@@ -198,11 +211,11 @@ export class Select2Picker {
198211
* Handle the conversion of the type from the modeled value to the String equivalence of the value used by select2
199212
*/
200213
_convertToInternal(val) {
201-
if( typeof val === 'undefined' || _.isNil(val)) {
214+
if (typeof val === 'undefined' || _.isNil(val)) {
202215
return undefined;
203216
}
204217
let retValue = val;
205-
switch(this.valueType) {
218+
switch (this.valueType) {
206219
case 'Number':
207220
retValue = val.toString();
208221
break;
@@ -215,9 +228,9 @@ export class Select2Picker {
215228
*/
216229
attached() {
217230
_.debounce(() => {
218-
if( this.items && this.items.length > 0 ) { // cached items are loaded
219-
this.valueChanged(this.value);
220-
}
231+
if (this.items && this.items.length > 0) { // cached items are loaded
232+
this.valueChanged(this.value);
233+
}
221234
}, 125)();
222235
}
223236

@@ -229,7 +242,7 @@ export class Select2Picker {
229242
* @param oldValue
230243
*/
231244
itemsChanged(newValue, oldValue) { //eslint-disable-line no-unused-vars
232-
if( newValue && newValue.length > 0 ) {
245+
if (newValue && newValue.length > 0) {
233246
_.defer(() => {
234247
this.valueChanged(this.value);
235248
});

src/resources/elements/select-picker/select-picker.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ select-picker {
7979
.select2-selection__clear {
8080
color: $theme-clear-color;
8181
margin-left: $theme-margin-thinner;
82-
margin-right: 0;
82+
margin-right: $theme-margin-thinner;
8383
margin-top: 0;
8484
transform: scale(1.5) translateY(0.5rem);
8585
}

0 commit comments

Comments
 (0)