mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
style: Remove useless func wrap for helium
This commit is contained in:
parent
35d0fcccc4
commit
822a1d8744
2 changed files with 264 additions and 269 deletions
|
|
@ -12,208 +12,205 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
angular.module('zeppelinWebApp').controller('HeliumCtrl', HeliumCtrl);
|
||||
|
||||
angular.module('zeppelinWebApp').controller('HeliumCtrl', HeliumCtrl);
|
||||
HeliumCtrl.$inject = ['$scope', '$rootScope', '$sce', 'baseUrlSrv', 'ngToast', 'heliumService'];
|
||||
|
||||
HeliumCtrl.$inject = ['$scope', '$rootScope', '$sce', 'baseUrlSrv', 'ngToast', 'heliumService'];
|
||||
function HeliumCtrl($scope, $rootScope, $sce, baseUrlSrv, ngToast, heliumService) {
|
||||
$scope.packageInfos = {};
|
||||
$scope.defaultVersions = {};
|
||||
$scope.showVersions = {};
|
||||
$scope.bundleOrder = [];
|
||||
$scope.bundleOrderChanged = false;
|
||||
|
||||
function HeliumCtrl($scope, $rootScope, $sce, baseUrlSrv, ngToast, heliumService) {
|
||||
$scope.packageInfos = {};
|
||||
$scope.defaultVersions = {};
|
||||
$scope.showVersions = {};
|
||||
$scope.bundleOrder = [];
|
||||
var buildDefaultVersionListToDisplay = function(packageInfos) {
|
||||
var defaultVersions = {};
|
||||
// show enabled version if any version of package is enabled
|
||||
for (var name in packageInfos) {
|
||||
var pkgs = packageInfos[name];
|
||||
for (var pkgIdx in pkgs) {
|
||||
var pkg = pkgs[pkgIdx];
|
||||
pkg.pkg.icon = $sce.trustAsHtml(pkg.pkg.icon);
|
||||
if (pkg.enabled) {
|
||||
defaultVersions[name] = pkg;
|
||||
pkgs.splice(pkgIdx, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// show first available version if package is not enabled
|
||||
if (!defaultVersions[name]) {
|
||||
defaultVersions[name] = pkgs[0];
|
||||
pkgs.splice(0, 1);
|
||||
}
|
||||
}
|
||||
$scope.defaultVersions = defaultVersions;
|
||||
};
|
||||
|
||||
var getAllPackageInfo = function() {
|
||||
heliumService.getAllPackageInfo().
|
||||
success(function(data, status) {
|
||||
$scope.packageInfos = data.body;
|
||||
buildDefaultVersionListToDisplay($scope.packageInfos);
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Can not load package info %o %o', status, data);
|
||||
});
|
||||
};
|
||||
|
||||
var getBundleOrder = function() {
|
||||
heliumService.getVisualizationPackageOrder().
|
||||
success(function(data, status) {
|
||||
$scope.bundleOrder = data.body;
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Can not get bundle order %o %o', status, data);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.bundleOrderListeners = {
|
||||
accept: function(sourceItemHandleScope, destSortableScope) {return true;},
|
||||
itemMoved: function(event) {},
|
||||
orderChanged: function(event) {
|
||||
$scope.bundleOrderChanged = true;
|
||||
}
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
getAllPackageInfo();
|
||||
getBundleOrder();
|
||||
$scope.bundleOrderChanged = false;
|
||||
};
|
||||
|
||||
var buildDefaultVersionListToDisplay = function(packageInfos) {
|
||||
var defaultVersions = {};
|
||||
// show enabled version if any version of package is enabled
|
||||
for (var name in packageInfos) {
|
||||
var pkgs = packageInfos[name];
|
||||
for (var pkgIdx in pkgs) {
|
||||
var pkg = pkgs[pkgIdx];
|
||||
pkg.pkg.icon = $sce.trustAsHtml(pkg.pkg.icon);
|
||||
if (pkg.enabled) {
|
||||
defaultVersions[name] = pkg;
|
||||
pkgs.splice(pkgIdx, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
init();
|
||||
|
||||
// show first available version if package is not enabled
|
||||
if (!defaultVersions[name]) {
|
||||
defaultVersions[name] = pkgs[0];
|
||||
pkgs.splice(0, 1);
|
||||
$scope.saveBundleOrder = function() {
|
||||
var confirm = BootstrapDialog.confirm({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: '',
|
||||
message: 'Save changes?',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
confirm.$modalFooter.find('button').addClass('disabled');
|
||||
confirm.$modalFooter.find('button:contains("OK")')
|
||||
.html('<i class="fa fa-circle-o-notch fa-spin"></i> Enabling');
|
||||
heliumService.setVisualizationPackageOrder($scope.bundleOrder).
|
||||
success(function(data, status) {
|
||||
init();
|
||||
confirm.close();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
confirm.close();
|
||||
console.log('Failed to save order');
|
||||
BootstrapDialog.show({
|
||||
title: 'Error on saving order ',
|
||||
message: data.message
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$scope.defaultVersions = defaultVersions;
|
||||
};
|
||||
|
||||
var getAllPackageInfo = function() {
|
||||
heliumService.getAllPackageInfo().
|
||||
success(function(data, status) {
|
||||
$scope.packageInfos = data.body;
|
||||
buildDefaultVersionListToDisplay($scope.packageInfos);
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Can not load package info %o %o', status, data);
|
||||
});
|
||||
};
|
||||
|
||||
var getBundleOrder = function() {
|
||||
heliumService.getVisualizationPackageOrder().
|
||||
success(function(data, status) {
|
||||
$scope.bundleOrder = data.body;
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Can not get bundle order %o %o', status, data);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.bundleOrderListeners = {
|
||||
accept: function(sourceItemHandleScope, destSortableScope) {return true;},
|
||||
itemMoved: function(event) {},
|
||||
orderChanged: function(event) {
|
||||
$scope.bundleOrderChanged = true;
|
||||
}
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
getAllPackageInfo();
|
||||
getBundleOrder();
|
||||
$scope.bundleOrderChanged = false;
|
||||
};
|
||||
|
||||
init();
|
||||
|
||||
$scope.saveBundleOrder = function() {
|
||||
var confirm = BootstrapDialog.confirm({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: '',
|
||||
message: 'Save changes?',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
confirm.$modalFooter.find('button').addClass('disabled');
|
||||
confirm.$modalFooter.find('button:contains("OK")')
|
||||
.html('<i class="fa fa-circle-o-notch fa-spin"></i> Enabling');
|
||||
heliumService.setVisualizationPackageOrder($scope.bundleOrder).
|
||||
success(function(data, status) {
|
||||
init();
|
||||
confirm.close();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
confirm.close();
|
||||
console.log('Failed to save order');
|
||||
BootstrapDialog.show({
|
||||
title: 'Error on saving order ',
|
||||
message: data.message
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var getLicense = function(name, artifact) {
|
||||
var pkg = _.filter($scope.defaultVersions[name], function(p) {
|
||||
return p.artifact === artifact;
|
||||
});
|
||||
|
||||
var license;
|
||||
if (pkg.length === 0) {
|
||||
pkg = _.filter($scope.packageInfos[name], function(p) {
|
||||
return p.pkg.artifact === artifact;
|
||||
});
|
||||
|
||||
if (pkg.length > 0) {
|
||||
license = pkg[0].pkg.license;
|
||||
}
|
||||
} else {
|
||||
license = pkg[0].license;
|
||||
}
|
||||
|
||||
if (!license) {
|
||||
license = 'Unknown';
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
$scope.enable = function(name, artifact) {
|
||||
var license = getLicense(name, artifact);
|
||||
|
||||
var confirm = BootstrapDialog.confirm({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: '',
|
||||
message: 'Do you want to enable ' + name + '?' +
|
||||
'<div style="color:gray">' + artifact + '</div>' +
|
||||
'<div style="border-top: 1px solid #efefef; margin-top: 10px; padding-top: 5px;">License</div>' +
|
||||
'<div style="color:gray">' + license + '</div>',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
confirm.$modalFooter.find('button').addClass('disabled');
|
||||
confirm.$modalFooter.find('button:contains("OK")')
|
||||
.html('<i class="fa fa-circle-o-notch fa-spin"></i> Enabling');
|
||||
heliumService.enable(name, artifact).
|
||||
success(function(data, status) {
|
||||
init();
|
||||
confirm.close();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
confirm.close();
|
||||
console.log('Failed to enable package %o %o. %o', name, artifact, data);
|
||||
BootstrapDialog.show({
|
||||
title: 'Error on enabling ' + name,
|
||||
message: data.message
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.disable = function(name) {
|
||||
var confirm = BootstrapDialog.confirm({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: '',
|
||||
message: 'Do you want to disable ' + name + '?',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
confirm.$modalFooter.find('button').addClass('disabled');
|
||||
confirm.$modalFooter.find('button:contains("OK")')
|
||||
.html('<i class="fa fa-circle-o-notch fa-spin"></i> Disabling');
|
||||
heliumService.disable(name).
|
||||
success(function(data, status) {
|
||||
init();
|
||||
confirm.close();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
confirm.close();
|
||||
console.log('Failed to disable package %o. %o', name, data);
|
||||
BootstrapDialog.show({
|
||||
title: 'Error on disabling ' + name,
|
||||
message: data.message
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.toggleVersions = function(pkgName) {
|
||||
if ($scope.showVersions[pkgName]) {
|
||||
$scope.showVersions[pkgName] = false;
|
||||
} else {
|
||||
$scope.showVersions[pkgName] = true;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
var getLicense = function(name, artifact) {
|
||||
var pkg = _.filter($scope.defaultVersions[name], function(p) {
|
||||
return p.artifact === artifact;
|
||||
});
|
||||
|
||||
var license;
|
||||
if (pkg.length === 0) {
|
||||
pkg = _.filter($scope.packageInfos[name], function(p) {
|
||||
return p.pkg.artifact === artifact;
|
||||
});
|
||||
|
||||
if (pkg.length > 0) {
|
||||
license = pkg[0].pkg.license;
|
||||
}
|
||||
} else {
|
||||
license = pkg[0].license;
|
||||
}
|
||||
|
||||
if (!license) {
|
||||
license = 'Unknown';
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
$scope.enable = function(name, artifact) {
|
||||
var license = getLicense(name, artifact);
|
||||
|
||||
var confirm = BootstrapDialog.confirm({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: '',
|
||||
message: 'Do you want to enable ' + name + '?' +
|
||||
'<div style="color:gray">' + artifact + '</div>' +
|
||||
'<div style="border-top: 1px solid #efefef; margin-top: 10px; padding-top: 5px;">License</div>' +
|
||||
'<div style="color:gray">' + license + '</div>',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
confirm.$modalFooter.find('button').addClass('disabled');
|
||||
confirm.$modalFooter.find('button:contains("OK")')
|
||||
.html('<i class="fa fa-circle-o-notch fa-spin"></i> Enabling');
|
||||
heliumService.enable(name, artifact).
|
||||
success(function(data, status) {
|
||||
init();
|
||||
confirm.close();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
confirm.close();
|
||||
console.log('Failed to enable package %o %o. %o', name, artifact, data);
|
||||
BootstrapDialog.show({
|
||||
title: 'Error on enabling ' + name,
|
||||
message: data.message
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.disable = function(name) {
|
||||
var confirm = BootstrapDialog.confirm({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: '',
|
||||
message: 'Do you want to disable ' + name + '?',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
confirm.$modalFooter.find('button').addClass('disabled');
|
||||
confirm.$modalFooter.find('button:contains("OK")')
|
||||
.html('<i class="fa fa-circle-o-notch fa-spin"></i> Disabling');
|
||||
heliumService.disable(name).
|
||||
success(function(data, status) {
|
||||
init();
|
||||
confirm.close();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
confirm.close();
|
||||
console.log('Failed to disable package %o. %o', name, data);
|
||||
BootstrapDialog.show({
|
||||
title: 'Error on disabling ' + name,
|
||||
message: data.message
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.toggleVersions = function(pkgName) {
|
||||
if ($scope.showVersions[pkgName]) {
|
||||
$scope.showVersions[pkgName] = false;
|
||||
} else {
|
||||
$scope.showVersions[pkgName] = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,80 +14,78 @@
|
|||
|
||||
import { HeliumType, } from './helium-type';
|
||||
|
||||
(function() {
|
||||
angular.module('zeppelinWebApp').service('heliumService', heliumService);
|
||||
angular.module('zeppelinWebApp').service('heliumService', heliumService);
|
||||
|
||||
heliumService.$inject = ['$http', 'baseUrlSrv', 'ngToast'];
|
||||
heliumService.$inject = ['$http', 'baseUrlSrv', 'ngToast'];
|
||||
|
||||
function heliumService($http, baseUrlSrv, ngToast) {
|
||||
function heliumService($http, baseUrlSrv, ngToast) {
|
||||
|
||||
var url = baseUrlSrv.getRestApiBase() + '/helium/bundle/load';
|
||||
if (process.env.HELIUM_BUNDLE_DEV) {
|
||||
url = url + '?refresh=true';
|
||||
}
|
||||
// name `heliumBundles` should be same as `HelumBundleFactory.HELIUM_BUNDLES_VAR`
|
||||
var heliumBundles = [];
|
||||
// map for `{ magic: interpreter }`
|
||||
let spellPerMagic = {};
|
||||
let visualizationBundles = [];
|
||||
|
||||
// load should be promise
|
||||
this.load = $http.get(url).success(function(response) {
|
||||
if (response.substring(0, 'ERROR:'.length) !== 'ERROR:') {
|
||||
// evaluate bundles
|
||||
eval(response);
|
||||
|
||||
// extract bundles by type
|
||||
heliumBundles.map(b => {
|
||||
if (b.type === HeliumType.SPELL) {
|
||||
const spell = new b.class(); // eslint-disable-line new-cap
|
||||
spellPerMagic[spell.getMagic()] = spell;
|
||||
} else if (b.type === HeliumType.VISUALIZATION) {
|
||||
visualizationBundles.push(b);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error(response);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param magic {string} e.g `%flowchart`
|
||||
* @returns {SpellBase} undefined if magic is not registered
|
||||
*/
|
||||
this.getSpellByMagic = function(magic) {
|
||||
return spellPerMagic[magic];
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Object} map for `{ magic : spell }`
|
||||
*/
|
||||
this.getAllSpells = function() {
|
||||
return spellPerMagic;
|
||||
};
|
||||
|
||||
this.getVisualizationBundles = function() {
|
||||
return visualizationBundles;
|
||||
};
|
||||
|
||||
this.getVisualizationPackageOrder = function() {
|
||||
return $http.get(baseUrlSrv.getRestApiBase() + '/helium/order/visualization');
|
||||
};
|
||||
|
||||
this.setVisualizationPackageOrder = function(list) {
|
||||
return $http.post(baseUrlSrv.getRestApiBase() + '/helium/order/visualization', list);
|
||||
};
|
||||
|
||||
this.getAllPackageInfo = function() {
|
||||
return $http.get(baseUrlSrv.getRestApiBase() + '/helium/all');
|
||||
};
|
||||
|
||||
this.enable = function(name, artifact) {
|
||||
return $http.post(baseUrlSrv.getRestApiBase() + '/helium/enable/' + name, artifact);
|
||||
};
|
||||
|
||||
this.disable = function(name) {
|
||||
return $http.post(baseUrlSrv.getRestApiBase() + '/helium/disable/' + name);
|
||||
};
|
||||
var url = baseUrlSrv.getRestApiBase() + '/helium/bundle/load';
|
||||
if (process.env.HELIUM_BUNDLE_DEV) {
|
||||
url = url + '?refresh=true';
|
||||
}
|
||||
})();
|
||||
// name `heliumBundles` should be same as `HelumBundleFactory.HELIUM_BUNDLES_VAR`
|
||||
var heliumBundles = [];
|
||||
// map for `{ magic: interpreter }`
|
||||
let spellPerMagic = {};
|
||||
let visualizationBundles = [];
|
||||
|
||||
// load should be promise
|
||||
this.load = $http.get(url).success(function(response) {
|
||||
if (response.substring(0, 'ERROR:'.length) !== 'ERROR:') {
|
||||
// evaluate bundles
|
||||
eval(response);
|
||||
|
||||
// extract bundles by type
|
||||
heliumBundles.map(b => {
|
||||
if (b.type === HeliumType.SPELL) {
|
||||
const spell = new b.class(); // eslint-disable-line new-cap
|
||||
spellPerMagic[spell.getMagic()] = spell;
|
||||
} else if (b.type === HeliumType.VISUALIZATION) {
|
||||
visualizationBundles.push(b);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error(response);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param magic {string} e.g `%flowchart`
|
||||
* @returns {SpellBase} undefined if magic is not registered
|
||||
*/
|
||||
this.getSpellByMagic = function(magic) {
|
||||
return spellPerMagic[magic];
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Object} map for `{ magic : spell }`
|
||||
*/
|
||||
this.getAllSpells = function() {
|
||||
return spellPerMagic;
|
||||
};
|
||||
|
||||
this.getVisualizationBundles = function() {
|
||||
return visualizationBundles;
|
||||
};
|
||||
|
||||
this.getVisualizationPackageOrder = function() {
|
||||
return $http.get(baseUrlSrv.getRestApiBase() + '/helium/order/visualization');
|
||||
};
|
||||
|
||||
this.setVisualizationPackageOrder = function(list) {
|
||||
return $http.post(baseUrlSrv.getRestApiBase() + '/helium/order/visualization', list);
|
||||
};
|
||||
|
||||
this.getAllPackageInfo = function() {
|
||||
return $http.get(baseUrlSrv.getRestApiBase() + '/helium/all');
|
||||
};
|
||||
|
||||
this.enable = function(name, artifact) {
|
||||
return $http.post(baseUrlSrv.getRestApiBase() + '/helium/enable/' + name, artifact);
|
||||
};
|
||||
|
||||
this.disable = function(name) {
|
||||
return $http.post(baseUrlSrv.getRestApiBase() + '/helium/disable/' + name);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue