Skip to content

Commit 32185c1

Browse files
committed
Add popup to confirm adding an annotation
1 parent dce337e commit 32185c1

5 files changed

Lines changed: 86 additions & 25 deletions

File tree

client/directives/anAnnotatable.directive.js

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ angular.module('annotate').directive('anAnnotatable',
1010
showAnnotations: '='
1111
},
1212
controller: function ($scope, $attrs, $element) {
13+
14+
$scope.addAnnotationPopup = {
15+
show: false,
16+
x: null,
17+
y: null,
18+
}
1319
var canvas = $element.children('.canvas')
1420
var image = $element.children('img')
1521

@@ -51,7 +57,13 @@ angular.module('annotate').directive('anAnnotatable',
5157
image.draggable = false
5258

5359
canvas.on('click', function (event) {
60+
61+
$scope.annotations.forEach(function (annotation) {
62+
annotation.open = false;
63+
})
64+
5465
if (event.target.className.indexOf('canvas') > -1) {
66+
5567
var xPos = event.offsetX
5668
var yPos = event.offsetY
5769

@@ -62,32 +74,52 @@ angular.module('annotate').directive('anAnnotatable',
6274
var yPosPercent = yPos / height * 100
6375

6476
$scope.$apply(function () {
65-
Meteor.call('incrementAnnotations', function (err, next) {
66-
if (err) console.log(err)
67-
Annotations.insert({
68-
image: $scope.image._id,
69-
xPos: xPosPercent,
70-
yPos: yPosPercent,
71-
date: new Date(),
72-
owner: Meteor.userId(),
73-
number: next,
74-
comments: []
75-
}, function (err, annotationId) {
76-
if (err) console.log(err)
77-
78-
$scope.annotations.forEach(function (annotation) {
79-
if (annotation._id === annotationId) {
80-
annotation.open = true
81-
}
82-
})
83-
})
84-
console.log('post-increment', next)
85-
})
77+
$scope.addAnnotationPopup.show = true;
78+
$scope.addAnnotationPopup.x = xPosPercent;
79+
$scope.addAnnotationPopup.y = yPosPercent;
8680
})
81+
//
8782
}
8883
// and then now add more things to the annotation
8984
})
9085

86+
$scope.confirmed = function (obj) {
87+
newAnnotation(obj.x, obj.y)
88+
$scope.closePopup (obj)
89+
}
90+
91+
$scope.closePopup = function (obj) {
92+
obj.x = null
93+
obj.y = null
94+
obj.show = false
95+
}
96+
97+
var newAnnotation = function (xPosPercent, yPosPercent) {
98+
// $scope.$apply(function () {
99+
Meteor.call('incrementAnnotations', function (err, next) {
100+
if (err) console.log(err)
101+
Annotations.insert({
102+
image: $scope.image._id,
103+
xPos: xPosPercent,
104+
yPos: yPosPercent,
105+
date: new Date(),
106+
owner: Meteor.userId(),
107+
number: next,
108+
comments: []
109+
}, function (err, annotationId) {
110+
if (err) console.log(err)
111+
112+
$scope.annotations.forEach(function (annotation) {
113+
if (annotation._id === annotationId) {
114+
annotation.open = true
115+
}
116+
})
117+
})
118+
console.log('post-increment', next)
119+
})
120+
// })
121+
}
122+
91123
$scope.annotationOpened = function (annotationId) {
92124
$scope.annotations.forEach(function (annotation) {
93125
if (annotation._id === annotationId) {

client/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
</div>
5454

5555
<div class="toggle-view row">
56-
<a class="tab"
56+
<a class="pill"
5757
ng-class="{'selected': view === 'single'}"
5858
ng-click="view = 'single'">1 column</a>
59-
<a class="tab"
59+
<a class="pill"
6060
ng-class="{'selected': view === 'double'}"
6161
ng-click="view = 'double'">2 columns</a>
6262
</div>

client/styles/components/image-container.import.less

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,18 @@
4444
}
4545
}
4646
}
47+
48+
.add-annotation {
49+
display: inline-block;
50+
background: white;
51+
padding: 1rem;
52+
position: absolute;
53+
margin-left: -10%;
54+
margin-top: -2%;
55+
box-shadow: 0px 0px 4px @grey;
56+
57+
button {
58+
font-size: .8rem;
59+
margin-left: .5rem;
60+
}
61+
}

client/styles/main.less

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ a {
7474
font-size: 1.2em;
7575
}
7676

77-
.tab {
77+
.pill {
7878
background-color: @link-color;
7979
color: @link-text;
8080
padding: .25rem .5rem;
81-
border-radius: 6px;
81+
border-radius: 4px;
8282
display: inline-block;
8383
cursor: pointer;
84+
border: 1px solid darken(@link-color, 5%);
8485

8586
&:hover {
8687
background-color: darken(@link-color, 10%);

client/templates/anAnnotatable.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,17 @@
99
annotation-opened="annotationOpened(annotationId)"
1010
an-index="$index">
1111
</div>
12+
<div class="add-annotation"
13+
ng-show="addAnnotationPopup.show"
14+
style="top: {{ addAnnotationPopup.y }}%; left: {{ addAnnotationPopup.x }}%">
15+
Add an annotation?
16+
<button class="pill"
17+
ng-click="confirmed(addAnnotationPopup)">
18+
Yes
19+
</button>
20+
<button class="pill"
21+
ng-click="closePopup(addAnnotationPopup)">
22+
No
23+
</button>
24+
</div>
1225
</div>

0 commit comments

Comments
 (0)