From 4b5bded58b6ee2735745465cb43035d7809406a1 Mon Sep 17 00:00:00 2001 From: pnogal <paulina.nogal@wisc.edu> Date: Thu, 21 Feb 2019 10:05:54 -0600 Subject: [PATCH] Include active term in user messages --- .../degree-planner.component.ts | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/app/degree-planner/degree-planner.component.ts b/src/app/degree-planner/degree-planner.component.ts index 4db1008..b87a209 100644 --- a/src/app/degree-planner/degree-planner.component.ts +++ b/src/app/degree-planner/degree-planner.component.ts @@ -4,8 +4,8 @@ import { withLatestFrom, distinctUntilChanged, } from 'rxjs/operators'; -import { OnInit } from '@angular/core'; -import { Observable, of } from 'rxjs'; +import { OnInit, OnDestroy } from '@angular/core'; +import { Observable, of, Subscription } from 'rxjs'; import { select } from '@ngrx/store'; import { Component } from '@angular/core'; import { MatSelectChange } from '@angular/material'; @@ -34,16 +34,18 @@ import { CloseCourseSearch, } from './store/actions/ui.actions'; +// Pipes +import { GetTermDescriptionPipe } from '@app/shared/pipes/get-term-description.pipe'; + @Component({ selector: 'cse-degree-planner', templateUrl: './degree-planner.component.html', styleUrls: ['./degree-planner.component.scss'], }) -export class DegreePlannerComponent implements OnInit { +export class DegreePlannerComponent implements OnInit, OnDestroy { public termsByAcademicYear: Object; public mobileView: MediaQueryList; public coursesData$: any; - public degreePlan$: Observable<DegreePlan | undefined>; public allDegreePlans$: Observable<DegreePlan[]>; public firstActiveTermCode$: Observable<string | undefined>; @@ -51,6 +53,8 @@ export class DegreePlannerComponent implements OnInit { public yearCodes$: Observable<string[]>; public isCourseSearchOpen$: Observable<boolean>; public isLoadingPlan$: Observable<boolean>; + public activeTermSubscription: Subscription; + public firstActiveTerm: string; constructor( private store: Store<GlobalState>, @@ -85,6 +89,11 @@ export class DegreePlannerComponent implements OnInit { ); } + // Unsubscribe from subs to prevent memeory leaks + public ngOnDestroy() { + this.activeTermSubscription.unsubscribe(); + } + public handleAcademicYearToggle(year: Year): void { // this.store.dispatch( // new ToggleAcademicYear({ year: year.twoDigitYearCode.toString() }), @@ -139,13 +148,22 @@ export class DegreePlannerComponent implements OnInit { } public onMakePrimayClick(currentPlan: DegreePlan) { + this.activeTermSubscription = this.store + .pipe(select(selectors.getActiveTerms)) + .subscribe(terms => { + this.firstActiveTerm = terms[0]; + }); + + const currentTerm: any = new GetTermDescriptionPipe().transform( + this.firstActiveTerm, + ); + this.dialog .open(ConfirmDialogComponent, { data: { title: 'Are you sure?', confirmText: 'Change plan', - text: - "This will change your primary plan and replace the current courses in your cart with the courses in this plan's active term", + text: `This will change your primary plan and replace the current courses in your cart with the courses in this plan's ${currentTerm} term`, }, }) .afterClosed() -- GitLab