-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'GaganSinghGit-create-unit-modal' into add-tii-integration
- Loading branch information
Showing
13 changed files
with
227 additions
and
199 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/app/admin/modals/create-new-unit-modal/create-new-unit-modal-content.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<h3 mat-dialog-title>Create Unit</h3> | ||
|
||
<form mat-dialog-content action="" #createUnitForm="ngForm" (ngSubmit)="createUnit(createUnitForm.value)" class="pt-8"> | ||
<div class="flex flex-col"> | ||
<mat-form-field appearance="outline"> | ||
<mat-label>Unit Code</mat-label> | ||
<input matInput placeholder="COS123456" name="unitCode" ngModel /> | ||
</mat-form-field> | ||
|
||
<mat-form-field appearance="outline"> | ||
<mat-label>Unit Name</mat-label> | ||
<input matInput placeholder="Introduction to OnTrack" name="unitName" ngModel /> | ||
</mat-form-field> | ||
|
||
<mat-form-field appearance="outline"> | ||
<mat-label>Teaching Period</mat-label> | ||
<mat-select (valueChange)="handleChangeTeachingPeriod($event)" name="selectedTeachingPeriod" ngModel> | ||
<mat-option value="custom"> Custom teaching period </mat-option> | ||
<mat-option *ngFor="let tp of teachingPeriods; let i = index" [value]="tp.id"> | ||
{{ tp.name }} | ||
</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
|
||
@if(showDates) { | ||
<mat-form-field appearance="outline"> | ||
<mat-label>Enter a date range</mat-label> | ||
<mat-date-range-input [rangePicker]="picker"> | ||
<input matStartDate placeholder="Start date" name="customStardDate" [(ngModel)]="startDate" /> | ||
<input matEndDate placeholder="End date" name="customEndDate" [(ngModel)]="endDate" /> | ||
</mat-date-range-input> | ||
<mat-hint>DD/MM/YYYY - DD/MM/YYYY</mat-hint> | ||
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle> | ||
<mat-date-range-picker #picker></mat-date-range-picker> | ||
</mat-form-field> | ||
} | ||
|
||
<mat-dialog-actions align="end"> | ||
<button mat-raised-button color="primary">Create</button> | ||
</mat-dialog-actions> | ||
</div> | ||
</form> |
71 changes: 71 additions & 0 deletions
71
src/app/admin/modals/create-new-unit-modal/create-new-unit-modal-content.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
import { TeachingPeriod } from 'src/app/api/models/teaching-period'; | ||
import { TeachingPeriodService } from 'src/app/api/services/teaching-period.service'; | ||
import { UnitService } from 'src/app/api/services/unit.service'; | ||
import { AlertService } from 'src/app/common/services/alert.service'; | ||
@Component({ | ||
selector: 'create-new-unit-modal-content', | ||
templateUrl: 'create-new-unit-modal-content.component.html', | ||
}) | ||
export class CreateNewUnitModalContentComponent implements OnInit { | ||
constructor( | ||
private dialogRef: MatDialogRef<CreateNewUnitModalContentComponent>, | ||
private unitService: UnitService, | ||
private teachingPeriodsService: TeachingPeriodService, | ||
private alerts: AlertService, | ||
) {} | ||
showDates = false; | ||
startDate: Date; | ||
endDate: Date; | ||
selectedTeachingPeriod: number = null; | ||
teachingPeriods: TeachingPeriod[]; | ||
|
||
ngOnInit(): void { | ||
this.teachingPeriodsService.fetchAll().subscribe((teachingPeriods) => { | ||
this.teachingPeriods = teachingPeriods; | ||
}); | ||
} | ||
|
||
public createUnit(unit: { unitName: string; unitCode: string; selectedTeachingPeriod: number }): void { | ||
let newUnit; | ||
|
||
if (this.selectedTeachingPeriod === null) { | ||
newUnit = { | ||
code: unit.unitCode, | ||
name: unit.unitName, | ||
start_date: this.startDate, | ||
end_date: this.endDate, | ||
}; | ||
} else { | ||
newUnit = { | ||
code: unit.unitCode, | ||
name: unit.unitName, | ||
teaching_period_id: this.selectedTeachingPeriod, | ||
}; | ||
} | ||
|
||
this.unitService | ||
.create({ | ||
unit: newUnit, | ||
}) | ||
.subscribe({ | ||
next: (unit) => { | ||
this.alerts.success(`Unit ${unit.code} - ${unit.name} has been created.`); | ||
this.dialogRef.close(unit); | ||
}, | ||
error: (error) => { | ||
this.alerts.error(`Unit Creation Failed: ${error}`); | ||
}, | ||
}); | ||
} | ||
public handleChangeTeachingPeriod(teachingPeriod: number | string): void { | ||
if (typeof teachingPeriod === 'string') { | ||
teachingPeriod = null; | ||
this.showDates = true; | ||
} else { | ||
this.showDates = false; | ||
this.selectedTeachingPeriod = teachingPeriod; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/app/admin/modals/create-new-unit-modal/create-new-unit-modal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Component } from '@angular/core'; | ||
import { MatDialog } from '@angular/material/dialog'; | ||
import { CreateNewUnitModalContentComponent } from './create-new-unit-modal-content.component'; | ||
|
||
@Component({ | ||
selector: 'create-new-unit-modal', | ||
template: '', | ||
}) | ||
export class CreateNewUnitModal { | ||
constructor(public dialog: MatDialog) {} | ||
public show(): void { | ||
this.dialog.open(CreateNewUnitModalContentComponent, { | ||
width: '500px', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.