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
#5987)

* feat(Virtual Machine): Add information confirmation date and responsible person

* adjusted

* further work

* adjustments

* removed unneccessary this

---------

Co-authored-by: denbicloud <[email protected]>
  • Loading branch information
vktrrdk and denbicloud authored Jan 9, 2024
1 parent 5e49004 commit f91add6
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/api-connector/virtualmachine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export class VirtualmachineService {
}

setVmNeeded(openstack_id: string): Observable<any> {
return this.http.post<any>(`${this.baseVmUrl}${openstack_id}/need/`, null, {
return this.http.post<any>(`${this.baseVmUrl}${openstack_id}/need/`, {
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 All @@ -45,6 +46,8 @@ export class VirtualMachine {
days_running: number;
backend: Backend;
conda_packages: CondaPackage[] = [];
still_used_confirmed_date: Date;
// still used confirmed date missing in webapp!

migrate_project_to_simple_vm: boolean = false;
project_is_migrated_to_simple_vm: boolean = false;
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,40 @@
</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-success">
<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" *ngIf="userSurname && userName">
<div class="callout callout-success">
<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>
<!-- adjust in model, still_used_confirmed_date and set on successful response-->
<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,7 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import {
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 @@ -8,11 +11,53 @@ import { VirtualMachine } from '../../virtualmachinemodels/virtualmachine';
@Component({
selector: 'app-virtualmachineinfo',
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;
console.log(changedVM);
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();
});
}
}
}
}
5 changes: 4 additions & 1 deletion src/app/virtualmachines/vmdetail/vmdetail.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
Expand Down Expand Up @@ -177,6 +177,7 @@ export class VmDetailComponent extends AbstractBaseClass implements OnInit {
private biocondaService: BiocondaService,
private clipboardService: ClipboardService,
private groupService: GroupService,
private cdr: ChangeDetectorRef,
) {
super();
}
Expand Down Expand Up @@ -242,6 +243,8 @@ export class VmDetailComponent extends AbstractBaseClass implements OnInit {
this.virtualmachineService.setVmNeeded(this.virtualMachine.openstackid).subscribe((res: any): void => {
if (res['still_needed']) {
this.virtualMachine.still_used_confirmation_requested = false;
this.virtualMachine.still_used_confirmed_date = new Date();
this.cdr.detectChanges();
}
});
}
Expand Down

0 comments on commit f91add6

Please sign in to comment.