From 694e8b03515f25e36cef855eddb835355eff4c51 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 13 Jan 2013 10:58:05 +0100 Subject: PagingTableService: o Adding support for showing a spinner if the query takes more than 500ms. o Adding a spinner when searching for people. --- .../webapp/apps/core/PagingTableService.js | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/main/resources/webapp/apps/core/PagingTableService.js') diff --git a/src/main/resources/webapp/apps/core/PagingTableService.js b/src/main/resources/webapp/apps/core/PagingTableService.js index f38b6f1..86d08f1 100755 --- a/src/main/resources/webapp/apps/core/PagingTableService.js +++ b/src/main/resources/webapp/apps/core/PagingTableService.js @@ -7,15 +7,29 @@ function PagingTableService() { query: "", startIndex: options.startIndex || 0, count: options.count || 10, - currentlySearching: false + currentlySearching: false, + queryStart: 0 }; var update = function(){ self.currentlySearching = true; + self.queryStart = new Date().getTime(); + + // This will update the spinner if the user want to show it. + var interval = setInterval(function () { + $scope.$apply(); + }, 500); + fetchCallback(self.startIndex, self.count, self.query, function(data) { + var now = new Date().getTime(); + console.log("Query took " + (now - self.queryStart) + "ms"); + + clearInterval(interval); + self.rows = data.rows; watcher(); self.currentlySearching = false; + self.queryStart = 0; }); }; @@ -56,6 +70,20 @@ function PagingTableService() { update(); }; + /* + * UI State queries + * + * TODO: the results should only be shown if the last query was successful. Add an 'error' state too. + */ + + self.showSpinner = function () { + return self.currentlySearching && new Date().getTime() - self.queryStart > 500; + }; + + self.showResults = function () { + return !self.currentlySearching; + }; + self.showPrev = function () { return self.startIndex > 0; }; -- cgit v1.2.3