Skip to content

Commit

Permalink
feat(Virtual Machine): Add information confirmation date and responsi…
Browse files Browse the repository at this point in the history
…ble person
  • Loading branch information
vktrrdk committed Dec 20, 2023
1 parent d06c9e7 commit 3eaae69
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/app/api-connector/virtualmachine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ export class VirtualmachineService {
.pipe(map((vm: VirtualMachine): VirtualMachine => new VirtualMachine(vm)));
}

setVmNeeded(openstack_id: string): Observable<any> {
return this.http.post<any>(`${this.baseVmUrl}${openstack_id}/need/`, null, {
setVmNeeded(openstack_id: string, elixir_id: string): Observable<any> {
const params: HttpParams = new HttpParams().set('user_elixir_id', elixir_id);

return this.http.post<any>(`${this.baseVmUrl}${openstack_id}/need/`, params, {
withCredentials: true,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ng-container *ngSwitchCase="VirtualMachineStates.staticDELETED">
<div class="callout callout-danger">
<small class="text-muted">Deleted at (d-m-y)</small><br />
<strong class="text-muted">{{ virtualMachine.deleted_at_date | date : 'dd-MM-yyyy' }}</strong>
<strong class="text-muted">{{ virtualMachine.deleted_at_date | date: 'dd-MM-yyyy' }}</strong>
</div>
</ng-container>
<ng-container *ngSwitchDefault>
Expand All @@ -53,6 +53,39 @@
</div>
</div>
</div>
<div class="row" *ngIf="virtualMachine.still_used_confirmation_requested_date">
<div class="col-3">
<div class="callout callout-info">
<small class="text-muted">Usage confirmation requested at (d-m-y)</small><br />
<strong class="text-muted">{{
virtualMachine.still_used_confirmation_requested_date | date: 'dd-MM-yyyy'
}}</strong>
</div>
</div>
<ng-container *ngIf="virtualMachine.still_used_confirmed_date">
<div class="col-3">
<div class="callout callout-info">
<small class="text-muted">Usage confirmed at (d-m-y)</small><br />
<strong class="text-muted">{{ virtualMachine.still_used_confirmed_date | date: 'dd-MM-yyyy' }}</strong>
</div>
</div>
<div class="col-6">
<div class="callout callout-info">
<small class="text-muted">Usage confirmed by {{ virtualMachine.still_used_confirmed_user_id }}</small
><br />
<strong class="text-muted">{{ this.userSurname }}, {{ this.userName }}</strong>
</div>
</div>
</ng-container>
<ng-container *ngIf="!virtualMachine.still_used_confirmed_date">
<div class="col-6">
<div class="callout callout-danger">
<small class="text-muted">Usage confirmed at (d-m-y)</small><br />
<strong class="text-muted">Usage not confirmed yet!</strong>
</div>
</div>
</ng-container>
</div>
<div class="row">
<div class="col-3">
<div class="callout">
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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();
});
}
}
}
}
20 changes: 15 additions & 5 deletions src/app/virtualmachines/vmdetail/vmdetail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3eaae69

Please sign in to comment.