Skip to content

Commit

Permalink
Further work towards conditional display of Visualize link. #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glaser committed Aug 20, 2014
1 parent 763ea74 commit c661b06
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 66 deletions.
83 changes: 51 additions & 32 deletions _site_generated/assets/js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion _site_generated/assets/views/ResultView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
<li><a target="_blank" ng-click="linkClicked($event)" href="{{ metadataXmlUrl() }}">METADATA XML</a><i class="icon-info-sign" tooltip-placement="bottom" tooltip="Metadata XML Document (ISO or FGDC)"></i></li>
<li><a target="_blank" ng-click="linkClicked($event)" href="{{ jsonUrl() }}">JSON</a><i class="icon-info-sign" tooltip-placement="bottom" tooltip="ESRI REST Service JSON"></i></li>

<li><a target="_blank" ng-click="linkClicked($event)" href="{{ marinePlannerUrl() }}">VISUALIZE</a><i class="icon-info-sign" tooltip-placement="bottom" tooltip="View on an interactive map"></i></li>
<li ng-show="marinePlannerUrl">
<a
target="_blank"
ng-click="linkClicked($event)"
href="{{ marinePlannerUrl }}">VISUALIZE
</a>
<i class="icon-info-sign" tooltip-placement="bottom" tooltip="View on an interactive map"></i>
</li>

</ul>
</div>
Expand Down
12 changes: 6 additions & 6 deletions site_raw/_includes/js/directives/Result.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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) {
Expand Down
71 changes: 45 additions & 26 deletions site_raw/_includes/js/services/MarinePlanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion site_raw/assets/views/ResultView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
<li><a target="_blank" ng-click="linkClicked($event)" href="{{ metadataXmlUrl() }}">METADATA XML</a><i class="icon-info-sign" tooltip-placement="bottom" tooltip="Metadata XML Document (ISO or FGDC)"></i></li>
<li><a target="_blank" ng-click="linkClicked($event)" href="{{ jsonUrl() }}">JSON</a><i class="icon-info-sign" tooltip-placement="bottom" tooltip="ESRI REST Service JSON"></i></li>

<li><a target="_blank" ng-click="linkClicked($event)" href="{{ marinePlannerUrl() }}">VISUALIZE</a><i class="icon-info-sign" tooltip-placement="bottom" tooltip="View on an interactive map"></i></li>
<li ng-show="marinePlannerUrl">
<a
target="_blank"
ng-click="linkClicked($event)"
href="{{ marinePlannerUrl }}">VISUALIZE
</a>
<i class="icon-info-sign" tooltip-placement="bottom" tooltip="View on an interactive map"></i>
</li>

</ul>
</div>
Expand Down

0 comments on commit c661b06

Please sign in to comment.