Skip to content

Commit dc4bcfa

Browse files
authored
Merge pull request #47 from czeckd/rest-duplicate
Rest duplicate
2 parents 040341c + 9a85266 commit dc4bcfa

File tree

6 files changed

+4784
-45
lines changed

6 files changed

+4784
-45
lines changed

CONTRIBUTING.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Angular Dual-Listbox
2+
=========
3+
4+
### Contributions
5+
6+
Bug reports and feature requests are best directed to the project's
7+
[issues](https://github.com/czeckd/angular-dual-listbox/issues) page.
8+
9+
## Bugs
10+
Please make sure you're using the latest version of `angular-dual-listbox` before opening an issue.
11+
Providing a use case, sample app, code gist, or steps to reproduce the problem make it more likely a
12+
fix will be found.
13+
14+
Forking this project or using the
15+
[custom-dual-listbox](https://github.com/czeckd/custom-dual-listbox) seed project as a basis for
16+
reproducing the issue is a good starting place. Please include code or a link to your git repository
17+
in your issue.
18+
19+
## Feature requests
20+
21+
New features may be added depending on the impact on the core functionality of the project.
22+
Specialization or corner cases, however, are best handled by a fork.
23+
24+
25+
### Submissions
26+
27+
In order for pull requests to be accepted, they must include a sign-off in git (See [git-commit
28+
--signoff](https://git-scm.com/docs/git-commit)) certifying the contribution is your own work, are
29+
subitting under the project's original license, and agreeing to the [Developer Certificate of
30+
Origin](https://developercertificate.org/).
31+

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
Angular Dual-Listbox
44
=========
55

6-
The **angular-dual-listbox** is an Angular 2+ component that provides two lists controls side-by-side that allows items in one list to be moved to the other list via drag-and-drop and/or a button-based interface.
7-
The component supports multiple select options from the list, programatic setting of list sources, and layout with direction and button formatting.
6+
The **angular-dual-listbox** is an Angular 4+ component that provides two lists controls
7+
side-by-side that allows items in one list to be moved to the other list via drag-and-drop and/or a
8+
button-based interface. The component supports multiple select options from the list, programatic
9+
setting of list sources, and layout with direction and button formatting.
810

911
A [working demo](http://czeckd.github.io/angular-dual-listbox/demo/) shows the dual listbox in action.
1012

@@ -71,12 +73,6 @@ The drag-and-drop between multiple ``<dual-list>`` components may cause
7173
undesired moves. For the time being, if the component is used, then it
7274
is recommended only have one ``<dual-list>`` visable to the user at a time.
7375

74-
## Contributions
75-
76-
Contributions may be welcomed depending on impact on the core functionality of the project. In order for pull requests to be accepted, they must include a sign-off in git (See [git-commit
77-
--signoff](https://git-scm.com/docs/git-commit)) certifying the contribution is your own work, are subitting under the project's original license, and agreeing to the [Developer Certificate of
78-
Origin](https://developercertificate.org/).
79-
8076
## License
8177
MIT
8278

lib/dual-list.component.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export class DualListComponent implements DoCheck, OnChanges {
107107
}
108108

109109
buildAvailable(source:Array<any>) : boolean {
110-
let sourceChanges = this.sourceDiffer.diff(source);
110+
const sourceChanges = this.sourceDiffer.diff(source);
111111
if (sourceChanges) {
112112
sourceChanges.forEachRemovedItem((r:any) => {
113-
let idx = this.findItemIndex(this.available.list, r.item, this.key);
113+
const idx = this.findItemIndex(this.available.list, r.item, this.key);
114114
if (idx !== -1) {
115115
this.available.list.splice(idx, 1);
116116
}
@@ -135,10 +135,10 @@ export class DualListComponent implements DoCheck, OnChanges {
135135

136136
buildConfirmed(destination:Array<any>) : boolean {
137137
let moved = false;
138-
let destChanges = this.destinationDiffer.diff(destination);
138+
const destChanges = this.destinationDiffer.diff(destination);
139139
if (destChanges) {
140140
destChanges.forEachRemovedItem((r:any) => {
141-
let idx = this.findItemIndex(this.confirmed.list, r.item, this.key);
141+
const idx = this.findItemIndex(this.confirmed.list, r.item, this.key);
142142
if (idx !== -1) {
143143
if (!this.isItemSelected(this.confirmed.pick, this.confirmed.list[idx])) {
144144
this.selectItem(this.confirmed.pick, this.confirmed.list[idx]);
@@ -149,7 +149,7 @@ export class DualListComponent implements DoCheck, OnChanges {
149149
});
150150

151151
destChanges.forEachAddedItem((r:any) => {
152-
let idx = this.findItemIndex(this.available.list, r.item, this.key);
152+
const idx = this.findItemIndex(this.available.list, r.item, this.key);
153153
if (idx !== -1) {
154154
if (!this.isItemSelected(this.available.pick, this.available.list[idx])) {
155155
this.selectItem(this.available.pick, this.available.list[idx]);
@@ -227,9 +227,9 @@ export class DualListComponent implements DoCheck, OnChanges {
227227
this.dragLeave();
228228
this.dragEnd();
229229

230-
let id = event.dataTransfer.getData('text');
230+
const id = event.dataTransfer.getData('text');
231231

232-
let mv = list.list.filter( (e:any) => e._id === id );
232+
const mv = list.list.filter( (e:any) => e._id === id );
233233
if (mv.length > 0) {
234234
for (let i = 0, len = mv.length; i < len; i += 1) {
235235
list.pick.push( mv[i] );
@@ -248,7 +248,7 @@ export class DualListComponent implements DoCheck, OnChanges {
248248
// Clear removed items.
249249
let pos = this.destination.length;
250250
while ((pos -= 1) >= 0) {
251-
let mv = this.confirmed.list.filter( conf => {
251+
const mv = this.confirmed.list.filter( conf => {
252252
if (typeof this.destination[pos] === 'object') {
253253
return conf._id === this.destination[pos][this.key];
254254
} else {
@@ -325,7 +325,7 @@ export class DualListComponent implements DoCheck, OnChanges {
325325
}
326326

327327
private makeUnavailable(source:BasicList, item:any) {
328-
let idx = source.list.indexOf(item);
328+
const idx = source.list.indexOf(item);
329329
if (idx !== -1) {
330330
source.list.splice(idx, 1);
331331
}
@@ -344,7 +344,7 @@ export class DualListComponent implements DoCheck, OnChanges {
344344
// Is the pick still in list?
345345
let mv:Array<any> = [];
346346
if (item) {
347-
let idx = this.findItemIndex(source.pick, item);
347+
const idx = this.findItemIndex(source.pick, item);
348348
if (idx !== -1) {
349349
mv[0] = source.pick[idx];
350350
}
@@ -356,14 +356,9 @@ export class DualListComponent implements DoCheck, OnChanges {
356356

357357
// Should only ever be 1
358358
if (mv.length === 1) {
359-
// Move if item wasn't already moved by drag-and-drop.
360-
if (item && item._id === mv[0]._id) {
359+
// Add if not already in target.
360+
if (target.list.filter(trg => trg._id === mv[0]._id).length === 0) {
361361
target.list.push( mv[0] );
362-
} else {
363-
// see if it is already in target?
364-
if ( target.list.filter( trg => { return trg._id === mv[0]._id; }).length === 0) {
365-
target.list.push( mv[0] );
366-
}
367362
}
368363

369364
this.makeUnavailable(source, mv[0]);
@@ -389,15 +384,15 @@ export class DualListComponent implements DoCheck, OnChanges {
389384
}
390385

391386
isItemSelected(list:Array<any>, item:any) {
392-
if (list.filter( e => { return Object.is(e, item); }).length > 0) {
387+
if (list.filter(e => Object.is(e, item)).length > 0) {
393388
return true;
394389
}
395390
return false;
396391
}
397392

398393
shiftClick(event:MouseEvent, index:number, source:BasicList, item:any) {
399394
if (event.shiftKey && source.last && !Object.is(item, source.last)) {
400-
let idx = source.sift.indexOf(source.last);
395+
const idx = source.sift.indexOf(source.last);
401396
if (index > idx) {
402397
for (let i = (idx + 1); i < index; i += 1) {
403398
this.selectItem(source.pick, source.sift[i]);
@@ -412,13 +407,13 @@ export class DualListComponent implements DoCheck, OnChanges {
412407
}
413408

414409
selectItem(list:Array<any>, item:any) {
415-
let pk = list.filter( (e:any) => {
410+
const pk = list.filter( (e:any) => {
416411
return Object.is(e, item);
417412
});
418413
if (pk.length > 0) {
419414
// Already in list, so deselect.
420415
for (let i = 0, len = pk.length; i < len; i += 1) {
421-
let idx = list.indexOf(pk[i]);
416+
const idx = list.indexOf(pk[i]);
422417
if (idx !== -1) {
423418
list.splice(idx, 1);
424419
}
@@ -468,7 +463,7 @@ export class DualListComponent implements DoCheck, OnChanges {
468463

469464
onFilter(source:BasicList) {
470465
if (source.picker.length > 0) {
471-
let filtered = source.list.filter( (item:any) => {
466+
const filtered = source.list.filter( (item:any) => {
472467
if (Object.prototype.toString.call(item) === '[object Object]') {
473468
if (item._name !== undefined) {
474469
return item._name.toLowerCase().indexOf(source.picker.toLowerCase()) !== -1;
@@ -530,13 +525,13 @@ export class DualListComponent implements DoCheck, OnChanges {
530525

531526
} else {
532527
// Complex, some action needs to be performed
533-
let parts = this.display[i].split('.');
528+
const parts = this.display[i].split('.');
534529

535-
let s = item[parts[0]];
530+
const s = item[parts[0]];
536531
if (s) {
537532
// Use brute force
538533
if (parts[1].indexOf('substring') !== -1) {
539-
let nums = (parts[1].substring(parts[1].indexOf('(') + 1, parts[1].indexOf(')'))).split(',');
534+
const nums = (parts[1].substring(parts[1].indexOf('(') + 1, parts[1].indexOf(')'))).split(',');
540535

541536
switch (nums.length) {
542537
case 1:

0 commit comments

Comments
 (0)