forked from doubtfire-lms/doubtfire-web
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
145 deletions.
There are no files selected for viewing
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
79 changes: 0 additions & 79 deletions
79
src/app/units/states/rollover/directives/unit-dates-selector/unit-dates-selector.coffee
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
<div class="unit-dates-selector"> | ||
<div class="panel panel-primary"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title">Create Unit</h3> | ||
Duplicate an existing unit by specifying the time period. | ||
</div> | ||
<form class="form-horizontal" role="form" name="rolloverUnitForm" (ngSubmit)="saveUnit()"> | ||
<div class="panel-body"> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label" for="teachingperiod">Teaching Period</label> | ||
<div class="col-sm-9"> | ||
<mat-form-field appearance="outline"> | ||
<mat-label>Select Teaching Period</mat-label> | ||
<mat-select | ||
name="toPeriod" | ||
[(value)]="saveData.toPeriod" | ||
(selectionChange)="teachingPeriodSelected($event)" | ||
[compareWith]="compareFn" | ||
> | ||
@for (element of teachingPeriodValues; track element) { | ||
<mat-option [value]="element.value"> | ||
{{ element.text }} | ||
</mat-option> | ||
} | ||
</mat-select> | ||
</mat-form-field> | ||
</div> | ||
</div> | ||
<!--/teaching-period-date--> | ||
|
||
<div class="form-group"> | ||
<label | ||
tooltip="Date for the start of teaching in the unit." | ||
class="col-sm-2 control-label" | ||
for="startdate" | ||
>Start Date</label | ||
> | ||
<div class="col-sm-9"> | ||
<mat-form-field> | ||
<input | ||
matInput | ||
[matDatepicker]="startDate" | ||
required="!unit.teachingPeriod" | ||
name="unitStartDate" | ||
[(ngModel)]="saveData.toPeriod.startDate" | ||
[disabled]="saveData.toPeriod" | ||
/> | ||
<mat-datepicker-toggle matIconSuffix [for]="startDate"></mat-datepicker-toggle> | ||
<mat-datepicker #startDate></mat-datepicker> | ||
</mat-form-field> | ||
</div> | ||
</div> | ||
<!--/start-date--> | ||
|
||
<div class="form-group"> | ||
<label class="col-sm-2 control-label" for="enddate">End Date</label> | ||
<div class="col-sm-9"> | ||
<mat-form-field> | ||
<input | ||
matInput | ||
[matDatepicker]="endDate" | ||
required="!unit.teachingPeriod" | ||
name="endDate" | ||
[(ngModel)]="saveData.toPeriod.endDate" | ||
[disabled]="saveData.toPeriod" | ||
/> | ||
<mat-datepicker-toggle matIconSuffix [for]="endDate"></mat-datepicker-toggle> | ||
<mat-datepicker #endDate></mat-datepicker> | ||
</mat-form-field> | ||
</div> | ||
</div> | ||
<!--/end-date--> | ||
</div> | ||
<div class="panel-footer text-right"> | ||
<input type="submit" value="Create Unit" class="btn btn-success" /> | ||
</div> | ||
</form> | ||
</div> | ||
</div> |
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,77 @@ | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {DoubtfireConstants} from 'src/app/config/constants/doubtfire-constants'; | ||
import {AlertService} from 'src/app/common/services/alert.service'; | ||
import {TeachingPeriodService} from 'src/app/api/services/teaching-period.service'; | ||
import {Unit} from 'src/app/api/models/unit'; | ||
import {UIRouter} from '@uirouter/angular'; | ||
import _ from 'lodash'; | ||
|
||
@Component({ | ||
selector: 'f-unit-dates-selector', | ||
templateUrl: './unit-dates-selector.component.html', | ||
//styleUrls: ['./unit-dates-selector.component.scss'], | ||
}) | ||
export class UnitDatesSelectorComponent implements OnInit { | ||
@Input() unit: Unit; | ||
externalName: string = ''; | ||
teachingPeriods: any[] = []; | ||
teachingPeriodValues: {value: any; text: string}[] = [{value: undefined, text: 'None'}]; | ||
saveData; | ||
|
||
constructor( | ||
private doubtfireConstants: DoubtfireConstants, | ||
private alertService: AlertService, | ||
private newTeachingPeriodService: TeachingPeriodService, | ||
private router: UIRouter, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.saveData = { | ||
id: this.unit.id, | ||
toPeriod: null, | ||
startDate: null, | ||
endDate: null, | ||
}; | ||
this.externalName = this.doubtfireConstants.ExternalName.value; | ||
// Load teaching periods | ||
this.newTeachingPeriodService.cache.values.subscribe((periods) => { | ||
this.teachingPeriodValues = [{value: undefined, text: 'None'}]; | ||
const other = periods | ||
.filter((tp) => tp.endDate.getTime() > Date.now()) | ||
.map((p) => ({value: p, text: '#{p.year} #{p.period}'})); | ||
_.each(other, (d) => this.teachingPeriodValues.push(d)); | ||
|
||
if (periods.length > 0) { | ||
this.saveData.toPeriod = periods[periods.length - 1]; | ||
} | ||
}); | ||
} | ||
compareFn(a, b): boolean { | ||
return (!a && !b) || a === b; | ||
} | ||
teachingPeriodSelected($event) { | ||
this.saveData.toPeriod = $event; | ||
} | ||
saveUnit() { | ||
let body; | ||
if (this.saveData.toPeriod) { | ||
body = { | ||
teaching_period_id: this.saveData.toPeriod.id, | ||
}; | ||
} else { | ||
body = { | ||
start_date: this.saveData.startDate, | ||
end_date: this.saveData.endDate, | ||
}; | ||
} | ||
this.unit.rolloverTo(body).subscribe({ | ||
next: (response) => { | ||
this.alertService.success('Unit created.', 2000); | ||
this.router.stateService.go('units/admin', {unitId: response.id}); | ||
}, | ||
error: (response) => { | ||
this.alertService.error(`Failed to creating unit. ${response}`, 6000); | ||
}, | ||
}); | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
src/app/units/states/rollover/directives/unit-dates-selector/unit-dates-selector.tpl.html
This file was deleted.
Oops, something went wrong.