From c661b06d47f4ff53a1e78a08b6eae2d8a8aa95df Mon Sep 17 00:00:00 2001 From: Tim Glaser Date: Wed, 20 Aug 2014 16:26:22 -0700 Subject: [PATCH] Further work towards conditional display of Visualize link. #118 --- _site_generated/assets/js/all.js | 83 ++++++++++++------- _site_generated/assets/views/ResultView.html | 9 +- site_raw/_includes/js/directives/Result.js | 12 +-- .../_includes/js/services/MarinePlanner.js | 71 ++++++++++------ site_raw/assets/views/ResultView.html | 9 +- 5 files changed, 118 insertions(+), 66 deletions(-) diff --git a/_site_generated/assets/js/all.js b/_site_generated/assets/js/all.js index 5eecbb2..11bdd98 100644 --- a/_site_generated/assets/js/all.js +++ b/_site_generated/assets/js/all.js @@ -30814,65 +30814,84 @@ angular.module('wcodpApp').factory('solr', ['$http', '$location', function($http angular.module('wcodpApp').factory('marinePlanner', ['$http', '$timeout', function($http, $timeout) { var _availableLayers = [], - _availableLayersEndpoint = 'http://visualize.westcoastoceans.org/geoportal-ids/', - _layerUrlPattern = 'http://visualize.westcoastoceans.org/{layerSlug}/'; + _availableLayersEndpoint = 'http://wcodp-md.apps.pointnineseven.com/data_manager/geoportal_ids', + _slugPlaceholder = '{layerSlug}', + _layerUrlPattern = 'http://wcodp-md.apps.pointnineseven.com/visualize/#' + _slugPlaceholder; /** - * The first time the function is called, it stores a promise for an - * ajax call to grab the full list of UUIDs for layers Todd has added - * to MP. The first use of the promise will cache the list for further - * uses of the promise. - */ - - - - /** - * [_getListOfLayers description] - * @param {Function} callback [description] - * @return {[type]} [description] + * The first time this function is called, it retreives this list and + * stores a cached version of it for later requests. */ function _getListOfLayers (callback) { if (_availableLayers.length > 0) { callback(_availableLayers); } else { // Grab list of visualizable layers from mp. - $http.get(_availableLayersEndpoint).success(function (data) { + //$http.get(_availableLayersEndpoint).success(function (data) { // 'data' should be a collection of objects, each containing // an id and a slug. // Cache result so we don't always have to fetch the list // from marine planner. - _availableLayers = data; + //_availableLayers = data; + + _availableLayers = { + geoportal_layers: [ + { + uuid: "174BE5C6-F9E8-4978-9F1B-CF0862920AA8", + name: "American Indian Trust Lands (USCB, 2010)", + slug: "american-indian-trust-lands-uscb-2010" + } + ] + }; // Satisfy the current request. callback(_availableLayers); - }).error(function (data) { - if (console) { console.log('Error getting available layers list from marine planner.'); } - }); + // }).error(function (data) { + // if (console) { console.log('Error getting available layers list from marine planner.'); } + // }); } } /** - * [_getLayerSlug description] - * @param {[type]} uuid [description] - * @param {[type]} list [description] - * @return {[type]} [description] + * Searches the contents of a list for an entry with a matching + * uuid and returns the slug variable of that entry. An example + * of the data structure is as follows + * + * [ + * { + * uuid: "sample-geoportal-uuid", + * name: "American Indian Trust Lands (USCB, 2010)", + * slug: "american-indian-trust-lands-uscb-2010" + * } + * ] + * */ function _getLayerSlug (uuid, list) { - // TODO, probably using underscore - return 'slug-slug'; + var cleanUuid = uuid.replace('{', '').replace('}', ''), + layerEntry; + if (_.isObject(list) && _.isArray(list.geoportal_layers)) { + layerEntry = _.findWhere(list.geoportal_layers, {'uuid': cleanUuid}); + return layerEntry ? layerEntry.slug : null; + } + return null; } return { + /** + * An asynchronous call to get a url, if any exists, from a Marine Planner + * end point that currently sits at: + * http://wcodp-md.apps.pointnineseven.com/data_manager/geoportal_ids + */ getMarinePlannerUrl: function (uuid, success_callback, error_callback) { _getListOfLayers(function (list) { var slug = _getLayerSlug(uuid, list), - url = slug ? _layerUrlPattern.replace('{layerSlug}', slug) : null; + url = slug ? _layerUrlPattern.replace(_slugPlaceholder, slug) : null; if (url) { success_callback(url); } else { @@ -31929,7 +31948,7 @@ angular.module('wcodpApp').directive('resultsList', ['$http', '$location', funct }]); -angular.module('wcodpApp').directive('result', ['$http', '$location', 'metadata', function($http, $location, metadata, marinePlanner) { +angular.module('wcodpApp').directive('result', ['$http', '$location', 'metadata', 'marinePlanner', function($http, $location, metadata, marinePlanner) { return { templateUrl: '/assets/views/ResultView.html', @@ -32134,20 +32153,20 @@ angular.module('wcodpApp').directive('result', ['$http', '$location', 'metadata' return scope.metadataXmlUrl() + '&f=pjson'; }; - scope.marinePlannerUrl = function () { + scope.getMarinePlannerUrl = function () { var uuid = scope.resultData['sys.sync.foreign.id_s']; - if (scope.marinePlannerUrl.length > 0) { - return scope.marinePlannerUrl; - } else { + if (scope.marinePlannerUrl.length === 0) { var success = function (result) { scope.marinePlannerUrl = result; }; var error = function () { - scope.marinePlannerUrl = '#error'; + scope.marinePlannerUrl = ''; }; marinePlanner.getMarinePlannerUrl(uuid, success, error); } }; + scope.getMarinePlannerUrl(); + scope.getLinks = function () { $http.get(scope.jsonUrl()).success(function (data) { diff --git a/_site_generated/assets/views/ResultView.html b/_site_generated/assets/views/ResultView.html index 465ce9d..2489222 100644 --- a/_site_generated/assets/views/ResultView.html +++ b/_site_generated/assets/views/ResultView.html @@ -21,7 +21,14 @@
  • METADATA XML
  • JSON
  • -
  • VISUALIZE
  • +
  • + VISUALIZE + + +
  • diff --git a/site_raw/_includes/js/directives/Result.js b/site_raw/_includes/js/directives/Result.js index f10a095..ea0cf6d 100644 --- a/site_raw/_includes/js/directives/Result.js +++ b/site_raw/_includes/js/directives/Result.js @@ -1,5 +1,5 @@ -angular.module('wcodpApp').directive('result', ['$http', '$location', 'metadata', function($http, $location, metadata, marinePlanner) { +angular.module('wcodpApp').directive('result', ['$http', '$location', 'metadata', 'marinePlanner', function($http, $location, metadata, marinePlanner) { return { templateUrl: '/assets/views/ResultView.html', @@ -204,20 +204,20 @@ angular.module('wcodpApp').directive('result', ['$http', '$location', 'metadata' return scope.metadataXmlUrl() + '&f=pjson'; }; - scope.marinePlannerUrl = function () { + scope.getMarinePlannerUrl = function () { var uuid = scope.resultData['sys.sync.foreign.id_s']; - if (scope.marinePlannerUrl.length > 0) { - return scope.marinePlannerUrl; - } else { + if (scope.marinePlannerUrl.length === 0) { var success = function (result) { scope.marinePlannerUrl = result; }; var error = function () { - scope.marinePlannerUrl = '#error'; + scope.marinePlannerUrl = ''; }; marinePlanner.getMarinePlannerUrl(uuid, success, error); } }; + scope.getMarinePlannerUrl(); + scope.getLinks = function () { $http.get(scope.jsonUrl()).success(function (data) { diff --git a/site_raw/_includes/js/services/MarinePlanner.js b/site_raw/_includes/js/services/MarinePlanner.js index c276634..d77394d 100644 --- a/site_raw/_includes/js/services/MarinePlanner.js +++ b/site_raw/_includes/js/services/MarinePlanner.js @@ -2,65 +2,84 @@ angular.module('wcodpApp').factory('marinePlanner', ['$http', '$timeout', function($http, $timeout) { var _availableLayers = [], - _availableLayersEndpoint = 'http://visualize.westcoastoceans.org/geoportal-ids/', - _layerUrlPattern = 'http://visualize.westcoastoceans.org/{layerSlug}/'; + _availableLayersEndpoint = 'http://wcodp-md.apps.pointnineseven.com/data_manager/geoportal_ids', + _slugPlaceholder = '{layerSlug}', + _layerUrlPattern = 'http://wcodp-md.apps.pointnineseven.com/visualize/#' + _slugPlaceholder; /** - * The first time the function is called, it stores a promise for an - * ajax call to grab the full list of UUIDs for layers Todd has added - * to MP. The first use of the promise will cache the list for further - * uses of the promise. - */ - - - - /** - * [_getListOfLayers description] - * @param {Function} callback [description] - * @return {[type]} [description] + * The first time this function is called, it retreives this list and + * stores a cached version of it for later requests. */ function _getListOfLayers (callback) { if (_availableLayers.length > 0) { callback(_availableLayers); } else { // Grab list of visualizable layers from mp. - $http.get(_availableLayersEndpoint).success(function (data) { + //$http.get(_availableLayersEndpoint).success(function (data) { // 'data' should be a collection of objects, each containing // an id and a slug. // Cache result so we don't always have to fetch the list // from marine planner. - _availableLayers = data; + //_availableLayers = data; + + _availableLayers = { + geoportal_layers: [ + { + uuid: "174BE5C6-F9E8-4978-9F1B-CF0862920AA8", + name: "American Indian Trust Lands (USCB, 2010)", + slug: "american-indian-trust-lands-uscb-2010" + } + ] + }; // Satisfy the current request. callback(_availableLayers); - }).error(function (data) { - if (console) { console.log('Error getting available layers list from marine planner.'); } - }); + // }).error(function (data) { + // if (console) { console.log('Error getting available layers list from marine planner.'); } + // }); } } /** - * [_getLayerSlug description] - * @param {[type]} uuid [description] - * @param {[type]} list [description] - * @return {[type]} [description] + * Searches the contents of a list for an entry with a matching + * uuid and returns the slug variable of that entry. An example + * of the data structure is as follows + * + * [ + * { + * uuid: "sample-geoportal-uuid", + * name: "American Indian Trust Lands (USCB, 2010)", + * slug: "american-indian-trust-lands-uscb-2010" + * } + * ] + * */ function _getLayerSlug (uuid, list) { - // TODO, probably using underscore - return 'slug-slug'; + var cleanUuid = uuid.replace('{', '').replace('}', ''), + layerEntry; + if (_.isObject(list) && _.isArray(list.geoportal_layers)) { + layerEntry = _.findWhere(list.geoportal_layers, {'uuid': cleanUuid}); + return layerEntry ? layerEntry.slug : null; + } + return null; } return { + /** + * An asynchronous call to get a url, if any exists, from a Marine Planner + * end point that currently sits at: + * http://wcodp-md.apps.pointnineseven.com/data_manager/geoportal_ids + */ getMarinePlannerUrl: function (uuid, success_callback, error_callback) { _getListOfLayers(function (list) { var slug = _getLayerSlug(uuid, list), - url = slug ? _layerUrlPattern.replace('{layerSlug}', slug) : null; + url = slug ? _layerUrlPattern.replace(_slugPlaceholder, slug) : null; if (url) { success_callback(url); } else { diff --git a/site_raw/assets/views/ResultView.html b/site_raw/assets/views/ResultView.html index 465ce9d..2489222 100644 --- a/site_raw/assets/views/ResultView.html +++ b/site_raw/assets/views/ResultView.html @@ -21,7 +21,14 @@
  • METADATA XML
  • JSON
  • -
  • VISUALIZE
  • +
  • + VISUALIZE + + +