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

Commit e5e06ef

Browse files
unknownunknown
authored andcommitted
Arrow Tool and Spinner Added
1 parent fefacf7 commit e5e06ef

File tree

8 files changed

+122
-222
lines changed

8 files changed

+122
-222
lines changed

src/main/webapp/app.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(function () {
2+
'use strict';
3+
4+
function main(cfpLoadingBarProvider) {
5+
cfpLoadingBarProvider.includeSpinner = false;
6+
cfpLoadingBarProvider.includeBar = true;
7+
}
8+
9+
angular.module('GroupDocsAnnotationApp').config(['cfpLoadingBarProvider', main]);
10+
11+
})();
12+

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
'use strict';
33

44
function main($rootScope, $scope, AnnotationListFactory, FilesFactory, DocumentInfoFactory) {
5-
5+
66
$scope.docInfo = DocumentInfoFactory.get();
77
$scope.selectedFile = FilesFactory.selectedFile;
88
$scope.annotationsList = AnnotationListFactory.query();
9-
$rootScope.selectedDrawingTool = 'select';
10-
9+
$rootScope.selectedDrawingTool = 'select';
1110
}
12-
1311
angular.module('GroupDocsAnnotationApp').controller('PageCanvasController', main);
14-
1512
})();
1613

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
$scope.selectRectangleTool = function ($event) {
77
$rootScope.selectedDrawingTool = 'rectangle';
88
};
9-
9+
$scope.selectArrowTool = function ($event) {
10+
$rootScope.selectedDrawingTool = 'arrow';
11+
};
1012
$scope.selectPencilTool = function ($event) {
1113
$rootScope.selectedDrawingTool = 'pencil';
1214
};
@@ -16,7 +18,7 @@
1618
$scope.selectPointTool = function ($event) {
1719
$rootScope.selectedDrawingTool = 'point';
1820
};
19-
21+
2022
$scope.selectSelectTool();
2123
}
2224

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

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function () {
22
'use strict';
33

4-
function main($rootScope, AnnotationFactory, AnnotationAddFactory) {
4+
function main($rootScope, cfpLoadingBar, AnnotationFactory, AnnotationAddFactory) {
55
return {
66
restrict: 'E',
77
link: {
@@ -11,7 +11,7 @@
1111
setupCanvas($rootScope, scope, element, attrs);
1212
setupPageImage($rootScope, scope, element, attrs);
1313
setupDrawingTools($rootScope, AnnotationFactory, AnnotationAddFactory, scope, element, attrs);
14-
setupAnnotations($rootScope, scope, element, attrs);
14+
// setupAnnotations has been moved to pageImage.onLoad
1515
setupAnnotationDeletion($rootScope, AnnotationFactory, scope, element, attrs);
1616
}
1717
}
@@ -42,12 +42,20 @@
4242
+ "&width=" + attrs.width
4343
+ "&height=" + attrs.height;
4444

45+
var loadingIndicator = new ps.Raster({
46+
source: '/loading_indicator.gif',
47+
position: ps.view.center
48+
});
49+
4550
var pageImage = new ps.Raster({
4651
source: pageImageUrl,
4752
position: ps.view.center
4853
});
54+
4955
pageImage.onLoad = function () {
5056
pageImage.scale(attrs.width / pageImage.width);
57+
setupAnnotations($rootScope, scope, element, attrs);
58+
loadingIndicator.remove();
5159
};
5260
}
5361

@@ -74,15 +82,24 @@
7482
currentObject = hitResult.item;
7583
currentObject.selected = true;
7684
$rootScope.selectedAnnotationGuid = currentObject.name;
77-
$rootScope.$apply();
85+
if (!$rootScope.$$phase) {
86+
$rootScope.$apply();
87+
}
88+
}
89+
else if (hitResult && hitResult.item._parent._name) {
90+
currentObject = hitResult.item._parent;
91+
currentObject.selected = true;
92+
$rootScope.selectedAnnotationGuid = currentObject._name;
93+
if (!$rootScope.$$phase) {
94+
$rootScope.$apply();
95+
}
7896
}
7997
break;
8098
case 'rectangle':
8199
var shape = new ps.Rectangle(event.point.x, event.point.y, 1, 1);
82100
currentObject = new ps.Path.Rectangle(shape);
83101
currentObject.strokeColor = 'black';
84102
currentObject.strokeWidth = 2;
85-
86103
break;
87104
case 'pencil':
88105
currentObject = new ps.Path();
@@ -104,7 +121,7 @@
104121
switch ($rootScope.selectedDrawingTool) {
105122
case 'select':
106123
angular.forEach(scope.annotationsList, function (item) {
107-
if (currentObject && item.annotation.guid === currentObject.name && item.annotation.type === 4) {
124+
if (currentObject && item.annotation.guid === currentObject.name && item.annotation.type === 4 && item.annotation.type === 8) {
108125
currentObject = null;
109126
}
110127
});
@@ -124,6 +141,28 @@
124141
currentObject.position.x += event.delta.x;
125142
currentObject.position.y += event.delta.y;
126143
break;
144+
case 'arrow':
145+
if (currentObject) {
146+
currentObject.remove();
147+
}
148+
var start = new ps.Point(event.downPoint);
149+
var end = new ps.Point(event.point);
150+
151+
var tailLine = new ps.Path.Line(start, end);
152+
var tailVector = end.subtract(start);
153+
var headLine = tailVector.normalize(10);
154+
155+
currentObject = new ps.Group([
156+
new ps.Path([start, end]),
157+
new ps.Path([
158+
end.add(headLine.rotate(150)),
159+
end,
160+
end.add(headLine.rotate(-150))
161+
])
162+
]);
163+
currentObject.strokeColor = 'black';
164+
currentObject.strokeWidth = 2;
165+
break;
127166
}
128167
};
129168

@@ -170,6 +209,11 @@
170209
}
171210
});
172211
break;
212+
case 'arrow':
213+
ant.type = 8;
214+
ant.svgPath = currentObject.exportSVG().firstChild.getAttribute('d');
215+
ant.svgPath += " " + currentObject.exportSVG().lastChild.getAttribute('d');
216+
break;
173217
}
174218

175219
if (ant.type) {
@@ -179,7 +223,9 @@
179223
currentObject.selected = true;
180224
currentObject = null;
181225
$rootScope.selectedAnnotationGuid = response.guid;
182-
$rootScope.$apply();
226+
if (!$rootScope.$$phase) {
227+
$rootScope.$apply();
228+
}
183229
});
184230
} else {
185231
currentObject = null;
@@ -189,9 +235,13 @@
189235
ps.tool.onKeyDown = function (event) {
190236
if (event.key === 'delete') {
191237
angular.forEach(ps.project.selectedItems, function (item) {
192-
if (item.name.length > 0) {
238+
if (item.name) {
193239
$rootScope.$broadcast('request-annotation-deletion', item.name);
194240
}
241+
else if (item._parent._name) {
242+
$rootScope.$broadcast('request-annotation-deletion', item._parent._name);
243+
}
244+
195245
});
196246
}
197247
}
@@ -226,6 +276,14 @@
226276

227277
break;
228278

279+
case 5:
280+
var line = new ps.Path();
281+
line.pathData = item.annotation.svgPath;
282+
line.strokeColor = 'black';
283+
line.strokeWidth = 2;
284+
line.name = item.annotation.guid;
285+
286+
break;
229287
case 4:
230288
var line = new ps.Path();
231289
line.pathData = item.annotation.svgPath;
@@ -242,6 +300,15 @@
242300
ptp.strokeWidth = 2;
243301
ptp.name = item.annotation.guid;
244302
break;
303+
case 8:
304+
var arrow = new ps.Group([
305+
new ps.Path(item.annotation.svgPath.split(" ")[0]),
306+
new ps.Path(item.annotation.svgPath.split(" ")[1])
307+
]);
308+
arrow.strokeColor = 'black';
309+
arrow.strokeWidth = 2;
310+
arrow.name = item.annotation.guid;
311+
break;
245312
}
246313
})
247314
}
@@ -263,14 +330,16 @@
263330
item.remove();
264331
ps.project.deselectAll();
265332
$rootScope.selectedAnnotationGuid = null;
266-
$rootScope.$apply();
333+
if (!$rootScope.$$phase) {
334+
$rootScope.$apply();
335+
}
267336
});
268337
}
269338

270339
});
271340
}
272341

273-
angular.module('GroupDocsAnnotationApp').directive('gdxAnnoPage', main);
342+
angular.module('GroupDocsAnnotationApp').directive('gdxAnnoPage', main, ['cfpLoadingBar']);
274343

275344
})();
276345

0 commit comments

Comments
 (0)