-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathaudit.component.ts
More file actions
146 lines (133 loc) · 4.81 KB
/
Copy pathaudit.component.ts
File metadata and controls
146 lines (133 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { AsyncPipe, NgClass, NgForOf, NgIf } from '@angular/common';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Subscription, merge } from 'rxjs';
import { take, tap } from 'rxjs/operators';
import { Angulartics2OnModule } from 'angulartics2';
import { AuditDataSource } from './audit-data-source';
import { BannerComponent } from '../ui-components/banner/banner.component';
import { CompanyService } from 'src/app/services/company.service';
import { ConnectionsService } from 'src/app/services/connections.service';
import { FormsModule } from '@angular/forms';
import { InfoDialogComponent } from './info-dialog/info-dialog.component';
import { Log } from 'src/app/models/logs';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatPaginator } from '@angular/material/paginator';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatSelectModule } from '@angular/material/select';
import { MatTableModule } from '@angular/material/table';
import { PlaceholderTableDataComponent } from '../skeletons/placeholder-table-data/placeholder-table-data.component';
import { RouterModule } from '@angular/router';
import { ServerError } from 'src/app/models/alert';
import { TableProperties } from 'src/app/models/table';
import { TablesService } from 'src/app/services/tables.service';
import { Title } from '@angular/platform-browser';
import { User } from '@sentry/angular-ivy';
import { UsersService } from 'src/app/services/users.service';
import { environment } from 'src/environments/environment';
import { normalizeTableName } from 'src/app/lib/normalize';
@Component({
selector: 'app-audit',
standalone: true,
imports: [
NgIf,
NgForOf,
NgClass,
AsyncPipe,
MatFormFieldModule,
MatSelectModule,
MatButtonModule,
MatTableModule,
MatPaginatorModule,
FormsModule,
RouterModule,
Angulartics2OnModule,
BannerComponent,
PlaceholderTableDataComponent
],
templateUrl: './audit.component.html',
styleUrls: ['./audit.component.css']
})
export class AuditComponent implements OnInit {
public isSaas = (environment as any).saas;
public connectionID: string;
public accesLevel: string;
public columns: string[];
public dataColumns: string[];
public tablesList: TableProperties[] = null;
public tableName: string = 'showAll';
public usersList: User[];
public userEmail: string = 'showAll';
public isServerError: boolean = false;
public serverError: ServerError;
public noTablesError: boolean = false;
public dataSource: AuditDataSource = null;
private getTitleSubscription: Subscription;
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor(
private _connections: ConnectionsService,
private _tables: TablesService,
private _users: UsersService,
private _companyService: CompanyService,
public dialog: MatDialog,
private title: Title
) { }
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
merge(this.paginator.page)
.pipe(
tap(() => this.loadLogsPage())
)
.subscribe();
}
ngOnInit(): void {
this._companyService.getCurrentTabTitle()
.pipe(take(1))
.subscribe(tabTitle => {
this.title.setTitle(`Connections | ${tabTitle || 'Rocketadmin'}`);
});
this.connectionID = this._connections.currentConnectionID;
this.accesLevel = this._connections.currentConnectionAccessLevel;
this.columns = ['Table', 'User', 'Action', 'Date', 'Status', 'Details'];
this.dataColumns = ['Table', 'User', 'Action', 'Date', 'Status'];
this.dataSource = new AuditDataSource(this._connections);
this.loadLogsPage();
this._tables.fetchTables(this.connectionID)
.subscribe(
res => {
if (res.length) {
this.tablesList = res.map((tableItem: TableProperties) => {
if (tableItem.display_name) return {...tableItem}
else return {...tableItem, normalizedTableName: normalizeTableName(tableItem.table)}
});
};
this.noTablesError = (res.length === 0)
},
(err) => {
this.isServerError = true;
this.serverError = {abstract: err.error.message, details: err.error.originalMessage};
})
if (this.accesLevel !== 'none') this._users.fetchConnectionUsers(this.connectionID)
.subscribe(res => {
this.usersList = res;
})
}
loadLogsPage() {
this.dataSource.fetchLogs({
connectionID: this.connectionID,
tableName: this.tableName,
userEmail: this.userEmail
});
}
openInfoLogDialog(log: Log) {
this.dialog.open(InfoDialogComponent, {
width: '50em',
data: log
})
}
openIntercome() {
// @ts-ignore
Intercom('show');
}
}