@aaamb/ngx-design-system 1.3.4 → 1.3.6
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.
- package/.editorconfig +17 -0
- package/.nvmrc +1 -0
- package/.postcssrc.json +5 -0
- package/.storybook/main.ts +20 -0
- package/.storybook/preview.ts +23 -0
- package/.storybook/storybook.css +1 -0
- package/.storybook/tsconfig.json +19 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +20 -0
- package/.vscode/tasks.json +42 -0
- package/CHANGELOG.md +10 -0
- package/LOCAL_DEVELOPMENT.md +129 -0
- package/angular.json +74 -0
- package/bitbucket-pipelines.yml +41 -0
- package/iac/bin/app.ts +42 -0
- package/iac/cdk.json +82 -0
- package/iac/lib/config/environments.ts +19 -0
- package/iac/lib/config/types.ts +13 -0
- package/iac/lib/stacks/certificate-stack.ts +34 -0
- package/iac/lib/stacks/frontend-stack.ts +120 -0
- package/iac/lib/stacks/index.ts +2 -0
- package/iac/package-lock.json +726 -0
- package/iac/package.json +25 -0
- package/iac/tsconfig.json +24 -0
- package/ng-package.json +8 -0
- package/package.json +58 -14
- package/src/components/button/button-green.stories.ts +101 -0
- package/src/components/button/button-text.stories.ts +105 -0
- package/src/components/button/button-white.stories.ts +105 -0
- package/src/components/button/button.component.stories.ts +91 -0
- package/src/components/button/button.component.ts +93 -0
- package/src/components/checkbox/checkbox.component.html +30 -0
- package/src/components/checkbox/checkbox.component.stories.ts +183 -0
- package/src/components/checkbox/checkbox.component.ts +211 -0
- package/src/components/datepicker-selector/datepicker-selector.component.html +103 -0
- package/src/components/datepicker-selector/datepicker-selector.component.stories.ts +69 -0
- package/src/components/datepicker-selector/datepicker-selector.component.ts +287 -0
- package/src/components/error-message/error-message.component.html +3 -0
- package/src/components/error-message/error-message.component.ts +13 -0
- package/src/components/filter-button/filter-button.component.html +286 -0
- package/src/components/filter-button/filter-button.component.stories.ts +123 -0
- package/src/components/filter-button/filter-button.component.ts +582 -0
- package/src/components/icon/icon.component.ts +20 -0
- package/src/components/icon/icon.html +1333 -0
- package/src/components/icon/icon.stories.ts +49 -0
- package/src/components/icon/icons-list.stories.ts +42 -0
- package/src/components/input/input.component.stories.ts +101 -0
- package/src/components/input/input.component.ts +317 -0
- package/src/components/input/input.html +160 -0
- package/src/components/input-datepicker/input-datepicker.component.ts +356 -0
- package/src/components/input-datepicker/input-datepicker.html +69 -0
- package/src/components/input-datepicker/input-datepicker.stories.ts +99 -0
- package/src/components/input-rangepicker/input-rangepicker.component.ts +365 -0
- package/src/components/input-rangepicker/input-rangepicker.html +54 -0
- package/src/components/input-rangepicker/input-rangepicker.stories.ts +88 -0
- package/src/components/input-weekpicker/input-weekpicker.component.ts +417 -0
- package/src/components/input-weekpicker/input-weekpicker.html +54 -0
- package/src/components/input-weekpicker/input-weekpicker.stories.ts +103 -0
- package/src/components/label/label.component.html +20 -0
- package/src/components/label/label.component.ts +22 -0
- package/src/components/modals/delicate-confirmation-modal/delicate-confirmation-modal.component.html +32 -0
- package/src/components/modals/delicate-confirmation-modal/delicate-confirmation-modal.component.stories.ts +57 -0
- package/src/components/modals/delicate-confirmation-modal/delicate-confirmation-modal.component.ts +48 -0
- package/src/components/modals/feedback-modal/feedback-modal.component.html +118 -0
- package/src/components/modals/feedback-modal/feedback-modal.component.stories.ts +93 -0
- package/src/components/modals/feedback-modal/feedback-modal.component.ts +187 -0
- package/src/components/modals/help-modal/help-modal.component.html +32 -0
- package/src/components/modals/help-modal/help-modal.component.stories.ts +76 -0
- package/src/components/modals/help-modal/help-modal.component.ts +54 -0
- package/src/components/modals/information-modal/information-modal.component.html +24 -0
- package/src/components/modals/information-modal/information-modal.component.stories.ts +62 -0
- package/src/components/modals/information-modal/information-modal.component.ts +35 -0
- package/src/components/modals/main-modal/main-modal.component.html +85 -0
- package/src/components/modals/main-modal/main-modal.component.stories.ts +127 -0
- package/src/components/modals/main-modal/main-modal.component.ts +85 -0
- package/src/components/modals/notification-modal/notification-modal.component.html +22 -0
- package/src/components/modals/notification-modal/notification-modal.component.stories.ts +59 -0
- package/src/components/modals/notification-modal/notification-modal.component.ts +37 -0
- package/src/components/selectors/multiple-selector/multiple-selector.component.html +51 -0
- package/src/components/selectors/multiple-selector/multiple-selector.component.stories.ts +306 -0
- package/src/components/selectors/multiple-selector/multiple-selector.component.ts +308 -0
- package/src/components/selectors/single-selector/single-selector.component.html +46 -0
- package/src/components/selectors/single-selector/single-selector.component.stories.ts +294 -0
- package/src/components/selectors/single-selector/single-selector.component.ts +239 -0
- package/src/components/side-nav/side-nav.component.stories.ts +157 -0
- package/src/components/side-nav/side-nav.component.ts +306 -0
- package/src/components/snackbar/snackbar.component.ts +150 -0
- package/src/components/snackbar/snackbar.html +21 -0
- package/src/components/snackbar/snackbar.stories.ts +51 -0
- package/src/components/state/state.component.ts +30 -0
- package/src/components/state/state.html +13 -0
- package/src/components/state/state.stories.ts +74 -0
- package/src/components/table/table.component.html +441 -0
- package/src/components/table/table.component.scss +28 -0
- package/src/components/table/table.component.stories.ts +655 -0
- package/src/components/table/table.component.ts +475 -0
- package/src/components/tabs/tabs.component.stories.ts +114 -0
- package/src/components/tabs/tabs.component.ts +69 -0
- package/src/core/types.ts +486 -0
- package/src/public-api.ts +23 -0
- package/styles/datepicker.css +41 -0
- package/tsconfig.json +37 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +13 -0
- package/fesm2022/aaamb-ngx-design-system.mjs +0 -4024
- package/fesm2022/aaamb-ngx-design-system.mjs.map +0 -1
- package/styles/compiled.css +0 -2
- package/types/aaamb-ngx-design-system.d.ts +0 -1132
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import { AdsFilterButtonOption } from '../../core/types';
|
|
3
|
+
import { FilterButtonComponent } from './filter-button.component';
|
|
4
|
+
|
|
5
|
+
const columnOptions: AdsFilterButtonOption[] = [
|
|
6
|
+
{ label: 'Owner Name', value: 'ownerName', valueType: 'text' },
|
|
7
|
+
{ label: 'Priority Score', value: 'priorityScore', valueType: 'number' },
|
|
8
|
+
{ label: 'Created At', value: 'createdAt', valueType: 'date' },
|
|
9
|
+
{ label: 'Has Insurance', value: 'hasInsurance', valueType: 'boolean' },
|
|
10
|
+
{ label: 'Status', value: 'status', valueType: 'status' },
|
|
11
|
+
{ label: 'Code Type', value: 'codeType', valueType: 'codes' },
|
|
12
|
+
{
|
|
13
|
+
label: 'Facility',
|
|
14
|
+
value: 'facility',
|
|
15
|
+
valueType: 'custom',
|
|
16
|
+
customOptions: [
|
|
17
|
+
{ label: 'North Clinic', value: 'north_clinic' },
|
|
18
|
+
{ label: 'Downtown Medical', value: 'downtown_medical' },
|
|
19
|
+
{ label: 'West Lab', value: 'west_lab' },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const sortableColumnOptions: AdsFilterButtonOption[] = [
|
|
25
|
+
{ label: 'Owner Name', value: 'ownerName' },
|
|
26
|
+
{ label: 'Priority Score', value: 'priorityScore' },
|
|
27
|
+
{ label: 'Created At', value: 'createdAt' },
|
|
28
|
+
{ label: 'Status', value: 'status' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const meta: Meta<FilterButtonComponent> = {
|
|
32
|
+
title: 'Components/FilterButton',
|
|
33
|
+
component: FilterButtonComponent,
|
|
34
|
+
args: {
|
|
35
|
+
buttonLabel: 'Filter',
|
|
36
|
+
buttonIcon: 'tune',
|
|
37
|
+
showButtonIcon: true,
|
|
38
|
+
buttonVariant: 'primary',
|
|
39
|
+
buttonColor: 'white',
|
|
40
|
+
buttonOpenVariant: 'primary',
|
|
41
|
+
buttonOpenColor: 'green',
|
|
42
|
+
buttonDisabled: false,
|
|
43
|
+
columnOptions,
|
|
44
|
+
columnPlaceholder: 'Select a filter field',
|
|
45
|
+
valuePlaceholder: 'Value',
|
|
46
|
+
noFiltersText: 'No filters applied',
|
|
47
|
+
sortableColumnOptions,
|
|
48
|
+
noSortText: 'No sorts applied',
|
|
49
|
+
},
|
|
50
|
+
argTypes: {
|
|
51
|
+
buttonLabel: { control: 'text' },
|
|
52
|
+
buttonIcon: { control: 'text' },
|
|
53
|
+
showButtonIcon: { control: 'boolean' },
|
|
54
|
+
buttonVariant: { control: 'select', options: ['primary', 'secondary'] },
|
|
55
|
+
buttonColor: { control: 'select', options: ['green', 'white', 'text'] },
|
|
56
|
+
buttonOpenVariant: { control: 'select', options: ['primary', 'secondary'] },
|
|
57
|
+
buttonOpenColor: { control: 'select', options: ['green', 'white', 'text'] },
|
|
58
|
+
buttonDisabled: { control: 'boolean' },
|
|
59
|
+
columnOptions: { control: 'object' },
|
|
60
|
+
columnPlaceholder: { control: 'text' },
|
|
61
|
+
valuePlaceholder: { control: 'text' },
|
|
62
|
+
noFiltersText: { control: 'text' },
|
|
63
|
+
sortableColumnOptions: { control: 'object' },
|
|
64
|
+
noSortText: { control: 'text' },
|
|
65
|
+
},
|
|
66
|
+
render: (args) => {
|
|
67
|
+
return {
|
|
68
|
+
props: {
|
|
69
|
+
...args,
|
|
70
|
+
appliedFormValue: '[]',
|
|
71
|
+
appliedSortValue: '[]',
|
|
72
|
+
onResetFilters() {
|
|
73
|
+
this['appliedFormValue'] = '[]';
|
|
74
|
+
},
|
|
75
|
+
onResetSorts() {
|
|
76
|
+
this['appliedSortValue'] = '[]';
|
|
77
|
+
},
|
|
78
|
+
onApplyFilters(filters: unknown) {
|
|
79
|
+
this['appliedFormValue'] = JSON.stringify(filters, null, 2);
|
|
80
|
+
},
|
|
81
|
+
onApplySorts(sorts: unknown) {
|
|
82
|
+
this['appliedSortValue'] = JSON.stringify(sorts, null, 2);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
template: `
|
|
86
|
+
<div class="h-fit p-6 w-full flex flex-col items-end justify-center bg-white gap-6">
|
|
87
|
+
<ads-filter-button
|
|
88
|
+
[buttonLabel]="buttonLabel"
|
|
89
|
+
[buttonIcon]="buttonIcon"
|
|
90
|
+
[showButtonIcon]="showButtonIcon"
|
|
91
|
+
[buttonVariant]="buttonVariant"
|
|
92
|
+
[buttonColor]="buttonColor"
|
|
93
|
+
[buttonOpenVariant]="buttonOpenVariant"
|
|
94
|
+
[buttonOpenColor]="buttonOpenColor"
|
|
95
|
+
[buttonDisabled]="buttonDisabled"
|
|
96
|
+
[columnOptions]="columnOptions"
|
|
97
|
+
[columnPlaceholder]="columnPlaceholder"
|
|
98
|
+
[valuePlaceholder]="valuePlaceholder"
|
|
99
|
+
[noFiltersText]="noFiltersText"
|
|
100
|
+
[sortableColumnOptions]="sortableColumnOptions"
|
|
101
|
+
[noSortText]="noSortText"
|
|
102
|
+
(resetFilters)="onResetFilters()"
|
|
103
|
+
(resetSorts)="onResetSorts()"
|
|
104
|
+
(applyFilters)="onApplyFilters($event)"
|
|
105
|
+
(applySorts)="onApplySorts($event)"
|
|
106
|
+
></ads-filter-button>
|
|
107
|
+
|
|
108
|
+
<div class="w-104 rounded-md border border-[#e7e7e7] bg-[#fafafa] p-4">
|
|
109
|
+
<p class="m-0 mb-2 font-medium text-sm">Last applied filters</p>
|
|
110
|
+
<pre class="m-0 max-h-80 overflow-auto text-xs leading-5">{{ appliedFormValue }}</pre>
|
|
111
|
+
<p class="m-0 mb-2 mt-4 font-medium text-sm">Last applied sorts</p>
|
|
112
|
+
<pre class="m-0 max-h-80 overflow-auto text-xs leading-5">{{ appliedSortValue }}</pre>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
`,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default meta;
|
|
121
|
+
type Story = StoryObj<FilterButtonComponent>;
|
|
122
|
+
|
|
123
|
+
export const Playground: Story = {};
|
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
Component,
|
|
4
|
+
ElementRef,
|
|
5
|
+
HostListener,
|
|
6
|
+
input,
|
|
7
|
+
output,
|
|
8
|
+
signal,
|
|
9
|
+
} from '@angular/core';
|
|
10
|
+
import {
|
|
11
|
+
FormArray,
|
|
12
|
+
FormBuilder,
|
|
13
|
+
FormGroup,
|
|
14
|
+
ReactiveFormsModule,
|
|
15
|
+
} from '@angular/forms';
|
|
16
|
+
import {
|
|
17
|
+
AdsButtonColor,
|
|
18
|
+
AdsFilterButtonOption,
|
|
19
|
+
AdsFilterButtonRow,
|
|
20
|
+
AdsFilterButtonSortRow,
|
|
21
|
+
AdsFilterButtonValueType,
|
|
22
|
+
AdsSingleSelectorOption,
|
|
23
|
+
AdsSingleSelectorValue,
|
|
24
|
+
AdsButtonVariant,
|
|
25
|
+
AdsIconName,
|
|
26
|
+
} from '../../core/types';
|
|
27
|
+
import { ButtonComponent } from '../button/button.component';
|
|
28
|
+
import { IconComponent } from '../icon/icon.component';
|
|
29
|
+
import { InputDatepickerComponent } from '../input-datepicker/input-datepicker.component';
|
|
30
|
+
import { InputComponent } from '../input/input.component';
|
|
31
|
+
import { SingleSelectorComponent } from '../selectors/single-selector/single-selector.component';
|
|
32
|
+
|
|
33
|
+
@Component({
|
|
34
|
+
selector: 'ads-filter-button',
|
|
35
|
+
standalone: true,
|
|
36
|
+
imports: [
|
|
37
|
+
CommonModule,
|
|
38
|
+
ReactiveFormsModule,
|
|
39
|
+
ButtonComponent,
|
|
40
|
+
IconComponent,
|
|
41
|
+
SingleSelectorComponent,
|
|
42
|
+
InputComponent,
|
|
43
|
+
InputDatepickerComponent,
|
|
44
|
+
],
|
|
45
|
+
templateUrl: './filter-button.component.html',
|
|
46
|
+
})
|
|
47
|
+
export class FilterButtonComponent {
|
|
48
|
+
private readonly codesValueOptions: AdsSingleSelectorOption[] = [
|
|
49
|
+
{ label: 'Common', value: 'common' },
|
|
50
|
+
{ label: 'Practice', value: 'practice' },
|
|
51
|
+
{ label: 'All', value: 'all' },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
private readonly booleanValueOptions: AdsSingleSelectorOption[] = [
|
|
55
|
+
{ label: 'Yes', value: true },
|
|
56
|
+
{ label: 'No', value: false },
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
private readonly statusValueOptions: AdsSingleSelectorOption[] = [
|
|
60
|
+
{ label: 'Active', value: false },
|
|
61
|
+
{ label: 'Inactive', value: true },
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
buttonLabel = input<string>('Filter');
|
|
65
|
+
buttonIcon = input<AdsIconName>('tune');
|
|
66
|
+
showButtonIcon = input<boolean>(true);
|
|
67
|
+
buttonVariant = input<AdsButtonVariant>('primary');
|
|
68
|
+
buttonColor = input<AdsButtonColor>('white');
|
|
69
|
+
buttonOpenVariant = input<AdsButtonVariant>('primary');
|
|
70
|
+
buttonOpenColor = input<AdsButtonColor>('green');
|
|
71
|
+
buttonDisabled = input<boolean>(false);
|
|
72
|
+
|
|
73
|
+
panelTitle = input<string>('Filters');
|
|
74
|
+
addFilterLabel = input<string>('Add Filter');
|
|
75
|
+
resetLabel = input<string>('Reset filters');
|
|
76
|
+
applyLabel = input<string>('Apply filters');
|
|
77
|
+
|
|
78
|
+
columnOptions = input<AdsFilterButtonOption[]>([]);
|
|
79
|
+
columnPlaceholder = input<string>('Select a filter field');
|
|
80
|
+
valuePlaceholder = input<string>('Value');
|
|
81
|
+
noFiltersText = input<string>('No filters applied');
|
|
82
|
+
|
|
83
|
+
sortableColumnOptions = input<AdsFilterButtonOption[]>([]);
|
|
84
|
+
noSortText = input<string>('No sorts applied');
|
|
85
|
+
|
|
86
|
+
addFilter = output<void>();
|
|
87
|
+
resetFilters = output<void>();
|
|
88
|
+
applyFilters = output<AdsFilterButtonRow[]>();
|
|
89
|
+
addSort = output<void>();
|
|
90
|
+
resetSorts = output<void>();
|
|
91
|
+
applySorts = output<AdsFilterButtonSortRow[]>();
|
|
92
|
+
openChange = output<boolean>();
|
|
93
|
+
|
|
94
|
+
isOpen = signal<boolean>(false);
|
|
95
|
+
filterForm: FormGroup;
|
|
96
|
+
|
|
97
|
+
private readonly sortDirectionOptions: AdsSingleSelectorOption[] = [
|
|
98
|
+
{ label: 'Ascending', value: 'ASC' },
|
|
99
|
+
{ label: 'Descending', value: 'DESC' },
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
constructor(
|
|
103
|
+
private readonly el: ElementRef<HTMLElement>,
|
|
104
|
+
private readonly fb: FormBuilder,
|
|
105
|
+
) {
|
|
106
|
+
this.filterForm = this.fb.group({
|
|
107
|
+
filters: this.fb.array([]),
|
|
108
|
+
sorts: this.fb.array([]),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get filtersArray(): FormArray {
|
|
113
|
+
return this.filterForm.get('filters') as FormArray;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get sortsArray(): FormArray {
|
|
117
|
+
return this.filterForm.get('sorts') as FormArray;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
rowValueType(index: number): AdsFilterButtonValueType {
|
|
121
|
+
const row = this.filtersArray.at(index) as FormGroup | null;
|
|
122
|
+
const valueType = row?.get('valueType')
|
|
123
|
+
?.value as AdsFilterButtonValueType | null;
|
|
124
|
+
|
|
125
|
+
return valueType ?? 'text';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
valueOptionsForRow(index: number): AdsSingleSelectorOption[] {
|
|
129
|
+
const rowType = this.rowValueType(index);
|
|
130
|
+
|
|
131
|
+
if (rowType === 'boolean') {
|
|
132
|
+
return this.booleanValueOptions;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (rowType === 'status') {
|
|
136
|
+
return this.statusValueOptions;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (rowType === 'codes') {
|
|
140
|
+
return this.codesValueOptions;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (rowType === 'custom') {
|
|
144
|
+
return this.getColumnCustomOptions(index);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
hasFilters(): boolean {
|
|
151
|
+
return this.filtersArray.length > 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
hasSorts(): boolean {
|
|
155
|
+
return this.sortsArray.length > 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
canApplyFilters(): boolean {
|
|
159
|
+
const hasValidFilterRows =
|
|
160
|
+
this.hasFilters() &&
|
|
161
|
+
this.filtersArray.controls.every((control) => {
|
|
162
|
+
const row = control as FormGroup;
|
|
163
|
+
const column = row.get('column')?.value;
|
|
164
|
+
const value = row.get('value')?.value;
|
|
165
|
+
const valueType = row.get('valueType')?.value as
|
|
166
|
+
| AdsFilterButtonValueType
|
|
167
|
+
| null;
|
|
168
|
+
|
|
169
|
+
if (column === null || column === undefined || column === '') {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (value === null || value === undefined) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (typeof value === 'string') {
|
|
178
|
+
if (valueType === 'date') {
|
|
179
|
+
return this.isValidDateValue(value);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return value.trim().length > 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (valueType === 'date') {
|
|
186
|
+
return this.isValidDateValue(value);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return true;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const hasValidSortRows =
|
|
193
|
+
this.hasSorts() &&
|
|
194
|
+
this.sortsArray.controls.every((control) => {
|
|
195
|
+
const row = control as FormGroup;
|
|
196
|
+
const column = row.get('column')?.value;
|
|
197
|
+
const direction = row.get('direction')?.value;
|
|
198
|
+
|
|
199
|
+
return !!column && !!direction;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return hasValidFilterRows || hasValidSortRows;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
canAddFilter(): boolean {
|
|
206
|
+
return this.filtersArray.length < this.columnOptions().length;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
canAddSort(): boolean {
|
|
210
|
+
return this.sortsArray.length < this.sortableColumnOptions().length;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
columnOptionsForRow(index: number): AdsFilterButtonOption[] {
|
|
214
|
+
const currentColumnValue = this.rowColumnValue(index);
|
|
215
|
+
const selectedValues = new Set(this.selectedColumnValues(index));
|
|
216
|
+
const currentOption = this.findColumnOption(currentColumnValue);
|
|
217
|
+
|
|
218
|
+
const orderedOptions: AdsFilterButtonOption[] = [];
|
|
219
|
+
const pushOption = (option: AdsFilterButtonOption | undefined): void => {
|
|
220
|
+
if (
|
|
221
|
+
!option ||
|
|
222
|
+
orderedOptions.some((item) => item.value === option.value)
|
|
223
|
+
) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
orderedOptions.push({
|
|
228
|
+
...option,
|
|
229
|
+
disabled:
|
|
230
|
+
selectedValues.has(option.value) &&
|
|
231
|
+
option.value !== currentColumnValue,
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
pushOption(currentOption);
|
|
236
|
+
|
|
237
|
+
for (const value of selectedValues) {
|
|
238
|
+
pushOption(this.findColumnOption(value));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const option of this.columnOptions()) {
|
|
242
|
+
pushOption(option);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return orderedOptions;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
togglePanel(): void {
|
|
249
|
+
if (this.buttonDisabled()) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const nextState = !this.isOpen();
|
|
254
|
+
this.isOpen.set(nextState);
|
|
255
|
+
this.openChange.emit(nextState);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
resolvedButtonVariant(): AdsButtonVariant {
|
|
259
|
+
return this.isOpen() ? this.buttonOpenVariant() : this.buttonVariant();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
resolvedButtonColor(): AdsButtonColor {
|
|
263
|
+
return this.isOpen() ? this.buttonOpenColor() : this.buttonColor();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
resolvedIconGapValue(): string {
|
|
267
|
+
return this.showButtonIcon() ? this.buttonIcon() : '';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
closePanel(): void {
|
|
271
|
+
if (!this.isOpen()) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.isOpen.set(false);
|
|
276
|
+
this.openChange.emit(false);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
onAddFilterClick(): void {
|
|
280
|
+
if (!this.canAddFilter()) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const selectedValues = new Set(this.selectedColumnValues(-1));
|
|
285
|
+
const nextColumnOption = this.columnOptions().find(
|
|
286
|
+
(option) => !selectedValues.has(option.value),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
if (!nextColumnOption) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
this.filtersArray.push(
|
|
294
|
+
this.createFilterRow(
|
|
295
|
+
nextColumnOption.value,
|
|
296
|
+
nextColumnOption.valueType ?? 'text',
|
|
297
|
+
),
|
|
298
|
+
);
|
|
299
|
+
this.addFilter.emit();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
onAddSortClick(): void {
|
|
303
|
+
if (!this.canAddSort()) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const selectedValues = new Set(this.selectedSortColumnValues(-1));
|
|
308
|
+
const nextColumnOption = this.sortableColumnOptions().find(
|
|
309
|
+
(option) => !selectedValues.has(option.value),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
if (!nextColumnOption) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
this.sortsArray.push(this.createSortRow(nextColumnOption.value, 'ASC'));
|
|
317
|
+
this.addSort.emit();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
onRemoveFilterClick(index: number): void {
|
|
321
|
+
this.filtersArray.removeAt(index);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
onRemoveSortClick(index: number): void {
|
|
325
|
+
this.sortsArray.removeAt(index);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
onColumnChange(
|
|
329
|
+
index: number,
|
|
330
|
+
columnValue: AdsSingleSelectorValue | null,
|
|
331
|
+
): void {
|
|
332
|
+
const row = this.filtersArray.at(index) as FormGroup | null;
|
|
333
|
+
|
|
334
|
+
if (!row) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const matchedOption = this.findColumnOption(columnValue);
|
|
339
|
+
row.patchValue({
|
|
340
|
+
valueType: matchedOption?.valueType ?? 'text',
|
|
341
|
+
value: '',
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
onResetClick(): void {
|
|
346
|
+
this.filtersArray.clear();
|
|
347
|
+
this.sortsArray.clear();
|
|
348
|
+
this.resetFilters.emit();
|
|
349
|
+
this.resetSorts.emit();
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
onApplyClick(): void {
|
|
353
|
+
if (!this.canApplyFilters()) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
this.applyFilters.emit(this.filterForm.getRawValue().filters ?? []);
|
|
358
|
+
this.applySorts.emit(this.filterForm.getRawValue().sorts ?? []);
|
|
359
|
+
this.closePanel();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
private createFilterRow(
|
|
363
|
+
column: AdsSingleSelectorValue | null,
|
|
364
|
+
valueType: AdsFilterButtonValueType,
|
|
365
|
+
): FormGroup {
|
|
366
|
+
return this.fb.group({
|
|
367
|
+
column: [column],
|
|
368
|
+
value: [''],
|
|
369
|
+
valueType: [valueType],
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private createSortRow(
|
|
374
|
+
column: AdsSingleSelectorValue | null,
|
|
375
|
+
direction: 'ASC' | 'DESC',
|
|
376
|
+
): FormGroup {
|
|
377
|
+
return this.fb.group({
|
|
378
|
+
column: [column],
|
|
379
|
+
direction: [direction],
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private rowColumnValue(index: number): AdsSingleSelectorValue | null {
|
|
384
|
+
const row = this.filtersArray.at(index) as FormGroup | null;
|
|
385
|
+
return (row?.get('column')?.value as AdsSingleSelectorValue | null) ?? null;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private selectedColumnValues(
|
|
389
|
+
excludedIndex: number,
|
|
390
|
+
): AdsSingleSelectorValue[] {
|
|
391
|
+
return this.filtersArray.controls
|
|
392
|
+
.map((control, index) => ({
|
|
393
|
+
value: (control as FormGroup).get('column')
|
|
394
|
+
?.value as AdsSingleSelectorValue | null,
|
|
395
|
+
index,
|
|
396
|
+
}))
|
|
397
|
+
.filter((item) => item.index !== excludedIndex && item.value !== null)
|
|
398
|
+
.map((item) => item.value as AdsSingleSelectorValue);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private selectedSortColumnValues(
|
|
402
|
+
excludedIndex: number,
|
|
403
|
+
): AdsSingleSelectorValue[] {
|
|
404
|
+
return this.sortsArray.controls
|
|
405
|
+
.map((control, index) => ({
|
|
406
|
+
value: (control as FormGroup).get('column')
|
|
407
|
+
?.value as AdsSingleSelectorValue | null,
|
|
408
|
+
index,
|
|
409
|
+
}))
|
|
410
|
+
.filter((item) => item.index !== excludedIndex && item.value !== null)
|
|
411
|
+
.map((item) => item.value as AdsSingleSelectorValue);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private findColumnOption(
|
|
415
|
+
columnValue: AdsSingleSelectorValue | null,
|
|
416
|
+
): AdsFilterButtonOption | undefined {
|
|
417
|
+
if (columnValue === null) {
|
|
418
|
+
return undefined;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return this.columnOptions().find((option) => option.value === columnValue);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
private getColumnCustomOptions(index: number): AdsSingleSelectorOption[] {
|
|
425
|
+
const selectedColumn = this.findColumnOption(this.rowColumnValue(index));
|
|
426
|
+
return selectedColumn?.customOptions ?? [];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
sortColumnOptionsForRow(index: number): AdsFilterButtonOption[] {
|
|
430
|
+
const currentColumnValue = this.rowSortColumnValue(index);
|
|
431
|
+
const selectedValues = new Set(this.selectedSortColumnValues(index));
|
|
432
|
+
const currentOption = this.findSortColumnOption(currentColumnValue);
|
|
433
|
+
|
|
434
|
+
const orderedOptions: AdsFilterButtonOption[] = [];
|
|
435
|
+
const pushOption = (option: AdsFilterButtonOption | undefined): void => {
|
|
436
|
+
if (
|
|
437
|
+
!option ||
|
|
438
|
+
orderedOptions.some((item) => item.value === option.value)
|
|
439
|
+
) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
orderedOptions.push({
|
|
444
|
+
...option,
|
|
445
|
+
disabled:
|
|
446
|
+
selectedValues.has(option.value) &&
|
|
447
|
+
option.value !== currentColumnValue,
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
pushOption(currentOption);
|
|
452
|
+
|
|
453
|
+
for (const value of selectedValues) {
|
|
454
|
+
pushOption(this.findSortColumnOption(value));
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
for (const option of this.sortableColumnOptions()) {
|
|
458
|
+
pushOption(option);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return orderedOptions;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
sortValueOptions(): AdsSingleSelectorOption[] {
|
|
465
|
+
return this.sortDirectionOptions;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
private rowSortColumnValue(index: number): AdsSingleSelectorValue | null {
|
|
469
|
+
const row = this.sortsArray.at(index) as FormGroup | null;
|
|
470
|
+
return (row?.get('column')?.value as AdsSingleSelectorValue | null) ?? null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
private findSortColumnOption(
|
|
474
|
+
columnValue: AdsSingleSelectorValue | null,
|
|
475
|
+
): AdsFilterButtonOption | undefined {
|
|
476
|
+
if (columnValue === null) {
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return this.sortableColumnOptions().find(
|
|
481
|
+
(option) => option.value === columnValue,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private isValidDateValue(value: unknown): boolean {
|
|
486
|
+
if (value instanceof Date) {
|
|
487
|
+
return !Number.isNaN(value.getTime());
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if (typeof value !== 'string') {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const trimmedValue = value.trim();
|
|
495
|
+
if (!trimmedValue) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const strictDatePattern = /^\d{2}\/\d{2}\/\d{4}$/;
|
|
500
|
+
if (!strictDatePattern.test(trimmedValue)) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const [monthPart, dayPart, yearPart] = trimmedValue.split('/');
|
|
505
|
+
const month = Number(monthPart);
|
|
506
|
+
const day = Number(dayPart);
|
|
507
|
+
const year = Number(yearPart);
|
|
508
|
+
|
|
509
|
+
if (
|
|
510
|
+
Number.isNaN(month) ||
|
|
511
|
+
Number.isNaN(day) ||
|
|
512
|
+
Number.isNaN(year) ||
|
|
513
|
+
month < 1 ||
|
|
514
|
+
month > 12 ||
|
|
515
|
+
day < 1 ||
|
|
516
|
+
day > 31
|
|
517
|
+
) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const date = new Date(year, month - 1, day);
|
|
522
|
+
return (
|
|
523
|
+
date.getFullYear() === year &&
|
|
524
|
+
date.getMonth() === month - 1 &&
|
|
525
|
+
date.getDate() === day
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
hasDateError(index: number): boolean {
|
|
530
|
+
const row = this.filtersArray.at(index) as FormGroup | null;
|
|
531
|
+
if (!row || this.rowValueType(index) !== 'date') {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const value = row.get('value')?.value;
|
|
536
|
+
|
|
537
|
+
if (value === null || value === undefined || value === '') {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return !this.isValidDateValue(value);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
@HostListener('document:click', ['$event'])
|
|
545
|
+
onDocumentClick(event: Event): void {
|
|
546
|
+
if (!this.isOpen()) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const target = event.target as Node | null;
|
|
551
|
+
if (!target) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const anyEvent = event as unknown as {
|
|
556
|
+
composedPath?: () => EventTarget[];
|
|
557
|
+
path?: EventTarget[];
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
const path =
|
|
561
|
+
typeof anyEvent.composedPath === 'function'
|
|
562
|
+
? anyEvent.composedPath()
|
|
563
|
+
: (anyEvent.path ?? []);
|
|
564
|
+
|
|
565
|
+
const clickedInsideComponent =
|
|
566
|
+
path.length > 0
|
|
567
|
+
? path.includes(this.el.nativeElement)
|
|
568
|
+
: this.el.nativeElement.contains(target);
|
|
569
|
+
|
|
570
|
+
const clickedOverlay = path.some(
|
|
571
|
+
(item) =>
|
|
572
|
+
item instanceof HTMLElement &&
|
|
573
|
+
(item.classList.contains('cdk-overlay-container') ||
|
|
574
|
+
item.classList.contains('cdk-overlay-pane') ||
|
|
575
|
+
item.classList.contains('ant-select-dropdown')),
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
if (!clickedInsideComponent && !clickedOverlay) {
|
|
579
|
+
this.closePanel();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|