Change button close to reset add change default changeDetection to onPush

This commit is contained in:
ArtemDzhereleiko 2021-08-30 12:53:28 +03:00
parent 327607e86d
commit 04317d6300
3 changed files with 24 additions and 6 deletions

View File

@ -61,8 +61,9 @@
<div fxLayout="row" class="tb-panel-actions" fxLayoutAlign="end center"> <div fxLayout="row" class="tb-panel-actions" fxLayoutAlign="end center">
<button type="button" <button type="button"
mat-button mat-button
(click)="cancel()"> [disabled]="resetButtonDisabled"
{{ 'action.cancel' | translate }} (click)="reset()">
{{ 'action.reset' | translate }}
</button> </button>
<button type="submit" <button type="submit"
mat-raised-button mat-raised-button

View File

@ -14,12 +14,12 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, Inject, InjectionToken } from '@angular/core'; import { Component, Inject, InjectionToken, ChangeDetectionStrategy } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { OverlayRef } from '@angular/cdk/overlay'; import { OverlayRef } from '@angular/cdk/overlay';
import { EntityType } from '@shared/models/entity-type.models'; import { EntityType } from '@shared/models/entity-type.models';
import { FilterEventBody } from '@shared/models/event.models'; import { FilterEventBody } from '@shared/models/event.models';
import { deepTrim } from '@core/utils'; import { deepTrim, isEqual } from '@core/utils';
export const EVENT_FILTER_PANEL_DATA = new InjectionToken<any>('AlarmFilterPanelData'); export const EVENT_FILTER_PANEL_DATA = new InjectionToken<any>('AlarmFilterPanelData');
@ -37,7 +37,8 @@ export interface FilterEntityColumn {
@Component({ @Component({
selector: 'tb-event-filter-panel', selector: 'tb-event-filter-panel',
templateUrl: './event-filter-panel.component.html', templateUrl: './event-filter-panel.component.html',
styleUrls: ['./event-filter-panel.component.scss'] styleUrls: ['./event-filter-panel.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class EventFilterPanelComponent { export class EventFilterPanelComponent {
@ -106,6 +107,21 @@ export class EventFilterPanelComponent {
this.overlayRef.dispose(); this.overlayRef.dispose();
} }
reset() {
const emptyInputValue = {};
for (const inputValue in this.eventFilterFormGroup.value) {
emptyInputValue[inputValue] = '';
}
this.eventFilterFormGroup.reset(emptyInputValue);
this.update();
}
get resetButtonDisabled() {
return isEqual(this.data.filterParams, {});
}
changeIsError(value: boolean | string) { changeIsError(value: boolean | string) {
if (this.conditionError && value === '') { if (this.conditionError && value === '') {
this.eventFilterFormGroup.get('error').reset('', {emitEvent: false}); this.eventFilterFormGroup.get('error').reset('', {emitEvent: false});

View File

@ -57,7 +57,8 @@
"download": "Download", "download": "Download",
"next-with-label": "Next: {{label}}", "next-with-label": "Next: {{label}}",
"read-more": "Read more", "read-more": "Read more",
"hide": "Hide" "hide": "Hide",
"reset": "Reset"
}, },
"aggregation": { "aggregation": {
"aggregation": "Aggregation", "aggregation": "Aggregation",