source: Sources/frontend/src/app/admin-panel/admin-panel.component.ts

Last change on this file was 8423429, checked in by AngelNasev <angel.nasev@…>, 17 months ago

Add backend and frontend projects

  • Property mode set to 100644
File size: 2.4 KB
Line 
1import {Component, OnInit} from '@angular/core';
2import {HttpClient} from "@angular/common/http";
3import {forkJoin} from "rxjs";
4import {Query1Interface} from "../Query1Interface";
5import {AdminPanelService} from "../admin-panel.service";
6import {Query2Interface} from "../Query2Interface";
7import {Query3Interface} from "../Query3Interface";
8import {Query4Interface} from "../Query4Interface";
9import {Query5Interface} from "../Query5Interface";
10import {ActiveUserInterface} from "../ActiveUserInterface";
11import {Router} from "@angular/router";
12import {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})
19export 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}
Note: See TracBrowser for help on using the repository browser.