Migration to AGL gerrit (update go import)
[src/xds/xds-agent.git] / webapp / src / app / pages / sdks / sdk-card / sdk-card.component.ts
1 /**
2 * @license
3 * Copyright (C) 2017-2018 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
5 *
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
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 */
18
19 import { Component, Input, Pipe, PipeTransform } from '@angular/core';
20 import { SdkService, ISdk, StatusType } from '../../../@core-xds/services/sdk.service';
21 import { AlertService } from '../../../@core-xds/services/alert.service';
22
23 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
24 import { ConfirmModalComponent, EType } from '../../confirm/confirm-modal/confirm-modal.component';
25
26 @Component({
27   selector: 'xds-sdk-card',
28   styleUrls: ['./sdk-card.component.scss'],
29   templateUrl: './sdk-card.component.html',
30 })
31 export class SdkCardComponent {
32
33   // FIXME workaround of https://github.com/angular/angular-cli/issues/2034
34   // should be removed with angular 5
35   // @Input() sdk: ISdk;
36   @Input() sdk = <ISdk>null;
37
38   constructor(
39     private alert: AlertService,
40     private sdkSvr: SdkService,
41     private modalService: NgbModal,
42   ) {
43   }
44
45   canRemove(sdk: ISdk) {
46     return sdk.status === StatusType.INSTALLED;
47   }
48
49   remove(sdk: ISdk) {
50     const modal = this.modalService.open(ConfirmModalComponent, {
51       size: 'lg',
52       backdrop: 'static',
53       container: 'nb-layout',
54     });
55     modal.componentInstance.title = 'Confirm SDK deletion';
56     modal.componentInstance.type = EType.YesNo;
57     modal.componentInstance.question = `
58     Do you <b>permanently remove '` + sdk.name + `'</b> SDK ?
59     <br><br>
60     <i><small>(SDK ID: ` + sdk.id + ` )</small></i>`;
61
62     modal.result
63       .then(res => {
64         if (res === 'yes') {
65           this.sdkSvr.remove(sdk).subscribe(
66             r => { },
67             err => this.alert.error(err),
68           );
69         }
70       });
71   }
72 }
73