Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ let BrowserCell = ({ type, value, hidden, width, current, onSelect, onEditChange
content = pieces.join(', ');
} else if (type === 'GeoPoint') {
content = `(${value.latitude}, ${value.longitude})`;
} else if (type === 'Polygon') {
content = value.coordinates.map(coord => `(${coord})`)
} else if (type === 'Relation') {
content = (
<div style={{ textAlign: 'center', cursor: 'pointer' }}>
Expand Down
34 changes: 34 additions & 0 deletions src/dashboard/Data/Browser/Editor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,40 @@ let Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit }
width={width}
onCommit={encodeCommit} />
);
} else if (type === 'Polygon') {
let encodeCommit = (json) => {
try {
let coordinates = JSON.parse(json);
if (coordinates.length < 3) {
throw 'Polygon must have at least 3 coordinates';
}
if (value && value.coordinates && value.coordinates.length === coordinates.length) {
let dirty = coordinates.some((coord, index) => {
if (value.coordinates[index][0] !== coord[0] || value.coordinates[index][1] !== coord[1]) {
return true;
}
});
if (!dirty) {
throw 'No change in coordinates';
}
}
let obj = {
'__type': 'Polygon',
coordinates
}
onCommit(obj);
} catch (e) {
onCommit(value);
}
}
content = (
<StringEditor
value={JSON.stringify(value && value.coordinates || [['lat', 'lon']], null, 2)}
resizable={true}
multiline={true}
width={width}
onCommit={encodeCommit} />
);
} else if (type === 'Date') {
if (readonly) {
content = (
Expand Down
1 change: 1 addition & 0 deletions src/lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const DataTypes = [
'Object',
'Array',
'GeoPoint',
'Polygon',
'File',
'Pointer',
'Relation',
Expand Down