function catalogDeleterController()

in ui-modules/utils/catalog-deleter/catalog-deleter.js [56:143]


    function catalogDeleterController($scope) {
        let vm = this;

        $scope.id = $scope.symbolicName + ':' + $scope.version;

        function getBundle(bundleSymbolicName, bundleVersion) {
            catalogApi.getBundle(bundleSymbolicName, bundleVersion).then(data => {
                $scope.bundle = data;

            }).catch(err => {
                console.log("Error loading bundle: ", err);
                $scope.bundleError = true;
            }).finally(() => {
                $scope.bundleLoading = false;
            });
        }

        if ($scope.mode==='bundle') {
            $scope.bundleLoading = true;
            getBundle($scope.symbolicName, $scope.version);

        } else {
            $scope.bundleLoading = true;
            catalogApi.getType($scope.symbolicName, $scope.version).then(data => {
                let bundleSymbolicName, bundleVersion;
                if (data.containingBundle) {
                    let parts = data.containingBundle.split(':');
                    if (parts.length>=1) {
                        bundleSymbolicName = parts[0];
                        if (parts.length>=2) {
                            bundleVersion = parts[1];
                            if (parts.length>2) {
                                throw 'Invalid containing bundle '+data.containingBundle;
                            }
                        }
                    }
                }
                if (!bundleSymbolicName) {
                    throw 'Unavailable or invalid containing bundle '+data.containingBundle;
                }

                getBundle(bundleSymbolicName, bundleVersion);

            }).catch(err => {
                console.log("Error loading type: ", err);
                if ($scope.mode==='location') {
                    // don't display an error, probably it is a legacy-installed location
                } else {
                    $scope.bundleError = true;
                }
                $scope.bundleLoading = false;
            });
        }

        vm.delete = () => {
            if ($scope.onDeleting) $scope.onDeleting();
            let promise;
            if ($scope.mode==='bundle') {
                promise = catalogApi.deleteBundle($scope.symbolicName, $scope.version)
            } else if ($scope.mode==='location') {
                promise = catalogApi.deleteLocation($scope.symbolicName, $scope.version)
            } else if ($scope.mode==='type') {
                // not used
                throw 'deleteType not supported';
            } else {
                // shouldn't happen
                throw 'Unknown mode: '+$scope.mode;
            }

            promise.then(data => {
                if ($scope.onDeleted) $scope.onDeleted(data);
            }).catch(error => {
                let errorMessage= ('undefined' === typeof error.message)? error.error.message: error.message;
                brSnackbar.create('Could not delete this bundle: ' + errorMessage);
                if ($scope.onFailed) $scope.onFailed(error);
            }).finally(() => {
                if ($scope.onDeletingFinished) $scope.onDeletingFinished();
            });
        };
        vm.checkSingleBomBundle = (bundle) => {
            if (bundle) {
                if (bundle.format=='brooklyn-bom-bundle' && bundle.types && bundle.types.length===1 && bundle.types[0].symbolicName===$scope.symbolicName && bundle.types[0].version===$scope.version) {
                    return 'single-bom-match';
                }
            }
            return 'default';
        }
    }