Commit 04317d630000bf03c09e02066f62b270a6f92b5d
1 parent
327607e8
Change button close to reset add change default changeDetection to onPush
Showing
3 changed files
with
24 additions
and
6 deletions
... | ... | @@ -61,8 +61,9 @@ |
61 | 61 | <div fxLayout="row" class="tb-panel-actions" fxLayoutAlign="end center"> |
62 | 62 | <button type="button" |
63 | 63 | mat-button |
64 | - (click)="cancel()"> | |
65 | - {{ 'action.cancel' | translate }} | |
64 | + [disabled]="resetButtonDisabled" | |
65 | + (click)="reset()"> | |
66 | + {{ 'action.reset' | translate }} | |
66 | 67 | </button> |
67 | 68 | <button type="submit" |
68 | 69 | mat-raised-button | ... | ... |
... | ... | @@ -14,12 +14,12 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | -import { Component, Inject, InjectionToken } from '@angular/core'; | |
17 | +import { Component, Inject, InjectionToken, ChangeDetectionStrategy } from '@angular/core'; | |
18 | 18 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
19 | 19 | import { OverlayRef } from '@angular/cdk/overlay'; |
20 | 20 | import { EntityType } from '@shared/models/entity-type.models'; |
21 | 21 | import { FilterEventBody } from '@shared/models/event.models'; |
22 | -import { deepTrim } from '@core/utils'; | |
22 | +import { deepTrim, isEqual } from '@core/utils'; | |
23 | 23 | |
24 | 24 | export const EVENT_FILTER_PANEL_DATA = new InjectionToken<any>('AlarmFilterPanelData'); |
25 | 25 | |
... | ... | @@ -37,7 +37,8 @@ export interface FilterEntityColumn { |
37 | 37 | @Component({ |
38 | 38 | selector: 'tb-event-filter-panel', |
39 | 39 | templateUrl: './event-filter-panel.component.html', |
40 | - styleUrls: ['./event-filter-panel.component.scss'] | |
40 | + styleUrls: ['./event-filter-panel.component.scss'], | |
41 | + changeDetection: ChangeDetectionStrategy.OnPush | |
41 | 42 | }) |
42 | 43 | export class EventFilterPanelComponent { |
43 | 44 | |
... | ... | @@ -106,6 +107,21 @@ export class EventFilterPanelComponent { |
106 | 107 | this.overlayRef.dispose(); |
107 | 108 | } |
108 | 109 | |
110 | + reset() { | |
111 | + const emptyInputValue = {}; | |
112 | + | |
113 | + for (const inputValue in this.eventFilterFormGroup.value) { | |
114 | + emptyInputValue[inputValue] = ''; | |
115 | + } | |
116 | + | |
117 | + this.eventFilterFormGroup.reset(emptyInputValue); | |
118 | + this.update(); | |
119 | + } | |
120 | + | |
121 | + get resetButtonDisabled() { | |
122 | + return isEqual(this.data.filterParams, {}); | |
123 | + } | |
124 | + | |
109 | 125 | changeIsError(value: boolean | string) { |
110 | 126 | if (this.conditionError && value === '') { |
111 | 127 | this.eventFilterFormGroup.get('error').reset('', {emitEvent: false}); | ... | ... |