From 3d677a4654f59c485f39255b766e0e51917579c4 Mon Sep 17 00:00:00 2001 From: Kevin Fox Date: Fri, 31 Jul 2015 16:48:19 -0700 Subject: [PATCH] Share model for apps/components views. This will enable multiple views of the same data. Apps and Components. Once this is done, the assets can be merged into one file on the server to make it easier for new types to be added. Change-Id: Ie54ee460730bd3584375f069fab28b7c2b004d8d --- .../project/app_catalog/app_catalog.js | 111 +++++++++++++----- .../project/app_catalog/main_panel.html | 57 +++++++++ app_catalog/templates/app_catalog/index.html | 44 +------ .../templates/component_catalog/index.html | 54 +-------- 4 files changed, 144 insertions(+), 122 deletions(-) create mode 100644 app_catalog/static/dashboard/project/app_catalog/main_panel.html diff --git a/app_catalog/static/dashboard/project/app_catalog/app_catalog.js b/app_catalog/static/dashboard/project/app_catalog/app_catalog.js index 17b0dd8..bc7a8b2 100644 --- a/app_catalog/static/dashboard/project/app_catalog/app_catalog.js +++ b/app_catalog/static/dashboard/project/app_catalog/app_catalog.js @@ -22,59 +22,64 @@ .module('hz.dashboard.project.app_catalog', ['hz.dashboard']) .filter('encodeURIComponent', function() { return window.encodeURIComponent; - }) - .controller('appCatalogTableCtrl', [ + }).controller('appCatalogTableCtrl', [ '$scope', '$http', - 'horizon.openstack-service-api.heat', + '$timeout', + 'appCatalogModel', appCatalogTableCtrl ]).controller('appComponentCatalogTableCtrl', [ '$scope', '$http', - 'horizon.openstack-service-api.glance', + '$timeout', + 'appCatalogModel', appComponentCatalogTableCtrl + ]).service('appCatalogModel', [ + '$http', + 'horizon.openstack-service-api.heat', + 'horizon.openstack-service-api.glance', + appCatalogModel ]).directive('stars', stars); - function appCatalogTableCtrl($scope, $http, heatAPI) { - var req = { + function appCatalogModel($http, heatAPI, glanceAPI) { + var callbacks = []; + this.register_callback = function(callback) { + callbacks.push(callback); + }; + var notify = function(){ + angular.forEach(callbacks, function(callback){ + callback(); + }); + }; + this.assets = []; + var $scope = this; + var heat_req = { url: 'http://apps.openstack.org/static/heat_templates.json', headers: {'X-Requested-With': undefined} } - $http(req).success(function(data) { - $scope.assets = data.assets; - for (var i in $scope.assets){ - var process = function(asset, url) { + $http(heat_req).success(function(data) { + for (var i in data.assets){ + var asset = data.assets[i]; + $scope.assets.push(asset); + var process = function(asset) { var url = asset.attributes.url; heatAPI.validate({'template_url': url}).success(function(data){ asset.validated = true; + notify(); }).error(function(data, status){ var str = 'ERROR: Could not retrieve template:' asset.validated = 'unsupported'; if(status == 400 && data.slice(0, str.length) == str) { asset.validated = 'error' } + notify(); }); } - process($scope.assets[i]); + process(asset); } + notify(); }); - } - - function update_found_assets($scope) { - if('assets' in $scope && 'glance_names' in $scope){ - for (var i in $scope.assets){ - var name = $scope.assets[i].name; - var is_installed = name in $scope.glance_names; - $scope.assets[i].installed = is_installed; - if(is_installed){ - $scope.assets[i].installed_id = $scope.glance_names[name]['id']; - } - } - } - } - - function appComponentCatalogTableCtrl($scope, $http, glanceAPI) { - var req = { + var glance_req = { url: 'http://apps.openstack.org/static/glance_images.json', headers: {'X-Requested-With': undefined} } @@ -87,13 +92,59 @@ } $scope.glance_names = glance_names; update_found_assets($scope) + notify(); }); - $http(req).success(function(data) { - $scope.assets = data.assets; + $http(glance_req).success(function(data) { + for (var i in data.assets){ + var asset = data.assets[i]; + $scope.assets.push(asset); + } + $scope.glance_loaded = true; update_found_assets($scope); + notify(); }); } + function appCatalogTableCtrl($scope, $http, $timeout, appCatalogModel) { + $scope.assets = [] + var update = function(){ + $scope.assets = [] + for (var i in appCatalogModel.assets){ + var asset = appCatalogModel.assets[i]; + if(typeof asset.tags !== "undefined" && asset.tags.indexOf('app') > -1){ + $scope.assets.push(asset); + } + } + }; + appCatalogModel.register_callback(update); + } + + function appComponentCatalogTableCtrl($scope, $http, $timeout, appCatalogModel) { + $scope.assets = appCatalogModel.assets + var update = function(){ + $timeout(function() { + $scope.assets = appCatalogModel.assets + }, 0, false); + }; + appCatalogModel.register_callback(update); + } + + function update_found_assets($scope) { + if('glance_loaded' in $scope && 'glance_names' in $scope){ + for (var i in $scope.assets){ + if($scope.assets[i].service.type != 'glance'){ + continue; + } + var name = $scope.assets[i].name; + var is_installed = name in $scope.glance_names; + $scope.assets[i].installed = is_installed; + if(is_installed){ + $scope.assets[i].installed_id = $scope.glance_names[name]['id']; + } + } + } + } + function stars() { var star = angular.element(''); star.addClass('fa fa-star'); diff --git a/app_catalog/static/dashboard/project/app_catalog/main_panel.html b/app_catalog/static/dashboard/project/app_catalog/main_panel.html new file mode 100644 index 0000000..b5849f4 --- /dev/null +++ b/app_catalog/static/dashboard/project/app_catalog/main_panel.html @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + +
NameLicense
+ + {$ asset.name $}{$ asset.license $} + + +
+
+
Name
+
{$ asset.name $}
+
Description
+
{$ asset.description $}
+
Company
+
{$ asset.provided_by.company $}
+
+
+ License Details +
+
+
+
diff --git a/app_catalog/templates/app_catalog/index.html b/app_catalog/templates/app_catalog/index.html index 4117edc..a05237a 100644 --- a/app_catalog/templates/app_catalog/index.html +++ b/app_catalog/templates/app_catalog/index.html @@ -8,47 +8,9 @@ {% block main %} - - - - - - - - - - - - - - - - - - - - - - - - -
NameLicense
- - {$ asset.name $}{$ asset.license $} - Checking - Error - Unsupported - Launch -
-
-
Name
-
{$ asset.name $}
-
Description
-
{$ asset.description $}
-
-
- + + {% endblock %} diff --git a/component_catalog/templates/component_catalog/index.html b/component_catalog/templates/component_catalog/index.html index 291a467..1155fce 100644 --- a/component_catalog/templates/component_catalog/index.html +++ b/component_catalog/templates/component_catalog/index.html @@ -8,57 +8,9 @@ {% block main %} - - - - - - - - - - - - - - - - - - - - - - - - -
NameLicense
- - {$ asset.name $}{$ asset.license $} - Install Instructions -
- Checking - Install - Launch - -
-
-
-
Name
-
{$ asset.name $}
-
Description
-
{$ asset.description $}
-
Company
-
{$ asset.provided_by.company $}
-
-
- License Details -
-
-
-
- + + {% endblock %}