Skip to content
Snippets Groups Projects
Commit dea461d9 authored by Scott Berg's avatar Scott Berg
Browse files

ROENROLL-1395

parent 39473db0
No related branches found
No related tags found
No related merge requests found
Pipeline #33342 passed
...@@ -128,7 +128,6 @@ ...@@ -128,7 +128,6 @@
</ng-container> </ng-container>
</mat-accordion> </mat-accordion>
</div> </div>
</mat-sidenav-content>
</mat-sidenav-container> </mat-sidenav-content>
</mat-sidenav-content>
</mat-sidenav-container> </mat-sidenav-container>
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<button mat-menu-item (click)="openCourseDetailsDialog(course)">Course Details</button> <button mat-menu-item (click)="openCourseDetailsDialog(course)">Course Details</button>
<button mat-menu-item [matMenuTriggerFor]="academicYearsGroup">Move</button> <button mat-menu-item [matMenuTriggerFor]="academicYearsGroup">Move</button>
<mat-menu #academicYearsGroup="matMenu" class="course-item-submenu"> <mat-menu #academicYearsGroup="matMenu" class="course-item-submenu">
<button mat-menu-item (click)="moveToSavedForLater(course)" *ngIf="type != 'saved'" class="saved-for-later-list">Saved for later</button>
<button mat-menu-item *ngFor="let term of (droppableTermCodes$ | async)" (click)="onMove(term)">{{ term | getTermDescription }}</button> <button mat-menu-item *ngFor="let term of (droppableTermCodes$ | async)" (click)="onMove(term)">{{ term | getTermDescription }}</button>
</mat-menu> </mat-menu>
<button mat-menu-item *ngIf="type !== 'saved'" (click)="onSaveForLater()">Save for later</button> <button mat-menu-item *ngIf="type !== 'saved'" (click)="onSaveForLater()">Save for later</button>
......
...@@ -205,9 +205,7 @@ export class CourseItemComponent implements OnInit { ...@@ -205,9 +205,7 @@ export class CourseItemComponent implements OnInit {
const termCode = term; const termCode = term;
const newIndex = 0; const newIndex = 0;
this.store.dispatch( this.store.dispatch(new AddCourse({ subjectCode, courseId, termCode }));
new AddCourse({ subjectCode, courseId, termCode, newIndex }),
);
} }
switchTerm(course, term) { switchTerm(course, term) {
...@@ -223,7 +221,8 @@ export class CourseItemComponent implements OnInit { ...@@ -223,7 +221,8 @@ export class CourseItemComponent implements OnInit {
.subscribe(courseDetails => { .subscribe(courseDetails => {
const dialogRef = this.dialog.open(CourseDetailsDialogComponent, { const dialogRef = this.dialog.open(CourseDetailsDialogComponent, {
maxWidth: '800px', maxWidth: '800px',
data: { courseDetails: courseDetails }, width: '80%',
data: { courseDetails: courseDetails, courseType: this.type },
}); });
}); });
} }
......
...@@ -52,14 +52,14 @@ export class AddCourse implements Action { ...@@ -52,14 +52,14 @@ export class AddCourse implements Action {
subjectCode: string; subjectCode: string;
courseId: string; courseId: string;
termCode: string; termCode: string;
newIndex: number; newIndex?: number;
}, },
) {} ) {}
} }
export class AddCourseSuccess implements Action { export class AddCourseSuccess implements Action {
public readonly type = CourseActionTypes.AddCourseSuccess; public readonly type = CourseActionTypes.AddCourseSuccess;
constructor(public payload: { course: Course; newIndex: number }) {} constructor(public payload: { course: Course; newIndex?: number }) {}
} }
export class RemoveCourse implements Action { export class RemoveCourse implements Action {
......
...@@ -104,6 +104,7 @@ export class DegreePlanEffects { ...@@ -104,6 +104,7 @@ export class DegreePlanEffects {
subjects: of(subjects), subjects: of(subjects),
expandedYears: of([] as string[]), expandedYears: of([] as string[]),
subjectDescriptions: of(descriptions), subjectDescriptions: of(descriptions),
search: of({ visible: false, selectedTerm: activeTermCodes[0] }),
}); });
}, },
), ),
......
...@@ -319,11 +319,11 @@ export function degreePlannerReducer( ...@@ -319,11 +319,11 @@ export function degreePlannerReducer(
const toYear = createYearWithCourse( const toYear = createYearWithCourse(
toTermCode, toTermCode,
course, course,
newIndex,
state.activeTermCodes, state.activeTermCodes,
fromYearCode === toYearCode fromYearCode === toYearCode
? fromYear ? fromYear
: state.visibleYears[toYearCode], : state.visibleYears[toYearCode],
newIndex,
); );
const visibleYears = { const visibleYears = {
...@@ -346,9 +346,9 @@ export function degreePlannerReducer( ...@@ -346,9 +346,9 @@ export function degreePlannerReducer(
const year: Year = createYearWithCourse( const year: Year = createYearWithCourse(
termCode, termCode,
course, course,
newIndex,
state.activeTermCodes, state.activeTermCodes,
state.visibleYears[yearCode], state.visibleYears[yearCode],
newIndex,
); );
const visibleYears = { const visibleYears = {
...@@ -570,14 +570,14 @@ const findCourse = (years: YearMapping, termCode: string, recordId: number) => { ...@@ -570,14 +570,14 @@ const findCourse = (years: YearMapping, termCode: string, recordId: number) => {
const createYearWithCourse = ( const createYearWithCourse = (
termCode: string, termCode: string,
course: Course, course: Course,
newIndex: number,
activeTermCodes: string[], activeTermCodes: string[],
year = generateYearForTermCode(termCode, activeTermCodes), year = generateYearForTermCode(termCode, activeTermCodes),
newIndex?: number,
): Year => { ): Year => {
const { termName } = parseTermCode(termCode); const { termName } = parseTermCode(termCode);
const term = year[termName]; const term = year[termName];
const courses = term.courses.slice(); const courses = term.courses.slice();
courses.splice(newIndex, 0, course); courses.splice(newIndex !== undefined ? newIndex : courses.length, 0, course);
return { ...year, [termName]: { ...term, courses } }; return { ...year, [termName]: { ...term, courses } };
}; };
......
...@@ -4,11 +4,19 @@ ...@@ -4,11 +4,19 @@
<div fxFlex="50" class="course-detail-title" fxLayoutAlign="start center"> <div fxFlex="50" class="course-detail-title" fxLayoutAlign="start center">
<h3>{{ courseDetails.fullCourseDesignation | titlecase }}<span class="course-detail-subtitle">{{ courseDetails.title }}</span></h3> <h3>{{ courseDetails.fullCourseDesignation | titlecase }}<span class="course-detail-subtitle">{{ courseDetails.title }}</span></h3>
</div> </div>
<!-- <div fxFlex="50" fxLayout="row" fxLayoutAlign="end start" > <div *ngIf="type === 'search' || type === 'saved'" fxFlex="50" fxLayout="row" fxLayoutAlign="end start" >
<mat-dialog-actions> <div style="margin-top: 10px;">
<button mat-raised-button class="btn-primary mat-button">See Sections</button> <form [formGroup]='termSelector' (ngSubmit)="addCourseToPlan($event)">
</mat-dialog-actions> <mat-form-field style="margin-right:20px;">
</div> --> <mat-select placeholder="Term" aria-label="Term" matInput formControlName="term">
<mat-option *ngFor="let term of (droppableTermCodes$ | async)" [value]="term">{{term | getTermDescription}}</mat-option>
</mat-select>
</mat-form-field>
<button mat-raised-button color="primary" mat-dialog-close (click)="addCourseToPlan($event)">Add to plan</button>
</form>
</div>
</div>
</div> </div>
</div> </div>
......
import { Component, OnInit, Inject } from '@angular/core'; import { Observable, Subscription } from 'rxjs';
import { Component, OnInit, OnDestroy, Inject } from '@angular/core';
import { CourseDetails } from '../../../core/models/course-details'; import { CourseDetails } from '../../../core/models/course-details';
import { MAT_DIALOG_DATA } from '@angular/material'; import { MAT_DIALOG_DATA } from '@angular/material';
import * as selectors from '@app/degree-planner/store/selectors';
import * as utils from '@app/degree-planner/shared/utils';
import { GlobalState } from '@app/core/state';
import { Store, select } from '@ngrx/store';
import { distinctUntilChanged } from 'rxjs/operators';
import { FormBuilder, FormGroup } from '@angular/forms';
import {
AddCourse,
RemoveSaveForLater,
} from '@app/degree-planner/store/actions/course.actions';
@Component({ @Component({
selector: 'cse-course-details', selector: 'cse-course-details',
templateUrl: './course-details.component.html', templateUrl: './course-details.component.html',
styleUrls: ['./course-details.component.scss'], styleUrls: ['./course-details.component.scss'],
}) })
export class CourseDetailsComponent implements OnInit { export class CourseDetailsComponent implements OnInit, OnDestroy {
courseDetails: CourseDetails; public courseDetails: CourseDetails;
public type: 'course' | 'search' | 'saved';
public selectedSearchTerm: string;
public termSelector: FormGroup;
constructor(@Inject(MAT_DIALOG_DATA) public data: any) { public selectedSearchTerm$: Observable<string>;
public droppableTermCodes$: Observable<string[]>;
public searchTermSubscription: Subscription;
constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
private store: Store<GlobalState>,
private fb: FormBuilder,
) {
this.courseDetails = data.courseDetails; this.courseDetails = data.courseDetails;
this.type = data.courseType;
} }
ngOnInit() {} ngOnInit() {
this.selectedSearchTerm$ = this.store.pipe(
select(selectors.getSelectedSearchTerm),
);
this.droppableTermCodes$ = this.store.pipe(
select(selectors.selectAllVisibleYears),
utils.yearsToDroppableTermCodes(),
distinctUntilChanged(utils.compareStringArrays),
);
this.searchTermSubscription = this.selectedSearchTerm$.subscribe(
termCode => {
this.selectedSearchTerm = termCode;
},
);
this.termSelector = this.fb.group({
term: this.selectedSearchTerm,
});
}
ngOnDestroy() {
this.searchTermSubscription.unsubscribe();
}
addCourseToPlan($event) {
$event.preventDefault();
const termCode = this.termSelector.value.term;
const subjectCode = this.courseDetails.subject.subjectCode;
const courseId = this.courseDetails.courseId;
switch (this.type) {
case 'search':
this.store.dispatch(new AddCourse({ subjectCode, courseId, termCode }));
break;
case 'saved':
this.store.dispatch(new AddCourse({ subjectCode, courseId, termCode }));
this.store.dispatch(new RemoveSaveForLater({ subjectCode, courseId }));
break;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment