From b090493f3b1bcd4c4b5b5cc2929062b822517c6e Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 22 Apr 2016 02:00:49 +0200 Subject: [PATCH] Feature/loading (#66) * [ux] stateless search * [ux] tell the user when we're loading --- lib/client/app.js | 67 ++++++++++++++++++++--------------------------- static/index.html | 10 +++++-- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/lib/client/app.js b/lib/client/app.js index 09a6248..f497d8f 100644 --- a/lib/client/app.js +++ b/lib/client/app.js @@ -67,56 +67,45 @@ angular.module("roarmap-h2020-view", ["ngRoute"]) }; }) - .service("roarmapSearch", function (roarmapLoader) { - - // TODO: Here we should probably also store the searched - // terms such that one also see them when he returns into - // the search tab rather than seeing an empty box. - var current = null; - return { - - beginSearch: function (terms, callback) { - current = []; - terms = terms.toLowerCase(); - roarmapLoader(function (error, institutions) { - if (error) { - callback(error); - return; - } - - // TODO: if performance becomes a bottleneck we could - // create once an index and then use such index - institutions.forEach(function (entry) { - if (entry.title.toLowerCase().indexOf(terms) >= 0) { - current.push(entry); - } - }); - callback(null, current); - }); - }, - - getCurrentSearch: function () { - return current; - }, - }; - }) - // TODO: all the following code should be adapted not to throw // errors but rather to write somewhere what went wrong. Also // indication that processing is ongoing would be a great thing. - .controller("SearchController", function ($scope, roarmapSearch) { + .controller("MainController", function ($scope, roarmapLoader) { + $scope.g = { + is_loaded: false + }; + $scope.$on('$viewContentLoaded', function () { + roarmapLoader(function (error, institutions) { + if (error) { + throw error; + } + $scope.g.is_loaded = true; + }); + }); + }) + + .controller("SearchController", function ($scope, roarmapLoader) { $scope.g = { terms: "", - result: roarmapSearch.getCurrentSearch(), + result: null }; $scope.search = function () { - roarmapSearch.beginSearch($scope.g.terms, - function (error, result) { + current = []; + terms = $scope.g.terms.toLowerCase(); + roarmapLoader(function (error, institutions) { if (error) { throw error; } - $scope.g.result = result; + + // TODO: if performance becomes a bottleneck we could + // create once an index and then use such index + institutions.forEach(function (entry) { + if (entry.title.toLowerCase().indexOf(terms) >= 0) { + current.push(entry); + } + }); + $scope.g.result = current; }); }; }) diff --git a/static/index.html b/static/index.html index 7272298..32566f5 100644 --- a/static/index.html +++ b/static/index.html @@ -10,7 +10,7 @@ -
+
@@ -38,6 +39,11 @@

+
+ + Loading ROARMAP data... please wait... + +