src/app/course.service.ts
Provides information and management for a variety of things, but mainly the courses the user selects via the CourseSelectionComponent. Also provides functionality for styling and counts based on Courses' IssueItems.
Properties |
Methods |
constructor()
|
|
Defined in src/app/course.service.ts:53
|
|
Constructor |
| addCourse | ||||||
addCourse(course: Course)
|
||||||
|
Defined in src/app/course.service.ts:67
|
||||||
|
Adds a course to the list of currently selected courses. This will also add and remove them from the user's local storage.
Parameters :
Returns :
void
|
| getBackgroundColorClasses | ||||||
getBackgroundColorClasses(status: )
|
||||||
|
Defined in src/app/course.service.ts:161
|
||||||
|
This is used to determine the background color for an issue card.
Parameters :
Returns :
string
The classes to apply to the element. |
| getCourseIssueCount | ||||||
getCourseIssueCount(status: )
|
||||||
|
Defined in src/app/course.service.ts:98
|
||||||
|
Gets the count of issues under a given status for a single course. Status is optional; returns total count if left blank.
Parameters :
Returns :
number
|
| getStatusIcon | ||||||
getStatusIcon(status: )
|
||||||
|
Defined in src/app/course.service.ts:128
|
||||||
|
This is used to determine the icon shown at the left of an issue on a card. It is determined by the status of the icon. (i.e. "fixed")
Parameters :
Returns :
string
The text used to display the icon. |
| getTextColorClasses | ||||||
getTextColorClasses(status: )
|
||||||
|
Defined in src/app/course.service.ts:145
|
||||||
|
This is used to determine the icon color for the status icon of an individual issue, as shown on an IssueItem card.
Parameters :
Returns :
string
The classes to apply to the element. |
| getTotalIssueCount | ||||||
getTotalIssueCount(status: )
|
||||||
|
Defined in src/app/course.service.ts:116
|
||||||
|
Gets the count of issues under a given status for all courses. Status is optional; returns total count if left blank.
Parameters :
Returns :
number
|
| removeCourse | ||||||
removeCourse(course: Course)
|
||||||
|
Defined in src/app/course.service.ts:85
|
||||||
|
Removes a course from the list of currently selected courses.
Parameters :
Returns :
void
|
| _selectedCourse |
_selectedCourse:
|
Type : Course
|
|
Defined in src/app/course.service.ts:22
|
|
The currently selected Course. |
| courseChange |
courseChange:
|
Default value : new EventEmitter<Course>()
|
|
Defined in src/app/course.service.ts:37
|
|
Emits when a the selected course has changed. Used by lazy-loading components. |
| courseSelectionOpen |
courseSelectionOpen:
|
Default value : false
|
|
Defined in src/app/course.service.ts:32
|
|
Whether or not the CourseSelectionComponent is open. |
| coursesObj |
coursesObj:
|
Type : object
|
Default value : {}
|
|
Defined in src/app/course.service.ts:17
|
|
Holds all of the currently selected Courses. |
| selectedIssueItem |
selectedIssueItem:
|
Type : IssueItem
|
|
Defined in src/app/course.service.ts:27
|
|
The currently selected IssueItem. |
| selectedCourse | ||||
getselectedCourse()
|
||||
|
Defined in src/app/course.service.ts:39
|
||||
setselectedCourse(course: )
|
||||
|
Defined in src/app/course.service.ts:43
|
||||
|
Parameters :
Returns :
void
|
| courses |
getcourses()
|
|
Defined in src/app/course.service.ts:51
|
import { Injectable, EventEmitter } from '@angular/core';
import { Course, IssueItem } from './interfaces';
/**
* Provides information and management for a variety of things, but mainly the
* courses the user selects via the {@link CourseSelectionComponent}. Also provides
* functionality for styling and counts based on {@link Course}s' {@link IssueItem}s.
*/
@Injectable({
providedIn: 'root'
})
export class CourseService {
/**
* Holds all of the currently selected {@link Course}s.
*/
coursesObj: object = {};
/**
* The currently selected {@link Course}.
*/
_selectedCourse: Course;
/**
* The currently selected {@link IssueItem}.
*/
selectedIssueItem: IssueItem;
/**
* Whether or not the {@link CourseSelectionComponent} is open.
*/
courseSelectionOpen = false;
/**
* Emits when a the selected course has changed. Used by lazy-loading components.
*/
courseChange = new EventEmitter<Course>();
get selectedCourse() {
return this._selectedCourse;
}
set selectedCourse(course: Course) {
if (course === this._selectedCourse || !course) return;
// Set the selected course to a reference, so we don't have issues when updating the course objects
this._selectedCourse = course;
this.courseChange.emit(this._selectedCourse);
this.selectedIssueItem = this._selectedCourse.issueItems ? this._selectedCourse.issueItems.find(issueItem => issueItem.course_id === course.id) : null;
}
get courses() {
return Object.keys(this.coursesObj).reduce((acc, key) => [...acc, this.coursesObj[key]], []);
}
/**
* Constructor
*/
constructor() { }
/**
* Adds a course to the list of currently selected courses. This
* will also add and remove them from the user's local storage.
* @param {number} courseId - The ID of the course
* @param {string} courseName - The full name of the course
* @param {string} courseCode - The course code
*/
addCourse(course: Course): void {
if (!this.coursesObj[`c${course.id}`]) {
if (!sessionStorage['katana_course' + course.id]) {
sessionStorage['katana_course' + course.id] = JSON.stringify(course);
}
if (!course.issueItems) {
course.issueItems = [];
}
this.coursesObj[`c${course.id}`] = course;
} else {
this.removeCourse(course);
}
}
/**
* Removes a course from the list of currently selected courses.
* @param {number} courseId - The ID of the course
*/
removeCourse(course: Course): void {
if (sessionStorage['katana_course' + course.id]) {
delete sessionStorage['katana_course' + course.id];
}
delete this.coursesObj[`c${course.id}`];
}
/**
* Gets the count of issues under a given status for a single course.
* Status is optional; returns total count if left blank.
* @param {string} status - The status desired
* @returns {number} - The number of issues with the specified status
*/
getCourseIssueCount(status): number {
if (this.selectedCourse) {
return this.selectedCourse.issueItems.reduce((acc, issueItem) => {
if (!status) {
return acc + issueItem.issues.length;
}
const issues = issueItem.issues.filter(issue => issue.status === status);
return acc + issues.length;
}, 0);
}
}
/**
* Gets the count of issues under a given status for all courses.
* Status is optional; returns total count if left blank.
* @param {string} status - The status desired
* @returns {number} - The number of issues with the specified status
*/
getTotalIssueCount(status): number {
return this.courses.reduce(acc => {
return acc + this.getCourseIssueCount(status);
}, 0);
}
/**
* This is used to determine the icon shown at the left of an issue on
* a card. It is determined by the status of the icon. (i.e. "fixed")
* @param {string} [status] The status of the issue.
* @returns {string} The text used to display the icon.
*/
getStatusIcon(status): string {
const statusIcons = {
'fixed': 'check_circle',
'approved': 'check_circle_outline',
'skipped': 'call_missed_outgoing',
'untouched': 'panorama_fish_eye',
'failed': 'warning'
};
return statusIcons[status];
}
/**
* This is used to determine the icon color for the status icon of an
* individual issue, as shown on an IssueItem card.
* @param {string} [status] The status of the issue.
* @returns {string} The classes to apply to the element.
*/
getTextColorClasses(status): string {
const statusColors = {
'fixed': 'blue-text text-accent-3',
'approved': 'green-text text-accent-4',
'skipped': 'blue-grey-text text-darken-2',
'untouched': 'blue-grey-text text-lighten-4',
'failed': 'red-text'
};
return statusColors[status];
}
/**
* This is used to determine the background color for an issue card.
* @param {string} [status] The status of the issue.
* @returns {string} The classes to apply to the element.
*/
getBackgroundColorClasses(status): string {
const statusColors = {
'fixed': 'blue lighten-4',
'approved': 'mint',
'skipped': 'blue-grey lighten-4',
'untouched': 'white',
'failed': 'red lighten-5'
};
return statusColors[status];
}
}