summaryrefslogtreecommitdiffstats
path: root/webapp/src/app/devel/deploy/deploy.component.ts
blob: 4dba256405278360872ae632162b623cb21a5f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Component, OnInit, Input } from "@angular/core";
import { Observable } from 'rxjs';
import { FormControl, FormGroup, Validators, FormBuilder } from '@angular/forms';

import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/startWith';

import { XDSAgentService, IXDSDeploy } from "../../services/xdsagent.service";
import { ConfigService, IConfig, IProject } from "../../services/config.service";
import { AlertService, IAlert } from "../../services/alert.service";
import { SdkService } from "../../services/sdk.service";

@Component({
    selector: 'panel-deploy',
    moduleId: module.id,
    templateUrl: './deploy.component.html',
    styleUrls: ['./deploy.component.css']
})

export class DeployComponent implements OnInit {

    @Input() curProject: IProject;

    deploying: boolean;
    deployForm: FormGroup;

    constructor(private configSvr: ConfigService,
        private xdsAgent: XDSAgentService,
        private fb: FormBuilder,
        private alert: AlertService,
    ) {
        this.deployForm = fb.group({
            boardIP: ["", Validators.nullValidator],
            wgtFile: ["", Validators.nullValidator],
        });
    }

    ngOnInit() {
        this.deploying = false;
        if (this.curProject && this.curProject.path) {
            this.deployForm.patchValue({ wgtFile: this.curProject.path });
        }
    }

    deploy() {
        this.deploying = true;

        this.xdsAgent.deploy(
            {
                boardIP: this.deployForm.value.boardIP,
                file: this.deployForm.value.wgtFile
            }
        ).subscribe(res => {
            this.deploying = false;
        }, err => {
            this.deploying = false;
            let msg = '<span>ERROR while deploying "' + this.deployForm.value.wgtFile + '"<br>';
            msg += err;
            msg += '</span>';
            this.alert.error(msg);
        });
    }
}