Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Commit e1a36b5

Browse files
committed
Change selected file at runtime
1 parent a3a2147 commit e1a36b5

File tree

6 files changed

+74
-29
lines changed

6 files changed

+74
-29
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.groupdocs.ui.servlet;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.groupdocs.annotation.domain.AnnotationReplyInfo;
5+
import com.groupdocs.annotation.domain.results.AddReplyResult;
6+
import com.groupdocs.annotation.domain.results.GetAnnotationResult;
7+
import com.groupdocs.annotation.handler.AnnotationImageHandler;
8+
import com.groupdocs.ui.Utils;
9+
10+
import javax.servlet.ServletException;
11+
import javax.servlet.annotation.WebServlet;
12+
import javax.servlet.http.HttpServlet;
13+
import javax.servlet.http.HttpServletRequest;
14+
import javax.servlet.http.HttpServletResponse;
15+
import java.io.IOException;
16+
import java.nio.file.*;
17+
import java.util.ArrayList;
18+
19+
@WebServlet("/files")
20+
public class FilesServlet extends HttpServlet {
21+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
22+
response.setHeader("Content-Type", "application/json");
23+
24+
ArrayList<String> list = new ArrayList<>();
25+
Files.newDirectoryStream(Paths.get(Utils.getStoragePath())).forEach(path -> {
26+
if (Files.isRegularFile(path)) {
27+
list.add(path.getFileName().toString());
28+
}
29+
});
30+
31+
new ObjectMapper().writeValue(response.getOutputStream(), list);
32+
}
33+
34+
}
35+

src/main/webapp/app.components.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,17 @@
44
var ANNOTATION_TYPE_AREA = 1;
55

66
angular.module('GroupDocsAnnotationApp')
7-
.factory('FilesFactory', FilesFactory)
87
.factory('DocumentInfoFactory', DocumentInfoFactory)
98
.factory('AnnotationListFactory', AnnotationListFactory)
109
.factory('AnnotationAddFactory', AnnotationAddFactory)
1110
.controller('AvailableFilesController', AvailableFilesController)
1211
.controller('ToolbarController', ToolbarController)
1312
;
1413

15-
function FilesFactory() {
16-
var fileList = [
17-
'candy.pdf'
18-
];
19-
return {
20-
list: function () {
21-
return fileList;
22-
}
23-
};
24-
}
25-
2614
function DocumentInfoFactory($rootScope, $resource) {
2715
return $resource('/document/info?file=:filename', {}, {
2816
get: {
29-
method: 'GET',
30-
params: {
31-
filename: $rootScope.selectedFile
32-
}
17+
method: 'GET'
3318
}
3419
});
3520
}
@@ -38,9 +23,6 @@
3823
return $resource('/annotation/list?file=:filename', {}, {
3924
query: {
4025
method: 'GET',
41-
params: {
42-
filename: $rootScope.selectedFile
43-
},
4426
isArray: true
4527
}
4628
});
@@ -49,16 +31,13 @@
4931
function AnnotationAddFactory($rootScope, $resource) {
5032
return $resource('/annotation/add?file=:filename', {}, {
5133
save: {
52-
method: 'POST',
53-
params: {
54-
filename: $rootScope.selectedFile
55-
}
34+
method: 'POST'
5635
}
5736
});
5837
}
5938

6039
function AvailableFilesController($scope, FilesFactory) {
61-
$scope.list = FilesFactory.list();
40+
$scope.list = FilesFactory.query();
6241
}
6342

6443
function ToolbarController($scope, $mdToast) {

src/main/webapp/app.controller.pageCanvas.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
function main($rootScope, $scope, AnnotationListFactory, DocumentInfoFactory) {
55

6-
$rootScope.docInfo = DocumentInfoFactory.get();
7-
$scope.annotationsList = AnnotationListFactory.query();
8-
$rootScope.selectedDrawingTool = 'select';
6+
$rootScope.$watch('selectedFile', function () {
7+
$rootScope.docInfo = DocumentInfoFactory.get({
8+
filename: $rootScope.selectedFile
9+
});
10+
$rootScope.annotationsList = AnnotationListFactory.query({
11+
filename: $rootScope.selectedFile
12+
});
13+
$rootScope.selectedDrawingTool = 'select';
14+
$rootScope.selectedAnnotationGuid = null;
15+
});
916
}
17+
1018
angular.module('GroupDocsAnnotationApp').controller('PageCanvasController', main);
1119
})();
1220

src/main/webapp/app.directive.gdxAnnoPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@
344344

345345
if (ant.type) {
346346
ant.pageNumber = attrs.number;
347-
AnnotationAddFactory.save(ant, function (response) {
347+
var a = new AnnotationAddFactory(ant);
348+
a.$save({ filename: $rootScope.selectedFile }, function (response) {
348349
currentObject.name = response.guid;
349350
currentObject.selected = true;
350351
currentObject = null;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function () {
2+
'use strict';
3+
4+
function main($resource) {
5+
6+
return $resource(
7+
'/files',
8+
{},
9+
{
10+
query: {
11+
method: 'GET',
12+
isArray: true
13+
}
14+
}
15+
);
16+
}
17+
18+
angular.module('GroupDocsAnnotationApp').factory('FilesFactory', main);
19+
20+
})();
21+

src/main/webapp/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<script src="//cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.4/paper-full.min.js"></script>
2222

2323
<script src="app.js"></script>
24+
<script src="app.factory.files.js"></script>
2425
<script src="app.components.js"></script>
2526
<script src="app.factory.annotation.js"></script>
2627
<script src="app.factory.replies.js"></script>
@@ -45,7 +46,7 @@ <h1>GroupDocs.Annotation for Java</h1>
4546
<md-tooltip>Download the annotated file</md-tooltip>
4647
</md-button>
4748
<div ng-controller="AvailableFilesController">
48-
<md-select ng-model="$root.selectedFile" aria-label="Files" ng-disabled="true">
49+
<md-select ng-model="$root.selectedFile" aria-label="Files">
4950
<md-option ng-value="item" ng-repeat="item in list">{{ item }}</md-option>
5051
</md-select>
5152
</div>

0 commit comments

Comments
 (0)