2017-02-17 23:46:43 +00:00
|
|
|
import { Input, Component } from 'angular-ts-decorators';
|
|
|
|
|
|
|
|
|
2017-02-18 05:35:33 +00:00
|
|
|
/**
|
|
|
|
* A component that allows the user to select the location of the Dockerfile in their source code repository.
|
|
|
|
*/
|
2017-02-17 23:46:43 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'dockerfilePathSelect',
|
2017-02-18 05:35:33 +00:00
|
|
|
templateUrl: '/static/js/directives/ui/dockerfile-path-select/dockerfile-path-select.component.html'
|
2017-02-17 23:46:43 +00:00
|
|
|
})
|
|
|
|
export class DockerfilePathSelectComponent implements ng.IComponentController {
|
|
|
|
|
|
|
|
// FIXME: Use one-way data binding
|
|
|
|
@Input('=') public currentPath: string;
|
|
|
|
@Input('=') public isValidPath: boolean;
|
|
|
|
@Input('=') public paths: string[];
|
|
|
|
@Input('=') public supportsFullListing: boolean;
|
|
|
|
private isUnknownPath: boolean = true;
|
|
|
|
private selectedPath: string | null = null;
|
|
|
|
|
|
|
|
public $onChanges(changes: ng.IOnChangesObject): void {
|
|
|
|
this.isValidPath = this.checkPath(this.currentPath, this.paths, this.supportsFullListing);
|
|
|
|
}
|
|
|
|
|
|
|
|
public setPath(path: string): void {
|
|
|
|
this.currentPath = path;
|
|
|
|
this.selectedPath = null;
|
|
|
|
this.isValidPath = this.checkPath(path, this.paths, this.supportsFullListing);
|
|
|
|
}
|
|
|
|
|
|
|
|
public setSelectedPath(path: string): void {
|
|
|
|
this.currentPath = path;
|
|
|
|
this.selectedPath = path;
|
|
|
|
this.isValidPath = this.checkPath(path, this.paths, this.supportsFullListing);
|
|
|
|
}
|
|
|
|
|
|
|
|
private checkPath(path: string = '', paths: string[] = [], supportsFullListing: boolean): boolean {
|
|
|
|
this.isUnknownPath = false;
|
|
|
|
var isValidPath: boolean = false;
|
|
|
|
|
|
|
|
if (path.length > 0 && path[0] === '/') {
|
|
|
|
isValidPath = true;
|
|
|
|
this.isUnknownPath = supportsFullListing && paths.indexOf(path) < 0;
|
|
|
|
}
|
|
|
|
return isValidPath;
|
|
|
|
}
|
|
|
|
}
|