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">
<button type="button"
mat-button
(click)="cancel()">
{{ 'action.cancel' | translate }}
[disabled]="resetButtonDisabled"
(click)="reset()">
{{ 'action.reset' | translate }}
</button>
<button type="submit"
mat-raised-button

View File

@ -14,12 +14,12 @@
/// 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 { OverlayRef } from '@angular/cdk/overlay';
import { EntityType } from '@shared/models/entity-type.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');
@ -37,7 +37,8 @@ export interface FilterEntityColumn {
@Component({
selector: 'tb-event-filter-panel',
templateUrl: './event-filter-panel.component.html',
styleUrls: ['./event-filter-panel.component.scss']
styleUrls: ['./event-filter-panel.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class EventFilterPanelComponent {
@ -106,6 +107,21 @@ export class EventFilterPanelComponent {
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) {
if (this.conditionError && value === '') {
this.eventFilterFormGroup.get('error').reset('', {emitEvent: false});

View File

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