1 | import {Component, OnInit} from '@angular/core';
|
---|
2 | import {HttpClient} from "@angular/common/http";
|
---|
3 | import {forkJoin} from "rxjs";
|
---|
4 | import {Query1Interface} from "../Query1Interface";
|
---|
5 | import {AdminPanelService} from "../admin-panel.service";
|
---|
6 | import {Query2Interface} from "../Query2Interface";
|
---|
7 | import {Query3Interface} from "../Query3Interface";
|
---|
8 | import {Query4Interface} from "../Query4Interface";
|
---|
9 | import {Query5Interface} from "../Query5Interface";
|
---|
10 | import {ActiveUserInterface} from "../ActiveUserInterface";
|
---|
11 | import {Router} from "@angular/router";
|
---|
12 | import {LoginService} from "../login.service";
|
---|
13 |
|
---|
14 | @Component({
|
---|
15 | selector: 'app-admin-panel',
|
---|
16 | templateUrl: './admin-panel.component.html',
|
---|
17 | styleUrls: ['./admin-panel.component.css']
|
---|
18 | })
|
---|
19 | export class AdminPanelComponent implements OnInit {
|
---|
20 | query1: Query1Interface[] | undefined;
|
---|
21 | query2: Query2Interface[] | undefined;
|
---|
22 | query3: Query3Interface[] | undefined;
|
---|
23 | query4: Query4Interface[] | undefined;
|
---|
24 | query5: Query5Interface[] | undefined;
|
---|
25 | activeUser: ActiveUserInterface | undefined;
|
---|
26 |
|
---|
27 | constructor(private http: HttpClient, private service: AdminPanelService, private loginService: LoginService, private router: Router) { }
|
---|
28 |
|
---|
29 | ngOnInit():void {
|
---|
30 | this.activeUser = this.loginService.activeUser!!;
|
---|
31 | if (!this.activeUser) {
|
---|
32 | this.router.navigate(['/'])
|
---|
33 | }
|
---|
34 | forkJoin([
|
---|
35 | this.service.getFirstQuery(),
|
---|
36 | this.service.getSecondQuery(),
|
---|
37 | this.service.getThirdQuery(),
|
---|
38 | this.service.getFourthQuery(),
|
---|
39 | this.service.getFifthQuery(),
|
---|
40 | ]).subscribe(results => {
|
---|
41 | this.query1 = results[0];
|
---|
42 | this.query2 = results[1];
|
---|
43 | this.query3 = results[2];
|
---|
44 | this.query4 = results[3];
|
---|
45 | this.query5 = results[4];
|
---|
46 | });
|
---|
47 | }
|
---|
48 | formatInterval(interval: string) {
|
---|
49 | const match = interval.match(/(\d+) years (\d+) mons (\d+) days (\d+) hours (\d+) mins (\d+\.\d+) secs/);
|
---|
50 | if (!match) {
|
---|
51 | return interval;
|
---|
52 | }
|
---|
53 | const [, years, months, days, hours, minutes, seconds] = match;
|
---|
54 | const units = [
|
---|
55 | { value: years, unit: 'years' },
|
---|
56 | { value: months, unit: 'months' },
|
---|
57 | { value: days, unit: 'days' },
|
---|
58 | { value: hours, unit: 'hours' },
|
---|
59 | { value: minutes, unit: 'minutes' },
|
---|
60 | { value: seconds, unit: 'seconds' },
|
---|
61 | ];
|
---|
62 | const result: string[] = [];
|
---|
63 | units.forEach(({ value, unit }) => {
|
---|
64 | if (value !== '0') {
|
---|
65 | result.push(`${value} ${unit}`);
|
---|
66 | }
|
---|
67 | });
|
---|
68 | return result.join(', ');
|
---|
69 | }
|
---|
70 | }
|
---|