@kris701/ez-ui 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,161 +1,161 @@
1
- import { CommonModule } from "@angular/common";
2
- import { Component, Input, signal } from "@angular/core";
3
- import { FormsModule } from "@angular/forms";
4
- import { TuiButton, TuiDropdown, TuiInput } from "@taiga-ui/core";
5
- import { TuiBadgeNotification, TuiBadgedContent, TuiButtonSelect, TuiDataListWrapper, TuiStringifyContentPipe } from "@taiga-ui/kit";
6
- import { FloatTable } from "../floattable";
7
- import { FloatTableFilter } from "../models/FloatTableFilter";
8
-
9
- @Component({
10
- selector: 'tuiThTextFilter',
11
- imports: [CommonModule, FormsModule, TuiDropdown, TuiDataListWrapper, TuiButton, TuiButtonSelect, TuiStringifyContentPipe, TuiBadgeNotification, TuiBadgedContent, TuiInput],
12
- template: `
13
- @if(tuiThTextFilter){
14
- <tui-badged-content>
15
- @if(filterApplied()){
16
- <tui-badge-notification
17
- size="s"
18
- tuiSlot="top"
19
- >
20
- 1
21
- </tui-badge-notification>
22
- }
23
- <button
24
- tuiButton size="s"
25
- iconStart="funnel"
26
- appearance="flat-grayscale"
27
- style="opacity:0.72"
28
- [tuiDropdown]="filterPop"
29
- [(tuiDropdownOpen)]="filterVisible"
30
- (click)="filterVisible.set(true)"
31
- ></button>
32
- </tui-badged-content>
33
-
34
- <ng-template #filterPop>
35
- <div class="flex flex-col gap-2 p-4" style="min-width:20rem">
36
- <button
37
- appearance="outline-grayscale"
38
- size="s"
39
- tuiButton
40
- tuiButtonSelect
41
- [(ngModel)]="filterType"
42
- >
43
- {{ filterType.label }}
44
- <tui-data-list-wrapper
45
- *tuiDropdown
46
- [itemContent]="stringify | tuiStringifyContent"
47
- [items]="filterTypes"
48
- />
49
- </button>
50
-
51
- <tui-textfield tuiTextfieldSize="s" (keydown.enter)="applyFilter(filterType.expression)">
52
- <input tuiInput [(ngModel)]="value"/>
53
- </tui-textfield>
54
- <button
55
- tuiButton size="s"
56
- iconStart="funnel"
57
- tuiButton
58
- (click)="applyFilter(filterType.expression)"
59
- >
60
- Apply
61
- </button>
62
-
63
- @if(filterApplied()){
64
- <button
65
- tuiButton size="s"
66
- iconStart="circle-x"
67
- tuiButton
68
- (click)="clearFilter()"
69
- >
70
- Clear
71
- </button>
72
- }
73
- </div>
74
- </ng-template>
75
- }
76
- `
77
- })
78
- export class TableTextFilter {
79
- @Input() tuiThTextFilter!: string;
80
-
81
- filterApplied = signal<boolean>(false);
82
- filterVisible = signal<boolean>(false);
83
-
84
- table : FloatTable;
85
-
86
- value : string = '';
87
- filterType : any;
88
- filterTypes : any[];
89
-
90
- protected readonly stringify = (item: any): string => `${item.label}`;
91
-
92
- constructor(table : FloatTable){
93
- this.table = table;
94
-
95
- this.filterTypes = [
96
- {
97
- label: 'Contains',
98
- expression: 'str;con'
99
- },
100
- {
101
- label: 'Not Contains',
102
- expression: 'str;ncon'
103
- },
104
- {
105
- label: 'Starts With',
106
- expression: 'str;sta'
107
- },
108
- {
109
- label: 'Ends With',
110
- expression: 'str;end'
111
- }
112
- ];
113
- this.filterType = this.filterTypes[0];
114
-
115
- this.table.onPresetChange.subscribe(x => {
116
- if (!x)
117
- {
118
- this.filterType = this.filterTypes[0];
119
- this.value = "";
120
- this.filterApplied.set(false);
121
- return;
122
- }
123
- var filter = x.filters.find(x => x.column == this.tuiThTextFilter);
124
- if (!filter)
125
- {
126
- this.filterType = this.filterTypes[0];
127
- this.value = "";
128
- this.filterApplied.set(false);
129
- return;
130
- }
131
- var type = this.filterTypes.find(x => x.expression == filter!.expression);
132
- if (!type)
133
- {
134
- this.filterType = this.filterTypes[0];
135
- this.value = "";
136
- this.filterApplied.set(false);
137
- return;
138
- }
139
-
140
- this.filterType = type;
141
- this.value = filter.value;
142
- this.filterApplied.set(true);
143
- })
144
- }
145
-
146
- applyFilter(expression : string){
147
- this.table.setFilter({
148
- column: this.tuiThTextFilter,
149
- value: this.value,
150
- expression: expression,
151
- } as FloatTableFilter);
152
- this.filterVisible.set(false);
153
- this.filterApplied.set(true);
154
- }
155
-
156
- clearFilter(){
157
- this.table.clearFilter(this.tuiThTextFilter);
158
- this.filterVisible.set(false);
159
- this.filterApplied.set(false);
160
- }
161
- }
1
+ import { CommonModule } from "@angular/common";
2
+ import { Component, Input, signal } from "@angular/core";
3
+ import { FormsModule } from "@angular/forms";
4
+ import { TuiButton, TuiDropdown, TuiInput } from "@taiga-ui/core";
5
+ import { TuiBadgeNotification, TuiBadgedContent, TuiButtonSelect, TuiDataListWrapper, TuiStringifyContentPipe } from "@taiga-ui/kit";
6
+ import { FloatTable } from "../floattable";
7
+ import { FloatTableFilter } from "../models/FloatTableFilter";
8
+
9
+ @Component({
10
+ selector: 'tuiThTextFilter',
11
+ imports: [CommonModule, FormsModule, TuiDropdown, TuiDataListWrapper, TuiButton, TuiButtonSelect, TuiStringifyContentPipe, TuiBadgeNotification, TuiBadgedContent, TuiInput],
12
+ template: `
13
+ @if(tuiThTextFilter){
14
+ <tui-badged-content>
15
+ @if(filterApplied()){
16
+ <tui-badge-notification
17
+ size="s"
18
+ tuiSlot="top"
19
+ >
20
+ 1
21
+ </tui-badge-notification>
22
+ }
23
+ <button
24
+ tuiButton size="s"
25
+ iconStart="funnel"
26
+ appearance="flat-grayscale"
27
+ style="opacity:0.72"
28
+ [tuiDropdown]="filterPop"
29
+ [(tuiDropdownOpen)]="filterVisible"
30
+ (click)="filterVisible.set(true)"
31
+ ></button>
32
+ </tui-badged-content>
33
+
34
+ <ng-template #filterPop>
35
+ <div class="flex flex-col gap-2 p-4" style="min-width:20rem">
36
+ <button
37
+ appearance="outline-grayscale"
38
+ size="s"
39
+ tuiButton
40
+ tuiButtonSelect
41
+ [(ngModel)]="filterType"
42
+ >
43
+ {{ filterType.label }}
44
+ <tui-data-list-wrapper
45
+ *tuiDropdown
46
+ [itemContent]="stringify | tuiStringifyContent"
47
+ [items]="filterTypes"
48
+ />
49
+ </button>
50
+
51
+ <tui-textfield tuiTextfieldSize="s" (keydown.enter)="applyFilter(filterType.expression)">
52
+ <input tuiInput [(ngModel)]="value"/>
53
+ </tui-textfield>
54
+ <button
55
+ tuiButton size="s"
56
+ iconStart="funnel"
57
+ tuiButton
58
+ (click)="applyFilter(filterType.expression)"
59
+ >
60
+ Apply
61
+ </button>
62
+
63
+ @if(filterApplied()){
64
+ <button
65
+ tuiButton size="s"
66
+ iconStart="circle-x"
67
+ tuiButton
68
+ (click)="clearFilter()"
69
+ >
70
+ Clear
71
+ </button>
72
+ }
73
+ </div>
74
+ </ng-template>
75
+ }
76
+ `
77
+ })
78
+ export class TableTextFilter {
79
+ @Input() tuiThTextFilter!: string;
80
+
81
+ filterApplied = signal<boolean>(false);
82
+ filterVisible = signal<boolean>(false);
83
+
84
+ table : FloatTable;
85
+
86
+ value : string = '';
87
+ filterType : any;
88
+ filterTypes : any[];
89
+
90
+ protected readonly stringify = (item: any): string => `${item.label}`;
91
+
92
+ constructor(table : FloatTable){
93
+ this.table = table;
94
+
95
+ this.filterTypes = [
96
+ {
97
+ label: 'Contains',
98
+ expression: 'str;con'
99
+ },
100
+ {
101
+ label: 'Not Contains',
102
+ expression: 'str;ncon'
103
+ },
104
+ {
105
+ label: 'Starts With',
106
+ expression: 'str;sta'
107
+ },
108
+ {
109
+ label: 'Ends With',
110
+ expression: 'str;end'
111
+ }
112
+ ];
113
+ this.filterType = this.filterTypes[0];
114
+
115
+ this.table.onPresetChange.subscribe(x => {
116
+ if (!x)
117
+ {
118
+ this.filterType = this.filterTypes[0];
119
+ this.value = "";
120
+ this.filterApplied.set(false);
121
+ return;
122
+ }
123
+ var filter = x.filters.find(x => x.column == this.tuiThTextFilter);
124
+ if (!filter)
125
+ {
126
+ this.filterType = this.filterTypes[0];
127
+ this.value = "";
128
+ this.filterApplied.set(false);
129
+ return;
130
+ }
131
+ var type = this.filterTypes.find(x => x.expression == filter!.expression);
132
+ if (!type)
133
+ {
134
+ this.filterType = this.filterTypes[0];
135
+ this.value = "";
136
+ this.filterApplied.set(false);
137
+ return;
138
+ }
139
+
140
+ this.filterType = type;
141
+ this.value = filter.value;
142
+ this.filterApplied.set(true);
143
+ })
144
+ }
145
+
146
+ applyFilter(expression : string){
147
+ this.table.setFilter({
148
+ column: this.tuiThTextFilter,
149
+ value: this.value,
150
+ expression: expression,
151
+ } as FloatTableFilter);
152
+ this.filterVisible.set(false);
153
+ this.filterApplied.set(true);
154
+ }
155
+
156
+ clearFilter(){
157
+ this.table.clearFilter(this.tuiThTextFilter);
158
+ this.filterVisible.set(false);
159
+ this.filterApplied.set(false);
160
+ }
161
+ }