Search on tags (client/server)

This commit is contained in:
jendib 2013-07-31 22:36:13 +02:00
parent fc5a1f2e71
commit 03e164ea38
5 changed files with 18 additions and 13 deletions

View File

@ -109,16 +109,21 @@ public class DocumentDao {
*/ */
public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCriteria criteria, SortCriteria sortCriteria) { public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCriteria criteria, SortCriteria sortCriteria) {
Map<String, Object> parameterMap = new HashMap<String, Object>(); Map<String, Object> parameterMap = new HashMap<String, Object>();
List<String> criteriaList = new ArrayList<String>();
StringBuilder sb = new StringBuilder("select d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3"); StringBuilder sb = new StringBuilder("select d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3");
sb.append(" from T_DOCUMENT d "); sb.append(" from T_DOCUMENT d ");
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) { if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
sb.append(" left join T_DOCUMENT_TAG dt on dt.DOT_IDDOCUMENT_C = d.DOC_ID_C "); int index = 0;
for (String tagId : criteria.getTagIdList()) {
sb.append(" left join T_DOCUMENT_TAG dt" + index + " on dt" + index + ".DOT_IDDOCUMENT_C = d.DOC_ID_C and dt" + index + ".DOT_IDTAG_C = :tagId" + index + " ");
criteriaList.add("dt" + index + ".DOT_ID_C is not null");
parameterMap.put("tagId" + index, tagId);
index++;
}
} }
// Adds search criteria // Adds search criteria
List<String> criteriaList = new ArrayList<String>();
if (criteria.getUserId() != null) { if (criteria.getUserId() != null) {
criteriaList.add("d.DOC_IDUSER_C = :userId"); criteriaList.add("d.DOC_IDUSER_C = :userId");
parameterMap.put("userId", criteria.getUserId()); parameterMap.put("userId", criteria.getUserId());
@ -135,10 +140,6 @@ public class DocumentDao {
criteriaList.add("d.DOC_CREATEDATE_D <= :createDateMax"); criteriaList.add("d.DOC_CREATEDATE_D <= :createDateMax");
parameterMap.put("createDateMax", criteria.getCreateDateMax()); parameterMap.put("createDateMax", criteria.getCreateDateMax());
} }
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
criteriaList.add("dt.DOT_IDTAG_C in :tagIdList");
parameterMap.put("tagIdList", criteria.getTagIdList());
}
criteriaList.add("d.DOC_DELETEDATE_D is null"); criteriaList.add("d.DOC_DELETEDATE_D is null");

View File

@ -1,2 +1 @@
- Client side search on tags
- Server side reordering files - Server side reordering files

View File

@ -22,6 +22,7 @@ App.controller('Document', function($scope, $state, Restangular) {
query: '', query: '',
createDateMin: null, createDateMin: null,
createDateMax: null, createDateMax: null,
tags: []
}; };
}; };
$scope.initSearch(); $scope.initSearch();
@ -38,7 +39,8 @@ App.controller('Document', function($scope, $state, Restangular) {
asc: $scope.asc, asc: $scope.asc,
search: $scope.search.query, search: $scope.search.query,
create_date_min: $scope.isAdvancedSearchCollapsed || !$scope.search.createDateMin ? null : $scope.search.createDateMin.getTime(), create_date_min: $scope.isAdvancedSearchCollapsed || !$scope.search.createDateMin ? null : $scope.search.createDateMin.getTime(),
create_date_max: $scope.isAdvancedSearchCollapsed || !$scope.search.createDateMax ? null : $scope.search.createDateMax.getTime() create_date_max: $scope.isAdvancedSearchCollapsed || !$scope.search.createDateMax ? null : $scope.search.createDateMax.getTime(),
'tags[]': $scope.isAdvancedSearchCollapsed ? null : _.pluck($scope.search.tags, 'id')
}) })
.then(function(data) { .then(function(data) {
$scope.documents = data.documents; $scope.documents = data.documents;

View File

@ -2,8 +2,5 @@
<ul class="inline"> <ul class="inline">
<li ng-repeat="tag in tags"><span class="label label-info">{{ tag.name }} <span class="icon-remove icon-white" ng-click="deleteTag(tag)"></span></span></li> <li ng-repeat="tag in tags"><span class="label label-info">{{ tag.name }} <span class="icon-remove icon-white" ng-click="deleteTag(tag)"></span></span></li>
</ul> </ul>
<p class="input-append">
<input type="text" id="{{ ref }}" placeholder="Type a tag" ng-model="input" typeahead="tag.name for tag in allTags | filter: $viewValue" typeahead-on-select="addTag()" /> <input type="text" id="{{ ref }}" placeholder="Type a tag" ng-model="input" typeahead="tag.name for tag in allTags | filter: $viewValue" typeahead-on-select="addTag()" />
<button type="submit" class="btn" ng-click="addTag()">Add</button>
</p>
</div> </div>

View File

@ -20,6 +20,12 @@
<input class="span4" ng-readonly="true" ng-change="loadDocuments()" type="text" id="inputCreateDateMax" datepicker-popup="yyyy-MM-dd" ng-model="search.createDateMax" starting-day="1" show-weeks="false" /> <input class="span4" ng-readonly="true" ng-change="loadDocuments()" type="text" id="inputCreateDateMax" datepicker-popup="yyyy-MM-dd" ng-model="search.createDateMax" starting-day="1" show-weeks="false" />
</div> </div>
</div> </div>
<div class="control-group">
<label class="control-label" for="inputTags">Tags</label>
<div class="controls">
<select-tag tags="search.tags" class="input-block-level" ref="inputTags" />
</div>
</div>
<div class="form-actions"> <div class="form-actions">
<button ng-click="initSearch()" class="btn btn-warning" type="submit">Reset search</button> <button ng-click="initSearch()" class="btn btn-warning" type="submit">Reset search</button>
</div> </div>