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

Create AddAcademicYear action

parent d4586c7c
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@
<button mat-button class="sidenav-link-btn"><i class="material-icons">print</i>Print</button>
<button mat-button class="sidenav-link-btn"><i class="material-icons">email</i> Share Plan</button>
<button mat-button class="sidenav-link-btn"><i class="material-icons">add_box</i> Add Degree Plan</button>
<button mat-button class="sidenav-link-btn" (click)="addAcademicYear()"><i class="material-icons">add_box</i> Add Academic Year</button>
</div>
</mat-expansion-panel>
</div>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
// Libraries
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
// State management
import { GlobalState } from '@app/core/state';
import { AddAcademicYearRequest } from '@app/degree-planner/store/actions/addAcademicYear.actions';
@Component({
selector: 'cse-sidenav-menu-item',
templateUrl: './sidenav-menu-item.component.html',
styleUrls: ['./sidenav-menu-item.component.scss'],
})
export class SidenavMenuItemComponent implements OnInit {
constructor() {}
ngOnInit() {}
export class SidenavMenuItemComponent {
constructor(private store: Store<GlobalState>) {}
public addAcademicYear() {
this.store.dispatch(new AddAcademicYearRequest());
}
}
import { Action } from '@ngrx/store';
export enum AddAcademicYearActionTypes {
AddAcademicYearRequest = '[AcademicYear] Add Academic Year Request',
}
export class AddAcademicYearRequest implements Action {
public readonly type = AddAcademicYearActionTypes.AddAcademicYearRequest;
}
......@@ -23,6 +23,10 @@ import {
WriteNoteSuccess,
DeleteNoteSuccess,
} from '@app/degree-planner/store/actions/note.actions';
import {
AddAcademicYearActionTypes,
AddAcademicYearRequest,
} from '@app/degree-planner/store/actions/addAcademicYear.actions';
import { SavedForLaterCourse } from '@app/core/models/saved-for-later-course';
import { DegreePlan } from '@app/core/models/degree-plan';
......@@ -36,6 +40,7 @@ type SupportedActions =
| AddCourseSuccess
| RemoveSaveForLaterSuccess
| AddSaveForLaterSuccess
| AddAcademicYearRequest
| MakePlanPrimary
| MakePlanPrimarySuccess
| MakePlanPrimaryFailure;
......@@ -64,6 +69,32 @@ export function degreePlannerReducer(
return { ...state, ...action.payload };
}
/**
* The `AddAcademicYearRequest` action is triggered after `addAcademicYear()`
* function runs. A new academic year container with three terms will be created.
*/
case AddAcademicYearActionTypes.AddAcademicYearRequest: {
const originalTerms = state.visibleTerms.map( term => {
return parseInt(term.termCode.substr(0, 3), 10);
});
const newAcademicYearCode = Math.max(...originalTerms) + 1;
const newVisibleTerms = [
...state.visibleTerms,
{ termCode: `${newAcademicYearCode}2`,
courses: []
},
{ termCode: `${newAcademicYearCode}4`,
courses: []
},
{ termCode: `${newAcademicYearCode}6`,
courses: []
}
];
return { ...state, visibleTerms: newVisibleTerms };
}
/**
* The `WriteNoteResponse` action is dispatched by the `Note.write$` effect
* upon a successful response from the `updateNote` or `createNote` API
......
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