UNPKG

fabric8-analytics-dependency-editor-jyas

Version:
219 lines 8.39 kB
import { Component, ViewChild } from '@angular/core'; import { LicenseUIModel, ErrorUIModel } from '../model/data.model'; import { AlertBoxComponent } from '../alert-box/alert-box.component'; import { DependencyEditorService } from '../shared/dependency-editor.service'; var LicenseComponent = /** @class */ (function () { function LicenseComponent(service) { this.service = service; this.isLoading = true; this.title = 'License'; this.icon = 'pficon pficon-on-running'; this.hasIssue = false; this.responseReady = false; this.toHave = false; this.licenseAll = []; this.licenseIssue = true; this.licenseDt = []; this.licenseCount = {}; this.liData = []; this.charts = null; this.alertConfig = null; this.config = {}; this.allLicenses = []; this.tooltipText = 'Shows the distinct licenses and the stack license'; this.isLoading = true; this.subscribeToLicenseInformation(); } LicenseComponent.prototype.subscribeToLicenseInformation = function () { var _this = this; this.service.licenseSubscription.subscribe(function (response) { if (response instanceof LicenseUIModel) { _this.licenseData = response.licenseData; _this.lisData = response.lisData; _this.allLicenses = response.allLicenses; _this.handleChanges(); } else if (response instanceof ErrorUIModel) { _this.config = { header: { tooltip: _this.tooltipText, icon: _this.icon, name: _this.title }, body: { defaultText: response.message } }; _this.alertConfig = _this.config; } _this.isLoading = false; }); this.service.needsLicenseChange.subscribe(function (response) { if (response) { _this.getLicenseData(); } }); }; LicenseComponent.prototype.handleChanges = function () { var _this = this; this.stackStatus = ''; if (this.licenseData && this.licenseData.status) { if (this.licenseData.status.toLowerCase() === 'successful') { this.hasIssue = false; this.stackLicense = this.licenseData.f8a_stack_licenses[0]; this.stackStatus = this.licenseData.status; } else if (this.licenseData.status.toLowerCase() === 'failure') { this.hasIssue = 'na'; this.stackLicense = 'Unknown'; this.stackStatus = this.licenseData.status; } else if (this.licenseData.status.toLowerCase() === 'conflict' || this.licenseData.status.toLowerCase() === 'unknown') { this.hasIssue = true; this.stackLicense = 'None'; this.stackStatus = this.licenseData.status; } } else if (this.lisData) { if (this.lisData.status.toLowerCase() === 'successful') { this.hasIssue = false; this.stackLicense = this.lisData.stack_license; this.stackStatus = this.lisData.status; } else if (this.lisData.status.toLowerCase() === 'failure') { this.hasIssue = 'na'; this.stackLicense = 'Unknown'; this.stackStatus = this.lisData.status; } else if (this.lisData.status.toLowerCase() === 'conflict' || this.lisData.status.toLowerCase() === 'unknown') { this.hasIssue = true; this.stackLicense = 'None'; this.stackStatus = this.lisData.status; } } else { this.stackLicense = null; this.stackStatus = null; } this.licenseAll = []; if (this.stackStatus === 'Successful' && this.allLicenses) { for (var x = 0; x < this.allLicenses.length; x++) { this.allLicenses.forEach(function (i) { _this.licenseAll.push(i); }); } } this.licenseChange(); }; LicenseComponent.prototype.ngOnChanges = function (changes) { this.handleChanges(); }; LicenseComponent.prototype.ngOnInit = function () { this.handleChanges(); }; LicenseComponent.prototype.getShow = function (event) { this.toHave = event.toShow; }; LicenseComponent.prototype.licenseChange = function () { var _this = this; if (this.stackStatus === 'Successful') { if (this.licenseAll) { this.licenseDt = []; this.licenseCount = {}; this.licenseAll.forEach(function (d) { _this.licenseDt = _this.licenseDt.concat(d); }); this.licenseDt.forEach(function (item) { _this.licenseCount[item] = (_this.licenseCount[item] || 0) + 1; }); this.liData = []; Object.keys(this.licenseCount).forEach(function (k) { _this.liData.push([ k, Math.round(_this.licenseCount[k] * 100 / _this.licenseDt.length) ]); }); } } this.displayLicenses(this.liData); }; LicenseComponent.prototype.displayLicenses = function (liData) { if (this.stackStatus === 'Successful') { this.charts = {}; this.charts['data'] = { columns: liData, type: 'donut' }; this.charts['options'] = { donut: { title: liData.length + ' Licenses', width: 10, label: { show: false } }, size: { height: 200, width: 280 } }; this.charts['configs'] = { legend: { show: true, position: 'right' } }; } // Forms configuration to make use of alert-box component this.config = { header: { icon: this.icon, tooltip: this.tooltipText, name: this.title, secondaryInfo: { mainText: this.stackLicense, subText: '(Stack Level)' } }, body: {} }; if (this.charts) { this.config['body']['graphic'] = this.charts; } else { this.config['body']['defaultText'] = 'Unable to render chart'; } this.alertConfig = this.config; this.isLoading = false; }; LicenseComponent.prototype.getLicenseData = function () { var _this = this; var payload = this.service.getPayload(); this.isLoading = true; this.service.getDependencyData('LICENSE', payload) .subscribe(function (response) { _this.service.licenseSubscription.next(new LicenseUIModel(null, response, response.distinct_licenses)); _this.isLoading = false; }, function (error) { _this.service.licenseSubscription.next(new ErrorUIModel(error.status, error.message)); _this.isLoading = false; }); }; LicenseComponent.decorators = [ { type: Component, args: [{ selector: 'app-license', styles: [require('./license.component.css').toString()], template: require('./license.component.html') },] }, ]; /** @nocollapse */ LicenseComponent.ctorParameters = function () { return [ { type: DependencyEditorService, }, ]; }; LicenseComponent.propDecorators = { 'alertBoxComponent': [{ type: ViewChild, args: [AlertBoxComponent,] },], }; return LicenseComponent; }()); export { LicenseComponent }; //# sourceMappingURL=license.component.js.map