Skip to content

Commit f276fc9

Browse files
authored
2984 upload coordinates editor for annotations (#2988)
* Wip annotations coord editor * wip coord editor * wip coord editor * wip * wip * wip * wip * Wip 04-06-2018 * wip coord form * wip tests * wip adding tests * added an epic test * Add some epics test for annotations * fix a problem with polygons and empty coord while dragging * Fixed edit problem * other fixes * move default text annotation in proper location and other fixes
1 parent 5d2212e commit f276fc9

48 files changed

Lines changed: 4765 additions & 1628 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
"react-copy-to-clipboard": "5.0.0",
144144
"react-data-grid": "2.0.59",
145145
"react-data-grid-addons": "3.0.11",
146-
"react-dnd": "2.4.0",
147-
"react-dnd-html5-backend": "2.4.1",
146+
"react-dnd": "2.6.0",
147+
"react-dnd-html5-backend": "2.6.0",
148148
"react-dock": "0.2.4",
149149
"react-dom": "15.6.2",
150150
"react-draggable": "2.2.6",

web/client/actions/__tests__/annotations-test.js

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ const {
3232
HIGHLIGHT,
3333
CLEAN_HIGHLIGHT,
3434
FILTER_ANNOTATIONS,
35-
showTextArea, SHOW_TEXT_AREA,
3635
addText, ADD_TEXT,
37-
cancelText, CANCEL_CLOSE_TEXT,
3836
changedProperties, CHANGED_PROPERTIES,
3937
changeStyler, CHANGE_STYLER,
40-
saveText, SAVE_TEXT,
4138
toggleUnsavedStyleModal, TOGGLE_STYLE_MODAL,
42-
stopDrawing, STOP_DRAWING,
39+
startDrawing, START_DRAWING,
4340
toggleUnsavedChangesModal, TOGGLE_CHANGES_MODAL,
4441
setUnsavedStyle, UNSAVED_STYLE,
4542
setUnsavedChanges, UNSAVED_CHANGES,
@@ -66,6 +63,13 @@ const {
6663
confirmCloseAnnotations,
6764
cancelCloseAnnotations,
6865
DOWNLOAD, download,
66+
CHANGED_SELECTED, changeSelected,
67+
SET_INVALID_SELECTED, setInvalidSelected,
68+
TOGGLE_GEOMETRY_MODAL, toggleUnsavedGeometryModal,
69+
resetCoordEditor, RESET_COORD_EDITOR,
70+
changeRadius, CHANGE_RADIUS,
71+
changeText, CHANGE_TEXT,
72+
ADD_NEW_FEATURE, addNewFeature,
6973
LOAD_ANNOTATIONS, loadAnnotations
7074
} = require('../annotations');
7175

@@ -103,18 +107,32 @@ describe('Test correctness of the annotations actions', () => {
103107
expect(result.type).toEqual(REMOVE_ANNOTATION);
104108
expect(result.id).toEqual('1');
105109
});
106-
it('showTextArea', () => {
107-
const result = showTextArea();
108-
expect(result.type).toEqual(SHOW_TEXT_AREA);
110+
it('addNewFeature', () => {
111+
const result = addNewFeature();
112+
expect(result.type).toEqual(ADD_NEW_FEATURE);
113+
});
114+
it('changeSelected', () => {
115+
const coordinates = [1, 2];
116+
const radius = 0;
117+
const text = "text";
118+
const result = changeSelected(coordinates, radius, text);
119+
expect(result.type).toEqual(CHANGED_SELECTED);
120+
expect(result.coordinates).toEqual(coordinates);
121+
expect(result.radius).toEqual(radius);
122+
expect(result.text).toEqual(text);
123+
});
124+
it('setInvalidSelected', () => {
125+
const errorFrom = "text";
126+
const coordinates = [1, 2];
127+
const result = setInvalidSelected(errorFrom, coordinates);
128+
expect(result.type).toEqual(SET_INVALID_SELECTED);
129+
expect(result.errorFrom).toEqual(errorFrom);
130+
expect(result.coordinates).toEqual(coordinates);
109131
});
110132
it('addText', () => {
111133
const result = addText();
112134
expect(result.type).toEqual(ADD_TEXT);
113135
});
114-
it('cancelText', () => {
115-
const result = cancelText();
116-
expect(result.type).toEqual(CANCEL_CLOSE_TEXT);
117-
});
118136
it('confirm remove annotation', () => {
119137
const result = confirmRemoveAnnotation('1');
120138
expect(result.type).toEqual(CONFIRM_REMOVE_ANNOTATION);
@@ -146,9 +164,9 @@ describe('Test correctness of the annotations actions', () => {
146164
const result = cancelEditAnnotation();
147165
expect(result.type).toEqual(CANCEL_EDIT_ANNOTATION);
148166
});
149-
it('stopDrawing', () => {
150-
const result = stopDrawing();
151-
expect(result.type).toEqual(STOP_DRAWING);
167+
it('startDrawing', () => {
168+
const result = startDrawing();
169+
expect(result.type).toEqual(START_DRAWING);
152170
});
153171
it('toggleUnsavedChangesModal', () => {
154172
const result = toggleUnsavedChangesModal();
@@ -158,12 +176,6 @@ describe('Test correctness of the annotations actions', () => {
158176
const result = toggleUnsavedStyleModal();
159177
expect(result.type).toEqual(TOGGLE_STYLE_MODAL);
160178
});
161-
it('saveText', () => {
162-
const text = "asdfasf!";
163-
const result = saveText(text);
164-
expect(result.type).toEqual(SAVE_TEXT);
165-
expect(result.value).toEqual(text);
166-
});
167179
it('changeStyler', () => {
168180
const stylerType = "marker";
169181
const result = changeStyler(stylerType);
@@ -265,6 +277,32 @@ describe('Test correctness of the annotations actions', () => {
265277
expect(result.type).toEqual(CONFIRM_CLOSE_ANNOTATIONS);
266278
});
267279

280+
it('changeRadius', () => {
281+
const radius = "";
282+
const components = "";
283+
const result = changeRadius(radius, components);
284+
expect(result.components).toEqual(components);
285+
expect(result.radius).toEqual(radius);
286+
expect(result.type).toEqual(CHANGE_RADIUS);
287+
});
288+
it('changeText', () => {
289+
const text = "";
290+
const components = "";
291+
const result = changeText(text, components);
292+
expect(result.type).toEqual(CHANGE_TEXT);
293+
expect(result.text).toEqual(text);
294+
expect(result.components).toEqual(components);
295+
});
296+
297+
it('toggleUnsavedGeometryModal', () => {
298+
const result = toggleUnsavedGeometryModal();
299+
expect(result.type).toEqual(TOGGLE_GEOMETRY_MODAL);
300+
});
301+
it('resetCoordEditor', () => {
302+
const result = resetCoordEditor();
303+
expect(result.type).toEqual(RESET_COORD_EDITOR);
304+
});
305+
268306
it('cancel close annotations', () => {
269307
const result = cancelCloseAnnotations();
270308
expect(result.type).toEqual(CANCEL_CLOSE_ANNOTATIONS);

web/client/actions/annotations.js

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,30 @@ const TOGGLE_STYLE = 'ANNOTATIONS:TOGGLE_STYLE';
2121
const SET_STYLE = 'ANNOTATIONS:SET_STYLE';
2222
const RESTORE_STYLE = 'ANNOTATIONS:RESTORE_STYLE';
2323
const UPDATE_ANNOTATION_GEOMETRY = 'ANNOTATIONS:UPDATE_GEOMETRY';
24+
const SET_INVALID_SELECTED = 'ANNOTATIONS:SET_INVALID_SELECTED';
2425
const VALIDATION_ERROR = 'ANNOTATIONS:VALIDATION_ERROR';
2526
const HIGHLIGHT = 'ANNOTATIONS:HIGHLIGHT';
2627
const CLEAN_HIGHLIGHT = 'ANNOTATIONS:CLEAN_HIGHLIGHT';
2728
const FILTER_ANNOTATIONS = 'ANNOTATIONS:FILTER';
2829
const CLOSE_ANNOTATIONS = 'ANNOTATIONS:CLOSE';
2930
const CONFIRM_CLOSE_ANNOTATIONS = 'ANNOTATIONS:CONFIRM_CLOSE';
3031
const CANCEL_CLOSE_ANNOTATIONS = 'ANNOTATIONS:CANCEL_CLOSE';
31-
const STOP_DRAWING = 'ANNOTATIONS:STOP_DRAWING';
32+
const START_DRAWING = 'ANNOTATIONS:START_DRAWING';
3233
const CHANGE_STYLER = 'ANNOTATIONS:CHANGE_STYLER';
3334
const UNSAVED_CHANGES = 'ANNOTATIONS:UNSAVED_CHANGES';
3435
const TOGGLE_CHANGES_MODAL = 'ANNOTATIONS:TOGGLE_CHANGES_MODAL';
36+
const TOGGLE_GEOMETRY_MODAL = 'ANNOTATIONS:TOGGLE_GEOMETRY_MODAL';
3537
const CHANGED_PROPERTIES = 'ANNOTATIONS:CHANGED_PROPERTIES';
3638
const UNSAVED_STYLE = 'ANNOTATIONS:UNSAVED_STYLE';
3739
const TOGGLE_STYLE_MODAL = 'ANNOTATIONS:TOGGLE_STYLE_MODAL';
38-
const SHOW_TEXT_AREA = 'ANNOTATIONS:SHOW_TEXT_AREA';
3940
const ADD_TEXT = 'ANNOTATIONS:ADD_TEXT';
40-
const CANCEL_CLOSE_TEXT = 'ANNOTATIONS:CANCEL_CLOSE_TEXT';
41-
const SAVE_TEXT = 'ANNOTATIONS:SAVE_TEXT';
4241
const DOWNLOAD = 'ANNOTATIONS:DOWNLOAD';
4342
const LOAD_ANNOTATIONS = 'ANNOTATIONS:LOAD_ANNOTATIONS';
43+
const CHANGED_SELECTED = 'ANNOTATIONS:CHANGED_SELECTED';
44+
const RESET_COORD_EDITOR = 'ANNOTATIONS:RESET_COORD_EDITOR';
45+
const CHANGE_RADIUS = 'ANNOTATIONS:CHANGE_RADIUS';
46+
const CHANGE_TEXT = 'ANNOTATIONS:CHANGE_TEXT';
47+
const ADD_NEW_FEATURE = 'ANNOTATIONS:ADD_NEW_FEATURE';
4448

4549
function loadAnnotations(features, override = false) {
4650
return {
@@ -62,31 +66,44 @@ const {head} = require('lodash');
6266
function editAnnotation(id) {
6367
return (dispatch, getState) => {
6468
const feature = head(head(getState().layers.flat.filter(l => l.id === 'annotations')).features.filter(f => f.properties.id === id));
65-
dispatch({
66-
type: EDIT_ANNOTATION,
67-
feature,
68-
featureType: feature.geometry.type
69-
});
69+
if (feature.type === "FeatureCollection") {
70+
dispatch({
71+
type: EDIT_ANNOTATION,
72+
feature,
73+
featureType: feature.type
74+
});
75+
} else {
76+
dispatch({
77+
type: EDIT_ANNOTATION,
78+
feature,
79+
featureType: feature.geometry.type
80+
});
81+
}
7082
};
7183
}
7284
function newAnnotation() {
7385
return {
7486
type: NEW_ANNOTATION
7587
};
7688
}
77-
function showTextArea() {
89+
function changeSelected(coordinates, radius, text) {
7890
return {
79-
type: SHOW_TEXT_AREA
91+
type: CHANGED_SELECTED,
92+
coordinates,
93+
radius,
94+
text
8095
};
8196
}
82-
function addText() {
97+
function setInvalidSelected(errorFrom, coordinates) {
8398
return {
84-
type: ADD_TEXT
99+
type: SET_INVALID_SELECTED,
100+
errorFrom,
101+
coordinates
85102
};
86103
}
87-
function cancelText() {
104+
function addText() {
88105
return {
89-
type: CANCEL_CLOSE_TEXT
106+
type: ADD_TEXT
90107
};
91108
}
92109
function changedProperties(field, value) {
@@ -220,30 +237,46 @@ function setUnsavedStyle(unsavedStyle) {
220237
unsavedStyle
221238
};
222239
}
240+
function addNewFeature() {
241+
return {
242+
type: ADD_NEW_FEATURE
243+
};
244+
}
223245
function cancelCloseAnnotations() {
224246
return {
225247
type: CANCEL_CLOSE_ANNOTATIONS
226248
};
227249
}
228-
function stopDrawing() {
250+
function startDrawing() {
229251
return {
230-
type: STOP_DRAWING
252+
type: START_DRAWING
231253
};
232254
}
233255
function toggleUnsavedChangesModal() {
234256
return {
235257
type: TOGGLE_CHANGES_MODAL
236258
};
237259
}
260+
function toggleUnsavedGeometryModal() {
261+
return {
262+
type: TOGGLE_GEOMETRY_MODAL
263+
};
264+
}
238265
function toggleUnsavedStyleModal() {
239266
return {
240267
type: TOGGLE_STYLE_MODAL
241268
};
242269
}
243-
function saveText(value) {
270+
function resetCoordEditor() {
244271
return {
245-
type: SAVE_TEXT,
246-
value
272+
type: RESET_COORD_EDITOR
273+
};
274+
}
275+
function changeRadius(radius, components) {
276+
return {
277+
type: CHANGE_RADIUS,
278+
radius,
279+
components
247280
};
248281
}
249282
function changeStyler(stylerType) {
@@ -252,6 +285,13 @@ function changeStyler(stylerType) {
252285
stylerType
253286
};
254287
}
288+
function changeText(text, components) {
289+
return {
290+
type: CHANGE_TEXT,
291+
text,
292+
components
293+
};
294+
}
255295
module.exports = {
256296
SHOW_ANNOTATION,
257297
EDIT_ANNOTATION,
@@ -275,17 +315,14 @@ module.exports = {
275315
CLOSE_ANNOTATIONS,
276316
CONFIRM_CLOSE_ANNOTATIONS,
277317
CANCEL_CLOSE_ANNOTATIONS,
278-
STOP_DRAWING, stopDrawing,
318+
START_DRAWING, startDrawing,
279319
CHANGE_STYLER, changeStyler,
280320
UNSAVED_CHANGES, setUnsavedChanges,
281321
UNSAVED_STYLE, setUnsavedStyle,
282322
TOGGLE_CHANGES_MODAL, toggleUnsavedChangesModal,
283323
TOGGLE_STYLE_MODAL, toggleUnsavedStyleModal,
284324
CHANGED_PROPERTIES, changedProperties,
285-
SHOW_TEXT_AREA, showTextArea,
286325
ADD_TEXT, addText,
287-
CANCEL_CLOSE_TEXT, cancelText,
288-
SAVE_TEXT, saveText,
289326
editAnnotation,
290327
newAnnotation,
291328
removeAnnotation,
@@ -309,5 +346,12 @@ module.exports = {
309346
confirmCloseAnnotations,
310347
cancelCloseAnnotations,
311348
DOWNLOAD, download,
312-
LOAD_ANNOTATIONS, loadAnnotations
349+
ADD_NEW_FEATURE, addNewFeature,
350+
LOAD_ANNOTATIONS, loadAnnotations,
351+
RESET_COORD_EDITOR, resetCoordEditor,
352+
CHANGE_TEXT, changeText,
353+
CHANGE_RADIUS, changeRadius,
354+
TOGGLE_GEOMETRY_MODAL, toggleUnsavedGeometryModal,
355+
SET_INVALID_SELECTED, setInvalidSelected,
356+
CHANGED_SELECTED, changeSelected
313357
};

web/client/actions/draw.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const END_DRAWING = 'DRAW:END_DRAWING';
1111
const SET_CURRENT_STYLE = 'DRAW:SET_CURRENT_STYLE';
1212
const GEOMETRY_CHANGED = 'DRAW:GEOMETRY_CHANGED';
1313
const DRAW_SUPPORT_STOPPED = 'DRAW:DRAW_SUPPORT_STOPPED';
14+
const FEATURES_SELECTED = 'DRAW:FEATURES_SELECTED';
15+
const DRAWING_FEATURE = 'DRAW:DRAWING_FEATURES';
1416

1517
function geometryChanged(features, owner, enableEdit, textChanged, circleChanged) {
1618
return {
@@ -22,6 +24,21 @@ function geometryChanged(features, owner, enableEdit, textChanged, circleChanged
2224
circleChanged
2325
};
2426
}
27+
/** used to manage the selected features
28+
* @param {object[]} features geojson
29+
*/
30+
function selectFeatures(features = []) {
31+
return {
32+
type: FEATURES_SELECTED,
33+
features
34+
};
35+
}
36+
function drawingFeatures(features = []) {
37+
return {
38+
type: DRAWING_FEATURE,
39+
features
40+
};
41+
}
2542
function drawStopped() {
2643
return {
2744
type: DRAW_SUPPORT_STOPPED
@@ -62,6 +79,8 @@ module.exports = {
6279
CHANGE_DRAWING_STATUS, changeDrawingStatus, drawSupportReset,
6380
END_DRAWING, endDrawing,
6481
SET_CURRENT_STYLE, setCurrentStyle,
82+
FEATURES_SELECTED, selectFeatures,
83+
DRAWING_FEATURE, drawingFeatures,
6584
DRAW_SUPPORT_STOPPED, drawStopped,
6685
GEOMETRY_CHANGED, geometryChanged
6786
};

0 commit comments

Comments
 (0)