This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/linear-workflow/linear-workflow.component.ts

69 lines
2.3 KiB
TypeScript
Raw Normal View History

2017-02-20 02:35:46 +00:00
import { Component, Output, Input } from 'angular-ts-decorators';
2017-02-21 23:59:26 +00:00
import { LinearWorkflowSectionComponent } from './linear-workflow-section.component';
2017-02-20 02:35:46 +00:00
2017-02-21 23:59:26 +00:00
/**
* A component that which displays a linear workflow of sections, each completed in order before the next
* step is made visible.
*/
2017-02-20 02:35:46 +00:00
@Component({
selector: 'linearWorkflow',
2017-02-21 23:59:26 +00:00
templateUrl: '/static/js/directives/ui/linear-workflow/linear-workflow.component.html',
transclude: true
2017-02-20 02:35:46 +00:00
})
export class LinearWorkflowComponent implements ng.IComponentController {
2017-02-21 23:59:26 +00:00
@Input('@') public doneTitle: string;
@Output() public onWorkflowComplete: (event: any) => void;
private sections: SectionInfo[] = [];
private currentSection: SectionInfo;
public addSection(component: LinearWorkflowSectionComponent): void {
2017-02-21 23:59:26 +00:00
this.sections.push({
index: this.sections.length,
component: component,
2017-02-21 23:59:26 +00:00
});
if (this.sections.length == 1) {
this.currentSection = this.sections[0];
this.currentSection.component.sectionVisible = true;
this.currentSection.component.isCurrentSection = true;
}
2017-02-21 23:59:26 +00:00
}
public onNextSection(): void {
if (this.currentSection.component.sectionValid && this.currentSection.index + 1 >= this.sections.length) {
this.onWorkflowComplete({});
2017-02-21 23:59:26 +00:00
}
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;
}
});
}
2017-02-21 23:59:26 +00:00
}
}
/**
* A type representing a section of the linear workflow.
*/
export type SectionInfo = {
index: number;
component: LinearWorkflowSectionComponent;
2017-02-20 02:35:46 +00:00
}