Skip to content

Refactoring course #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 16, 2023
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ import { TypedInputComponent } from './typed-form/typed-input.component';
import { TypedInputFieldComponent } from './typed-form/typed-input-field.component';
import { TypedSettingsService } from './data/typedSettings.service';
import { OTACManagementComponent } from './event/otacmanagement/otacmanagement.component';
import { CourseWizardComponent } from './course/course-wizard/course-wizard.component';
import { CourseDetailsComponent } from './course/course-details/course-details.component';

const appInitializerFn = (appConfig: AppConfigService) => {
return () => {
Expand Down Expand Up @@ -130,6 +132,7 @@ export function jwtOptionsFactory() {
EditEnvironmentComponent,
ContentComponent,
CourseComponent,
CourseDetailsComponent,
NewCourseComponent,
CourseFormComponent,
AddScenarioComponent,
Expand Down Expand Up @@ -175,6 +178,7 @@ export function jwtOptionsFactory() {
TypedInputFieldComponent,
SettingsComponent,
OTACManagementComponent,
CourseWizardComponent,
],
imports: [
BrowserModule,
Expand Down
52 changes: 52 additions & 0 deletions src/app/course/course-details/course-details.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<div>
<clr-stack-view>
<clr-stack-block>
<clr-stack-label>Basic Information</clr-stack-label>
<clr-stack-block>
<clr-stack-label class="stackbox-header">Option</clr-stack-label>
<clr-stack-content class="stackbox-header">Value</clr-stack-content>
</clr-stack-block>
<clr-stack-block>
<clr-stack-label>Name</clr-stack-label>
<clr-stack-content>{{ course.name }}</clr-stack-content>
</clr-stack-block>
<clr-stack-block>
<clr-stack-label>Description</clr-stack-label>
<clr-stack-content>{{ course.description }}</clr-stack-content>
</clr-stack-block>
<clr-stack-block>
<clr-stack-label>Keepalive Duration</clr-stack-label>
<clr-stack-content>{{ course.keepalive_duration }}</clr-stack-content>
</clr-stack-block>
<clr-stack-block>
<clr-stack-label>Pause Duration</clr-stack-label>
<clr-stack-content>{{ course.pause_duration }}</clr-stack-content>
</clr-stack-block>
<clr-stack-block>
<clr-stack-label>Virtual Machine</clr-stack-label>
<clr-stack-content>{{
course.virtualmachines.length
}}</clr-stack-content>
</clr-stack-block>
<clr-stack-block>
<clr-stack-label>Scenarios</clr-stack-label>
<clr-stack-content
><span class="label" *ngFor="let scenario of course.scenarios">
{{ scenario.name }}</span
></clr-stack-content
>
</clr-stack-block>
</clr-stack-block>
<clr-stack-block *ngIf="course.categories.length > 0">
<clr-stack-label>Dynamic Scenarios</clr-stack-label>
<clr-stack-block>
<clr-stack-label>Dynamic Scenarios</clr-stack-label>
<clr-stack-content
><span class="label" *ngFor="let categorie of course.categories">
{{ categorie }}</span
></clr-stack-content
>
</clr-stack-block>
</clr-stack-block>
</clr-stack-view>
</div>
Empty file.
12 changes: 12 additions & 0 deletions src/app/course/course-details/course-details.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component, Input } from '@angular/core';
import { Course } from 'src/app/data/course';

@Component({
selector: 'course-details',
templateUrl: './course-details.component.html',
styleUrls: ['./course-details.component.scss'],
})
export class CourseDetailsComponent {
@Input()
course: Course;
}
6 changes: 6 additions & 0 deletions src/app/course/course-form/course-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
<clr-control-error *clrIfError="'required'">Course name is required</clr-control-error>
<clr-control-error *clrIfError="'minlength'">Course name must be longer than 4 characters
</clr-control-error>
<clr-control-error *clrIfError="'pattern'">
Non latin letters is forbidden
</clr-control-error>
</clr-input-container>
<clr-input-container>
<label>Description</label>
<input clrInput type="text" formControlName="course_description" required>
<clr-control-error *clrIfError="'required'">Course description is required</clr-control-error>
<clr-control-error *clrIfError="'minlength'">Course description must be longer than 4 characters
</clr-control-error>
<clr-control-error *clrIfError="'pattern'">
Non latin letters is forbidden
</clr-control-error>
</clr-input-container>
<div class="clr-form-control clr-row">
<label for="keepalive_amount" class="clr-control-label">Keepalive Duration</label>
Expand Down
25 changes: 22 additions & 3 deletions src/app/course/course-form/course-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { KeepaliveValidator } from 'src/app/validators/keepalive.validator';
import { Course } from 'src/app/data/course';
Expand All @@ -14,6 +14,7 @@ export class CourseFormComponent implements OnInit {
@Output()
formReady: EventEmitter<FormGroup> = new EventEmitter(null);


constructor() { }

ngOnInit(): void {
Expand Down Expand Up @@ -67,18 +68,36 @@ export class CourseFormComponent implements OnInit {
}
}


resetFormToRenew(): void {
this.courseDetails.reset({
'course_name': null,
'course_description': null,
'virtualmachines': null,
'keepalive_amount': 10,
'keepalive_unit': 'm',
'pauseable': true,
'keep_vm': true,
'pause_duration': 1,
'scenarios': null,
});
this.formReady.emit(this.courseDetails);
}

ngOnChanges(): void {
this.reset();
}

public courseDetails: FormGroup = new FormGroup({
'course_name': new FormControl(null, [
Validators.required,
Validators.minLength(4)
Validators.minLength(4),
Validators.pattern(/^[a-zA-Z0-9 ]+$/)
]),
'course_description': new FormControl(null, [
Validators.required,
Validators.minLength(4)
Validators.minLength(4),
Validators.pattern(/^[a-zA-Z0-9 ]+$/)
]),
'keepalive_amount': new FormControl(10, [
Validators.required
Expand Down
Loading