From 46ebce2d6f91fb3159fd219343f1e3aa75ae1094 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 3 Jan 2019 11:37:14 -0500 Subject: [PATCH] Fix error reporting urls and make sure sidebar not showing stale data --- modules/services/keepRight.js | 6 ++++++ modules/services/osm.js | 5 +++-- modules/svg/keepRight.js | 15 --------------- modules/ui/inspector.js | 12 ++++++------ modules/ui/keepRight_details.js | 6 +++--- modules/ui/keepRight_editor.js | 10 +++++++--- modules/ui/keepRight_header.js | 8 +++----- modules/ui/note_comments.js | 4 ++-- modules/ui/note_editor.js | 4 ++-- modules/ui/note_header.js | 4 ++-- modules/ui/note_report.js | 23 ++++++++++------------- modules/ui/sidebar.js | 29 +++++++++++++++++++---------- modules/ui/view_on_keepRight.js | 16 ++++++++-------- modules/ui/view_on_osm.js | 5 +---- 14 files changed, 72 insertions(+), 75 deletions(-) diff --git a/modules/services/keepRight.js b/modules/services/keepRight.js index 15e1efb16..9bae8840e 100644 --- a/modules/services/keepRight.js +++ b/modules/services/keepRight.js @@ -396,5 +396,11 @@ export default { delete _krCache.keepRight[error.id]; updateRtree(encodeErrorRtree(error), false); // false = remove + }, + + + errorURL: function(error) { + return apibase + 'report_map.php?schema=' + error.schema + '&error=' + error.id; } + }; diff --git a/modules/services/osm.js b/modules/services/osm.js index de3a91f4d..d3e52cda5 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -431,8 +431,9 @@ export default { return urlroot + '/note/' + note.id; }, - keepRightURL: function(error) { - return 'https://www.keepright.at/report_map.php?schema=' + error.schema + '&error=' + error.id; + + noteReportURL: function(note) { + return urlroot + '/reports/new?reportable_type=Note&reportable_id=' + note.id; }, diff --git a/modules/svg/keepRight.js b/modules/svg/keepRight.js index 17b8b2395..0ef3c6146 100644 --- a/modules/svg/keepRight.js +++ b/modules/svg/keepRight.js @@ -24,7 +24,6 @@ export function svgKeepRight(projection, context, dispatch) { if (svgKeepRight.initialized) return; // run once svgKeepRight.enabled = false; svgKeepRight.initialized = true; - svgKeepRight.visibleErrors = [30]; } @@ -184,20 +183,6 @@ export function svgKeepRight(projection, context, dispatch) { }; - drawKeepRight.visibleErrors = function(_) { - if (!arguments.length) return svgKeepRight.visibleErrors; - svgKeepRight.visibleErrors.push(_); - if (svgKeepRight.visibleErrors) { - showLayer(); - } else { - hideLayer(); - } - dispatch.call('change'); - return this; - }; - - - init(); return drawKeepRight; } diff --git a/modules/ui/inspector.js b/modules/ui/inspector.js index f4785ddc3..7e634b602 100644 --- a/modules/ui/inspector.js +++ b/modules/ui/inspector.js @@ -92,9 +92,9 @@ export function uiInspector(context) { } - inspector.state = function(_) { + inspector.state = function(val) { if (!arguments.length) return _state; - _state = _; + _state = val; entityEditor.state(_state); // remove any old field help overlay that might have gotten attached to the inspector @@ -104,16 +104,16 @@ export function uiInspector(context) { }; - inspector.entityID = function(_) { + inspector.entityID = function(val) { if (!arguments.length) return _entityID; - _entityID = _; + _entityID = val; return inspector; }; - inspector.newFeature = function(_) { + inspector.newFeature = function(val) { if (!arguments.length) return _newFeature; - _newFeature = _; + _newFeature = val; return inspector; }; diff --git a/modules/ui/keepRight_details.js b/modules/ui/keepRight_details.js index 1c0602b51..01702365d 100644 --- a/modules/ui/keepRight_details.js +++ b/modules/ui/keepRight_details.js @@ -32,7 +32,7 @@ export function uiKeepRightDetails(context) { var details = selection.selectAll('.kr_error-details') .data( (_error ? [_error] : []), - function(d) { return d.status + d.id; } + function(d) { return d.id + '-' + (d.status || 0); } ); details.exit() @@ -69,9 +69,9 @@ export function uiKeepRightDetails(context) { } - keepRightDetails.error = function(_) { + keepRightDetails.error = function(val) { if (!arguments.length) return _error; - _error = _; + _error = val; return keepRightDetails; }; diff --git a/modules/ui/keepRight_editor.js b/modules/ui/keepRight_editor.js index 01f120226..532c8c3e2 100644 --- a/modules/ui/keepRight_editor.js +++ b/modules/ui/keepRight_editor.js @@ -71,8 +71,12 @@ export function uiKeepRightEditor(context) { function keepRightSaveSection(selection) { var isSelected = (_error && _error.id === context.selectedErrorID()); + var isShown = (_error && (isSelected || _error.newComment || _error.comment)); var saveSection = selection.selectAll('.error-save') - .data((isSelected ? [_error] : []), function(d) { return d.status + d.id; }); + .data( + (isShown ? [_error] : []), + function(d) { return d.id + '-' + (d.status || 0); } + ); // exit saveSection.exit() @@ -206,9 +210,9 @@ export function uiKeepRightEditor(context) { } - keepRightEditor.error = function(_) { + keepRightEditor.error = function(val) { if (!arguments.length) return _error; - _error = _; + _error = val; return keepRightEditor; }; diff --git a/modules/ui/keepRight_header.js b/modules/ui/keepRight_header.js index 2e14992ef..e2a63e2f4 100644 --- a/modules/ui/keepRight_header.js +++ b/modules/ui/keepRight_header.js @@ -31,14 +31,12 @@ export function uiKeepRightHeader() { var header = selection.selectAll('.kr_error-header') .data( (_error ? [_error] : []), - function(d) { return d.status + d.id; } + function(d) { return d.id + '-' + (d.status || 0); } ); header.exit() .remove(); - - var headerEnter = header.enter() .append('div') .attr('class', 'kr_error-header'); @@ -62,9 +60,9 @@ export function uiKeepRightHeader() { } - keepRightHeader.error = function(_) { + keepRightHeader.error = function(val) { if (!arguments.length) return _error; - _error = _; + _error = val; return keepRightHeader; }; diff --git a/modules/ui/note_comments.js b/modules/ui/note_comments.js index 4534ea10b..cbb004095 100644 --- a/modules/ui/note_comments.js +++ b/modules/ui/note_comments.js @@ -110,9 +110,9 @@ export function uiNoteComments() { } - noteComments.note = function(_) { + noteComments.note = function(val) { if (!arguments.length) return _note; - _note = _; + _note = val; return noteComments; }; diff --git a/modules/ui/note_editor.js b/modules/ui/note_editor.js index 9df0a8f69..5de11ff5d 100644 --- a/modules/ui/note_editor.js +++ b/modules/ui/note_editor.js @@ -425,9 +425,9 @@ export function uiNoteEditor(context) { } - noteEditor.note = function(_) { + noteEditor.note = function(val) { if (!arguments.length) return _note; - _note = _; + _note = val; return noteEditor; }; diff --git a/modules/ui/note_header.js b/modules/ui/note_header.js index 8fc2a0e95..c19338c49 100644 --- a/modules/ui/note_header.js +++ b/modules/ui/note_header.js @@ -49,9 +49,9 @@ export function uiNoteHeader() { } - noteHeader.note = function(_) { + noteHeader.note = function(val) { if (!arguments.length) return _note; - _note = _; + _note = val; return noteHeader; }; diff --git a/modules/ui/note_report.js b/modules/ui/note_report.js index 759f9ba13..09b78a4e4 100644 --- a/modules/ui/note_report.js +++ b/modules/ui/note_report.js @@ -1,23 +1,20 @@ import { t } from '../util/locale'; +import { osmNote } from '../osm'; +import { services } from '../services'; import { svgIcon } from '../svg'; -import { - osmNote -} from '../osm'; export function uiNoteReport() { var _note; - var url = 'https://www.openstreetmap.org/reports/new?reportable_id='; function noteReport(selection) { + var url; + if (services.osm && (_note instanceof osmNote) && (!_note.isNew())) { + url = services.osm.noteReportURL(_note); + } - if (!(_note instanceof osmNote)) return; - - url += _note.id + '&reportable_type=Note'; - - var data = ((!_note || _note.isNew()) ? [] : [_note]); var link = selection.selectAll('.note-report') - .data(data, function(d) { return d.id; }); + .data(url ? [url] : []); // exit link.exit() @@ -28,7 +25,7 @@ export function uiNoteReport() { .append('a') .attr('class', 'note-report') .attr('target', '_blank') - .attr('href', url) + .attr('href', function(d) { return d; }) .call(svgIcon('#iD-icon-out-link', 'inline')); linkEnter @@ -37,9 +34,9 @@ export function uiNoteReport() { } - noteReport.note = function(_) { + noteReport.note = function(val) { if (!arguments.length) return _note; - _note = _; + _note = val; return noteReport; }; diff --git a/modules/ui/sidebar.js b/modules/ui/sidebar.js index 576ea072c..f9a669f5e 100644 --- a/modules/ui/sidebar.js +++ b/modules/ui/sidebar.js @@ -10,6 +10,7 @@ import { } from 'd3-selection'; import { osmEntity, osmNote, krError } from '../osm'; +import { services } from '../services'; import { uiDataEditor, uiFeatureList, uiInspector, uiNoteEditor, uiKeepRightEditor } from './index'; import { textDirection } from '../util/locale'; @@ -22,7 +23,7 @@ export function uiSidebar(context) { var _current; var _wasData = false; var _wasNote = false; - var _was_krError = false; + var _wasKRError = false; function sidebar(selection) { @@ -119,6 +120,11 @@ export function uiSidebar(context) { if (context.mode().id === 'drag-note') return; _wasNote = true; + var osm = services.osm; + if (osm) { + datum = osm.getNote(datum.id); // marker may contain stale data - get latest + } + sidebar .show(noteEditor.note(datum)); @@ -126,10 +132,15 @@ export function uiSidebar(context) { .classed('inspector-hover', true); } else if (datum instanceof krError) { - _was_krError = true; - var kr_errors = d3_selectAll('.kr_error'); - kr_errors - .classed('hover', function(d) { return d === datum; }); + _wasKRError = true; + + var keepRight = services.keepRight; + if (keepRight) { + datum = keepRight.getError(datum.id); // marker may contain stale data - get latest + } + + d3_selectAll('.kr_error') + .classed('hover', function(d) { return d.id === datum.id; }); sidebar .show(keepRightEditor.error(datum)); @@ -162,14 +173,12 @@ export function uiSidebar(context) { inspector .state('hide'); - } else if (_wasData || _wasNote) { + } else if (_wasData || _wasNote || _wasKRError) { _wasNote = false; _wasData = false; + _wasKRError = false; d3_selectAll('.note').classed('hover', false); - sidebar.hide(); - } else if (_was_krError) { - d3_selectAll('.kr_error') - .classed('hover', false); + d3_selectAll('.kr_error').classed('hover', false); sidebar.hide(); } } diff --git a/modules/ui/view_on_keepRight.js b/modules/ui/view_on_keepRight.js index 0574a3e57..d0b28a4cb 100644 --- a/modules/ui/view_on_keepRight.js +++ b/modules/ui/view_on_keepRight.js @@ -1,21 +1,21 @@ import { t } from '../util/locale'; +import { services } from '../services'; import { svgIcon } from '../svg'; import { krError } from '../osm'; -export function uiViewOnKeepRight(context) { +export function uiViewOnKeepRight() { var _error; // a keepright error function viewOnKeepRight(selection) { var url; - if (_error instanceof krError) { - url = context.connection().keepRightURL(_error); + if (services.keepRight && (_error instanceof krError)) { + url = services.keepRight.errorURL(_error); } - var data = ((!_error) ? [] : [_error]); var link = selection.selectAll('.view-on-keepRight') - .data(data, function(d) { return d.id; }); + .data(url ? [url] : []); // exit link.exit() @@ -26,7 +26,7 @@ export function uiViewOnKeepRight(context) { .append('a') .attr('class', 'view-on-keepRight') .attr('target', '_blank') - .attr('href', url) + .attr('href', function(d) { return d; }) .call(svgIcon('#iD-icon-out-link', 'inline')); linkEnter @@ -35,9 +35,9 @@ export function uiViewOnKeepRight(context) { } - viewOnKeepRight.what = function(_) { + viewOnKeepRight.what = function(val) { if (!arguments.length) return _error; - _error = _; + _error = val; return viewOnKeepRight; }; diff --git a/modules/ui/view_on_osm.js b/modules/ui/view_on_osm.js index b013f158b..7bf265275 100644 --- a/modules/ui/view_on_osm.js +++ b/modules/ui/view_on_osm.js @@ -1,9 +1,6 @@ import { t } from '../util/locale'; +import { osmEntity, osmNote } from '../osm'; import { svgIcon } from '../svg'; -import { - osmEntity, - osmNote -} from '../osm'; export function uiViewOnOSM(context) {