From 7bb1f48464b749518e3b07f36d135ac8e6be8cc1 Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 17 Aug 2013 01:48:33 +0200 Subject: [PATCH] Display and edit language on document (client) --- docs-parent/TODO | 1 - .../docs/rest/resource/DocumentResource.java | 1 + .../webapp/app/docs/controller/Document.js | 40 ++++++++++++------ .../app/docs/controller/DocumentEdit.js | 5 ++- docs-web/src/main/webapp/img/flag/eng.png | Bin 0 -> 599 bytes docs-web/src/main/webapp/img/flag/fra.png | Bin 0 -> 545 bytes .../webapp/partial/docs/document.edit.html | 9 ++++ .../webapp/partial/docs/document.view.html | 6 +-- 8 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 docs-web/src/main/webapp/img/flag/eng.png create mode 100644 docs-web/src/main/webapp/img/flag/fra.png diff --git a/docs-parent/TODO b/docs-parent/TODO index fddeffdb..413e0ed8 100644 --- a/docs-parent/TODO +++ b/docs-parent/TODO @@ -1,4 +1,3 @@ -- Add language on document (client) - Index title and description (server) - Use Lucene for title and description searching (server) - Index OCR-ized content (server) diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java index 38509e0c..1ca40807 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java @@ -89,6 +89,7 @@ public class DocumentResource extends BaseResource { document.put("title", documentDb.getTitle()); document.put("description", documentDb.getDescription()); document.put("create_date", documentDb.getCreateDate().getTime()); + document.put("language", documentDb.getLanguage()); // Add tags TagDao tagDao = new TagDao(); diff --git a/docs-web/src/main/webapp/app/docs/controller/Document.js b/docs-web/src/main/webapp/app/docs/controller/Document.js index f8b9d95e..4e642fe2 100644 --- a/docs-web/src/main/webapp/app/docs/controller/Document.js +++ b/docs-web/src/main/webapp/app/docs/controller/Document.js @@ -3,7 +3,7 @@ /** * Document controller. */ -App.controller('Document', function($scope, $state, Restangular) { +App.controller('Document', function($scope, $timeout, $state, Restangular) { /** * Documents table sort status. */ @@ -13,24 +13,28 @@ App.controller('Document', function($scope, $state, Restangular) { $scope.currentPage = 1; $scope.limit = 10; $scope.search = ''; + + // A timeout promise is used to slow down search requests to the server + // We keep track of it for cancellation purpose + var timeoutPromise; /** * Load new documents page. */ $scope.pageDocuments = function() { Restangular.one('document') - .getList('list', { - offset: $scope.offset, - limit: $scope.limit, - sort_column: $scope.sortColumn, - asc: $scope.asc, - search: $scope.search - }) - .then(function(data) { - $scope.documents = data.documents; - $scope.totalDocuments = data.total; - $scope.numPages = Math.ceil(data.total / $scope.limit); - }); + .getList('list', { + offset: $scope.offset, + limit: $scope.limit, + sort_column: $scope.sortColumn, + asc: $scope.asc, + search: $scope.search + }) + .then(function (data) { + $scope.documents = data.documents; + $scope.totalDocuments = data.total; + $scope.numPages = Math.ceil(data.total / $scope.limit); + }); }; /** @@ -57,7 +61,15 @@ App.controller('Document', function($scope, $state, Restangular) { * Watch for search scope change. */ $scope.$watch('search', function(prev, next) { - $scope.loadDocuments(); + if (timeoutPromise) { + // Cancel previous timeout + $timeout.cancel(timeoutPromise); + } + + // Call API later + timeoutPromise = $timeout(function () { + $scope.loadDocuments(); + }, 200); }, true); /** diff --git a/docs-web/src/main/webapp/app/docs/controller/DocumentEdit.js b/docs-web/src/main/webapp/app/docs/controller/DocumentEdit.js index 08807ff8..89615192 100644 --- a/docs-web/src/main/webapp/app/docs/controller/DocumentEdit.js +++ b/docs-web/src/main/webapp/app/docs/controller/DocumentEdit.js @@ -46,7 +46,10 @@ App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams, $scope.document = data; }); } else { - $scope.document = { tags: [] }; + $scope.document = { + tags: [], + language: 'fra' + }; } /** diff --git a/docs-web/src/main/webapp/img/flag/eng.png b/docs-web/src/main/webapp/img/flag/eng.png new file mode 100644 index 0000000000000000000000000000000000000000..ff701e19f6d2c0658fb23b1d94124cba4ce60851 GIT binary patch literal 599 zcmV-d0;v6oP)U(k2*|8J(R-+sudaynhucHbwAMTnor{mwqO^w7JHzaBsT z{O^B8RYf5+LvDs&KmRKVd78=o{`1#HTiEo_OolaGleS)G+IQ#sUI`b*pv<`1zCJ=H0jd{{2S>p`ri%{LsXJ%FbMS z$#S`6f|?OG!^Jxczkf6Q`UNF{l0Sd`ad7zm>({^EzyAS6{{CgrkluOb3l1A>ZU2~A zK+FZ=zkmP!`TOVhpFbzBzFaPmD2$N3;+$pK?>zdet`f0002ovPDHLkV1gy;I?Vt8 literal 0 HcmV?d00001 diff --git a/docs-web/src/main/webapp/img/flag/fra.png b/docs-web/src/main/webapp/img/flag/fra.png new file mode 100644 index 0000000000000000000000000000000000000000..8332c4ec23c853944c29b02d7b32a88033f48a71 GIT binary patch literal 545 zcmV++0^a?JP)lgG%);U`26kn-@hOg zU%!6+4+cOs(0HIde9xZz`}Onxub&LUB0x(30+2WcIRJn#2ut|?gWYu1Cf+!-K%B8# zdf?1WA}#uZ8oj7u>$I1i0Al&`=O0k%-@icgAIJnM0xA6maSq6BK-ECw|NZ*S`0Lj% z1_pot6puj;05Ax`F!=umqj7^frO?t|3^&I1kxUq9yECc+jQpY84SWH_0#pxl$?v~F z@*hy-KN0|X07U)z`4{NpU%#2aHUI<=%a31wK(7Du52Oc(|3O^?R1IN+RRjI-n*kVB z3=9AP#PZ|EACPLGJ%9cJNh|>9B%spYzZw7h1%?tp0I_@ndg9MNE>313@6R75NcceF zkr51-#U+7;F#`Sf7i0rK0I_`g_NQ&Z +
+ +
+ +
+
diff --git a/docs-web/src/main/webapp/partial/docs/document.view.html b/docs-web/src/main/webapp/partial/docs/document.view.html index 23441a8c..b26c3dee 100644 --- a/docs-web/src/main/webapp/partial/docs/document.view.html +++ b/docs-web/src/main/webapp/partial/docs/document.view.html @@ -1,6 +1,6 @@ - + -
+
@@ -9,7 +9,7 @@