X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=webapp%2Fsrc%2Fapp%2Fpages%2Fbuild%2Fbuild.component.ts;h=42975c114ce0834a5b0c67e261a883de73dd5c87;hb=a2cc38902ff7528870822110c4f04329a3918564;hp=5adb9bcb78631a1a16ae5bbeec3cd82ecbbe505f;hpb=38c0c21a969e621c725245ce91c78e77076c5ce7;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 5adb9bc..42975c1 100644 --- a/webapp/src/app/pages/build/build.component.ts +++ b/webapp/src/app/pages/build/build.component.ts @@ -1,11 +1,31 @@ +/** +* @license +* Copyright (C) 2017-2018 "IoT.bzh" +* Author Sebastien Douheret +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + import { Component, ViewEncapsulation, AfterViewChecked, ElementRef, ViewChild, OnInit, Input } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { FormControl, FormGroup, Validators, FormBuilder } from '@angular/forms'; -import { CookieService } from 'ngx-cookie'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import 'rxjs/add/operator/scan'; import 'rxjs/add/operator/startWith'; +import { BuildSettingsModalComponent } from './build-settings-modal/build-settings-modal.component'; + import { XDSAgentService, ICmdOutput } from '../../@core-xds/services/xdsagent.service'; import { ProjectService, IProject } from '../../@core-xds/services/project.service'; import { AlertService, IAlert } from '../../@core-xds/services/alert.service'; @@ -26,48 +46,27 @@ export class BuildComponent implements OnInit, AfterViewChecked { // @Input() curProject: IProject; @Input() curProject = null; - public buildForm: FormGroup; - public subpathCtrl = new FormControl('', Validators.required); - public debugEnable = false; public buildIsCollapsed = false; public cmdOutput: string; public cmdInfo: string; + public curPrj: IProject; private startTime: Map = new Map(); constructor( private prjSvr: ProjectService, private xdsSvr: XDSAgentService, - private fb: FormBuilder, private alertSvr: AlertService, private sdkSvr: SdkService, - private cookie: CookieService, + private modalService: NgbModal, ) { this.cmdOutput = ''; - this.cmdInfo = ''; // TODO: to be remove (only for debug) - this.buildForm = fb.group({ - subpath: this.subpathCtrl, - cmdClean: ['', Validators.nullValidator], - cmdPrebuild: ['', Validators.nullValidator], - cmdBuild: ['', Validators.nullValidator], - cmdPopulate: ['', Validators.nullValidator], - cmdArgs: ['', Validators.nullValidator], - envVars: ['', Validators.nullValidator], - }); + this.cmdInfo = ''; // TODO: to be remove (only for debug) } ngOnInit() { - // Set default settings - // TODO save & restore values from cookies - this.buildForm.patchValue({ - subpath: '', - cmdClean: 'rm -rf build', - cmdPrebuild: 'mkdir -p build && cd build && cmake ..', - cmdBuild: 'cd build && make', - cmdPopulate: 'cd build && make remote-target-populate', - cmdArgs: '', - envVars: '', - }); + // Retreive current project + this.prjSvr.curProject$.subscribe(p => this.curPrj = p); // Command output data tunneling this.xdsSvr.CmdOutput$.subscribe(data => { @@ -88,74 +87,78 @@ export class BuildComponent implements OnInit, AfterViewChecked { }); this._scrollToBottom(); - - // only use for debug - this.debugEnable = (this.cookie.get('debug_build') === '1'); } ngAfterViewChecked() { this._scrollToBottom(); } - reset() { + resetOutput() { this.cmdOutput = ''; } - clean() { - this._exec( - this.buildForm.value.cmdClean, - this.buildForm.value.subpath, - [], - this.buildForm.value.envVars); + isSetupValid(): boolean { + return (typeof this.curPrj !== 'undefined'); } - preBuild() { - this._exec( - this.buildForm.value.cmdPrebuild, - this.buildForm.value.subpath, - [], - this.buildForm.value.envVars); - } - - build() { - this._exec( - this.buildForm.value.cmdBuild, - this.buildForm.value.subpath, - [], - this.buildForm.value.envVars + settingsShow() { + if (!this.isSetupValid()) { + return this.alertSvr.warning('Please select first a valid project.', true); + } + const modal = this.modalService.open( + BuildSettingsModalComponent, + { size: 'lg', container: 'nb-layout' }, ); } - populate() { - this._exec( - this.buildForm.value.cmdPopulate, - this.buildForm.value.subpath, - [], // args - this.buildForm.value.envVars - ); - } + execCmd(cmdName: string) { + if (!this.isSetupValid()) { + return this.alertSvr.warning('Please select first a valid project.', true); + } - execCmd() { - this._exec( - this.buildForm.value.cmdArgs, - this.buildForm.value.subpath, - [], - this.buildForm.value.envVars - ); - } + if (!this.curPrj.uiSettings) { + return this.alertSvr.warning('Invalid setting structure', true); + } - private _exec(cmd: string, dir: string, args: string[], env: string) { - if (!this.curProject) { - this.alertSvr.warning('No active project', true); + 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); } - // const prjID = this.curProject.id; - const prjID = this.prjSvr.getCurrent().id; + const prjID = this.curPrj.id; + const dir = this.curPrj.uiSettings.subpath; + const args: string[] = []; + const sdkid = this.sdkSvr.getCurrentId(); + + 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()));