Skip to content

Commit

Permalink
fix(Modification Requests): Adjusted handling for adjustments and add…
Browse files Browse the repository at this point in the history
…ed back-button on submit of adjustmnent, removed unneccessary resource information
  • Loading branch information
vktrrdk committed Jan 24, 2025
1 parent 6f9b8b1 commit 3afad0b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ModificationRequestComponent } from '../../projectmanagement/modals/mod
import { ConfirmationModalComponent } from '../../shared/modal/confirmation-modal.component'
import { ClientLimitsComponent } from '../../vo_manager/clients/modals/client-limits..component'
import { NotificationModalComponent } from '../../shared/modal/notification-modal'
import { ApplicationModification } from '../application_modification.model'

@Component({
selector: 'app-application-vo-actions',
Expand All @@ -38,6 +39,7 @@ export class ApplicationVoActionsComponent extends AbstractBaseClass implements
bsModalRef: BsModalRef
is_vo_admin: boolean = false
selectedComputeCenter: ComputecenterComponent
modificationAdjustment: ApplicationModification;

ngOnInit() {
this.is_vo_admin = is_vo
Expand Down Expand Up @@ -94,7 +96,8 @@ export class ApplicationVoActionsComponent extends AbstractBaseClass implements
showModificationAdjustmentModal() {
const initialState = {
project: this.application,
adjustment: true
adjustment: true,
preSavedAdjustment: this.modificationAdjustment,
}

this.bsModalRef = this.modalService.show(ModificationRequestComponent, {
Expand Down Expand Up @@ -423,6 +426,10 @@ export class ApplicationVoActionsComponent extends AbstractBaseClass implements
subscribeToBsModalRef(): void {
this.subscription.add(
this.bsModalRef.content.event.subscribe((result: any) => {
if ('backToInput' in result) {
this.modificationAdjustment = result['adjustedModification'];
this.showModificationAdjustmentModal();
}
let action = null
if ('action' in result) {
action = result['action']
Expand All @@ -433,9 +440,6 @@ export class ApplicationVoActionsComponent extends AbstractBaseClass implements
if (action === ConfirmationActions.APPROVE_MODIFICATION) {
this.approveModificationRequest()
}
if ('closed' in result) {
// this.switchApproveLocked(false);
}
if (action === ConfirmationActions.DECLINE_MODIFICATION) {
this.declineModificationRequest()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h6 class="col-md-8 form-control-label">
</i>
</div>
<div *ngIf="!flavorRetrievalInProgress; else flavorRetrievalSpinner" >
<div *ngFor="let flavor_name of getFlavorNamesByType(flavorType)" class="form-group row my-4">
<div *ngFor="let flavor_name of getFlavorNamesByType(flavorType)" class="form-group row my-4 py-2">
<div class="col-4">
<label class="text-muted" for="{{ flavor_name }}_old">
<strong>{{ flavor_name }}</strong>
Expand Down Expand Up @@ -78,7 +78,7 @@ <h6 class="col-md-8 form-control-label">
<ng-container
*ngFor="let flavor_instance of shown_flavors[flavorType.long_name][flavor_name]; let i = index"
>
<ng-container *ngIf="shown_flavors[flavorType.long_name][flavor_name].length > 1; else elseFlavorBlock">
<ng-container>
<ng-container *ngIf="flavor_instance.disabled">
<div class="col-4">
<div class="input-group">
Expand Down Expand Up @@ -148,49 +148,6 @@ <h6 class="col-md-8 form-control-label">
</div>
</ng-container>
</ng-container>
<ng-template #elseFlavorBlock>
<div [ngClass]="adjustment ? 'col-4' : 'col-8'">
<div class="input-group">
<input
class="form-control"
[name]="adjustment ? flavor_instance.name + '_requested' : flavor_instance.name"
id="{{ flavor_instance.name }}"
type="number"
min="0"
step="1"
[disabled]="adjustment"
attr.data-test-id="{{ flavor_instance.type.shortcut + '_' + i }}"
placeholder="e.g 1"
[ngModel]="
adjustment
? (project.project_modification_request | flavorCounter: flavor_instance)
: (temp_project_modification | flavorCounter: flavor_instance)
"
#name="ngModel"
(change)="checkFlavorPairs(flavor_instance, $event)"
[attr.appMinAmount]="adjustment ? null : 0"
[attr.appInteger]="adjustment ? null : true"
value="{{
adjustment
? (project.project_modification_request | flavorCounter: flavor_instance)
: (temp_project_modification | flavorCounter: flavor_instance)
}}"
[attr.readonly]="flavor_instance.disabled || adjustment ? true : null"
aria-describedby="{{ flavor_instance.name }}_help"
[ngClass]="{
'is-invalid': name?.invalid && !adjustment,
'is-valid': name?.valid && !adjustment,
}"
/>
</div>
<div id="{{ flavor_instance.name }}_help" class="form-text text-muted" *ngIf="!adjustment">
Number of VMs you would like to run in the future
</div>
<div id="{{ flavor_instance.name }}_help" class="form-text text-muted" *ngIf="adjustment">
Number of VMs the user would like to run in the future
</div>
</div>
</ng-template>
</ng-container>
<ng-container *ngIf="adjustment">
<div *ngIf="shown_flavors[flavorType.long_name][flavor_name].length > 1" class="col-4"></div>
Expand Down Expand Up @@ -733,22 +690,7 @@ <h6 class="col-md-8 form-control-label">
>, so we may calculate and set the correct amount for your project.
</strong>
</div>
<div class="form-group row">
<label id="total_cores_label" class="col-md-8">
<strong
>Total number of cores (old | new): {{ project.project_application_total_cores }} |
{{ temp_project_modification.total_cores }}</strong
>
</label>
</div>
<div class="form-group row">
<label id="total_ram_label" class="col-md-8">
<strong
>Total amount of RAM (old | new): {{ project.project_application_total_ram }} |
{{ temp_project_modification.total_ram }} GB</strong
>
</label>
</div>

</form>

<div *ngIf="modificationForm.invalid || !min_vm" class="alert alert-warning" role="alert">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class ModificationRequestComponent implements OnInit, OnDestroy {

project: Application
preSavedModification: ApplicationModification;
preSavedAdjustment: ApplicationModification;
temp_project_modification: ApplicationModification

adjusted_project_modification: ApplicationModification
Expand Down Expand Up @@ -155,21 +156,47 @@ export class ModificationRequestComponent implements OnInit, OnDestroy {
this.shown_flavors[mod_flavor.type.long_name][mod_flavor.name].push(mod_flavor);
this.shown_flavors[disabled_flavor.type.long_name][disabled_flavor.name].push(disabled_flavor)
this.temp_project_modification.flavors.push(mod_flavor)

} else {
// else in shown_flavors, may be different than old one
this.shown_flavors[flavor.type.long_name][flavor.name][idx].counter = flavor.counter;
const mod_flavor: Flavor = new Flavor(this.shown_flavors[flavor.type.long_name][flavor.name][idx])
this.temp_project_modification.flavors.push(mod_flavor)
this.shown_flavors[mod_flavor.type.long_name][mod_flavor.name].splice(idx, 0, mod_flavor)
this.shown_flavors[mod_flavor.type.long_name][mod_flavor.name][idx].setDisabled(true);

}
}
this.buildMissingFlavorPairs();

if (this.preSavedModification) {
this.temp_project_modification = new ApplicationModification(this.preSavedModification);
}
if (this.preSavedAdjustment) {
this.adjusted_project_modification = new ApplicationModification(this.preSavedAdjustment);
}
this.temp_project_modification.calculateRamCores()
}

buildMissingFlavorPairs(): void {
let copyOfShownFlavors: ShownFlavors = this.shown_flavors;

for (const flavorType of Object.keys(copyOfShownFlavors)) {
for (const flavorName of Object.keys(copyOfShownFlavors[flavorType])) {
let tempFlavors: Flavor[] = copyOfShownFlavors[flavorType][flavorName];
if (tempFlavors.length === 1) {
let generatedFlavor: Flavor = new Flavor(tempFlavors[0]);
generatedFlavor.setDisabled(!generatedFlavor.disabled);
if (generatedFlavor.disabled) {
this.shown_flavors[flavorType][flavorName].unshift(generatedFlavor);
} else {
this.shown_flavors[flavorType][flavorName].push(generatedFlavor);
}
}
}
}
}

checkFlavorPairs(flavor: Flavor, event: any): void {
const amount: number = Number(event.target.value)
const idx: number = this.temp_project_modification.flavors.findIndex(
Expand Down Expand Up @@ -328,12 +355,22 @@ export class ModificationRequestComponent implements OnInit, OnDestroy {
this.event.emit({ reload: true })
}
} else if ('enterData' in result) {
this.event.emit(
{
backToInput: true,
modification: this.temp_project_modification,
}
)
if (adjustment) {
this.event.emit(
{
backToInput: true,
adjustedModification: this.adjusted_project_modification,
}
)
} else {
this.event.emit(
{
backToInput: true,
modification: this.temp_project_modification,
}
)
}

} else {
this.event.emit({ reload: false })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h4 class="modal-title">{{ project?.project_application_shortname }}</h4>
</button>

<button
*ngIf="modificationExtension && !adjustedModification"
*ngIf="modificationExtension"
class="btn btn-primary col-md-3"
type="reset"
(click)="bsModalRef.hide(); chainDataInput()"
Expand Down

0 comments on commit 3afad0b

Please sign in to comment.