7a352ddfbc
* starting UtilService refactor * pre find-replace angular.module('quay') => angular.module('QuayModule') * successfully switched to ng-metadata for backported Angular2 API * working with parent component reference in child * fixing @Output to use EventEmitter * fixed @Output events for custom git trigger * more fixes * refactored QuayPages module for backwards-compatibility * reinitialized test.db * use minified libraries * replaced references for angular-ts-decorators * fixed ng-show
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { Component, Output, Input, EventEmitter } from 'ng-metadata/core';
|
|
import { LinearWorkflowSectionComponent } from './linear-workflow-section.component';
|
|
|
|
|
|
/**
|
|
* A component that which displays a linear workflow of sections, each completed in order before the next
|
|
* step is made visible.
|
|
*/
|
|
@Component({
|
|
selector: 'linear-workflow',
|
|
templateUrl: '/static/js/directives/ui/linear-workflow/linear-workflow.component.html',
|
|
legacy: {
|
|
transclude: true
|
|
}
|
|
})
|
|
export class LinearWorkflowComponent {
|
|
|
|
@Input('@') public doneTitle: string;
|
|
@Output() public onWorkflowComplete: EventEmitter<any> = new EventEmitter();
|
|
private sections: SectionInfo[] = [];
|
|
private currentSection: SectionInfo;
|
|
|
|
public addSection(component: LinearWorkflowSectionComponent): void {
|
|
this.sections.push({
|
|
index: this.sections.length,
|
|
component: component,
|
|
});
|
|
|
|
if (this.sections.length == 1) {
|
|
this.currentSection = this.sections[0];
|
|
this.currentSection.component.sectionVisible = true;
|
|
this.currentSection.component.isCurrentSection = true;
|
|
}
|
|
}
|
|
|
|
public onNextSection(): void {
|
|
if (this.currentSection.component.sectionValid && this.currentSection.index + 1 >= this.sections.length) {
|
|
this.onWorkflowComplete.emit({});
|
|
}
|
|
else if (this.currentSection.component.sectionValid && this.currentSection.index + 1 < this.sections.length) {
|
|
this.currentSection.component.isCurrentSection = false;
|
|
this.currentSection = this.sections[this.currentSection.index + 1];
|
|
this.currentSection.component.sectionVisible = true;
|
|
this.currentSection.component.isCurrentSection = true;
|
|
}
|
|
}
|
|
|
|
public onSectionInvalid(sectionId: string): void {
|
|
var invalidSection = this.sections.filter(section => section.component.sectionId == sectionId)[0];
|
|
if (invalidSection.index <= this.currentSection.index) {
|
|
invalidSection.component.isCurrentSection = true;
|
|
this.currentSection = invalidSection;
|
|
this.sections.forEach((section) => {
|
|
if (section.index > invalidSection.index) {
|
|
section.component.sectionVisible = false;
|
|
section.component.isCurrentSection = false;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* A type representing a section of the linear workflow.
|
|
*/
|
|
export type SectionInfo = {
|
|
index: number;
|
|
component: LinearWorkflowSectionComponent;
|
|
}
|