aboutsummaryrefslogtreecommitdiffstats
path: root/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/select.service.ts
blob: ba6f579ea01247ef26f71524e159d059107f6abc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* tslint:disable:array-type member-access variable-name */
import {Injectable} from '@angular/core';

@Injectable()
export class SelectService {
  selection: string[] = [];

  selected(indexName: string): boolean {
	if (this.selection === undefined || this.selection === []) {
		return null;
	}

	for (let item of this.selection) {
		if (item === indexName) {
		return true;
		}
	}
	return false;
  }

  handleSingleSelect(optionIndex: string) {
	this.selection = [];
	this.selection.push(optionIndex);
	return this.selection;
  }

  handleMutipleSelect(optionIndex: string) {
	if (this.selected(optionIndex)) {
		this.selection = this.handleSecondSelect(optionIndex);
	} else {
		this.selection.push(optionIndex);
	}
	return this.selection;
  }

  handleSecondSelect(optionIndex: string) {
	let selectedOption = [];
	for (let option of this.selection) {
		if (option !== optionIndex) {
		selectedOption.push(option);
		}
	}
	return selectedOption;
  }

  select(optionIndex: string, isMutiple: boolean): string[] {
	if (!isMutiple) {
		return this.handleSingleSelect(optionIndex);
	} else {
		return this.handleMutipleSelect(optionIndex);
	}
  }

  deselect() {
	this.selection = [];
  }
}