e51b7f2d5fc12730a3b57439a3760f5b28d528d2
[src/xds/xds-server.git] / webapp / src / app / devel / deploy / deploy.component.ts
1 import { Component, OnInit, Input } from "@angular/core";
2 import { Observable } from 'rxjs';
3 import { FormControl, FormGroup, Validators, FormBuilder } from '@angular/forms';
4
5 import 'rxjs/add/operator/scan';
6 import 'rxjs/add/operator/startWith';
7
8 import { XDSAgentService, IXDSDeploy } from "../../services/xdsagent.service";
9 import { ConfigService, IConfig, IProject } from "../../services/config.service";
10 import { AlertService, IAlert } from "../../services/alert.service";
11 import { SdkService } from "../../services/sdk.service";
12
13 @Component({
14     selector: 'panel-deploy',
15     moduleId: module.id,
16     templateUrl: './deploy.component.html',
17     styleUrls: ['./deploy.component.css']
18 })
19
20 export class DeployComponent implements OnInit {
21
22     @Input() curProject: IProject;
23
24     deploying: boolean;
25     deployForm: FormGroup;
26
27     constructor(private configSvr: ConfigService,
28         private xdsAgent: XDSAgentService,
29         private fb: FormBuilder,
30         private alert: AlertService,
31     ) {
32         this.deployForm = fb.group({
33             boardIP: ["", Validators.nullValidator],
34             wgtFile: ["", Validators.nullValidator],
35         });
36     }
37
38     ngOnInit() {
39         this.deploying = false;
40         if (this.curProject && this.curProject.pathClient) {
41             this.deployForm.patchValue({ wgtFile: this.curProject.pathClient });
42         }
43     }
44
45     deploy() {
46         this.deploying = true;
47
48         this.xdsAgent.deploy(
49             {
50                 boardIP: this.deployForm.value.boardIP,
51                 file: this.deployForm.value.wgtFile
52             }
53         ).subscribe(res => {
54             this.deploying = false;
55         }, err => {
56             this.deploying = false;
57             let msg = '<span>ERROR while deploying "' + this.deployForm.value.wgtFile + '"<br>';
58             msg += err;
59             msg += '</span>';
60             this.alert.error(msg);
61         });
62     }
63 }