k15t-aui-ng2
Version:
aui-ng2 is a set of angular 2 components, directives and services to simplify the integration with Atlassian products based on AUI/ADG. The library is still under development and is considered in an experimental state. So be aware that things will change
28 lines (21 loc) • 797 B
text/typescript
import {SelectionStrategy} from './selection-strategy';
export class MultiSelectionStrategy implements SelectionStrategy {
public selection: any[];
private idGetter: (item: any) => string;
private labelGetter: (item: any) => string;
constructor(idGetter, labelGetter, selection) {
this.idGetter = idGetter;
this.labelGetter = labelGetter;
this.selection = selection;
}
selectItem(item): void {
this.selection.push(item);
}
deSelectItem(id): void {
this.selection = this.selection.filter((other) => this.idGetter(other) !== id);
}
getSelection(): [string, any] {
let value = this.selection.map((item) => ({id: this.idGetter(item), text: this.labelGetter(item)}));
return ['data', value];
}
}