Skip to content

Commit

Permalink
feat: code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
likuanppd committed Dec 23, 2024
1 parent 80299b0 commit fa5c623
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 145 deletions.
3 changes: 3 additions & 0 deletions src/app/doubtfire-angular.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ import {FTaskSheetViewComponent} from './units/states/tasks/viewer/directives/f-
import {TasksViewerComponent} from './units/states/tasks/tasks-viewer/tasks-viewer.component';
import {UnitCodeComponent} from './common/unit-code/unit-code.component';
import {GradeService} from './common/services/grade.service';
import {UnitDatesSelectorComponent} from 'src/app/units/states/rollover/directives/unit-dates-selector/unit-dates-selector.component';

@NgModule({
// Components we declare
Expand Down Expand Up @@ -325,6 +326,7 @@ import {GradeService} from './common/services/grade.service';
FUsersComponent,
FTaskBadgeComponent,
FUnitsComponent,
UnitDatesSelectorComponent,
],
// Services we provide
providers: [
Expand Down Expand Up @@ -375,6 +377,7 @@ import {GradeService} from './common/services/grade.service';
AudioRecorderServiceProvider,
plagiarismReportModalProvider,
UnitStudentsEditorComponent,
UnitDatesSelectorComponent,
ConfirmationModalProvider,
{
provide: HTTP_INTERCEPTORS,
Expand Down
6 changes: 5 additions & 1 deletion src/app/doubtfire-angularjs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ import 'build/src/app/units/states/edit/directives/unit-staff-editor/unit-staff-
import 'build/src/app/units/states/edit/directives/unit-ilo-editor/unit-ilo-editor.js';
import 'build/src/app/units/states/edit/directives/directives.js';
import 'build/src/app/units/states/edit/edit.js';
import 'build/src/app/units/states/rollover/directives/unit-dates-selector/unit-dates-selector.js';
import 'build/src/app/units/states/rollover/directives/directives.js';
import 'build/src/app/units/states/rollover/rollover.js';
import 'build/src/app/units/states/index/index.js';
Expand Down Expand Up @@ -163,6 +162,7 @@ import {UnitTutorialsManagerComponent} from './units/states/edit/directives/unit
import {TutorialService} from './api/services/tutorial.service';
import {TutorialStreamService} from './api/services/tutorial-stream.service';
import {UnitStudentsEditorComponent} from './units/states/edit/directives/unit-students-editor/unit-students-editor.component';
import {UnitDatesSelectorComponent} from 'src/app/units/states/rollover/directives/unit-dates-selector/unit-dates-selector.component';
import {CampusService} from './api/services/campus.service';
import {WebcalService} from './api/services/webcal.service';
import {StudentTutorialSelectComponent} from './units/states/edit/directives/unit-students-editor/student-tutorial-select/student-tutorial-select.component';
Expand Down Expand Up @@ -401,6 +401,10 @@ DoubtfireAngularJSModule.directive(
'unitStudentsEditor',
downgradeComponent({component: UnitStudentsEditorComponent}),
);
DoubtfireAngularJSModule.directive(
'fUnitDatesSelector',
downgradeComponent({component: UnitDatesSelectorComponent}),
);
DoubtfireAngularJSModule.directive(
'fTaskDefinitionEditor',
downgradeComponent({component: TaskDefinitionEditorComponent}),
Expand Down

This file was deleted.

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>
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);
},
});
}
}

This file was deleted.

0 comments on commit fa5c623

Please sign in to comment.