src/app/course-tabs/course-chip/course-chip.component.ts
Represents a Course to be acted on. Generated based on the array of Courses stored in CourseService.
| selector | app-course-chip |
| styleUrls | course-chip.component.css |
| templateUrl | ./course-chip.component.html |
Properties |
|
Methods |
Inputs |
constructor(courseService: CourseService, toolService: ToolService)
|
||||||||||||
|
Constructor
Parameters :
|
course
|
The Course this chip represents
Type: |
| buildInstructorName |
buildInstructorName()
|
|
Formats the instructor's name to fit on the chip appropriately.
Returns :
string
The formatted instructor name. |
| openCourse |
openCourse()
|
|
Opens the course in Canvas in a new tab.
Returns :
void
|
| Public courseService |
courseService:
|
Type : CourseService
|
|
Allows this component to identify the currently selected course.
|
import { Component, Input } from '@angular/core';
import { CourseService } from '../../course.service';
import { ToolService } from '../../tool.service'; // Used in course-chip.component.html (i.e. DO NOT DELETE)
import { Course } from '../../interfaces';
/**
* Represents a {@link Course} to be acted on. Generated based on the array of Courses stored in {@link CourseService}.
*/
@Component({
selector: 'app-course-chip',
templateUrl: './course-chip.component.html',
styleUrls: ['./course-chip.component.css']
})
export class CourseChipComponent {
/**
* The {@link Course} this chip represents
*/
@Input() course: Course;
/**
* Constructor
* @param courseService Allows this component to identify the currently selected course.
* @param toolService Allows this component to identify if the tool view is open.
* Used in course-chip.component.html (i.e. DO NOT DELETE).
*/
constructor(public courseService: CourseService,
private toolService: ToolService) { }
/**
* Opens the course in Canvas in a new tab.
*/
openCourse(): void {
window.open('https://byui.instructure.com/courses/' + this.course.id, '_blank');
}
/**
* Formats the instructor's name to fit on the chip appropriately.
* @returns {string} The formatted instructor name.
*/
buildInstructorName(): string {
const names = this.course.instructor.replace(/,/, '').split(' ');
let instructorName = this.course.instructor === 'none' ? 'No Instructor' : this.course.instructor;
if (names.length > 1 && this.course.instructor.includes(',')) {
instructorName = `${names[1][0]}. ${names[0]}`;
} else if (names.length > 1) {
instructorName = `${names[0][0]}. ${names[1]}`;
}
return instructorName;
}
/**
* Opens the course in Canvas in a new tab.
* @param {string} status Issue status to match
* @returns {number} The total number of issues matching the provided status.
*/
getIssueCount(status): number | string {
if (!this.course.issueItems) return 0;
if (this.course.error) return 'E';
return this.course.issueItems.reduce((acc, issueItem) => {
let issues = issueItem.issues.filter(issue => {
if (!status) return true;
return issue.status === status;
});
return acc + issues.length;
}, 0);
}
}
<div class="courseChip__container no-select">
<div class="courseChip blue-grey z-depth-1" [class.selectable]="toolService.toolViewOpen" [class.selected]="courseService.selectedCourse === course && toolService.toolViewOpen"
(click)="courseService.selectedCourse = course">
<span class="courseChip__courseDetails">
{{course.course_code}}
<div class="courseChip__instructorName">
{{buildInstructorName()}}
</div>
</span>
<div *ngIf="!course.processing && toolService.toolViewOpen" class="blue-grey darken-2 white-text courseChip__issueCount"
[class.error]="course.error !== undefined">
<span class="white-text countBadge__count">
{{getIssueCount()}}
</span>
</div>
<div *ngIf="course.processing" class="loading-dancer">.</div>
</div>
<i class=" material-icons smooth-width" *ngIf="courseService.courseSelectionOpen" (click)="courseService.removeCourse(course)">
clear
</i>
<i class="material-icons smooth-width" *ngIf="courseService.courseSelectionOpen" (click)="openCourse()">
open_in_new
</i>
</div>