1 import { Component, OnDestroy, OnInit } from '@angular/core';
3 import { LogsService } from '../../../shared/api/logs.service';
7 templateUrl: './logs.component.html',
8 styleUrls: ['./logs.component.scss']
10 export class LogsComponent implements OnInit, OnDestroy {
13 audit_log: Array<any>;
17 dateInputFormat: 'YYYY-MM-DD',
18 containerClass: 'theme-default'
20 prioritys: Array<{ name: string; value: string }> = [
21 { name: 'Info', value: '[INF]' },
22 { name: 'Warning', value: '[WRN]' },
23 { name: 'Error', value: '[ERR]' },
24 { name: 'All', value: 'All' }
29 startTime: Date = new Date();
30 endTime: Date = new Date();
31 constructor(private logsService: LogsService) {
32 this.startTime.setHours(0, 0);
33 this.endTime.setHours(23, 59);
38 this.interval = window.setInterval(() => {
44 clearInterval(this.interval);
48 this.logsService.getLogs().subscribe((data: any) => {
49 this.contentData = data;
54 abstractfilters(): any {
55 const priority = this.priority;
56 const key = this.search.toLowerCase().replace(/,/g, '');
58 let yearMonthDay: string;
59 if (this.selectedDate) {
60 const m = this.selectedDate.getMonth() + 1;
61 const d = this.selectedDate.getDate();
63 const year = this.selectedDate.getFullYear().toString();
64 const month = m <= 9 ? `0${m}` : `${m}`;
65 const day = d <= 9 ? `0${d}` : `${d}`;
66 yearMonthDay = `${year}-${month}-${day}`;
71 const sHour = this.startTime ? this.startTime.getHours() : 0;
72 const sMinutes = this.startTime ? this.startTime.getMinutes() : 0;
73 const sTime = sHour * 60 + sMinutes;
75 const eHour = this.endTime ? this.endTime.getHours() : 23;
76 const eMinutes = this.endTime ? this.endTime.getMinutes() : 59;
77 const eTime = eHour * 60 + eMinutes;
79 return { priority, key, yearMonthDay, sTime, eTime };
82 filterExecutor(logs: Array<any>, filters: any): Array<any> {
83 return logs.filter((line) => {
84 const hour = parseInt(line.stamp.slice(11, 13), 10);
85 const minutes = parseInt(line.stamp.slice(14, 16), 10);
86 let prio: string, y_m_d: string, timeSpan: number;
88 prio = filters.priority === 'All' ? line.priority : filters.priority;
89 y_m_d = filters.yearMonthDay ? filters.yearMonthDay : line.stamp;
90 timeSpan = hour * 60 + minutes;
92 line.priority === prio &&
93 line.message.toLowerCase().indexOf(filters.key) !== -1 &&
94 line.stamp.indexOf(y_m_d) !== -1 &&
95 timeSpan >= filters.sTime &&
96 timeSpan <= filters.eTime
102 const filters = this.abstractfilters();
103 this.clog = this.filterExecutor(this.contentData.clog, filters);
104 this.audit_log = this.filterExecutor(this.contentData.audit_log, filters);
112 this.selectedDate = null;