File

src/app/home-page/options-view/options-view.component.ts

Description

Container for the options page. Holds all related options components.

Metadata

selector app-options-view
styleUrls options-view.component.css
templateUrl ./options-view.component.html

Index

Properties
Methods

Constructor

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

Constructor

Parameters :
Name Type Optional Description
toolService ToolService no

Provides information and management for available courses.

katanaService KatanaService no

Provides functionality to make API calls to the Katana server.

courseService CourseService no

Provides information and management for selected courses.

router Router no

Used to navigate the user as needed.

Methods

closeModal
closeModal()

Closes the modal using angular2-materialize.

Returns : void
noCourseModalOpen
noCourseModalOpen()

Determines the open/close status of the "no courses selected" modal.

Returns : boolean

Whether or not the modal is currently open.

onSubmit
onSubmit()

Actions taken when the user clicks the "Run Tool" button. Gathers up the answers on the options form, then submits them to the Katana Service to run the tool in discovery mode.

Returns : void
openModal
openModal()

Opens the modal using angular2-materialize.

Returns : void

Properties

Public courseService
courseService: CourseService
Type : CourseService
Provides information and management for selected courses.
formGroup
formGroup: FormGroup
Type : FormGroup

The FormGroup to use for the form.

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.

optionModel
optionModel: OptionModel
Type : OptionModel

The OptionModel to use for the form.

options
options: DiscoverOption[]
Type : DiscoverOption[]

The options to display on the page.

Public toolService
toolService: ToolService
Type : ToolService
Provides information and management for available courses.
import { Component, EventEmitter } from '@angular/core';
import { Router } from '@angular/router';
import { ToolService } from '../../tool.service';
import { CourseService } from '../../course.service';
import { KatanaService } from '../../katana.service';
import { MaterializeAction } from 'angular2-materialize';
import { FormGroup } from '@angular/forms';
import { DiscoverOption } from '../../interfaces';
import { OptionModel } from '../../classes';

/**
 * Container for the options page. Holds all related
 * options components.
 */
@Component({
    selector: 'app-options-view',
    templateUrl: './options-view.component.html',
    styleUrls: ['./options-view.component.css']
})
export class OptionsViewComponent {

    /**
     * The options to display on the page.
     */
    options: DiscoverOption[];
    /**
     * The {@link OptionModel} to use for the form.
     */
    optionModel: OptionModel;
    /**
     * The FormGroup to use for the form.
     */
    formGroup: FormGroup;

    /**
     * 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 {ToolService} toolService Provides information and management for available courses.
     * @param {KatanaService} katanaService Provides functionality to make API calls to the Katana server.
     * @param {CourseService} courseService Provides information and management for selected courses.
     * @param {Router} router Used to navigate the user as needed.
     */
    constructor(public toolService: ToolService,
        public katanaService: KatanaService,
        public courseService: CourseService,
        private router: Router) {

        this.optionModel = new OptionModel(this.toolService.selectedTool.discoverOptions);
        this.formGroup = this.optionModel.toGroup();
    }

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

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

    /**
     * Determines the open/close status of the "no courses selected" modal.
     * @returns {boolean} Whether or not the modal is currently open.
     */
    noCourseModalOpen(): boolean {
        return !!document.querySelector('#fixModal.open');
    }

    /**
     * Actions taken when the user clicks the "Run Tool" button.
     * Gathers up the answers on the options form, then submits
     * them to the Katana Service to run the tool in discovery mode.
     */
    onSubmit(): void {
        if (this.courseService.courses.length === 0) {
            this.openModal();
            return;
        }

        const options = { categories: [] };
        Object.keys(this.formGroup.controls).forEach(key => {
            options[key] = this.formGroup.controls[key].value;
        });

        const categoryInputs = Array.from(document.querySelectorAll('.canvas-category')) as HTMLInputElement[];
        categoryInputs.forEach(category => {
            if (category.checked) {
                options.categories.push(category.id);
            }
        });

        // Send request
        this.toolService.selectedDiscoverOptions = options;
        this.katanaService.discoverIssues(this.courseService.courses)
            .catch(console.error);
        this.router.navigate([`home/tools/${this.toolService.selectedTool.id}/issues`]);
    }

}
<div [class.frosted]="this.courseService.courseSelectionOpen" class="optionsView">
    <div class="optionsView__container card">

        <form materialize (ngSubmit)="onSubmit()" [formGroup]="formGroup" #optionsForm="ngForm">
            <div class="card-content">
                <h1 style="padding:0;font-size:24px">Options</h1>
                <h2 class="cobalt-text">
                    {{toolService.selectedTool.title}}
                </h2>

                <div>
                    <h3>Description</h3>
                    <div>{{toolService.selectedTool.description}}</div>
                </div>

                <div>
                    <h3>Categories</h3>
                    <div style="display:flex">
                        <div class="categories-container" *ngFor="let category of toolService.selectedTool.categories">
                            <input [id]="category" type="checkbox" class="filled-in blue accent-3 canvas-category" checked="checked">
                            <label [for]="category">{{category}}</label>
                        </div>
                    </div>
                </div>

                <div *ngFor="let option of optionModel.options" class="form-row">
                    <h3>{{option.title}}</h3>
                    <div class="option__description">{{option.description}}</div>
                    <div [ngSwitch]="option.type" class="option__container" [class.multiselect]="option.type === 'multiselect'" [class.required]="!formGroup.controls[option.key].valid">
                        <div class="option__text" *ngSwitchCase="'text'">
                            <input type="{{option.type}}" id="{{option.key}}" [formControlName]="option.key">
                        </div>
                        <div *ngSwitchCase="'dropdown'">
                            <select style="display: block" [formControlName]="option.key">
                                <option *ngFor="let choice of option.choices">{{choice}}</option>
                            </select>
                        </div>
                        <div *ngSwitchCase="'multiselect'">
                            <select style="display: block" [formControlName]="option.key" multiple>
                                <option *ngFor="let choice of option.choices">{{choice}}</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card-action">
                <button type="button" class="btn white blue-grey-text text-darken-4" routerLink="/">Cancel</button>
                <button type="submit" class="waves-effect waves btn blue" [disabled]="!formGroup.valid">Run Tool</button>
            </div>
        </form>
    </div>
</div>

<!-- Modal - Must stay beneath the main container -->
<div id="fixModal" class="modal" materialize="modal" [materializeActions]="modalActions">
    <div class="modal-content">
        <h4>No Courses Selected</h4>
        <p>You must select at least one course before continuing.</p>
    </div>
    <div class="modal-footer">
        <a class="modal-action modal-close waves-effect btn blue">Got it!</a>
    </div>
</div>
<div *ngIf="noCourseModalOpen()" class="arrowIndicator">
    <div>
        Click here to Add Courses
    </div>
    <i style="font-size: 40px;margin-right: 15px;" class="material-icons">arrow_forward</i>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""