APPC CDT to Support Multiple Templates for VNFCs
[appc/cdt.git] / src / app / about-us / aboutus.component.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5
6 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
7 ===================================================================
8
9 Unless otherwise specified, all software contained herein is licensed
10 under the Apache License, Version 2.0 (the License);
11 you may not use this software except in compliance with the License.
12 You may obtain a copy of the License at
13
14     http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21 ============LICENSE_END============================================
22 */
23
24
25 import { Component, OnInit, OnDestroy } from '@angular/core';
26 import { Http } from '@angular/http';
27 import { Subscription } from 'rxjs/Subscription';
28 import { Observable } from 'rxjs/Observable';
29 import { NotificationsService } from 'angular2-notifications';
30 import { saveAs } from 'file-saver';
31 import { DialogService } from 'ng2-bootstrap-modal';
32 import { ConfirmComponent } from '../shared/confirmModal/confirm.component';
33 import { appConstants } from '../../constants/app-constants';
34 import {UtilityService} from '../shared/services/utilityService/utility.service';
35
36 @Component({
37     selector: 'app-help',
38     templateUrl: './aboutus.component.html',
39     styleUrls: ['./aboutus.component.css']
40 })
41 export class AboutUsComponent implements OnInit, OnDestroy {
42     clName= "AboutUsComponent";
43     public releaseName: any;
44     public versionNo: any;
45     public contactUsMail: any;
46     public data: any;
47     closeResult: string;
48     versionLogSubscription: Subscription;
49     options = {
50         timeOut: 1000,
51         showProgressBar: true,
52         pauseOnHover: true,
53         clickToClose: true,
54         maxLength: 200
55     };
56
57     constructor(
58       private http: Http, private dialogService: DialogService, private notificationsService: NotificationsService,
59       private utilSvc: UtilityService ) {
60     }
61
62     ngOnInit() {
63         this.versionNo = require('./appVersion.json').versionNo;
64         this.releaseName = require('./appVersion.json').releaseName;
65         this.contactUsMail = require('../cdt.application.properties.json').CONTACT_US;
66     }
67
68     ngOnDestroy() {
69         if (this.versionLogSubscription) {
70             this.versionLogSubscription.unsubscribe();
71         }
72     }
73
74     versionLogFile(): Observable<any> {
75         return this.http.get('app/about-us/versionLog.txt');
76     }
77
78     open(content) {
79         this.versionLogSubscription = this.versionLogFile()
80             .subscribe((res) => {
81                 this.data = res.text();
82                 this.dialogService.addDialog(ConfirmComponent, {
83                     title: 'VERSION CHANGE LOG',
84                     message: this.data,
85                     cancelButtonText: 'CLOSE',
86                     confirmButtonText: 'DOWNLOAD'
87                 }).subscribe(isConfirmed => {
88                     if (isConfirmed) {
89                         this.downloadLogFile()
90                     } else {
91                         // do nothing
92                     }
93                 });
94
95             },
96         (error)=>{
97             this.notificationsService.error(appConstants.errors.error, 'unable to fetch change log details');
98         });
99     }
100
101     downloadLogFile() {
102         var blob = new Blob([this.data], {
103             type: 'text/plain;charset=utf-8'
104         });
105         saveAs(blob, 'versionLog.txt');
106     }
107
108     tlPlus() { //.. increase tracelvl - more tracing in console
109       let tracelvl= this.utilSvc.getTracelvl();
110       if( tracelvl < 2 ) {
111         tracelvl++; this.utilSvc.setTracelvl( tracelvl);
112       };
113       console.log( this.clName+": tlPlus: tracelvl="+this.utilSvc.getTracelvl() );
114     }
115
116     tlMinus() { //.. decrease tracelvl - less tracing in console
117       let tracelvl= this.utilSvc.getTracelvl();
118       if( tracelvl > 0 ) {
119         tracelvl--; this.utilSvc.setTracelvl( tracelvl);
120       };
121       console.log( this.clName+": tlMinus: tracelvl="+this.utilSvc.getTracelvl() );
122     }
123 }