-
Notifications
You must be signed in to change notification settings - Fork 671
Expand file tree
/
Copy pathapp.component.ts
More file actions
115 lines (90 loc) · 3.39 KB
/
Copy pathapp.component.ts
File metadata and controls
115 lines (90 loc) · 3.39 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
Component, Pipe, PipeTransform, enableProdMode, ViewChild, provideZoneChangeDetection, ChangeDetectionStrategy,
} from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { DxListModule, DxCheckBoxModule } from 'devextreme-angular';
import { DxTreeViewModule, DxTreeViewComponent, DxTreeViewTypes } from 'devextreme-angular/ui/tree-view';
import { DxSelectBoxModule, DxSelectBoxTypes } from 'devextreme-angular/ui/select-box';
import { Service, Employee } from './app.service';
@Pipe({ name: 'title', standalone: true })
export class TitlePipe implements PipeTransform {
transform(item: Record<string, unknown>): string {
return item.text + (item.price ? ` ($${item.price})` : '');
}
}
if (!/localhost/.test(document.location.host)) {
enableProdMode();
}
let modulePrefix = '';
// @ts-ignore
if (window && window.config?.packageConfigPaths) {
modulePrefix = '/app';
}
@Component({
selector: 'demo-app',
templateUrl: `.${modulePrefix}/app.component.html`,
styleUrls: [`.${modulePrefix}/app.component.css`],
providers: [Service],
changeDetection: ChangeDetectionStrategy.Eager,
preserveWhitespaces: true,
imports: [
DxTreeViewModule,
DxListModule,
DxCheckBoxModule,
DxSelectBoxModule,
TitlePipe,
],
})
export class AppComponent {
@ViewChild(DxTreeViewComponent, { static: false }) treeView: DxTreeViewComponent<Employee>;
employees: Employee[];
selectedEmployees: Employee[] = [];
checkboxVisibilityOptions: DxTreeViewTypes.TreeViewCheckBoxMode[] = ['normal', 'selectAll', 'none'];
checkboxVisibility = this.checkboxVisibilityOptions[0];
selectionModes: DxTreeViewTypes.SingleOrMultiple[] = ['multiple', 'single'];
selectionMode = this.selectionModes[0];
disabledNodeSelectionModes: DxTreeViewTypes.DisabledNodeSelectionMode[] = ['never', 'recursiveAndAll'];
disabledNodeSelectionMode = this.disabledNodeSelectionModes[0];
recursiveSelection = true;
selectOnClick = false;
isRecursiveDisabled = false;
isSelectionModeDisabled = false;
constructor(service: Service) {
this.employees = service.getEmployees();
}
treeViewSelectionChanged(e: DxTreeViewTypes.SelectionChangedEvent<Employee>) {
this.syncSelection(e.component);
}
treeViewContentReady(e: DxTreeViewTypes.ContentReadyEvent<Employee>) {
this.syncSelection(e.component);
}
syncSelection(treeView: DxTreeViewComponent<Employee>['instance']) {
const selectedEmployees = treeView.getSelectedNodes()
.map((node) => node.itemData);
this.selectedEmployees = selectedEmployees;
}
checkboxVisibilityValueChanged(e: DxSelectBoxTypes.ValueChangedEvent) {
this.checkboxVisibility = e.value;
this.isSelectionModeDisabled = e.value === 'selectAll';
if (e.value === 'selectAll') {
this.selectionMode = 'multiple';
this.isRecursiveDisabled = false;
}
}
selectionModeValueChanged(e: DxSelectBoxTypes.ValueChangedEvent) {
this.selectionMode = e.value;
this.isRecursiveDisabled = e.value === 'single';
if (e.value === 'single') {
this.recursiveSelection = false;
this.treeView.instance.unselectAll();
}
}
disabledNodeSelectionModeValueChanged(e: DxSelectBoxTypes.ValueChangedEvent) {
this.disabledNodeSelectionMode = e.value;
}
}
bootstrapApplication(AppComponent, {
providers: [
provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }),
],
});