From 3eaae69e2c1b5b530ac69f19936b1bb84338f37d Mon Sep 17 00:00:00 2001 From: vktrrdk Date: Wed, 20 Dec 2023 12:08:35 +0000 Subject: [PATCH] feat(Virtual Machine): Add information confirmation date and responsible person --- .../api-connector/virtualmachine.service.ts | 6 +- .../virtualmachinemodels/virtualmachine.ts | 1 + .../virtualmachineinfo.component.html | 35 ++++++++++- .../virtualmachineinfo.component.ts | 59 +++++++++++++++++-- .../vmdetail/vmdetail.component.ts | 20 +++++-- 5 files changed, 109 insertions(+), 12 deletions(-) diff --git a/src/app/api-connector/virtualmachine.service.ts b/src/app/api-connector/virtualmachine.service.ts index a6d8b8e71b..e533ef65a7 100644 --- a/src/app/api-connector/virtualmachine.service.ts +++ b/src/app/api-connector/virtualmachine.service.ts @@ -401,8 +401,10 @@ export class VirtualmachineService { .pipe(map((vm: VirtualMachine): VirtualMachine => new VirtualMachine(vm))); } - setVmNeeded(openstack_id: string): Observable { - return this.http.post(`${this.baseVmUrl}${openstack_id}/need/`, null, { + setVmNeeded(openstack_id: string, elixir_id: string): Observable { + const params: HttpParams = new HttpParams().set('user_elixir_id', elixir_id); + + return this.http.post(`${this.baseVmUrl}${openstack_id}/need/`, params, { withCredentials: true, }); } diff --git a/src/app/virtualmachines/virtualmachinemodels/virtualmachine.ts b/src/app/virtualmachines/virtualmachinemodels/virtualmachine.ts index f69ba22a4b..f83a9ed625 100644 --- a/src/app/virtualmachines/virtualmachinemodels/virtualmachine.ts +++ b/src/app/virtualmachines/virtualmachinemodels/virtualmachine.ts @@ -22,6 +22,7 @@ export class VirtualMachine { created_at_date: string; deleted_at_date: string; still_used_confirmation_requested_date: Date; + still_used_confirmed_user_id: string; stopped_at: string; elixir_id: string; fixed_ip: string; diff --git a/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.html b/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.html index 4ce3f08dea..99d1937196 100644 --- a/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.html +++ b/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.html @@ -28,7 +28,7 @@
Deleted at (d-m-y)
- {{ virtualMachine.deleted_at_date | date : 'dd-MM-yyyy' }} + {{ virtualMachine.deleted_at_date | date: 'dd-MM-yyyy' }}
@@ -53,6 +53,39 @@ +
+
+
+ Usage confirmation requested at (d-m-y)
+ {{ + virtualMachine.still_used_confirmation_requested_date | date: 'dd-MM-yyyy' + }} +
+
+ +
+
+ Usage confirmed at (d-m-y)
+ {{ virtualMachine.still_used_confirmed_date | date: 'dd-MM-yyyy' }} +
+
+
+
+ Usage confirmed by {{ virtualMachine.still_used_confirmed_user_id }}
+ {{ this.userSurname }}, {{ this.userName }} +
+
+
+ +
+
+ Usage confirmed at (d-m-y)
+ Usage not confirmed yet! +
+
+
+
diff --git a/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.ts b/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.ts index 0ec2a5b3ce..03bfd5b8c3 100644 --- a/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.ts +++ b/src/app/virtualmachines/vmdetail/virtualmachineinfo/virtualmachineinfo.component.ts @@ -1,4 +1,13 @@ -import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; +import { + ChangeDetectionStrategy, + Component, + Input, + OnChanges, + SimpleChanges, + OnInit, + ChangeDetectorRef, +} from '@angular/core'; +import { UserService } from 'app/api-connector/user.service'; import { VirtualMachineStates } from '../../virtualmachinemodels/virtualmachinestates'; import { VirtualMachine } from '../../virtualmachinemodels/virtualmachine'; @@ -10,9 +19,51 @@ import { VirtualMachine } from '../../virtualmachinemodels/virtualmachine'; templateUrl: './virtualmachineinfo.component.html', changeDetection: ChangeDetectionStrategy.OnPush, styleUrls: ['./virtualmachineinfo.component.scss'], + + providers: [UserService], }) -export class VirtualmachineinfoComponent { +export class VirtualmachineinfoComponent implements OnChanges, OnInit { VirtualMachineStates: VirtualMachineStates = new VirtualMachineStates(); - @Input() virtualMachine: VirtualMachine; - @Input() cluster_machine: boolean = false; + @Input() virtualMachine: VirtualMachine; + @Input() cluster_machine: boolean = false; + + userName: string = ''; + userSurname: string = ''; + + constructor( + private userService: UserService, + private changeDetectorRef: ChangeDetectorRef, + ) { + this.userService = userService; + this.changeDetectorRef = changeDetectorRef; + } + + ngOnInit(): void { + if (this.virtualMachine) { + if (this.virtualMachine.still_used_confirmed_user_id) { + this.userService + .getMemberDetailsByElixirId(this.virtualMachine.still_used_confirmed_user_id) + .subscribe((result: any) => { + this.userName = result['firstName']; + this.userSurname = result['lastName']; + this.changeDetectorRef.detectChanges(); + }); + } + } + } + + ngOnChanges(changes: SimpleChanges): void { + const { changedVM } = changes; + if (changedVM) { + if (changedVM['virtualMachine']['currentValue']['still_used_confirmed_user_id']) { + this.userService + .getMemberDetailsByElixirId(this.virtualMachine.still_used_confirmed_user_id) + .subscribe((result: any) => { + this.userName = result['firstName']; + this.userSurname = result['lastName']; + this.changeDetectorRef.detectChanges(); + }); + } + } + } } diff --git a/src/app/virtualmachines/vmdetail/vmdetail.component.ts b/src/app/virtualmachines/vmdetail/vmdetail.component.ts index 669dcb6832..b852106365 100644 --- a/src/app/virtualmachines/vmdetail/vmdetail.component.ts +++ b/src/app/virtualmachines/vmdetail/vmdetail.component.ts @@ -239,11 +239,21 @@ export class VmDetailComponent extends AbstractBaseClass implements OnInit { } setVmNeeded(): void { - this.virtualmachineService.setVmNeeded(this.virtualMachine.openstackid).subscribe((res: any): void => { - if (res['still_needed']) { - this.virtualMachine.still_used_confirmation_requested = false; - } - }); + this.userService.getLoggedUserElixirId().subscribe( + (result: any) => { + this.virtualmachineService + .setVmNeeded(this.virtualMachine.openstackid, result['elixir_id']) + .subscribe((res: any): void => { + if (res['still_needed']) { + this.virtualMachine.still_used_confirmation_requested = false; + } + }); + }, + (error: any) => { + console.log(error); + + }, + ); } checkVmVolumesStatus(): void {