Skip to content

Commit

Permalink
feat(Archive Run): Use select runs option enum
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan committed Aug 31, 2023
1 parent 0287de6 commit f260318
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<mat-icon>arrow_drop_down</mat-icon>
</button>
<mat-menu #selectRunsMenu="matMenu">
<button mat-menu-item (click)="selectRunsOptionChosen('all')" i18n>All</button>
<button mat-menu-item (click)="selectRunsOptionChosen('none')" i18n>None</button>
<button mat-menu-item (click)="selectRunsOptionChosen('completed')" i18n>Completed</button>
<button mat-menu-item (click)="selectRunsOptionChosen('running')" i18n>Running</button>
<button mat-menu-item (click)="selectRunsOptionChosen('scheduled')" i18n>Scheduled</button>
<button mat-menu-item (click)="selectRunsOptionChosen('ALL')" i18n>All</button>
<button mat-menu-item (click)="selectRunsOptionChosen('NONE')" i18n>None</button>
<button mat-menu-item (click)="selectRunsOptionChosen('COMPLETED')" i18n>Completed</button>
<button mat-menu-item (click)="selectRunsOptionChosen('RUNNING')" i18n>Running</button>
<button mat-menu-item (click)="selectRunsOptionChosen('SCHEDULED')" i18n>Scheduled</button>
</mat-menu>
</div>
<div *ngIf="numSelectedRuns > 0" class="secondary-text" i18n>{{ numSelectedRuns }} selected</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Subscription } from 'rxjs';
import { Project } from '../../domain/project';
import { ArchiveProjectService } from '../../services/archive-project.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SelectRunsOption } from './select-runs-option';

@Component({
selector: 'select-runs-controls',
Expand All @@ -20,7 +21,7 @@ export class SelectRunsControlsComponent {
@Input() runs: TeacherRun[] = [];
protected selectedAllRuns: boolean = false;
protected selectedSomeRuns: boolean = false;
@Output() selectRunsOptionChosenEvent = new EventEmitter<string>();
@Output() selectRunsOptionChosenEvent = new EventEmitter<SelectRunsOption>();
@Input() showArchived: boolean = false;

constructor(
Expand All @@ -42,12 +43,12 @@ export class SelectRunsControlsComponent {

protected selectAllRunsCheckboxClicked(): void {
this.selectRunsOptionChosenEvent.emit(
this.selectedAllRuns || this.selectedSomeRuns ? 'none' : 'all'
this.selectedAllRuns || this.selectedSomeRuns ? SelectRunsOption.None : SelectRunsOption.All
);
}

protected selectRunsOptionChosen(value: string): void {
this.selectRunsOptionChosenEvent.emit(value);
this.selectRunsOptionChosenEvent.emit(value as SelectRunsOption);
}

protected archiveSelectedRuns(archive: boolean): Subscription {
Expand Down
7 changes: 7 additions & 0 deletions src/app/teacher/select-runs-controls/select-runs-option.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum SelectRunsOption {
All = 'ALL',
None = 'NONE',
Completed = 'COMPLETED',
Running = 'RUNNING',
Scheduled = 'SCHEDULED'
}
25 changes: 4 additions & 21 deletions src/app/teacher/teacher-run-list/teacher-run-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UserService } from '../../services/user.service';
import { mergeMap } from 'rxjs/operators';
import { ArchiveProjectService } from '../../services/archive-project.service';
import { runSpansDays } from '../../../assets/wise5/common/datetime/datetime';
import { SelectRunsOption } from '../select-runs-controls/select-runs-option';

@Component({
selector: 'app-teacher-run-list',
Expand Down Expand Up @@ -210,27 +211,9 @@ export class TeacherRunListComponent implements OnInit {
run.selected = false;
}
}

protected selectRunsOptionChosen(value: string): void {
this.filteredRuns.forEach((run: TeacherRun) => {
switch (value) {
case 'all':
run.selected = true;
break;
case 'none':
run.selected = false;
break;
case 'completed':
run.selected = run.isCompleted(this.configService.getCurrentServerTime());
break;
case 'running':
run.selected = run.isActive(this.configService.getCurrentServerTime());
break;
case 'scheduled':
run.selected = run.isScheduled(this.configService.getCurrentServerTime());
break;
}
});
protected selectRunsOptionChosen(option: SelectRunsOption): void {
const now = this.configService.getCurrentServerTime();
this.filteredRuns.forEach((run: TeacherRun) => run.updateSelected(option, now));
this.runSelectedStatusChanged();
}

Expand Down
21 changes: 21 additions & 0 deletions src/app/teacher/teacher-run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Run } from '../domain/run';
import { SelectRunsOption } from './select-runs-controls/select-runs-option';

export class TeacherRun extends Run {
archived: boolean;
Expand All @@ -9,4 +10,24 @@ export class TeacherRun extends Run {
constructor(jsonObject: any = {}) {
super(jsonObject);
}

updateSelected(selectRunsOption: SelectRunsOption, currentTime: number): void {
switch (selectRunsOption) {
case SelectRunsOption.All:
this.selected = true;
break;
case SelectRunsOption.None:
this.selected = false;
break;
case SelectRunsOption.Completed:
this.selected = this.isCompleted(currentTime);
break;
case SelectRunsOption.Running:
this.selected = this.isActive(currentTime);
break;
case SelectRunsOption.Scheduled:
this.selected = this.isScheduled(currentTime);
break;
}
}
}

0 comments on commit f260318

Please sign in to comment.