UNPKG

fabric8-analytics-dependency-editor-jyas

Version:
297 lines 13.1 kB
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core'; import * as _ from 'lodash'; import { DependencyEditorService } from '../shared/dependency-editor.service'; import { ErrorMessageHandler } from '../shared/error-message-handler'; import { ErrorUIModel, LicenseUIModel } from '../model/data.model'; import { DependencySnapshot } from '../utils/dependency-snapshot'; import { TimerObservable } from 'rxjs/observable/TimerObservable'; import 'rxjs/add/operator/takeWhile'; import { DepEditorUtils } from '../shared/utils'; var DependencyEditorComponent = /** @class */ (function () { function DependencyEditorComponent(service, errorMessageHandler) { this.service = service; this.errorMessageHandler = errorMessageHandler; this.githubUrl = ''; this.boosterInfo = null; this.githubRef = ''; this.metadataInfo = null; this.blankResponse = null; this.depSnapshot = new EventEmitter(); this.emitMetadata = new EventEmitter(); this.navId = new EventEmitter(); this.allLicenses = []; this.dependenciesAdded = []; this.dependencyAdded = []; this.packageLength = 0; this.addPackageLength = 0; this.listView = 'View Dependency List'; this.metadata = {}; this.error = null; this.isDepSelectedFromSearch = false; } DependencyEditorComponent.prototype.ngOnInit = function () { var _this = this; this.service.dependencySelected .subscribe(function (depSelected) { _this.isDepSelectedFromSearch = true; _this.depToAdd = depSelected; var obj = { depFull: null, depSnapshot: { package: depSelected.name, version: depSelected.version }, action: 'add' }; _this.callDepServices(obj); }); this.service.dependencyRemoved .subscribe(function (data) { _this.callDepServices(data); }); }; DependencyEditorComponent.prototype.ngOnChanges = function (changes) { if (changes['githubUrl'] && changes['githubUrl']['currentValue'] && changes['githubRef'] && changes['githubRef']['currentValue']) { this.postStackAnalyses(this.githubUrl, this.githubRef); } if (changes['blankResponse'] && changes['blankResponse']['currentValue']) { this.blankMissionFlow(); } }; DependencyEditorComponent.prototype.blankMissionFlow = function () { this.getDependencyInsights(this.blankResponse); // this.getCveData(this.blankResponse); this.getLicenseData(this.blankResponse); }; DependencyEditorComponent.prototype.ngOnDestroy = function () { DepEditorUtils.isLoaded = false; this.service.cacheHiddenDependency = []; }; DependencyEditorComponent.prototype.doContinue = function () { }; DependencyEditorComponent.prototype.callDepServices = function (eventData) { this.reset(); this.service.updateDependencyAddedSnapshot(eventData); if (this.isDepSelectedFromSearch) { DependencySnapshot.DEP_FULL_ADDED.push(this.depToAdd); this.isDepSelectedFromSearch = false; } this.dependenciesAdded = DependencySnapshot.DEP_FULL_ADDED; this.depSnapshot.emit(DependencySnapshot.DEP_SNAPSHOT_ADDED); var payload = this.service.getPayload(); this.getDependencyInsights(payload); this.emitLicenseChangeNeeded(); this.emitSecurityChangeNeeded(); }; DependencyEditorComponent.prototype.checkIfAlternatePresent = function (alternates) { alternates.forEach(function (alternate) { DependencySnapshot.DEP_FULL_ADDED.forEach(function (depAdded) { if (alternate.name === depAdded.name) { depAdded.alternate = alternate.alternate; } }); }); }; DependencyEditorComponent.prototype.checkIfSecurityPresent = function (analyzedDependencies) { DependencySnapshot.DEP_FULL_ADDED.forEach(function (depFullAdded) { if (!depFullAdded.security) { var objWithSecurity = _.find(analyzedDependencies, function (dep) { return dep.name === depFullAdded.name; }); } }); }; DependencyEditorComponent.prototype.getMetadata = function (event) { this.metadata = event; this.emitMetadata.emit(this.metadata); }; DependencyEditorComponent.prototype.showDependencyModal = function (event) { this.modalDependencyPreview.open(); this.packageLength = DependencySnapshot.DEP_SNAPSHOT.length; this.addPackageLength = DependencySnapshot.DEP_SNAPSHOT_ADDED.length; }; DependencyEditorComponent.prototype.closemodal = function () { this.modalDependencyPreview.close(); }; DependencyEditorComponent.prototype.navToStep = function (id) { this.navId.emit(id); }; DependencyEditorComponent.prototype.reset = function () { this.companions = null; this.alternate = null; this.dependenciesAdded = null; this.cveData = null; this.licenseData = null; }; DependencyEditorComponent.prototype.setDependencies = function (result) { if (result && result.user_stack_info && result.user_stack_info.dependencies) { this.dependencies = result.user_stack_info.dependencies; } }; DependencyEditorComponent.prototype.setCompanions = function (result) { if (result && result.companion) { this.companions = result.companion; } else { this.companions = null; } }; DependencyEditorComponent.prototype.setLicenseData = function (result) { this.licenseData = result.user_stack_info.license_analysis; this.allLicenses = result.user_stack_info.distinct_licenses; this.service.licenseSubscription.next(new LicenseUIModel(this.licenseData, null, this.allLicenses)); }; DependencyEditorComponent.prototype.setAlternate = function (result) { if (result && result.alternate) { this.alternate = result.alternate; } }; DependencyEditorComponent.prototype.postStackAnalyses = function (githubUrl, githubRef) { var _this = this; this.service.postStackAnalyses(githubUrl, githubRef) .subscribe(function (data) { var subs = null; var rec = null; var interval = 5000; var alive = true; var counter = 0; var observable = _this.service .getStackAnalyses(data['id']); TimerObservable.create(0, interval) .takeWhile(function () { return alive; }) .subscribe(function () { if (rec) { subs.unsubscribe(); alive = false; } subs = observable.subscribe(function (response) { var result = response.result && response.result[0] || null; if (result !== null) { rec = result.recommendation; DependencySnapshot.ECOSYSTEM = result.user_stack_info.ecosystem; DependencySnapshot.DEP_SNAPSHOT = result.user_stack_info.dependencies; DependencySnapshot.REQUEST_ID = response.request_id; if (rec) { alive = false; _this.setCompanions(rec); _this.setAlternate(rec); } _this.setDependencies(result); _this.setLicenseData(result); _this.emitSecurityChangeNeeded(); } }, function (error) { // Handle server errors here alive = false; _this.errorStack = error && error.message; _this.emitErrors(error); }); if (counter++ > 4) { alive = false; } }); }, function (error) { // Handle server errors here _this.errorPostStack = error && error.message; _this.emitErrors(error); }); }; DependencyEditorComponent.prototype.emitErrors = function (error) { this.error = error; this.service.licenseSubscription.next(error); this.service.securitySubscription.next(error); }; DependencyEditorComponent.prototype.getLicenseData = function (payload) { var _this = this; this.service.getDependencyData('LICENSE', payload) .subscribe(function (response) { _this.service.licenseSubscription.next(new LicenseUIModel(null, response, response.distinct_licenses)); }, function (error) { _this.service.licenseSubscription.next(new ErrorUIModel(error.status, error.message)); }); }; DependencyEditorComponent.prototype.getDependencyInsights = function (payload) { var _this = this; var subs = null; var rec = null; var interval = 5000; var alive = true; var counter = 0; // const persist = false; // const urlToHit = this.getDepInsightsUrl + '?persist=' + persist; var observable = this.service .getDependencyData('DEPEDITORANALYSIS', payload); TimerObservable.create(0, interval) .takeWhile(function () { return alive; }) .subscribe(function () { if (rec) { subs.unsubscribe(); alive = false; } subs = observable.subscribe(function (response) { rec = response && response.result && response.result[0] || null; if (rec) { if (rec.recommendation) { var recommendation = response.result[0].recommendation; alive = false; _this.setCompanions(recommendation); _this.setAlternate(recommendation); _this.checkIfAlternatePresent(recommendation.alternate); } var resultInformationModel = response.result[0]; _this.checkIfSecurityPresent(resultInformationModel.user_stack_info.analyzed_dependencies); DependencySnapshot.REQUEST_ID = response.request_id; _this.handleInitialLoads(resultInformationModel); } }, function (error) { // Handle server errors here alive = false; _this.errorInsight = error && error.message; }); if (counter++ > 4) { alive = false; } }); }; DependencyEditorComponent.prototype.handleInitialLoads = function (resultInformationModel) { DependencySnapshot.ECOSYSTEM = resultInformationModel.user_stack_info.ecosystem; DependencySnapshot.DEP_SNAPSHOT = resultInformationModel.user_stack_info.dependencies; this.setDependencies(resultInformationModel); this.setCompanions(resultInformationModel.recommendation); this.setAlternate(resultInformationModel.recommendation); this.setLicenseData(resultInformationModel); this.emitSecurityChangeNeeded(); }; DependencyEditorComponent.prototype.emitLicenseChangeNeeded = function () { this.service.needsLicenseChange.next(true); }; DependencyEditorComponent.prototype.emitSecurityChangeNeeded = function () { this.service.needsSecurityChange.next(true); }; DependencyEditorComponent.decorators = [ { type: Component, args: [{ selector: 'app-dependency-editor', styles: [require('./dependency-editor.component.css').toString()], template: require('./dependency-editor.component.html') },] }, ]; /** @nocollapse */ DependencyEditorComponent.ctorParameters = function () { return [ { type: DependencyEditorService, }, { type: ErrorMessageHandler, }, ]; }; DependencyEditorComponent.propDecorators = { 'githubUrl': [{ type: Input },], 'boosterInfo': [{ type: Input },], 'githubRef': [{ type: Input },], 'metadataInfo': [{ type: Input },], 'blankResponse': [{ type: Input },], 'depSnapshot': [{ type: Output },], 'emitMetadata': [{ type: Output },], 'navId': [{ type: Output },], 'modalDependencyPreview': [{ type: ViewChild, args: ['dependencyPreview',] },], }; return DependencyEditorComponent; }()); export { DependencyEditorComponent }; //# sourceMappingURL=dependency-editor.component.js.map