1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-13 09:46:17 +00:00

Search on shared status (server)

This commit is contained in:
jendib
2013-08-15 18:33:58 +02:00
parent ea1e226b50
commit c14797bd5a
11 changed files with 203 additions and 22 deletions

View File

@@ -129,7 +129,8 @@ public class DocumentResource extends BaseResource {
@QueryParam("search") String search,
@QueryParam("create_date_min") String createDateMinStr,
@QueryParam("create_date_max") String createDateMaxStr,
@QueryParam("tags") List<String> tagIdList) throws JSONException {
@QueryParam("tags") List<String> tagIdList,
@QueryParam("shared") Boolean shared) throws JSONException {
if (!authenticate()) {
throw new ForbiddenClientException();
}
@@ -150,6 +151,7 @@ public class DocumentResource extends BaseResource {
documentCriteria.setCreateDateMin(createDateMin);
documentCriteria.setCreateDateMax(createDateMax);
documentCriteria.setTagIdList(tagIdList);
documentCriteria.setShared(shared);
if (!Strings.isNullOrEmpty(search)) {
documentCriteria.setSearch(search);
}
@@ -161,6 +163,7 @@ public class DocumentResource extends BaseResource {
document.put("title", documentDto.getTitle());
document.put("description", documentDto.getDescription());
document.put("create_date", documentDto.getCreateTimestamp());
document.put("shared", documentDto.getShared());
// Get tags
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId());

View File

@@ -5,14 +5,14 @@
*/
var App = angular.module('docs',
// Dependencies
['ui.state', 'ui.bootstrap', 'ui.route', 'ui.keypress', 'ui.validate',
['ui.state', 'ui.bootstrap', 'ui.keypress', 'ui.validate',
'ui.sortable', 'restangular', 'ngSanitize', 'ngMobile', 'colorpicker.module']
)
/**
* Configuring modules.
*/
.config(function($stateProvider, $httpProvider, $routeProvider, RestangularProvider) {
.config(function($stateProvider, $httpProvider, RestangularProvider) {
// Configuring UI Router
$stateProvider
.state('main', {

View File

@@ -5,13 +5,13 @@
*/
var App = angular.module('share',
// Dependencies
['ui.state', 'ui.bootstrap', 'ui.route', 'restangular', 'ngSanitize', 'ngMobile']
['ui.state', 'ui.bootstrap', 'restangular', 'ngSanitize', 'ngMobile']
)
/**
* Configuring modules.
*/
.config(function($stateProvider, $httpProvider, $routeProvider, RestangularProvider) {
.config(function($stateProvider, $httpProvider, RestangularProvider) {
// Configuring UI Router
$stateProvider
.state('main', {

View File

@@ -0,0 +1,83 @@
'use strict';
/**
* File view controller.
*/
App.controller('FileView', function($dialog, $state, $stateParams) {
var dialog = $dialog.dialog({
keyboard: true,
templateUrl: 'partial/share/file.view.html',
controller: function($scope, $state, $stateParams, Restangular, dialog) {
// Load files
Restangular.one('file').getList('list', { id: $stateParams.documentId, share: $stateParams.shareId }).then(function(data) {
$scope.files = data.files;
// Search current file
_.each($scope.files, function(value) {
if (value.id == $stateParams.fileId) {
$scope.file = value;
}
});
});
/**
* Navigate to the next file.
*/
$scope.nextFile = function() {
_.each($scope.files, function(value, key) {
if (value.id == $stateParams.fileId) {
var next = $scope.files[key + 1];
if (next) {
dialog.close({});
$state.transitionTo('share.file', { documentId: $stateParams.documentId, shareId: $stateParams.shareId, fileId: next.id });
}
}
});
};
/**
* Navigate to the previous file.
*/
$scope.previousFile = function() {
_.each($scope.files, function(value, key) {
if (value.id == $stateParams.fileId) {
var previous = $scope.files[key - 1];
if (previous) {
dialog.close({});
$state.transitionTo('share.file', { documentId: $stateParams.documentId, shareId: $stateParams.shareId, fileId: previous.id });
}
}
});
};
/**
* Open the file in a new window.
*/
$scope.openFile = function() {
window.open('api/file/' + $stateParams.fileId + '/data?share=' + $stateParams.shareId);
};
/**
* Close the file preview.
*/
$scope.closeFile = function () {
dialog.close();
};
// Close the dialog when the user exits this state
var off = $scope.$on('$stateChangeStart', function(event, toState){
if (dialog.isOpen()) {
dialog.close(toState.name == 'share.file' ? {} : null);
}
off();
});
}
});
// Returns to share view on file close
dialog.open().then(function(result) {
if (result == null) {
$state.transitionTo('share', { documentId: $stateParams.documentId, shareId: $stateParams.shareId });
}
});
});

View File

@@ -0,0 +1,21 @@
<div class="text-center">
<div class="btn-group pull-left">
<button type="button" class="btn" ng-click="closeFile()"><span class="icon-remove"></span></button>
</div>
<div class="btn-group">
<button type="button" class="btn" ng-click="previousFile()">Previous</button>
<button type="button" class="btn" ng-click="nextFile()">Next</button>
</div>
<div class="btn-group pull-right">
<button type="button" class="btn" ng-click="openFile()"><span class="icon-share"></span></button>
</div>
</div>
<img ng-if="$stateParams.fileId && (file.mimetype == 'image/png' || file.mimetype == 'image/jpeg' || file.mimetype == 'image/gif')" ng-src="api/file/{{ $stateParams.fileId }}/data?share={{ $stateParams.shareId }}" />
<div class="text-center" ng-if="$stateParams.fileId && file.mimetype == 'application/pdf'">
<img ng-src="api/file/{{ $stateParams.fileId }}/data?thumbnail=true&share={{ $stateParams.shareId }}" />
</div>

View File

@@ -58,6 +58,15 @@ public class TestDocumentResource extends BaseJerseyTest {
String document1Id = json.optString("id");
Assert.assertNotNull(document1Id);
// Share this document
WebResource fileShareResource = resource().path("/share");
fileShareResource.addFilter(new CookieAuthenticationFilter(document1Token));
postParams = new MultivaluedMapImpl();
postParams.add("id", document1Id);
response = fileShareResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class);
// List all documents
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
@@ -114,6 +123,19 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertTrue(documents.length() == 1);
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
// Search documents by shared status
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("shared", true);
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
documents = json.getJSONArray("documents");
Assert.assertTrue(documents.length() == 1);
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
Assert.assertEquals(true, documents.getJSONObject(0).getBoolean("shared"));
// Search documents (nothing)
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));

View File

@@ -64,12 +64,12 @@ public class TestShareResource extends BaseJerseyTest {
String file1Id = json.getString("id");
// Share this document
WebResource fileShareResource = resource().path("/share");
fileShareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
WebResource shareResource = resource().path("/share");
shareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
postParams = new MultivaluedMapImpl();
postParams.add("id", document1Id);
postParams.add("name", "4 All");
response = fileShareResource.put(ClientResponse.class, postParams);
response = shareResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class);
String share1Id = json.getString("id");
@@ -109,9 +109,9 @@ public class TestShareResource extends BaseJerseyTest {
Assert.assertEquals(163510, fileBytes.length);
// Deletes the share
fileShareResource = resource().path("/share/" + share1Id);
fileShareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
response = fileShareResource.delete(ClientResponse.class);
shareResource = resource().path("/share/" + share1Id);
shareResource.addFilter(new CookieAuthenticationFilter(share1AuthenticationToken));
response = shareResource.delete(ClientResponse.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.getEntity(JSONObject.class);
Assert.assertEquals("ok", json.getString("status"));