Skip to content

Commit 40f8fda

Browse files
authored
Merge pull request #51 from czeckd/multiple-dual-lists
Multiple dual lists
2 parents dc4bcfa + da724be commit 40f8fda

File tree

5 files changed

+86
-85
lines changed

5 files changed

+86
-85
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { AngularDualListBoxModule } from 'angular-dual-listbox';
2828
})
2929
export class AppModule {}
3030
```
31+
See also the [basic-dual-list-demo](https://github.com/czeckd/basic-dual-listbox-demo) for a sample project using this module.
32+
3133

3234
## Usage
3335
Basic usage is:
@@ -56,7 +58,7 @@ The html template packaged with this component is based on Bootstap 3; however i
5658

5759
```typescript
5860
import { Component } from '@angular/core';
59-
import { DualListComponent } from 'angular-dual-listbox/index';
61+
import { DualListComponent } from 'angular-dual-listbox/dual-list.component';
6062

6163
@Component({
6264
selector: 'custom-dual-list',
@@ -66,12 +68,10 @@ import { DualListComponent } from 'angular-dual-listbox/index';
6668
export class CustomDualListComponent extends DualListComponent {
6769
}
6870
```
69-
See [`dual-list.component.html`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.html) and [`dual-list.component.css`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.css) for template and style guidance.
70-
71-
## Known issue
72-
The drag-and-drop between multiple ``<dual-list>`` components may cause
73-
undesired moves. For the time being, if the component is used, then it
74-
is recommended only have one ``<dual-list>`` visable to the user at a time.
71+
See [`dual-list.component.html`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.html) and
72+
[`dual-list.component.css`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.css) for template and style guidance.
73+
There is also an Angular-CLI seed project, [custom-dual-listbox](https://github.com/czeckd/custom-dual-listbox), available with an example of a
74+
customized view and extended functionality.
7575

7676
## License
7777
MIT

demo/systemjs.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function(global) {
22

3-
var ngVer = '@4.0.0';
3+
var ngVer = '@4.4.4';
44

55
// map tells the System loader where to look for things
66
var map = {

lib/dual-list.component.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { BasicList } from './basic-list';
55

66
export type compareFunction = (a:any, b:any) => number;
77

8+
var nextId = 0;
9+
810
@Component({
911
selector: 'dual-list',
1012
styleUrls: [ 'lib/dual-list.component.css' ],
@@ -20,6 +22,7 @@ export class DualListComponent implements DoCheck, OnChanges {
2022

2123
static DEFAULT_FORMAT = { add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: DualListComponent.LTR };
2224

25+
@Input() id = `dual-list-${nextId++}`;
2326
@Input() key = '_id';
2427
@Input() display = '_name';
2528
@Input() height = '100px';
@@ -206,13 +209,17 @@ export class DualListComponent implements DoCheck, OnChanges {
206209
this.selectItem(list.pick, item);
207210
}
208211
list.dragStart = true;
209-
event.dataTransfer.setData('text', item['_id']);
212+
213+
// Set a custom type to be this dual-list's id.
214+
event.dataTransfer.setData(this.id, item['_id']);
210215
}
211216

212217
allowDrop(event:DragEvent, list:BasicList) {
213-
event.preventDefault();
214-
if (!list.dragStart) {
215-
list.dragOver = true;
218+
if (event.dataTransfer.types.length && (event.dataTransfer.types[0] === this.id)) {
219+
event.preventDefault();
220+
if (!list.dragStart) {
221+
list.dragOver = true;
222+
}
216223
}
217224
return false;
218225
}
@@ -223,23 +230,17 @@ export class DualListComponent implements DoCheck, OnChanges {
223230
}
224231

225232
drop(event:DragEvent, list:BasicList) {
226-
event.preventDefault();
227-
this.dragLeave();
228-
this.dragEnd();
229-
230-
const id = event.dataTransfer.getData('text');
233+
if (event.dataTransfer.types.length && (event.dataTransfer.types[0] === this.id)) {
234+
event.preventDefault();
235+
this.dragLeave();
236+
this.dragEnd();
231237

232-
const mv = list.list.filter( (e:any) => e._id === id );
233-
if (mv.length > 0) {
234-
for (let i = 0, len = mv.length; i < len; i += 1) {
235-
list.pick.push( mv[i] );
238+
if (list === this.available) {
239+
this.moveItem(this.available, this.confirmed);
240+
} else {
241+
this.moveItem(this.confirmed, this.available);
236242
}
237243
}
238-
if (list === this.available) {
239-
this.moveItem(this.available, this.confirmed);
240-
} else {
241-
this.moveItem(this.confirmed, this.available);
242-
}
243244
}
244245

245246
private trueUp() {

package-lock.json

Lines changed: 49 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-dual-listbox",
33
"description": "Angular 4+ component for a dual listbox control.",
4-
"version": "4.3.2",
4+
"version": "4.4.0",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/czeckd/angular-dual-listbox.git"
@@ -32,26 +32,26 @@
3232
"@angular/forms": ">=4.0.0"
3333
},
3434
"devDependencies": {
35-
"@angular/common": "^4.3.6",
36-
"@angular/compiler": "^4.3.6",
37-
"@angular/compiler-cli": "^4.3.6",
38-
"@angular/core": "^4.3.6",
39-
"@angular/forms": "^4.3.6",
40-
"@angular/platform-browser": "^4.3.6",
41-
"@angular/platform-browser-dynamic": "^4.3.6",
35+
"@angular/common": "^4.4.4",
36+
"@angular/compiler": "^4.4.4",
37+
"@angular/compiler-cli": "^4.4.4",
38+
"@angular/core": "^4.4.4",
39+
"@angular/forms": "^4.4.4",
40+
"@angular/platform-browser": "^4.4.4",
41+
"@angular/platform-browser-dynamic": "^4.4.4",
4242
"@types/core-js": "^0.9.43",
4343
"@types/node": "^6.0.88",
4444
"bootstrap": "^3.3.7",
4545
"concurrently": "^2.2.0",
4646
"core-js": "^2.5.1",
4747
"lite-server": "^2.2.2",
48-
"rimraf": "^2.6.1",
48+
"rimraf": "^2.6.2",
4949
"rollup": "^0.41.6",
5050
"rxjs": "^5.2.0",
5151
"systemjs": "0.19.47",
5252
"ts-node": "^3.0.2",
5353
"tslint": "~4.5.0",
5454
"typescript": "~2.2.0",
55-
"zone.js": "^0.8.17"
55+
"zone.js": "^0.8.18"
5656
}
5757
}

0 commit comments

Comments
 (0)