X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=webapp%2Fsrc%2Fapp%2Fpages%2Fbuild%2Fbuild.component.ts;h=3ebdfe5c6b9f5ac4f6b8ce7e5f6eab0354afe9f7;hb=1f0c46a7f3b6c00ac236311444ef6583855b8f9a;hp=99b7e54a06fd4b0054c6f1de12bbc86f5165bdeb;hpb=4d843d2bde236ec23810d0904dfb8aebbc53a37b;p=src%2Fxds%2Fxds-agent.git diff --git a/webapp/src/app/pages/build/build.component.ts b/webapp/src/app/pages/build/build.component.ts index 99b7e54..3ebdfe5 100644 --- a/webapp/src/app/pages/build/build.component.ts +++ b/webapp/src/app/pages/build/build.component.ts @@ -31,6 +31,7 @@ export class BuildComponent implements OnInit, AfterViewChecked { public buildIsCollapsed = false; public cmdOutput: string; public cmdInfo: string; + public curPrj: IProject; private startTime: Map = new Map(); @@ -42,11 +43,13 @@ export class BuildComponent implements OnInit, AfterViewChecked { private modalService: NgbModal, ) { this.cmdOutput = ''; - this.cmdInfo = ''; // TODO: to be remove (only for debug) - + this.cmdInfo = ''; // TODO: to be remove (only for debug) } ngOnInit() { + // Retreive current project + this.prjSvr.curProject$.subscribe(p => this.curPrj = p); + // Command output data tunneling this.xdsSvr.CmdOutput$.subscribe(data => { this.cmdOutput += data.stdout; @@ -76,71 +79,67 @@ export class BuildComponent implements OnInit, AfterViewChecked { this.cmdOutput = ''; } - settingsShow() { - const activeModal = this.modalService.open(BuildSettingsModalComponent, { size: 'lg', container: 'nb-layout' }); - activeModal.componentInstance.modalHeader = 'Large Modal'; + isSetupValid(): boolean { + return (typeof this.curPrj !== 'undefined'); } - clean() { - const curPrj = this.prjSvr.getCurrent(); - this._exec( - curPrj.uiSettings.cmdClean, - curPrj.uiSettings.subpath, - [], - curPrj.uiSettings.envVars.join(' ')); - } + settingsShow() { + if (!this.isSetupValid()) { + return this.alertSvr.warning('Please select first a valid project.', true); + } - preBuild() { - const curPrj = this.prjSvr.getCurrent(); - this._exec( - curPrj.uiSettings.cmdPrebuild, - curPrj.uiSettings.subpath, - [], - curPrj.uiSettings.envVars.join(' ')); + const activeModal = this.modalService.open(BuildSettingsModalComponent, { size: 'lg', container: 'nb-layout' }); + activeModal.componentInstance.modalHeader = 'Large Modal'; } - build() { - const curPrj = this.prjSvr.getCurrent(); - this._exec( - curPrj.uiSettings.cmdBuild, - curPrj.uiSettings.subpath, - [], - curPrj.uiSettings.envVars.join(' '), - ); - } + execCmd(cmdName: string) { + if (!this.isSetupValid()) { + return this.alertSvr.warning('Please select first a valid project.', true); + } - populate() { - const curPrj = this.prjSvr.getCurrent(); - this._exec( - curPrj.uiSettings.cmdPopulate, - curPrj.uiSettings.subpath, - [], // args - curPrj.uiSettings.envVars.join(' '), - ); - } + if (!this.curPrj.uiSettings) { + return this.alertSvr.warning('Invalid setting structure', true); + } - execCmd() { - const curPrj = this.prjSvr.getCurrent(); - this._exec( - curPrj.uiSettings.cmdArgs.join(' '), - curPrj.uiSettings.subpath, - [], - curPrj.uiSettings.envVars.join(' '), - ); - } + let cmd = ''; + switch (cmdName) { + case 'clean': + cmd = this.curPrj.uiSettings.cmdClean; + break; + case 'prebuild': + cmd = this.curPrj.uiSettings.cmdPrebuild; + break; + case 'build': + cmd = this.curPrj.uiSettings.cmdBuild; + break; + case 'populate': + cmd = this.curPrj.uiSettings.cmdPopulate; + break; + case 'exec': + if (this.curPrj.uiSettings.cmdArgs instanceof Array)  { + cmd = this.curPrj.uiSettings.cmdArgs.join(' '); + } else { + cmd = this.curPrj.uiSettings.cmdArgs; + } + break; + default: + return this.alertSvr.warning('Unknown command name ' + cmdName); + } - private _exec(cmd: string, dir: string, args: string[], env: string) { - this.curProject = this.prjSvr.getCurrent(); - const prjID = this.curProject.id; + const prjID = this.curPrj.id; + const dir = this.curPrj.uiSettings.subpath; + const args: string[] = []; + const sdkid = this.sdkSvr.getCurrentId(); - if (!this.curProject) { - return this.alertSvr.warning('No active project', true); + let env = ''; + if (this.curPrj.uiSettings.envVars instanceof Array) { + env = this.curPrj.uiSettings.envVars.join(' '); + } else { + env = this.curPrj.uiSettings.envVars; } this.cmdOutput += this._outputHeader(); - const sdkid = this.sdkSvr.getCurrentId(); - // Detect key=value in env string to build array of string const envArr = []; env.split(';').forEach(v => envArr.push(v.trim()));