Skip to content

Commit

Permalink
Add readonly to instructor audit logs page
Browse files Browse the repository at this point in the history
  • Loading branch information
ziqing26 committed Mar 14, 2022
1 parent 8744a25 commit ed0beb7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>Student Activity Logs</h1>
</div>
<div class="input-group">
<div class="col-md-6 input-group">
<input id="logs-from-datepicker" type="text" class="form-control" ngbDatepicker [minDate]="earliestSearchDate" [maxDate]="formModel.logsDateTo" [(ngModel)]="formModel.logsDateFrom" #logsFromDp="ngbDatepicker"/>
<input id="logs-from-datepicker" type="text" class="form-control" ngbDatepicker readonly [minDate]="earliestSearchDate" [maxDate]="formModel.logsDateTo" [(ngModel)]="formModel.logsDateFrom" #logsFromDp="ngbDatepicker"/>
<button class="btn btn-light" (click)="logsFromDp.toggle()" type="button">
<i class="fas fa-calendar-alt"></i>
</button>
Expand Down Expand Up @@ -54,7 +54,7 @@ <h1>Student Activity Logs</h1>
</div>
<div class="input-group">
<div class="col-md-6 input-group">
<input id="logs-to-datepicker" type="text" class="form-control" ngbDatepicker [minDate]="formModel.logsDateFrom" [maxDate]="dateToday" [(ngModel)]="formModel.logsDateTo" #logsToDp="ngbDatepicker"/>
<input id="logs-to-datepicker" type="text" class="form-control" ngbDatepicker readonly [minDate]="formModel.logsDateFrom" [maxDate]="dateToday" [(ngModel)]="formModel.logsDateTo" #logsToDp="ngbDatepicker"/>
<button class="btn btn-light" (click)="logsToDp.toggle()" type="button">
<i class="fas fa-calendar-alt"></i>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
.no-activity-body {
padding: .5rem 1rem;
}

.form-control {
&[readonly] {
background-color: white;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,11 @@ export class InstructorAuditLogsPageComponent implements OnInit {
this.searchResults = [];
const selectedCourse: Course | undefined =
this.courses.find((course: Course) => course.courseId === this.formModel.courseId);

const timeZone: string = selectedCourse ? selectedCourse.timeZone : this.timezoneService.guessTimezone();
const searchFrom: number = this.timezoneService.resolveLocalDateTime(
this.formModel.logsDateFrom, this.formModel.logsTimeFrom, timeZone, true);
this.formModel.logsDateFrom, this.formModel.logsTimeFrom, timeZone, true);
const searchUntil: number = this.timezoneService.resolveLocalDateTime(
this.formModel.logsDateTo, this.formModel.logsTimeTo, timeZone, true);

const indexOfInvalidTime: number = [searchFrom, searchUntil].findIndex(isNaN);
const sequenceOfTimeChecked: string[] = ['Search period from', 'Search period until'];

if (indexOfInvalidTime !== -1) {
const errorMessage: string = `Invalid datetime range for ${sequenceOfTimeChecked[indexOfInvalidTime]}`;
this.statusMessageService.showErrorToast(errorMessage);
this.isLoading = false;
this.isSearching = false;
return;
}
this.formModel.logsDateTo, this.formModel.logsTimeTo, timeZone, true);

this.logsService.searchFeedbackSessionLog({
courseId: this.formModel.courseId,
Expand All @@ -148,7 +136,6 @@ export class InstructorAuditLogsPageComponent implements OnInit {
}, (e: ErrorMessageOutput) => {
this.statusMessageService.showErrorToast(e.error.message);
});

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,42 +397,26 @@ export class InstructorSessionEditPageComponent extends InstructorSessionBasePag
this.sessionEditFormModel.isEditable = false;
this.feedbackSessionModelBeforeEditing = JSON.parse(JSON.stringify(this.sessionEditFormModel));
this.sessionEditFormModel.isSaving = true;
let sessionVisibleTime: number = 0;
let responseVisibleTime: number = 0;

const submissionStartTime: number = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.submissionStartDate, this.sessionEditFormModel.submissionStartTime,
this.sessionEditFormModel.timeZone, true);
const submissionEndTime: number = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.submissionEndDate, this.sessionEditFormModel.submissionEndTime,
this.sessionEditFormModel.timeZone, true);
let sessionVisibleTime: number = 0;
if (this.sessionEditFormModel.sessionVisibleSetting === SessionVisibleSetting.CUSTOM) {
sessionVisibleTime = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.customSessionVisibleDate, this.sessionEditFormModel.customSessionVisibleTime,
this.sessionEditFormModel.timeZone, true);
}
let responseVisibleTime: number = 0;
if (this.sessionEditFormModel.responseVisibleSetting === ResponseVisibleSetting.CUSTOM) {
responseVisibleTime = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.customResponseVisibleDate, this.sessionEditFormModel.customResponseVisibleTime,
this.sessionEditFormModel.timeZone, true);
}

const indexOfInvalidTime: number =
[submissionStartTime, submissionEndTime, sessionVisibleTime, responseVisibleTime]
.findIndex(isNaN);
const sequenceOfTimeChecked: string[] = [
'submission opening time',
'submission closing time',
'session visible time',
'response visible time'];

if (indexOfInvalidTime !== -1) {
const errorMessage: string = `Invalid datetime range for ${sequenceOfTimeChecked[indexOfInvalidTime]}`;
this.statusMessageService.showErrorToast(errorMessage);
this.sessionEditFormModel.isSaving = false;
return;
}

this.feedbackSessionsService.updateFeedbackSession(this.courseId, this.feedbackSessionName, {
instructions: this.sessionEditFormModel.instructions,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,42 +275,26 @@ export class InstructorSessionsPageComponent extends InstructorSessionModalPageC
*/
addNewSessionHandler(): void {
this.sessionEditFormModel.isSaving = true;
let sessionVisibleTime: number = 0;
let responseVisibleTime: number = 0;

const submissionStartTime: number = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.submissionStartDate, this.sessionEditFormModel.submissionStartTime,
this.sessionEditFormModel.timeZone, true);
const submissionEndTime: number = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.submissionEndDate, this.sessionEditFormModel.submissionEndTime,
this.sessionEditFormModel.timeZone, true);
let sessionVisibleTime: number = 0;
if (this.sessionEditFormModel.sessionVisibleSetting === SessionVisibleSetting.CUSTOM) {
sessionVisibleTime = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.customSessionVisibleDate, this.sessionEditFormModel.customSessionVisibleTime,
this.sessionEditFormModel.timeZone, true);
}
let responseVisibleTime: number = 0;
if (this.sessionEditFormModel.responseVisibleSetting === ResponseVisibleSetting.CUSTOM) {
responseVisibleTime = this.timezoneService.resolveLocalDateTime(
this.sessionEditFormModel.customResponseVisibleDate, this.sessionEditFormModel.customResponseVisibleTime,
this.sessionEditFormModel.timeZone, true);
}

const indexOfInvalidTime: number =
[submissionStartTime, submissionEndTime, sessionVisibleTime, responseVisibleTime]
.findIndex(isNaN);
const sequenceOfTimeChecked: string[] = [
'submission opening time',
'submission closing time',
'session visible time',
'response visible time'];

if (indexOfInvalidTime !== -1) {
const errorMessage: string = `Invalid datetime range for ${sequenceOfTimeChecked[indexOfInvalidTime]}`;
this.statusMessageService.showErrorToast(errorMessage);
this.sessionEditFormModel.isSaving = false;
return;
}

this.feedbackSessionsService.createFeedbackSession(this.sessionEditFormModel.courseId, {
feedbackSessionName: this.sessionEditFormModel.feedbackSessionName,
instructions: this.sessionEditFormModel.instructions,
Expand All @@ -331,8 +315,8 @@ export class InstructorSessionsPageComponent extends InstructorSessionModalPageC

// begin to populate session with template
const templateSession: TemplateSession | undefined =
this.feedbackSessionsService.getTemplateSessions().find(
(t: TemplateSession) => t.name === this.sessionEditFormModel.templateSessionName);
this.feedbackSessionsService.getTemplateSessions().find(
(t: TemplateSession) => t.name === this.sessionEditFormModel.templateSessionName);
if (!templateSession) {
return;
}
Expand Down

0 comments on commit ed0beb7

Please sign in to comment.