Skip to content

Commit

Permalink
Content only scenarios in admin-ui (#198)
Browse files Browse the repository at this point in the history
* Content only scenarios in admin-ui

* edit scenario wizard to enable creating content-only scenarios

* spelling

* Add content-only courses
  • Loading branch information
jggoebel authored Apr 4, 2024
1 parent 9bc1bd8 commit d492925
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 213 deletions.
159 changes: 112 additions & 47 deletions src/app/course/course-wizard/course-wizard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,52 @@
</clr-wizard-page>

<clr-wizard-page
(clrWizardPageNext)="saveCourseWizard()"
[clrWizardPageNextDisabled]="
!VMAllowNext || editVirtualMachines.length == 0
courseHasAtLeastOneVMSet() && !courseHasValidVMCConfiguration()
"
(clrWizardPageNext)="saveCourseWizard()"
>
<ng-template clrPageTitle>Virtual Machine</ng-template>
<div
class="alert alert-warning"
role="alert"
*ngIf="!courseHasAtLeastOneVMSet()"
>
<div class="alert-items">
<div class="alert-item static">
<div class="alert-icon-wrapper">
<cds-icon
class="alert-icon"
shape="exclamation-triangle"
></cds-icon>
</div>
<span class="alert-text"
>This Course will be a content-only course until you configure a
VirtualMachine</span
>
</div>
</div>
</div>
<div
class="alert alert-warning"
role="alert"
*ngIf="courseHasAtLeastOneVMSet() && !courseHasValidVMCConfiguration()"
>
<div class="alert-items">
<div class="alert-item static">
<div class="alert-icon-wrapper">
<cds-icon
class="alert-icon"
shape="exclamation-triangle"
></cds-icon>
</div>
<span class="alert-text"
>There are invalid VirtualMachineSets. No Empty VMSets
allowed.</span
>
</div>
</div>
</div>
<ng-template clrPageTitle>Virtual Machines</ng-template>
<vmset
#virtualmachine
Expand Down Expand Up @@ -317,6 +358,26 @@
<ng-template clrPageTitle>Finalize</ng-template>
<p>Confirm the following details before finishing</p>
<h4>Course</h4>
<div
class="alert alert-warning"
role="alert"
*ngIf="!courseHasAtLeastOneVMSet()"
>
<div class="alert-items">
<div class="alert-item static">
<div class="alert-icon-wrapper">
<cds-icon
class="alert-icon"
shape="exclamation-triangle"
></cds-icon>
</div>
<span class="alert-text"
>This Course will be a content-only course until you configure a
VirtualMachine</span
>
</div>
</div>
</div>
<table class="table table-compact" *ngIf="selectedCourse">
<thead>
<tr>
Expand Down Expand Up @@ -467,52 +528,56 @@ <h4>Course</h4>
</tr>
</tbody>
</table>
<h4>VM Information</h4>
<table class="table table-compact">
<thead>
<tr>
<th>VM Name</th>
<th>VM Template</th>
</tr>
</thead>
<tbody>
<ng-container
*ngFor="let i of editSelectedCourse.virtualmachines | keyvalue"
>
<tr *ngFor="let q of showVM(i.value) | keyvalue">
<!-- view of unedit value -->
<ng-container *ngIf="getSelectedCourseVM(i.key, q.key) != 0">
<td>{{ q.key }}</td>
</ng-container>
<ng-container *ngIf="getSelectedCourseVM(i.key, q.key) == q.value">
<td>{{ q.value }}</td>
</ng-container>
<!-- view of new key -->
<ng-container *ngIf="getSelectedCourseVM(i.key, q.key) === 0">
<td class="add-elem">{{ q.key }}</td>
<td class="add-elem">{{ q.value }}</td>
</ng-container>
<!-- view of edit value (delete VM and create VM with the same VM Name) -->
<ng-container *ngIf="isEditedVM(i.key, q.key, q.value)">
<td class="add-elem">{{ q.value }}</td>
</ng-container>
</tr>
</ng-container>
<!-- view deleted key -->
<ng-container
*ngFor="let i of selectedCourse.virtualmachines | keyvalue"
>
<tr *ngFor="let q of showVM(i.value) | keyvalue">
<ng-container
*ngIf="getEditSelectedCourseVM(i.key, q.key) != q.value"
>
<td class="del-elem">{{ q.key }}</td>
<td class="del-elem">{{ q.value }}</td>
</ng-container>
<ng-container *ngIf="courseHasAtLeastOneVMSet()">
<h4>VM Information</h4>
<table class="table table-compact">
<thead>
<tr>
<th>VM Name</th>
<th>VM Template</th>
</tr>
</ng-container>
</tbody>
</table>
</thead>
<tbody>
<ng-container
*ngFor="let i of editSelectedCourse.virtualmachines | keyvalue"
>
<tr *ngFor="let q of showVM(i.value) | keyvalue">
<!-- view of unedit value -->
<ng-container *ngIf="getSelectedCourseVM(i.key, q.key) != 0">
<td>{{ q.key }}</td>
</ng-container>
<ng-container
*ngIf="getSelectedCourseVM(i.key, q.key) == q.value"
>
<td>{{ q.value }}</td>
</ng-container>
<!-- view of new key -->
<ng-container *ngIf="getSelectedCourseVM(i.key, q.key) === 0">
<td class="add-elem">{{ q.key }}</td>
<td class="add-elem">{{ q.value }}</td>
</ng-container>
<!-- view of edit value (delete VM and create VM with the same VM Name) -->
<ng-container *ngIf="isEditedVM(i.key, q.key, q.value)">
<td class="add-elem">{{ q.value }}</td>
</ng-container>
</tr>
</ng-container>
<!-- view deleted key -->
<ng-container
*ngFor="let i of selectedCourse.virtualmachines | keyvalue"
>
<tr *ngFor="let q of showVM(i.value) | keyvalue">
<ng-container
*ngIf="getEditSelectedCourseVM(i.key, q.key) != q.value"
>
<td class="del-elem">{{ q.key }}</td>
<td class="del-elem">{{ q.value }}</td>
</ng-container>
</tr>
</ng-container>
</tbody>
</table>
</ng-container>
</clr-wizard-page>
</clr-wizard>
<add-scenario
Expand Down
88 changes: 56 additions & 32 deletions src/app/course/course-wizard/course-wizard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class CourseWizardComponent implements OnChanges, OnInit {
public isFormValid: boolean = false;
public newCategory: boolean = false;
public courseDetailsActive: boolean = false;
public VMAllowNext: boolean = false;
public seeExamples: boolean = false;
public newCourseOpen: boolean = false;
public modified: boolean = false;
Expand Down Expand Up @@ -149,19 +148,33 @@ export class CourseWizardComponent implements OnChanges, OnInit {
this.wizard.reset();
this.wizard.open();
}
VMSAllow() {
if(this.editVirtualMachines.length!=0){
if (Object.keys(this.editVirtualMachines[0]).length !== 0)
this.VMAllowNext = true;
if (Object.keys(this.editVirtualMachines[0]).length == 0)
this.VMAllowNext = false;

courseHasAtLeastOneVMSet(): boolean {
return this.editVirtualMachines.length > 0;
}

courseHasValidVMCConfiguration(): boolean {
console.log(this.editVirtualMachines);
if (this.editVirtualMachines.length > 0) {
const validVMSets = this.editVirtualMachines.filter(
(virtualmachine, i) => {
if (Object.keys(virtualmachine).length > 0) {
return true;
}
return false;
}
);
if (validVMSets.length == this.editVirtualMachines.length) {
return true;
}
}
return false;
}

openEditCourse(course: Course) {
this.wizard.reset();
this.selectedCourse = course;
this.editCourse(course);
this.VMSAllow();
this.wizard.open();
this.wizard.navService.goTo(this.wizard.pages.last, true);
this.wizard.pages.first.makeCurrent();
Expand Down Expand Up @@ -202,20 +215,19 @@ export class CourseWizardComponent implements OnChanges, OnInit {
course.categories = this.editCategories;
}
newCourseWizard() {
this.setCourseValues(this.course)
this.setCourseValues(this.course);
}
updateCourseWizard() {
this.setCourseValues(this.selectedCourse)
}
updateFinalPageWizard() {
if (this.wizardCourse == 'edit'){
this.setCourseValues(this.editSelectedCourse)
this.setCourseValues(this.selectedCourse);
}
updateFinalPageWizard() {
if (this.wizardCourse == 'edit') {
this.setCourseValues(this.editSelectedCourse);
}
}

setVM(vms: {}[]) {
this.editVirtualMachines = vms;
this.VMSAllow();
this.setModified();
}
setModified() {
Expand Down Expand Up @@ -304,9 +316,8 @@ export class CourseWizardComponent implements OnChanges, OnInit {
}

whenFinish() {

if (this.wizardCourse == 'create') this.createCourse();
if (this.wizardCourse == 'edit') {
if (this.wizardCourse == 'edit') {
this.updateCourseWizard();
this.updateCourse();
}
Expand Down Expand Up @@ -348,32 +359,45 @@ export class CourseWizardComponent implements OnChanges, OnInit {
this.isAlert = true;
}
);
}
}

getSelectedCourseVM(index: any, vmname: any) {
const selectedCourseVMs = this.showVM( this.selectedCourse.virtualmachines[index])
return selectedCourseVMs.has(vmname) ? selectedCourseVMs.get(vmname) : 0;
getSelectedCourseVM(index: any, vmname: any) {
const selectedCourseVMs = this.showVM(
this.selectedCourse.virtualmachines[index]
);
return selectedCourseVMs.has(vmname) ? selectedCourseVMs.get(vmname) : 0;
}

getEditSelectedCourseVM(index: any, vmname: any) {
const editSelectedCourseVMs = this.showVM( this.editSelectedCourse.virtualmachines[index])
return editSelectedCourseVMs.has(vmname) ? editSelectedCourseVMs.get(vmname) : 0;
getEditSelectedCourseVM(index: any, vmname: any) {
const editSelectedCourseVMs = this.showVM(
this.editSelectedCourse.virtualmachines[index]
);
return editSelectedCourseVMs.has(vmname)
? editSelectedCourseVMs.get(vmname)
: 0;
}

showVM(vms: any) {
return new Map(Object.entries(JSON.parse(JSON.stringify(vms) )))
showVM(vms: any) {
if(!vms){
return new Map();
}
return new Map(Object.entries(JSON.parse(JSON.stringify(vms))));
}

isScenarioInList(scenario: Scenario, list?: Scenario[]): boolean {
return list.some(item => item.name === scenario.name);
isScenarioInList(scenario: Scenario, list?: Scenario[]): boolean {
return list.some((item) => item.name === scenario.name);
}

isEditedVM(index: any, vmname: string, templateName: any): boolean {
// This function determines if the currently selected VM is either beeing edited throug the following condition:
const isEdited = this.getSelectedCourseVM(index, vmname) != templateName && this.getSelectedCourseVM(index, vmname) != 0
const isEdited =
this.getSelectedCourseVM(index, vmname) != templateName &&
this.getSelectedCourseVM(index, vmname) != 0;
// ... or if it was deleted and created again with the same vm name through the following condition:
const deletedAndCreatedWithSameName = this.getSelectedCourseVM(index, vmname) === 0 && this.getEditSelectedCourseVM(index, vmname) != templateName
const deletedAndCreatedWithSameName =
this.getSelectedCourseVM(index, vmname) === 0 &&
this.getEditSelectedCourseVM(index, vmname) != templateName;
// this.getSelectedCourseVM(index, vmname) != templateName && this.getSelectedCourseVM(index, vmname) != 0
return isEdited || deletedAndCreatedWithSameName
return isEdited || deletedAndCreatedWithSameName;
}
}
Loading

0 comments on commit d492925

Please sign in to comment.