Skip to content

Commit 549fe72

Browse files
authored
Display error message if no suitable environment found during event creation (#134)
* Display error message if no suitable environment found during event creation * Removed imports * Display unavailable vmts * Remove logging * Reset page bug * Modify error message
1 parent 0216c08 commit 549fe72

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/app/event/new-scheduled-event/new-scheduled-event.component.html

+25-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,31 @@
209209
Please wait...
210210
</span>
211211
</ng-container>
212-
<ng-container *ngIf="!checkingEnvironments">
212+
<ng-container *ngIf="noEnvironmentsAvailable">
213+
<span>
214+
No suitable environments found.
215+
</span>
216+
</ng-container>
217+
<ng-container *ngIf="unavailableVMTs.length > 0">
218+
<span>
219+
No suitable environments found for the following VM Templates:
220+
</span>
221+
<thead>
222+
<tr>
223+
<th class="left">ID</th>
224+
</tr>
225+
</thead>
226+
<tbody [formGroup]="simpleModeVmCounts">
227+
<ng-container *ngFor="let vmt of unavailableVMTs;">
228+
<tr>
229+
<td class="left">
230+
{{vmt}}
231+
</td>
232+
</tr>
233+
</ng-container>
234+
</tbody>
235+
</ng-container>
236+
<ng-container *ngIf="!checkingEnvironments && !noEnvironmentsAvailable && unavailableVMTs.length == 0">
213237
<clr-datagrid [(clrDgSelected)]="selectedEnvironments">
214238
<clr-dg-column>
215239
<clr-icon shape="building"></clr-icon>&nbsp;Environment

src/app/event/new-scheduled-event/new-scheduled-event.component.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { ScenarioService } from "src/app/data/scenario.service";
1313
import { Course } from "src/app/data/course";
1414
import { CourseService } from "src/app/data/course.service";
1515
import { EnvironmentService } from "src/app/data/environment.service";
16-
import { combineAll, concatMap, map, filter } from "rxjs/operators";
16+
import { combineAll, concatMap, map, filter, defaultIfEmpty } from "rxjs/operators";
1717
import { Environment } from "src/app/data/environment";
18-
import { from, of } from "rxjs";
1918
import { EnvironmentAvailability } from "src/app/data/environmentavailability";
2019
import { ScheduledeventService } from "src/app/data/scheduledevent.service";
2120
import {
@@ -31,6 +30,7 @@ import {
3130
import { DlDateTimePickerChange } from "angular-bootstrap-datetimepicker";
3231
import { QuicksetValidator } from "src/app/validators/quickset.validator";
3332
import { RbacService } from 'src/app/data/rbac.service';
33+
import { of } from "rxjs";
3434

3535
@Component({
3636
selector: "new-scheduled-event",
@@ -58,6 +58,8 @@ export class NewScheduledEventComponent implements OnInit {
5858

5959
public availableEnvironments: EnvironmentAvailability[] = [];
6060
public checkingEnvironments: boolean = true;
61+
public noEnvironmentsAvailable: boolean = false;
62+
public unavailableVMTs: string[] = []
6163
public environments: Environment[] = [];
6264
public keyedEnvironments: Map<string, Environment> = new Map();
6365
public selectedEnvironments: EnvironmentAvailability[] = [];
@@ -563,6 +565,8 @@ export class NewScheduledEventComponent implements OnInit {
563565
// display those results
564566
public checkEnvironments() {
565567
this.checkingEnvironments = true;
568+
this.noEnvironmentsAvailable = false;
569+
this.unavailableVMTs = [];
566570
var templates: Map<string, boolean> = new Map();
567571

568572
// add all chosen templates to the list
@@ -586,7 +590,7 @@ export class NewScheduledEventComponent implements OnInit {
586590
.pipe(
587591
concatMap((e: Environment[]) => {
588592
this.environments = e;
589-
return from(e);
593+
return e
590594
}),
591595
filter((e: Environment) => {
592596
// first add to keyed environment, regardless of if we use it or not
@@ -611,11 +615,21 @@ export class NewScheduledEventComponent implements OnInit {
611615
map((ea: EnvironmentAvailability) => {
612616
return of(ea);
613617
}),
614-
combineAll()
618+
combineAll(),
619+
defaultIfEmpty([])
615620
)
616621
.subscribe((ea: EnvironmentAvailability[]) => {
617622
this.availableEnvironments = ea;
618623
this.checkingEnvironments = false;
624+
this.noEnvironmentsAvailable = ea.length == 0 ? true: false;
625+
626+
ea.forEach((e => {
627+
Object.keys(e.available_count).forEach(vmt => {
628+
templates.delete(vmt);
629+
})
630+
}))
631+
632+
this.unavailableVMTs = Array.from(templates.keys());
619633

620634
if (this.event) {
621635
// we are updating instead of creating new

0 commit comments

Comments
 (0)