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 { DomSanitizer } from '@angular/platform-browser';
21 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
23 import { AlertService } from '../../../@core-xds/services/alert.service';
24 import { SdkService, ISdk } from '../../../@core-xds/services/sdk.service';
27 selector: 'xds-sdk-install-modal',
30 <div class="modal-header">
34 <div class="modal-body row">
35 <div class="col-12 text-center">
36 Installation of <b> {{ sdk?.name }} '</b> <span [innerHTML]="instStatus"></span>
40 <div class="col-12 text-center">
41 <textarea rows="20" class="textarea-scroll" #scrollOutput [innerHtml]="installOutput"></textarea>
43 <div class="col-12 text-center">
44 <button type="button" class="btn" tabindex="1"
45 [ngClass]="(btnName=='Cancel')?'btn-default':'btn-primary'"
46 (click)="onBtnClick()">{{ btnName }}</button>
50 <!-- <div *ngIf="footer!=''" class="modal-footer">
51 <div class="col-12 text-center">
62 font-family: monospace;
68 export class SdkInstallComponent implements OnInit {
70 @ViewChild('scrollOutput') private scrollContainer: ElementRef;
73 private modalRef: NgbActiveModal,
74 private sanitizer: DomSanitizer,
75 private alert: AlertService,
76 private sdkSvr: SdkService,
85 this.instStatus = 'in progress...';
87 this.onInstallSub = this.sdkSvr.onInstall().subscribe(ev => {
90 this.instStatus = '<font color="green"> Done. </font>';
93 this.alert.info('SDK ' + ev.sdk.name + ' successfully installed.');
96 if (ev.sdk.lastError !== '') {
97 this.alert.error(ev.sdk.lastError);
99 this.alert.error('SDK ' + ev.sdk.name + ' installation failed. ' + ev.error);
104 if (ev.stdout !== '') {
105 this.installOutput += ev.stdout;
107 if (ev.stderr !== '') {
108 this.installOutput += ev.stderr;
110 this._scrollToBottom();
116 this.onInstallSub.unsubscribe();
117 if (this.btnName === 'Cancel') {
119 this.instStatus = '<b><font color="red"> ABORTED </font></b>';
120 this.sdkSvr.abortInstall(this.sdk).subscribe(r => { }, err => this.alert.error(err));
122 this.modalRef.close();
126 private _scrollToBottom(): void {
128 this.scrollContainer.nativeElement.scrollTop = this.scrollContainer.nativeElement.scrollHeight;