From 9d4b79c91cec7273b82cf4b537c7a4172c6e2601 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 22 Aug 2019 13:34:15 +0300 Subject: [PATCH] UI: Audit logs. --- ui-ngx/package.json | 2 +- ui-ngx/src/app/core/auth/auth.service.ts | 9 +- ui-ngx/src/app/core/http/audit-log.service.ts | 59 ++++++++ .../audit-log-details-dialog.component.html | 45 ++++++ .../audit-log-details-dialog.component.scss | 25 ++++ .../audit-log-details-dialog.component.ts | 124 ++++++++++++++++ .../audit-log/audit-log-table-config.ts | 138 ++++++++++++++++++ .../audit-log/audit-log-table.component.html | 18 +++ .../audit-log/audit-log-table.component.scss | 22 +++ .../audit-log/audit-log-table.component.ts | 133 +++++++++++++++++ .../entity/entities-table.component.html | 4 +- .../entity/entity-tabs.component.ts | 14 ++ .../home/components/home-components.module.ts | 10 +- .../pages/asset/asset-tabs.component.html | 21 +++ .../home/pages/asset/asset-tabs.component.ts | 38 +++++ .../modules/home/pages/asset/asset.module.ts | 3 + .../asset/assets-table-config.resolver.ts | 2 + .../audit-log/audit-log-routing.module.ts | 41 ++++++ .../home/pages/audit-log/audit-log.module.ts | 31 ++++ .../customer/customer-tabs.component.html | 21 +++ .../pages/customer/customer-tabs.component.ts | 38 +++++ .../home/pages/customer/customer.module.ts | 7 +- .../customers-table-config.resolver.ts | 2 + .../dashboard/dashboard-tabs.component.html | 21 +++ .../dashboard/dashboard-tabs.component.ts | 38 +++++ .../home/pages/dashboard/dashboard.module.ts | 3 + .../dashboards-table-config.resolver.ts | 2 + .../pages/device/device-tabs.component.html | 14 +- .../pages/device/device-tabs.component.ts | 2 - .../entity-view-tabs.component.html | 21 +++ .../entity-view/entity-view-tabs.component.ts | 38 +++++ .../pages/entity-view/entity-view.module.ts | 3 + .../entity-views-table-config.resolver.ts | 2 + .../modules/home/pages/home-pages.module.ts | 4 +- .../rulechain/rulechain-tabs.component.html | 21 +++ .../rulechain/rulechain-tabs.component.ts | 39 +++++ .../home/pages/rulechain/rulechain.module.ts | 7 +- .../rulechains-table-config.resolver.ts | 2 + .../shared/components/user-menu.component.ts | 4 - .../src/app/shared/models/audit-log.models.ts | 102 +++++++++++++ .../src/app/shared/models/id/audit-log-id.ts | 24 +++ ui-ngx/src/app/shared/shared.module.ts | 6 - 42 files changed, 1125 insertions(+), 35 deletions(-) create mode 100644 ui-ngx/src/app/core/http/audit-log.service.ts create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.html create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.scss create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.ts create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-table-config.ts create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.html create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.scss create mode 100644 ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/asset/asset-tabs.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/asset/asset-tabs.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/audit-log/audit-log-routing.module.ts create mode 100644 ui-ngx/src/app/modules/home/pages/audit-log/audit-log.module.ts create mode 100644 ui-ngx/src/app/modules/home/pages/customer/customer-tabs.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/customer/customer-tabs.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/dashboard/dashboard-tabs.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/dashboard/dashboard-tabs.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/entity-view/entity-view-tabs.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/entity-view/entity-view-tabs.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/rulechain/rulechain-tabs.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/rulechain/rulechain-tabs.component.ts create mode 100644 ui-ngx/src/app/shared/models/audit-log.models.ts create mode 100644 ui-ngx/src/app/shared/models/id/audit-log-id.ts diff --git a/ui-ngx/package.json b/ui-ngx/package.json index 6908849900..b180dcfdc6 100644 --- a/ui-ngx/package.json +++ b/ui-ngx/package.json @@ -3,7 +3,7 @@ "version": "3.0.0", "scripts": { "ng": "ng", - "start": "ng serve --host 0.0.0.0 --open", + "start": "ng serve --open", "build": "ng build", "build:prod": "ng build --prod --vendor-chunk", "test": "ng test", diff --git a/ui-ngx/src/app/core/auth/auth.service.ts b/ui-ngx/src/app/core/auth/auth.service.ts index 2df91a6416..1ae48af68c 100644 --- a/ui-ngx/src/app/core/auth/auth.service.ts +++ b/ui-ngx/src/app/core/auth/auth.service.ts @@ -165,7 +165,14 @@ export class AuthService { if (captureLastUrl) { this.redirectUrl = this.router.url; } - this.clearJwtToken(); + this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true)) + .subscribe(() => { + this.clearJwtToken(); + }, + () => { + this.clearJwtToken(); + } + ); } private notifyUserLoaded(isUserLoaded: boolean) { diff --git a/ui-ngx/src/app/core/http/audit-log.service.ts b/ui-ngx/src/app/core/http/audit-log.service.ts new file mode 100644 index 0000000000..5c98d849e8 --- /dev/null +++ b/ui-ngx/src/app/core/http/audit-log.service.ts @@ -0,0 +1,59 @@ +/// +/// Copyright © 2016-2019 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { Injectable } from '@angular/core'; +import { defaultHttpOptions } from './http-utils'; +import { Observable } from 'rxjs/index'; +import { HttpClient } from '@angular/common/http'; +import { PageLink, TimePageLink } from '@shared/models/page/page-link'; +import { PageData } from '@shared/models/page/page-data'; +import { AuditLog } from '@shared/models/audit-log.models'; +import { EntityId } from '@shared/models/id/entity-id'; + +@Injectable({ + providedIn: 'root' +}) +export class AuditLogService { + + constructor( + private http: HttpClient + ) { } + + public getAuditLogs(pageLink: TimePageLink, + ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable> { + return this.http.get>(`/api/audit/logs${pageLink.toQuery()}`, + defaultHttpOptions(ignoreLoading, ignoreErrors)); + } + + public getAuditLogsByCustomerId(customerId: string, pageLink: TimePageLink, + ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable> { + return this.http.get>(`/api/audit/logs/customer/${customerId}${pageLink.toQuery()}`, + defaultHttpOptions(ignoreLoading, ignoreErrors)); + } + + public getAuditLogsByUserId(userId: string, pageLink: TimePageLink, + ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable> { + return this.http.get>(`/api/audit/logs/user/${userId}${pageLink.toQuery()}`, + defaultHttpOptions(ignoreLoading, ignoreErrors)); + } + + public getAuditLogsByEntityId(entityId: EntityId, pageLink: TimePageLink, + ignoreErrors: boolean = false, ignoreLoading: boolean = false): Observable> { + return this.http.get>(`/api/audit/logs/entity/${entityId.entityType}/${entityId.id}${pageLink.toQuery()}`, + defaultHttpOptions(ignoreLoading, ignoreErrors)); + } + +} diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.html b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.html new file mode 100644 index 0000000000..a07587a5b6 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.html @@ -0,0 +1,45 @@ + + +

audit-log.audit-log-details

+ + +
+
+ +
+
+ + +
+
+
+
+ + +
diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.scss b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.scss new file mode 100644 index 0000000000..7aedf2416a --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.scss @@ -0,0 +1,25 @@ +/** + * Copyright © 2016-2019 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:host { + .tb-audit-log-action-data, + .tb-audit-log-failure-details { + width: 100%; + min-width: 400px; + height: 100%; + min-height: 50px; + border: 1px solid #c0c0c0; + } +} diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.ts new file mode 100644 index 0000000000..4980c61b49 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-details-dialog.component.ts @@ -0,0 +1,124 @@ +/// +/// Copyright © 2016-2019 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + Component, + ElementRef, + Inject, + OnInit, + Renderer2, + ViewChild +} from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { PageComponent } from '@shared/components/page.component'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; +import { ActionStatus, AuditLog } from '@shared/models/audit-log.models'; + +import * as ace from 'ace-builds'; + +export interface AuditLogDetailsDialogData { + auditLog: AuditLog; +} + +@Component({ + selector: 'tb-audit-log-details-dialog', + templateUrl: './audit-log-details-dialog.component.html', + styleUrls: ['./audit-log-details-dialog.component.scss'] +}) +export class AuditLogDetailsDialogComponent extends PageComponent implements OnInit { + + @ViewChild('actionDataEditor', {static: true}) + actionDataEditorElmRef: ElementRef; + private actionDataEditor: ace.Ace.Editor; + + @ViewChild('failureDetailsEditor', {static: true}) + failureDetailsEditorElmRef: ElementRef; + private failureDetailsEditor: ace.Ace.Editor; + + auditLog: AuditLog; + displayFailureDetails: boolean; + actionData: string; + actionFailureDetails: string; + + @ViewChild('entityDetailsForm', {static: true}) entityDetailsFormAnchor: TbAnchorComponent; + + constructor(protected store: Store, + @Inject(MAT_DIALOG_DATA) public data: AuditLogDetailsDialogData, + public dialogRef: MatDialogRef, + private renderer: Renderer2) { + super(store); + } + + ngOnInit(): void { + this.auditLog = this.data.auditLog; + this.displayFailureDetails = this.auditLog.actionStatus === ActionStatus.FAILURE; + this.actionData = this.auditLog.actionData ? JSON.stringify(this.auditLog.actionData, null, 2) : ''; + this.actionFailureDetails = this.auditLog.actionFailureDetails; + + this.actionDataEditor = this.createEditor(this.actionDataEditorElmRef, this.actionData); + if (this.displayFailureDetails) { + this.failureDetailsEditor = this.createEditor(this.failureDetailsEditorElmRef, this.actionFailureDetails); + } + } + + createEditor(editorElementRef: ElementRef, content: string): ace.Ace.Editor { + const editorElement = editorElementRef.nativeElement; + let editorOptions: Partial = { + mode: 'ace/mode/java', + theme: 'ace/theme/github', + showGutter: false, + showPrintMargin: false, + readOnly: true + }; + + const advancedOptions = { + enableSnippets: false, + enableBasicAutocompletion: false, + enableLiveAutocompletion: false + }; + + editorOptions = {...editorOptions, ...advancedOptions}; + const editor = ace.edit(editorElement, editorOptions); + editor.session.setUseWrapMode(false); + editor.setValue(content, -1); + this.updateEditorSize(editorElement, content, editor); + return editor; + } + + updateEditorSize(editorElement: any, content: string, editor: ace.Ace.Editor) { + let newHeight = 200; + let newWidth = 600; + if (content && content.length > 0) { + const lines = content.split('\n'); + newHeight = 16 * lines.length + 16; + let maxLineLength = 0; + lines.forEach((row) => { + const line = row.replace(/\t/g, ' ').replace(/\n/g, ''); + const lineLength = line.length; + maxLineLength = Math.max(maxLineLength, lineLength); + }); + newWidth = 8 * maxLineLength + 16; + } + newHeight = Math.min(400, newHeight); + this.renderer.setStyle(editorElement, 'minHeight', newHeight.toString() + 'px'); + this.renderer.setStyle(editorElement, 'height', newHeight.toString() + 'px'); + this.renderer.setStyle(editorElement, 'width', newWidth.toString() + 'px'); + editor.resize(); + } + +} diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table-config.ts b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table-config.ts new file mode 100644 index 0000000000..26ad0f2edd --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table-config.ts @@ -0,0 +1,138 @@ +/// +/// Copyright © 2016-2019 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + DateEntityTableColumn, + EntityTableColumn, + EntityTableConfig +} from '@home/models/entity/entities-table-config.models'; +import { + actionStatusTranslations, + actionTypeTranslations, + AuditLog, + AuditLogMode +} from '@shared/models/audit-log.models'; +import { + EntityTypeResource, + EntityTypeTranslation, + entityTypeTranslations +} from '@shared/models/entity-type.models'; +import { AuditLogService } from '@core/http/audit-log.service'; +import { TranslateService } from '@ngx-translate/core'; +import { DatePipe } from '@angular/common'; +import { Direction } from '@shared/models/page/sort-order'; +import { MatDialog } from '@angular/material'; +import { PageLink, TimePageLink } from '@shared/models/page/page-link'; +import { Observable } from 'rxjs'; +import { PageData } from '@shared/models/page/page-data'; +import { EntityId } from '@shared/models/id/entity-id'; +import { UserId } from '@shared/models/id/user-id'; +import { CustomerId } from '@shared/models/id/customer-id'; +import { + AuditLogDetailsDialogComponent, + AuditLogDetailsDialogData +} from '@home/components/audit-log/audit-log-details-dialog.component'; + +export class AuditLogTableConfig extends EntityTableConfig { + + constructor(private auditLogService: AuditLogService, + private translate: TranslateService, + private datePipe: DatePipe, + private dialog: MatDialog, + private auditLogMode: AuditLogMode = AuditLogMode.TENANT, + public entityId: EntityId = null, + public userId: UserId = null, + public customerId: CustomerId = null, + updateOnInit = true) { + super(); + this.loadDataOnInit = updateOnInit; + this.tableTitle = ''; + this.useTimePageLink = true; + this.detailsPanelEnabled = false; + this.selectionEnabled = false; + this.searchEnabled = true; + this.addEnabled = false; + this.entitiesDeleteEnabled = false; + this.actionsColumnTitle = 'audit-log.details'; + this.entityTranslations = { + noEntities: 'audit-log.no-audit-logs-prompt', + search: 'audit-log.search' + }; + this.entityResources = { + } as EntityTypeResource; + + this.entitiesFetchFunction = pageLink => this.fetchAuditLogs(pageLink); + + this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC}; + + this.columns.push( + new DateEntityTableColumn('createdTime', 'audit-log.timestamp', this.datePipe, '150px')); + + if (this.auditLogMode !== AuditLogMode.ENTITY) { + this.columns.push( + new EntityTableColumn('entityType', 'audit-log.entity-type', '100%', + (entity) => translate.instant(entityTypeTranslations.get(entity.entityId.entityType).type)), + new EntityTableColumn('entityName', 'audit-log.entity-name'), + ); + } + + if (this.auditLogMode !== AuditLogMode.USER) { + this.columns.push( + new EntityTableColumn('userName', 'audit-log.user') + ); + } + + this.columns.push( + new EntityTableColumn('actionType', 'audit-log.type', '100%', + (entity) => translate.instant(actionTypeTranslations.get(entity.actionType))), + new EntityTableColumn('actionStatus', 'audit-log.status', '100%', + (entity) => translate.instant(actionStatusTranslations.get(entity.actionStatus))) + ); + + this.cellActionDescriptors.push( + { + name: this.translate.instant('audit-log.details'), + icon: 'more_horiz', + isEnabled: () => true, + onAction: ($event, entity) => this.showAuditLogDetails(entity) + } + ); + } + + fetchAuditLogs(pageLink: TimePageLink): Observable> { + switch (this.auditLogMode) { + case AuditLogMode.TENANT: + return this.auditLogService.getAuditLogs(pageLink); + case AuditLogMode.ENTITY: + return this.auditLogService.getAuditLogsByEntityId(this.entityId, pageLink); + case AuditLogMode.USER: + return this.auditLogService.getAuditLogsByUserId(this.userId.id, pageLink); + case AuditLogMode.CUSTOMER: + return this.auditLogService.getAuditLogsByCustomerId(this.customerId.id, pageLink); + } + } + + showAuditLogDetails(entity: AuditLog) { + this.dialog.open(AuditLogDetailsDialogComponent, { + disableClose: true, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + auditLog: entity + } + }); + } + +} diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.html b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.html new file mode 100644 index 0000000000..42d385746a --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.html @@ -0,0 +1,18 @@ + + diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.scss b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.scss new file mode 100644 index 0000000000..4108c47242 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.scss @@ -0,0 +1,22 @@ +/** + * Copyright © 2016-2019 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:host ::ng-deep { + tb-entities-table.tb-details-mode { + .mat-drawer-container { + background-color: white; + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.ts b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.ts new file mode 100644 index 0000000000..9913395e00 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/audit-log/audit-log-table.component.ts @@ -0,0 +1,133 @@ +/// +/// Copyright © 2016-2019 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { Component, Input, OnInit, ViewChild } from '@angular/core'; +import { AuditLogService } from '@core/http/audit-log.service'; +import { TranslateService } from '@ngx-translate/core'; +import { DatePipe } from '@angular/common'; +import { MatDialog } from '@angular/material'; +import { AuditLogMode } from '@shared/models/audit-log.models'; +import { EntityId } from '@shared/models/id/entity-id'; +import { UserId } from '@shared/models/id/user-id'; +import { CustomerId } from '@shared/models/id/customer-id'; +import { AuditLogTableConfig } from '@home/components/audit-log/audit-log-table-config'; +import { EntitiesTableComponent } from '@home/components/entity/entities-table.component'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { Authority } from '@shared/models/authority.enum'; +import { getCurrentAuthUser } from '@core/auth/auth.selectors'; + +@Component({ + selector: 'tb-audit-log-table', + templateUrl: './audit-log-table.component.html', + styleUrls: ['./audit-log-table.component.scss'] +}) +export class AuditLogTableComponent implements OnInit { + + @Input() + auditLogMode: AuditLogMode; + + @Input() + detailsMode: boolean; + + activeValue = false; + dirtyValue = false; + entityIdValue: EntityId; + userIdValue: UserId; + customerIdValue: CustomerId; + + @Input() + set active(active: boolean) { + if (this.activeValue !== active) { + this.activeValue = active; + if (this.activeValue && this.dirtyValue) { + this.dirtyValue = false; + this.entitiesTable.updateData(); + } + } + } + + @Input() + set entityId(entityId: EntityId) { + this.entityIdValue = entityId; + if (this.auditLogTableConfig && this.auditLogTableConfig.entityId !== entityId) { + this.auditLogTableConfig.entityId = entityId; + this.entitiesTable.resetSortAndFilter(this.activeValue); + if (!this.activeValue) { + this.dirtyValue = true; + } + } + } + + @Input() + set userId(userId: UserId) { + this.userIdValue = userId; + if (this.auditLogTableConfig && this.auditLogTableConfig.userId !== userId) { + this.auditLogTableConfig.userId = userId; + this.entitiesTable.resetSortAndFilter(this.activeValue); + if (!this.activeValue) { + this.dirtyValue = true; + } + } + } + + @Input() + set customerId(customerId: CustomerId) { + this.customerIdValue = customerId; + if (this.auditLogTableConfig && this.auditLogTableConfig.customerId !== customerId) { + this.auditLogTableConfig.customerId = customerId; + this.entitiesTable.resetSortAndFilter(this.activeValue); + if (!this.activeValue) { + this.dirtyValue = true; + } + } + } + + @ViewChild(EntitiesTableComponent, {static: true}) entitiesTable: EntitiesTableComponent; + + auditLogTableConfig: AuditLogTableConfig; + + constructor(private auditLogService: AuditLogService, + private translate: TranslateService, + private datePipe: DatePipe, + private dialog: MatDialog, + private store: Store) { + } + + ngOnInit() { + let updateOnInit = this.activeValue; + this.dirtyValue = !this.activeValue; + if (!this.auditLogMode) { + const authUser = getCurrentAuthUser(this.store); + if (authUser.authority === Authority.TENANT_ADMIN) { + this.auditLogMode = AuditLogMode.TENANT; + } + updateOnInit = true; + } + this.auditLogTableConfig = new AuditLogTableConfig( + this.auditLogService, + this.translate, + this.datePipe, + this.dialog, + this.auditLogMode, + this.entityIdValue, + this.userIdValue, + this.customerIdValue, + updateOnInit + ); + } + +} diff --git a/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html b/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html index 268ce79e41..adfe8f00a7 100644 --- a/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html +++ b/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html @@ -158,10 +158,10 @@ [ngStyle]="cellStyle(entity, column, row, col)"> - + {{ entitiesTableConfig.actionsColumnTitle ? (entitiesTableConfig.actionsColumnTitle | translate) : '' }} - +