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, OnInit, Input, ViewChild, AfterViewChecked, ElementRef } from '@angular/core';
20 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
22 import { AlertService } from '../../../@core-xds/services/alert.service';
23 import { SdkService, ISdk } from '../../../@core-xds/services/sdk.service';
25 import 'rxjs/add/operator/bufferTime';
28 selector: 'xds-sdk-install-modal',
31 <div class="modal-header">
35 <div class="modal-body row">
36 <div class="col-12 text-center">
37 Installation of <b> {{ sdk?.name }} '</b> <span [innerHTML]="instStatus"></span>
41 <div class="col-12 text-center">
42 <textarea rows="20" class="textarea-scroll" #scrollOutput [innerHtml]="installOutput"></textarea>
44 <div class="col-12 text-center">
45 <button type="button" class="btn" tabindex="1"
46 [ngClass]="(btnName=='Cancel')?'btn-default':'btn-primary'"
47 (click)="onBtnClick()">{{ btnName }}</button>
51 <!-- <div *ngIf="footer!=''" class="modal-footer">
52 <div class="col-12 text-center">
63 font-family: monospace;
69 export class SdkInstallComponent implements OnInit {
71 @ViewChild('scrollOutput') private scrollContainer: ElementRef;
74 private modalRef: NgbActiveModal,
75 private alert: AlertService,
76 private sdkSvr: SdkService,
85 this.instStatus = 'in progress...';
87 this.onInstallSub = this.sdkSvr.onInstall()
88 .bufferTime(500) // prevent browser freeze
94 this.instStatus = '<font color="green"> Done. </font>';
97 this.alert.info('SDK ' + ev.sdk.name + ' successfully installed.');
100 if (ev.sdk.lastError !== '') {
101 this.alert.error(ev.sdk.lastError);
103 this.alert.error('SDK ' + ev.sdk.name + ' installation failed. ' + ev.error);
108 if (ev.stdout !== '') {
111 if (ev.stderr !== '') {
117 this.installOutput += out;
118 this._scrollToBottom();
124 this.onInstallSub.unsubscribe();
125 if (this.btnName === 'Cancel') {
127 this.instStatus = '<b><font color="red"> ABORTED </font></b>';
128 this.sdkSvr.abortInstall(this.sdk).subscribe(r => { }, err => this.alert.error(err));
130 this.modalRef.close();
134 private _scrollToBottom(): void {
136 this.scrollContainer.nativeElement.scrollTop = this.scrollContainer.nativeElement.scrollHeight;