|
1 | 1 | (function () { |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | - function main($rootScope, AnnotationFactory, AnnotationAddFactory) { |
| 4 | + function main($rootScope, cfpLoadingBar, AnnotationFactory, AnnotationAddFactory) { |
5 | 5 | return { |
6 | 6 | restrict: 'E', |
7 | 7 | link: { |
|
11 | 11 | setupCanvas($rootScope, scope, element, attrs); |
12 | 12 | setupPageImage($rootScope, scope, element, attrs); |
13 | 13 | setupDrawingTools($rootScope, AnnotationFactory, AnnotationAddFactory, scope, element, attrs); |
14 | | - setupAnnotations($rootScope, scope, element, attrs); |
| 14 | + // setupAnnotations has been moved to pageImage.onLoad |
15 | 15 | setupAnnotationDeletion($rootScope, AnnotationFactory, scope, element, attrs); |
16 | 16 | } |
17 | 17 | } |
|
42 | 42 | + "&width=" + attrs.width |
43 | 43 | + "&height=" + attrs.height; |
44 | 44 |
|
| 45 | + var loadingIndicator = new ps.Raster({ |
| 46 | + source: '/loading_indicator.gif', |
| 47 | + position: ps.view.center |
| 48 | + }); |
| 49 | + |
45 | 50 | var pageImage = new ps.Raster({ |
46 | 51 | source: pageImageUrl, |
47 | 52 | position: ps.view.center |
48 | 53 | }); |
| 54 | + |
49 | 55 | pageImage.onLoad = function () { |
50 | 56 | pageImage.scale(attrs.width / pageImage.width); |
| 57 | + setupAnnotations($rootScope, scope, element, attrs); |
| 58 | + loadingIndicator.remove(); |
51 | 59 | }; |
52 | 60 | } |
53 | 61 |
|
|
74 | 82 | currentObject = hitResult.item; |
75 | 83 | currentObject.selected = true; |
76 | 84 | $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 | + } |
78 | 96 | } |
79 | 97 | break; |
80 | 98 | case 'rectangle': |
81 | 99 | var shape = new ps.Rectangle(event.point.x, event.point.y, 1, 1); |
82 | 100 | currentObject = new ps.Path.Rectangle(shape); |
83 | 101 | currentObject.strokeColor = 'black'; |
84 | 102 | currentObject.strokeWidth = 2; |
85 | | - |
86 | 103 | break; |
87 | 104 | case 'pencil': |
88 | 105 | currentObject = new ps.Path(); |
|
104 | 121 | switch ($rootScope.selectedDrawingTool) { |
105 | 122 | case 'select': |
106 | 123 | 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) { |
108 | 125 | currentObject = null; |
109 | 126 | } |
110 | 127 | }); |
|
124 | 141 | currentObject.position.x += event.delta.x; |
125 | 142 | currentObject.position.y += event.delta.y; |
126 | 143 | 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; |
127 | 166 | } |
128 | 167 | }; |
129 | 168 |
|
|
170 | 209 | } |
171 | 210 | }); |
172 | 211 | 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; |
173 | 217 | } |
174 | 218 |
|
175 | 219 | if (ant.type) { |
|
179 | 223 | currentObject.selected = true; |
180 | 224 | currentObject = null; |
181 | 225 | $rootScope.selectedAnnotationGuid = response.guid; |
182 | | - $rootScope.$apply(); |
| 226 | + if (!$rootScope.$$phase) { |
| 227 | + $rootScope.$apply(); |
| 228 | + } |
183 | 229 | }); |
184 | 230 | } else { |
185 | 231 | currentObject = null; |
|
189 | 235 | ps.tool.onKeyDown = function (event) { |
190 | 236 | if (event.key === 'delete') { |
191 | 237 | angular.forEach(ps.project.selectedItems, function (item) { |
192 | | - if (item.name.length > 0) { |
| 238 | + if (item.name) { |
193 | 239 | $rootScope.$broadcast('request-annotation-deletion', item.name); |
194 | 240 | } |
| 241 | + else if (item._parent._name) { |
| 242 | + $rootScope.$broadcast('request-annotation-deletion', item._parent._name); |
| 243 | + } |
| 244 | + |
195 | 245 | }); |
196 | 246 | } |
197 | 247 | } |
|
226 | 276 |
|
227 | 277 | break; |
228 | 278 |
|
| 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; |
229 | 287 | case 4: |
230 | 288 | var line = new ps.Path(); |
231 | 289 | line.pathData = item.annotation.svgPath; |
|
242 | 300 | ptp.strokeWidth = 2; |
243 | 301 | ptp.name = item.annotation.guid; |
244 | 302 | 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; |
245 | 312 | } |
246 | 313 | }) |
247 | 314 | } |
|
263 | 330 | item.remove(); |
264 | 331 | ps.project.deselectAll(); |
265 | 332 | $rootScope.selectedAnnotationGuid = null; |
266 | | - $rootScope.$apply(); |
| 333 | + if (!$rootScope.$$phase) { |
| 334 | + $rootScope.$apply(); |
| 335 | + } |
267 | 336 | }); |
268 | 337 | } |
269 | 338 |
|
270 | 339 | }); |
271 | 340 | } |
272 | 341 |
|
273 | | - angular.module('GroupDocsAnnotationApp').directive('gdxAnnoPage', main); |
| 342 | + angular.module('GroupDocsAnnotationApp').directive('gdxAnnoPage', main, ['cfpLoadingBar']); |
274 | 343 |
|
275 | 344 | })(); |
276 | 345 |
|
0 commit comments