Skip to content
Snippets Groups Projects
Commit 1859ee57 authored by pnogal's avatar pnogal Committed by Paulina Nogal
Browse files

Display cart courses

parent a81653c6
No related branches found
No related tags found
No related merge requests found
<div class="course-item {{disabled ? 'disabled' : ''}}"> <div class="course-item {{ disabled ? 'disabled' : '' }}">
<div fxLayout="row" fxLayoutAlign="space-between start"> <div fxLayout="row" fxLayoutAlign="space-between start">
<div fxLayout="column" fxLayoutAlign="space-between start" fxFlex="80" (click)="openCourseDetailsDialog(course)"> <div
fxLayout="column"
fxLayoutAlign="space-between start"
fxFlex="80"
(click)="openCourseDetailsDialog(course)"
>
<div fxLayout="row" fxLayoutAlign="start center"> <div fxLayout="row" fxLayoutAlign="start center">
<div class="icon-number-wrapper"> <div class="icon-number-wrapper">
<p class="course-number"> <p class="course-number">
{{ course.subject }} {{course.catalogNumber}} {{ course.subject }} {{ course.catalogNumber }}
</p> </p>
<span [ngSwitch]="status"> <span [ngSwitch]="status">
<i *ngSwitchCase="'Enrolled'" class="material-icons in-progress-icon" matTooltip="Course in progress" matTooltipPosition="above">check_circle</i> <i
<i *ngSwitchCase="'Waitlisted'" class="material-icons problem-icon" matTooltip="Course is waitlisted" matTooltipPosition="above">report_problem</i> *ngSwitchCase="'Enrolled'"
<i *ngSwitchCase="'Incomplete'" class="material-icons error-icon" matTooltip="Course is incomplete" matTooltipPosition="above">error</i> class="material-icons in-progress-icon"
</span> matTooltip="Course in progress"
</div> matTooltipPosition="above"
>check_circle</i
>
<i
*ngSwitchCase="'Waitlisted'"
class="material-icons problem-icon"
matTooltip="Course is waitlisted"
matTooltipPosition="above"
>report_problem</i
>
<i
*ngSwitchCase="'Incomplete'"
class="material-icons error-icon"
matTooltip="Course is incomplete"
matTooltipPosition="above"
>error</i
>
</span>
</div>
</div> </div>
<div fxLayout="row" fxLayoutAlign="start center"> <div fxLayout="row" fxLayoutAlign="start center">
<p class="course-title">{{course.title}}</p> <p class="course-title">{{ course.title }}</p>
</div> </div>
</div> </div>
<div fxLayout="column" fxLayoutAlign="space-between end" fxFlex="20"> <div fxLayout="column" fxLayoutAlign="space-between end" fxFlex="20">
<div *ngIf="!disabled" fxLayout="row" fxLayoutAlign="end center"> <div *ngIf="!disabled" fxLayout="row" fxLayoutAlign="end center">
<mat-icon [matMenuTriggerFor]="courseMenu" (menuOpened)="onMenuOpen()" aria-label="Course menu" matTooltip="Course Menu" matTooltipPosition="right" <mat-icon
class="material-icons">more_horiz</mat-icon> [matMenuTriggerFor]="courseMenu"
(menuOpened)="onMenuOpen()"
aria-label="Course menu"
matTooltip="Course Menu"
matTooltipPosition="right"
class="material-icons"
>more_horiz</mat-icon
>
<mat-menu #courseMenu="matMenu" class="course-item-menu"> <mat-menu #courseMenu="matMenu" class="course-item-menu">
<button mat-menu-item (click)="openCourseDetailsDialog(course)">Course Details</button> <button mat-menu-item (click)="openCourseDetailsDialog(course)">
<button mat-menu-item [matMenuTriggerFor]="academicYearsGroup">Move</button> Course Details
</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 *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
<button mat-menu-item *ngIf="type !== 'search'" (click)="onRemove()">Remove</button> mat-menu-item
*ngIf="type !== 'saved'"
(click)="onSaveForLater()"
>
Save for later
</button>
<button mat-menu-item *ngIf="type !== 'search'" (click)="onRemove()">
Remove
</button>
</mat-menu> </mat-menu>
</div> </div>
<div *ngIf="disabled" fxLayout="row" fxLayoutAlign="end center"> <div *ngIf="disabled" fxLayout="row" fxLayoutAlign="end center">
<p>{{ course.grade || '&nbsp;' }}</p> <p>{{ course.grade || '&nbsp;' }}</p>
</div> </div>
<div fxLayout="row" fxLayoutAlign="end center"> <div fxLayout="row" fxLayoutAlign="end center">
<p class="course-credits">{{ course.credits ? course.credits : course.creditRange }} Cr</p> <p class="course-credits">
{{ course.credits ? course.credits : course.creditRange }} Cr
</p>
</div> </div>
</div> </div>
</div> </div>
......
<mat-card class="term-container"> <mat-card class="term-container">
<div class="term-inner"> <div class="term-inner">
<div fxLayout="row" class="term-header" fxLayoutAlign="space-between center"> <div
fxLayout="row"
class="term-header"
fxLayoutAlign="space-between center"
>
<h2>{{ termCode | getTermDescription }}</h2> <h2>{{ termCode | getTermDescription }}</h2>
<div fxLayout="row" fxLayoutAlign="space-between center"> <div fxLayout="row" fxLayoutAlign="space-between center">
<p class="text-right semi-bold credits">{{ credits$ | async }} Cr</p> <p class="text-right semi-bold credits">{{ credits$ | async }} Cr</p>
...@@ -10,7 +14,13 @@ ...@@ -10,7 +14,13 @@
aria-label="Open dialog with notes in this term" aria-label="Open dialog with notes in this term"
color="primary" color="primary"
matTooltip="Edit Note" matTooltip="Edit Note"
<<<<<<< HEAD
matTooltipPosition="above"> matTooltipPosition="above">
=======
(click)="openNotesDialog(note)"
matTooltipPosition="above"
>
>>>>>>> Display cart courses
insert_drive_file insert_drive_file
</mat-icon> </mat-icon>
</button> </button>
...@@ -21,18 +31,31 @@ ...@@ -21,18 +31,31 @@
aria-label="Open dialog with notes in this term" aria-label="Open dialog with notes in this term"
color="primary" color="primary"
matTooltip="Add Note" matTooltip="Add Note"
<<<<<<< HEAD
matTooltipPosition="above"> matTooltipPosition="above">
note_add note_add
</mat-icon> </mat-icon>
</button> </button>
</ng-template> </ng-template>
=======
(click)="openNotesDialog()"
matTooltipPosition="above"
>
note_add
</mat-icon>
</ng-template>
</button>
>>>>>>> Display cart courses
</div> </div>
</div> </div>
<div id="term-{{termCode}}" class="term-body" cdkDropList <div
id="term-{{ termCode }}"
class="term-body"
cdkDropList
[cdkDropListData]="(term$ | async).termCode" [cdkDropListData]="(term$ | async).termCode"
[cdkDropListConnectedTo]="dropZoneIds$ | async" [cdkDropListConnectedTo]="dropZoneIds$ | async"
(cdkDropListDropped)="drop($event)"> (cdkDropListDropped)="drop($event)"
>
<!-- Render term note (if it exists) --> <!-- Render term note (if it exists) -->
<ng-container *ngIf="note$ | async as note"> <ng-container *ngIf="note$ | async as note">
<ng-container *ngIf="note.isLoaded; else noteIsLoading"> <ng-container *ngIf="note.isLoaded; else noteIsLoading">
...@@ -50,33 +73,96 @@ ...@@ -50,33 +73,96 @@
</ng-template> </ng-template>
</ng-container> </ng-container>
<!-- Render list of cart courses in this term -->
<div
*ngIf="(term$ | async).era == 'active'"
fxLayout="row"
class="term-header"
fxLayoutAlign="space-between center"
>
<h3>My Courses: Cart</h3>
<div fxLayout="row" fxLayoutAlign="space-between center">
<p class="text-right semi-bold credits">
{{ cartCredits$ | async }} Cr
</p>
<button mat-icon-button>
<a href="/my-courses">
<mat-icon
aria-label="Go to cart"
color="primary"
matTooltip="Go to cart"
matTooltipPosition="above"
>
shopping_cart
</mat-icon>
</a>
</button>
</div>
</div>
<div
class="course-wrapper"
*ngFor="let course of (courses$ | async)"
cdkDrag
[cdkDragData]="course"
>
<ng-container class="course-wrapper-inner" *ngIf="course.id !== null">
<cse-course-item
type="course"
[course]="course"
[isPastTerm]="isPastTerm$ | async"
>
</cse-course-item>
</ng-container>
</div>
<div class="no-courses" *ngIf="(courses$ | async).length == 0">
<p>
No courses planned
</p>
</div>
<!-- Render list of courses in this term --> <!-- Render list of courses in this term -->
<div class="course-wrapper" *ngFor="let course of courses$ | async" <div
class="course-wrapper"
*ngFor="let course of (courses$ | async)"
cdkDrag cdkDrag
[cdkDragDisabled]="(isPastTerm$ | async) || course.id === null" [cdkDragDisabled]="(isPastTerm$ | async) || course.id === null"
[cdkDragData]="course"> [cdkDragData]="course"
<div class="course-wrapper-inner"> >
<ng-container class="course-wrapper-inner" *ngIf="course.id === null">
<cse-course-item <cse-course-item
type="course" type="course"
[course]="course" [course]="course"
[isPastTerm]="(isPastTerm$ | async)" [isPastTerm]="isPastTerm$ | async"
[isCurrentTerm]="(isCurrentTerm$ | async)" [isCurrentTerm]="isCurrentTerm$ | async"
[disabled]="(isPastTerm$ | async) || (course.id === null)"> [disabled]="(isPastTerm$ | async) || course.id === null"
>
</cse-course-item> </cse-course-item>
</div> </ng-container>
</div> </div>
<div
<div class="no-courses" *ngIf="(courses$ | async).length === 0"> class="no-courses"
<p>{{ (isPastTerm$ | async) ? 'No Courses Taken' : 'No Courses Planned' }}</p> *ngIf="
(courses$ | async).length === 0 && (term$ | async).era == 'passt'
"
>
<p>
{{
(isPastTerm$ | async) ? 'No courses Taken' : 'No enrolled courses'
}}
</p>
</div> </div>
</div> </div>
</div> </div>
<!-- Add course -->
<div class="add-new-wrapper" *ngIf="(isPastTerm$ | async) === false"> <div class="add-new-wrapper" *ngIf="(isPastTerm$ | async) === false">
<button <button
mat-raised-button mat-raised-button
class="add-course-button" class="add-course-button"
(click)="openCourseSearch()"> (click)="openCourseSearch()"
>
+ Add Course + Add Course
</button> </button>
</div> </div>
</mat-card> </mat-card>
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
h2 { h2 {
margin: 0; margin: 0;
} }
h3 {
font-weight: 400;
}
.mat-icon-button { .mat-icon-button {
line-height: 20px; line-height: 20px;
......
...@@ -25,13 +25,20 @@ import * as utils from '@app/degree-planner/shared/utils'; ...@@ -25,13 +25,20 @@ import * as utils from '@app/degree-planner/shared/utils';
const isntUndefined = <T>(thing: T | undefined): thing is T => { const isntUndefined = <T>(thing: T | undefined): thing is T => {
return thing !== undefined; return thing !== undefined;
}; };
const sumCredits = (courses: Course[]): number => { const sumCredits = (courses: Course[]): number => {
return courses.reduce((sum, course) => { return courses.reduce((sum, course) => {
return sum + course.credits; return sum + course.credits;
}, 0); }, 0);
}; };
const sumCreditsInCart = (courses: Course[]): number => {
return courses
.filter(course => course.id)
.reduce((sum, course) => {
return sum + parseInt(course.creditRange);
}, 0);
};
@Component({ @Component({
selector: 'cse-term-container', selector: 'cse-term-container',
templateUrl: './term-container.component.html', templateUrl: './term-container.component.html',
...@@ -46,6 +53,7 @@ export class TermContainerComponent implements OnInit { ...@@ -46,6 +53,7 @@ export class TermContainerComponent implements OnInit {
public note$: Observable<PlannedTermNote | undefined>; public note$: Observable<PlannedTermNote | undefined>;
public courses$: Observable<Course[]>; public courses$: Observable<Course[]>;
public credits$: Observable<number>; public credits$: Observable<number>;
public cartCredits$: Observable<number>;
public isPastTerm$: Observable<boolean>; public isPastTerm$: Observable<boolean>;
public dropZoneIds$: Observable<string[]>; public dropZoneIds$: Observable<string[]>;
public isCurrentTerm$: Observable<boolean>; public isCurrentTerm$: Observable<boolean>;
...@@ -80,6 +88,11 @@ export class TermContainerComponent implements OnInit { ...@@ -80,6 +88,11 @@ export class TermContainerComponent implements OnInit {
distinctUntilChanged(), distinctUntilChanged(),
); );
this.cartCredits$ = this.courses$.pipe(
map(sumCreditsInCart),
distinctUntilChanged(),
);
this.isPastTerm$ = this.term$.pipe( this.isPastTerm$ = this.term$.pipe(
map(term => term.era === 'past'), map(term => term.era === 'past'),
distinctUntilChanged(), distinctUntilChanged(),
......
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