3 * Copyright (C) 2017-2018 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import { Component, Input, OnInit } from '@angular/core';
20 import { Observable } from 'rxjs/Observable';
21 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
22 import { FormControl, FormGroup, Validators, ValidationErrors, FormBuilder, ValidatorFn, AbstractControl } from '@angular/forms';
24 import { AlertService } from '../../../@core-xds/services/alert.service';
25 import { ProjectService, IProject } from '../../../@core-xds/services/project.service';
29 selector: 'xds-build-settings-modal',
30 templateUrl: 'build-settings-modal.component.html',
33 export class BuildSettingsModalComponent implements OnInit {
34 // @Input('server-id') serverID: string;
35 private serverID: string;
38 userEditedLabel = false;
40 settingsProjectForm: FormGroup;
41 subpathCtrl = new FormControl('', Validators.nullValidator);
43 private curPrj: IProject;
46 private alert: AlertService,
47 private projectSvr: ProjectService,
48 private fb: FormBuilder,
49 private activeModal: NgbActiveModal,
51 this.settingsProjectForm = fb.group({
52 subpath: this.subpathCtrl,
53 cmdClean: ['', Validators.required],
54 cmdPrebuild: ['', Validators.nullValidator],
55 cmdBuild: ['', Validators.required],
56 cmdPopulate: ['', Validators.nullValidator],
57 cmdArgs: ['', Validators.nullValidator],
58 envVars: ['', Validators.nullValidator],
63 this.curPrj = this.projectSvr.getCurrent();
64 this.settingsProjectForm.patchValue(this.curPrj.uiSettings);
68 this.activeModal.close();
72 this.settingsProjectForm.patchValue(this.projectSvr.getDefaultSettings());
76 if (!this.closeAction) {
80 this.curPrj.uiSettings = this.settingsProjectForm.value;
81 this.projectSvr.setSettings(this.curPrj)
83 this.alert.info('Settings of project "' + prj.label + '" successfully updated.');
86 // Reset Value for the next creation
87 this.settingsProjectForm.reset();
90 this.alert.error(err, 60);