fabric8-analytics-dep-editor
Version: 
142 lines • 5.44 kB
JavaScript
import { Component, Input, ViewChild } from '@angular/core';
import { AlertBoxComponent } from '../alert-box/alert-box.component';
var LicenseComponent = /** @class */ (function () {
    function LicenseComponent() {
        this.allLicenses = [];
        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 = {};
    }
    LicenseComponent.prototype.ngOnChanges = function () {
        var _this = this;
        this.stackStatus = '';
        if (this.licenseData) {
            if (this.licenseData.status.toLowerCase() === 'successful') {
                this.hasIssue = false;
                this.stackLicense = this.licenseData.current_stack_license;
                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') {
            for (var x = 0; x < this.allLicenses.length; x++) {
                this.allLicenses.forEach(function (i) {
                    _this.licenseAll.push(i);
                });
                this.licenseChange();
            }
        }
    };
    LicenseComponent.prototype.ngOnInit = function () { };
    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['data'] = {
                columns: liData,
                type: 'donut'
            };
            this.charts['options'] = {
                donut: {
                    title: liData.length + ' Licenses',
                    width: 10,
                    label: {
                        show: false
                    }
                },
                size: {
                    height: 200,
                    width: 230
                }
            };
            this.charts['configs'] = {
                legend: {
                    show: true,
                    position: 'right'
                }
            };
        }
    };
    LicenseComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-license',
                    styles: [require('./license.component.less').toString()],
                    template: require('./license.component.html')
                },] },
    ];
    /** @nocollapse */
    LicenseComponent.ctorParameters = function () { return []; };
    LicenseComponent.propDecorators = {
        'licenseData': [{ type: Input },],
        'lisData': [{ type: Input },],
        'allLicenses': [{ type: Input },],
        'boosterInfo': [{ type: Input },],
        'alertBoxComponent': [{ type: ViewChild, args: [AlertBoxComponent,] },],
    };
    return LicenseComponent;
}());
export { LicenseComponent };
//# sourceMappingURL=license.component.js.map