From 742ff183bfdfa644dc36a99a736c00a6979a3f84 Mon Sep 17 00:00:00 2001
From: Benjamin Gamard
Date: Sun, 12 Nov 2017 23:24:10 +0100
Subject: [PATCH] #158: advanced search form (wip)
---
docs-web/src/main/webapp/src/app/docs/app.js | 20 +++++
.../app/docs/controller/document/Document.js | 36 ++++++++-
.../src/partial/docs/document.edit.html | 17 +---
.../webapp/src/partial/docs/document.html | 79 ++++++++++++++-----
.../src/main/webapp/src/style/bootstrap.css | 2 +-
docs-web/src/main/webapp/src/style/main.less | 22 ++++++
6 files changed, 136 insertions(+), 40 deletions(-)
diff --git a/docs-web/src/main/webapp/src/app/docs/app.js b/docs-web/src/main/webapp/src/app/docs/app.js
index 4d08b550..707bef6a 100644
--- a/docs-web/src/main/webapp/src/app/docs/app.js
+++ b/docs-web/src/main/webapp/src/app/docs/app.js
@@ -422,6 +422,26 @@ angular.module('docs',
Restangular.one('theme').get().then(function(data) {
$rootScope.appName = data.name;
});
+
+ // Languages
+ $rootScope.acceptedLanguages = [
+ { key: 'eng', label: 'English' },
+ { key: 'fra', label: 'Français' },
+ { key: 'ita', label: 'Italiano' },
+ { key: 'deu', label: 'Deutsch' },
+ { key: 'spa', label: 'Español' },
+ { key: 'por', label: 'Português' },
+ { key: 'pol', label: 'Polski' },
+ { key: 'rus', label: 'русский' },
+ { key: 'ukr', label: 'українська' },
+ { key: 'ara', label: 'العربية' },
+ { key: 'hin', label: 'हिन्दी' },
+ { key: 'chi_sim', label: '简体中文' },
+ { key: 'chi_tra', label: '繁体中文' },
+ { key: 'jpn', label: '日本語' },
+ { key: 'tha', label: 'ภาษาไทย' },
+ { key: 'kor', label: '한국어' }
+ ];
})
/**
* Initialize ngProgress.
diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js b/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js
index 3e40cad2..88decb32 100644
--- a/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js
+++ b/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js
@@ -3,7 +3,7 @@
/**
* Document controller.
*/
-angular.module('docs').controller('Document', function ($scope, $rootScope, $timeout, $state, Restangular) {
+angular.module('docs').controller('Document', function ($scope, $rootScope, $timeout, $state, Restangular, $q) {
/**
* Documents table sort status.
*/
@@ -13,6 +13,7 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim
$scope.currentPage = 1;
$scope.limit = _.isUndefined(localStorage.documentsPageSize) ? 10 : localStorage.documentsPageSize;
$scope.search = $state.params.search ? $state.params.search : '';
+ $scope.searchOpened = false;
$scope.setSearch = function (search) { $scope.search = search };
// A timeout promise is used to slow down search requests to the server
@@ -115,9 +116,9 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim
};
// Load tags
- var tags = [];
+ $scope.tags = [];
Restangular.one('tag/list').get().then(function (data) {
- tags = data.tags;
+ $scope.tags = data.tags;
});
/**
@@ -125,11 +126,29 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim
* @param parent
*/
$scope.getChildrenTags = function(parent) {
- return _.filter(tags, function(tag) {
+ return _.filter($scope.tags, function(tag) {
return tag.parent === parent;
});
};
+ /**
+ * Returns a promise for typeahead user.
+ */
+ $scope.getUserTypeahead = function($viewValue) {
+ var deferred = $q.defer();
+ Restangular.one('user/list')
+ .get({
+ search: $viewValue,
+ sort_column: 1,
+ asc: true
+ }).then(function(data) {
+ deferred.resolve(_.pluck(_.filter(data.users, function(user) {
+ return user.username.indexOf($viewValue) !== -1;
+ }), 'username'));
+ });
+ return deferred.promise;
+ };
+
// Hack to reload the pagination directive after language change
$scope.paginationShown = true;
$rootScope.$on('$translateChangeSuccess', function () {
@@ -138,4 +157,13 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim
$scope.paginationShown = true;
});
})
+
+ // Advanced search
+ $scope.searchDropdownAnchor = angular.element(document.querySelector('.search-dropdown-anchor'));
+ $scope.openSearch = function () {
+ var opened = $scope.searchOpened;
+ $timeout(function () {
+ $scope.searchOpened = !opened;
+ });
+ }
});
\ No newline at end of file
diff --git a/docs-web/src/main/webapp/src/partial/docs/document.edit.html b/docs-web/src/main/webapp/src/partial/docs/document.edit.html
index bc2f4ea9..9a50cb83 100644
--- a/docs-web/src/main/webapp/src/partial/docs/document.edit.html
+++ b/docs-web/src/main/webapp/src/partial/docs/document.edit.html
@@ -51,22 +51,7 @@
diff --git a/docs-web/src/main/webapp/src/partial/docs/document.html b/docs-web/src/main/webapp/src/partial/docs/document.html
index fb961775..a96544a2 100644
--- a/docs-web/src/main/webapp/src/partial/docs/document.html
+++ b/docs-web/src/main/webapp/src/partial/docs/document.html
@@ -5,38 +5,79 @@
{{ 'document.add_document' | translate }}
-
-
+
+
-
-
+ {{advsearch}}
+
diff --git a/docs-web/src/main/webapp/src/style/bootstrap.css b/docs-web/src/main/webapp/src/style/bootstrap.css
index 05c874c5..a8a29b40 100644
--- a/docs-web/src/main/webapp/src/style/bootstrap.css
+++ b/docs-web/src/main/webapp/src/style/bootstrap.css
@@ -2990,7 +2990,7 @@ select[multiple].input-lg {
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
- font-weight: normal;
+ font-weight: bold;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
diff --git a/docs-web/src/main/webapp/src/style/main.less b/docs-web/src/main/webapp/src/style/main.less
index f38810ce..e31c74c6 100644
--- a/docs-web/src/main/webapp/src/style/main.less
+++ b/docs-web/src/main/webapp/src/style/main.less
@@ -287,6 +287,28 @@ input[readonly].share-link {
}
}
+// Advanced search
+.btn-open-search > * {
+ vertical-align: middle;
+}
+
+.btn-open-search .glyphicon {
+ top: 0;
+}
+
+.search-dropdown-anchor {
+ position: relative;
+}
+
+.search-dropdown-menu {
+ left: 0 !important;
+ top: 34px !important;
+ padding-top: 15px;
+ padding-left: 15px;
+ padding-right: 15px;
+ padding-bottom: 0;
+}
+
// Vertical alignment
.vertical-center {
min-height: 100vh;