diff --git a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts index a10200060a..973ab99382 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts @@ -52,6 +52,7 @@ import { export class EventTableConfig extends EntityTableConfig { eventTypeValue: EventType | DebugEventType; + hideClearEventAction = false; private filterParams: FilterEventBody = {}; private filterColumns: FilterEntityColumn[] = []; @@ -140,15 +141,30 @@ export class EventTableConfig extends EntityTableConfig { { name: this.translate.instant('event.clean-events'), icon: 'delete', - isEnabled: () => true, - onAction: ($event) => { - this.eventService.clearEvents(this.entityId, this.eventType, this.filterParams, this.tenantId, this.table.pageLink as TimePageLink).subscribe( + isEnabled: () => !this.hideClearEventAction, + onAction: $event => this.clearEvents($event) + }); + } + + clearEvents($event) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('event.clear-request-title'), + this.translate.instant('event.clear-request-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes') + ).subscribe((res) => { + if (res) { + this.eventService.clearEvents(this.entityId, this.eventType, this.filterParams, + this.tenantId, this.table.pageLink as TimePageLink).subscribe( () => { this.table.paginator.pageIndex = 0; this.table.updateData(); } ); - } + } }); } diff --git a/ui-ngx/src/app/modules/home/components/event/event-table.component.ts b/ui-ngx/src/app/modules/home/components/event/event-table.component.ts index 00aeb4f50c..e1e4129757 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { ChangeDetectorRef, Component, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; +import { AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { DatePipe } from '@angular/common'; import { MatDialog } from '@angular/material/dialog'; @@ -25,13 +25,14 @@ import { EventService } from '@core/http/event.service'; import { DialogService } from '@core/services/dialog.service'; import { DebugEventType, EventType } from '@shared/models/event.models'; import { Overlay } from '@angular/cdk/overlay'; +import { Subscription } from 'rxjs'; @Component({ selector: 'tb-event-table', templateUrl: './event-table.component.html', styleUrls: ['./event-table.component.scss'] }) -export class EventTableComponent implements OnInit { +export class EventTableComponent implements OnInit, AfterViewInit { @Input() tenantId: string; @@ -77,6 +78,8 @@ export class EventTableComponent implements OnInit { eventTableConfig: EventTableConfig; + private isEmptyData$: Subscription; + constructor(private eventService: EventService, private dialogService: DialogService, private translate: TranslateService, @@ -106,4 +109,14 @@ export class EventTableComponent implements OnInit { ); } + ngAfterViewInit() { + this.isEmptyData$ = this.entitiesTable.dataSource.isEmpty().subscribe(value => this.eventTableConfig.hideClearEventAction = value); + } + + ngOnDestroy() { + if (this.isEmptyData$) { + this.isEmptyData$.unsubscribe(); + } + } + } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 9775e5c09d..0ac52c99e1 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1887,7 +1887,9 @@ "has-error": "Has error", "entity-id": "Entity Id", "entity-type": "Entity type", - "clear-filter": "Clear Filter" + "clear-filter": "Clear Filter", + "clear-request-title": "Clear all events", + "clear-request-text": "Are you sure you want to clear all events?" }, "extension": { "extensions": "Extensions", diff --git a/ui-ngx/src/assets/locale/locale.constant-ru_RU.json b/ui-ngx/src/assets/locale/locale.constant-ru_RU.json index 6acb91c7c5..51d08e8939 100644 --- a/ui-ngx/src/assets/locale/locale.constant-ru_RU.json +++ b/ui-ngx/src/assets/locale/locale.constant-ru_RU.json @@ -959,7 +959,9 @@ "messages-processed": "Сообщения обработаны", "errors-occurred": "Возникли ошибки", "all-events": "Все", - "entity-type": "Тип объекта" + "entity-type": "Тип объекта", + "clear-request-title": "Удалить все события", + "clear-request-text": "Вы точно хотите удалить все события?" }, "extension": { "extensions": "Расширение", diff --git a/ui-ngx/src/assets/locale/locale.constant-uk_UA.json b/ui-ngx/src/assets/locale/locale.constant-uk_UA.json index 943598baef..003c7881ca 100644 --- a/ui-ngx/src/assets/locale/locale.constant-uk_UA.json +++ b/ui-ngx/src/assets/locale/locale.constant-uk_UA.json @@ -1211,7 +1211,9 @@ "messages-processed": "Повідомлення опрацьовані", "errors-occurred": "Виникли помилки", "all-events": "Всі", - "entity-type": "Тип сутності" + "entity-type": "Тип сутності", + "clear-request-title": "Видалити всі події", + "clear-request-text": "Ви впевнені, що хочете видалити всі події?" }, "extension": { "extensions": "Розширення",