File

src/app/tool-page/issue-nav/issue-nav.component.ts

Description

Container for managing various actions on the tool view page, such as the "Fix All Approved" button.

Metadata

selector app-issue-nav
styleUrls issue-nav.component.css
templateUrl ./issue-nav.component.html

Index

Properties
Methods

Constructor

constructor(courseService: CourseService, toolService: ToolService, katanaService: KatanaService)

Constructor

Parameters :
Name Type Optional Description
courseService CourseService no

Provides information and management for selected courses.

toolService ToolService no

Provides information and management for available tools.

katanaService KatanaService no

Provides functionality to make API calls to the Katana server.

Methods

closeModal
closeModal()

Closes the modal using angular2-materialize.

Returns : void
downloadIssues
downloadIssues()

Downloads a CSV to the user's computer containing all of the currently displayed issues.

Returns : void
getIssueItems
getIssueItems(course: )

Returns the user the IssueItems belonging to the provided course.

Parameters :
Name Optional Description
course no

The course to retrieve the IssueItems from.

Returns : any

The IssueItems belonging to the provided course.

openModal
openModal()

Opens the modal using angular2-materialize.

Returns : void
selectIssueItem
selectIssueItem(course: , issue: )

Sets the currently selected course and currently selected IssueItem.

Parameters :
Name Optional Description
course no

The course to set as the currently selected course.

issue no

The issue to use to set the currently selected IssueItem.

Returns : void

Properties

Public courseService
courseService: CourseService
Type : CourseService
Provides information and management for selected courses.
Public katanaService
katanaService: KatanaService
Type : KatanaService
Provides functionality to make API calls to the Katana server.
modalActions
modalActions: EventEmitter<string | MaterializeAction>
Type : EventEmitter<string | MaterializeAction>
Default value : new EventEmitter<string | MaterializeAction>()

From angular2-materialize, which allows the modal to open and close.

Public toolService
toolService: ToolService
Type : ToolService
Provides information and management for available tools.
import { Component } from '@angular/core';
import { CourseService } from '../../course.service';
import { KatanaService } from '../../katana.service';
import { MaterializeAction } from 'angular2-materialize';
import { EventEmitter } from '@angular/core';
import { ToolService } from '../../tool.service';
import { csvFormatRows } from 'd3-dsv';

/**
 * Container for managing various actions on the tool view page,
 * such as the "Fix All Approved" button.
 */
@Component({
    selector: 'app-issue-nav',
    templateUrl: './issue-nav.component.html',
    styleUrls: ['./issue-nav.component.css']
})
export class IssueNavComponent {

    /**
     * From [angular2-materialize]{@link https://www.npmjs.com/package/angular2-materialize},
     * which allows the modal to open and close.
     */
    modalActions: EventEmitter<string | MaterializeAction> = new EventEmitter<string | MaterializeAction>();

    /**
     * Constructor
     * @param courseService Provides information and management for selected courses.
     * @param toolService Provides information and management for available tools.
     * @param katanaService Provides functionality to make API calls to the Katana server.
     */
    constructor(public courseService: CourseService,
        public toolService: ToolService,
        public katanaService: KatanaService) { }


    /**
     * Opens the modal using [angular2-materialize]{@link https://www.npmjs.com/package/angular2-materialize}.
     */
    openModal() {
        this.modalActions.emit({ action: 'modal', params: ['open'] });
    }

    /**
     * Closes the modal using [angular2-materialize]{@link https://www.npmjs.com/package/angular2-materialize}.
     */
    closeModal() {
        this.modalActions.emit({ action: 'modal', params: ['close'] });
    }

    /**
     * Returns the user the {@link IssueItem}s belonging to the provided course.
     * @param course The course to retrieve the IssueItems from.
     * @returns {IssueItem[]} The IssueItems belonging to the provided course.
     */
    getIssueItems(course) {
        if (!course.issueItems) { return []; }
        return course.issueItems.reduce((acc, issueItem) => {
            if (!issueItem.issues) { return acc; }
            return [...acc, ...issueItem.issues];
        }, []);
    }

    /**
     * Sets the currently selected course and currently selected {@link IssueItem}.
     * @param course The course to set as the currently selected course.
     * @param issue The issue to use to set the currently selected IssueItem.
     */
    selectIssueItem(course, issue) {
        this.courseService.selectedCourse = course;
        this.courseService.selectedIssueItem = course.issueItems.find(issueItem => issueItem.issues.includes(issue));
        this.closeModal();
    }

    /**
     * Downloads a CSV to the user's computer containing all of the
     * currently displayed issues.
     */
    downloadIssues() {
        let csvReport = '';
        this.courseService.courses.forEach((course, i) => {
            course.issueItems.forEach((issueItem, j) => {
                if (i < 1 && j < 1) {
                    csvReport = csvFormatRows([[
                        'Issue Title',
                        'Status',
                        'Option Values',
                        'Item Title',
                        'Item ID',
                        'Course ID',
                        'Category',
                        'Link',
                        'Details',
                    ]].concat(issueItem.issues.map(issue => {
                        const flatIssueDetails = Object.entries(issue.details).reduce((acc, pair) => {
                            const detail = `${pair[0]}: ${pair[1]}`;
                            return acc.concat(detail);
                        }, []);

                        return [
                            issue.title,
                            issue.status,
                            issue.optionValues ? issue.optionValues : '',
                            issueItem.title,
                            issueItem.item_id,
                            issueItem.course_id,
                            issueItem.category,
                            issueItem.link,
                            ...flatIssueDetails
                        ];
                    }))) + '\n';
                } else {
                    // Make the log without the header
                    csvReport += csvFormatRows(issueItem.issues.map(issue => {
                        const flatIssueDetails = Object.entries(issue.details).reduce((acc, pair) => {
                            const detail = `${pair[0]}: ${pair[1]}`;
                            return acc.concat(detail);
                        }, []);
                        return [
                            issue.title,
                            issue.status,
                            issue.optionValues ? issue.optionValues : '',
                            issueItem.title,
                            issueItem.item_id,
                            issueItem.course_id,
                            issueItem.category,
                            issueItem.link,
                            ...flatIssueDetails
                        ];
                    })) + '\n';
                }
            });
        });

        // Setup the link to download the csv report
        const fileName = 'csvReport.csv';
        const a = <HTMLAnchorElement>document.getElementById('download');
        const blob = new Blob([csvReport], { type: 'octet/stream' });
        const url = window.URL.createObjectURL(blob);

        a.href = url;
        a.download = fileName;
    }
}
<div materialize class="issueApproval navy" *ngIf="courseService.selectedCourse.error === undefined && toolService.selectedTool.toolType === 'fix'">

    <!-- Container to hold the fix approved and kebob menu buttons -->
    <div class="issueApproval__buttonContainer">
        <!-- Fix Approved Button -->
        <div class="issueApproval__button">
            <a href="#fixModal" class="modal-trigger waves-effect white-text waves btn-flat" (click)="openModal('fixApproved')">
                <i class="material-icons left">build</i>
                Fix Approved Issues
            </a>
        </div>
    </div>

    <!-- The dropdown menu from the kebob menu -->
    <ul id="dropdown1" class="dropdown-content">
        <li>
            <a (click)="downloadIssues()" id="download">
                <i class="material-icons left">cloud_download</i>
                Download CSV
            </a>
        </li>
    </ul>

    <!-- The Kebob menu at the far right of the bottom bar -->
    <div>
        <a materialize="dropdown" [materializeParams]="[{constrain_width: false, alignment: 'left'}]" class="dropdown-button issueApproval_moreButton"
            data-activates="dropdown1">
            <i class="material-icons blue-grey-text text-lighten-3">more_vert</i>
        </a>
    </div>
</div>

<!-- Modal - Must stay beneath the main container -->
<div id="fixModal" class="modal modal-fixed-footer" materialize="modal" [materializeActions]="modalActions">

    <div class="modal-content">
        <h4>Issues</h4>

        <table class="striped">
            <tbody>
                <tr *ngFor="let course of courseService.courses" class="flex-container" style="width:100%">
                    <td>
                        <app-stat-badge class="overview-statBadge" (click)="closeModal();courseService.selectedCourse = course" [statTitle]="course.course_code"
                            [statCount]="getIssueItems(course).length" [side]="'left'"></app-stat-badge>
                    </td>
                    <td style="flex-grow:1;display:flex;flex-wrap:wrap;margin-left: 10px">
                        <i *ngFor="let issue of getIssueItems(course)" class="material-icons issueIcon" [ngClass]="courseService.getTextColorClasses(issue.status)"
                            (click)="selectIssueItem(course, issue)">
                            {{courseService.getStatusIcon(issue.status)}}
                        </i>
                    </td>
                    <!-- <td>
                        <a class="waves-effect btn-flat blue-text text-accent-3 right" (click)="katanaService.fixIssues([course])">Fix</a>
                    </td> -->
                </tr>
            </tbody>
        </table>

    </div>
    <div class="modal-footer">
        <a class="modal-action modal-close waves-effect btn-flat blue-grey-text text-darken-3 left" (click)="closeModal()">Cancel</a>
        <a class="modal-action modal-close waves-effect btn blue accent-3" (click)="katanaService.fixIssues(courseService.courses)">Fix All Approved Issues</a>
    </div>

</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""