Skip to content

Commit

Permalink
MR menu added to uisidebar and selectmode. uiMapRouletteMenu is getti…
Browse files Browse the repository at this point in the history
…ng the right data now
  • Loading branch information
tannerwuster committed Dec 12, 2024
1 parent 943f96a commit 2ced05c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
2 changes: 2 additions & 0 deletions modules/modes/SelectMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { uiDetectionInspector } from '../ui/detection_inspector.js';
import { uiKeepRightEditor } from '../ui/keepRight_editor.js';
import { uiNoteEditor } from '../ui/note_editor.js';
import { uiMapRouletteEditor } from '../ui/maproulette_editor.js';
import { uiMapRouletteMenu } from '../ui/maproulette_menu.js';

const DEBUG = false;

Expand Down Expand Up @@ -157,6 +158,7 @@ export class SelectMode extends AbstractMode {

} else if (datum instanceof QAItem && datum.service === 'maproulette') {
sidebarContent = uiMapRouletteEditor(context).error(datum);
uiMapRouletteMenu(context).error(datum);
sidebarContent
.on('change', () => {
gfx.immediateRedraw(); // force a redraw (there is no history change that would otherwise do this)
Expand Down
4 changes: 4 additions & 0 deletions modules/ui/UiSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UiInspector } from './UiInspector.js';
import { uiDetectionInspector } from './detection_inspector.js';
import { uiKeepRightEditor } from './keepRight_editor.js';
import { uiMapRouletteEditor } from './maproulette_editor.js';
import { uiMapRouletteMenu } from './maproulette_menu.js';
import { uiOsmoseEditor } from './osmose_editor.js';
import { uiNoteEditor } from './note_editor.js';
import { UiRapidInspector } from './UiRapidInspector.js';
Expand Down Expand Up @@ -54,6 +55,7 @@ export class UiSidebar {
this.Inspector = new UiInspector(context);
this.KeepRightEditor = uiKeepRightEditor(context);
this.MapRouletteEditor = uiMapRouletteEditor(context);
this.MapRouletteMenu= uiMapRouletteMenu(context);
this.NoteEditor = uiNoteEditor(context);
this.OsmoseEditor = uiOsmoseEditor(context);
this.RapidInspector = new UiRapidInspector(context);
Expand Down Expand Up @@ -268,6 +270,7 @@ export class UiSidebar {
Component = this.OsmoseEditor;
} else if (service.id === 'maproulette') {
Component = this.MapRouletteEditor;
this.MapRouletteMenu.error(datum);
}
}

Expand Down Expand Up @@ -553,6 +556,7 @@ export class UiSidebar {
this.Inspector.entityIDs([]);
this.KeepRightEditor.error(null);
this.MapRouletteEditor.error(null);
this.MapRouletteMenu.error(null);
this.NoteEditor.note(null);
this.OsmoseEditor.error(null);
this.RapidInspector.datum = null;
Expand Down
54 changes: 25 additions & 29 deletions modules/ui/maproulette_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ export function uiMapRouletteMenu(context) {
return;
}
_mapRouletteApiKey = apiKey;
console.log('MapRoulette API key retrieved:', _mapRouletteApiKey);
d.action(d3_event, d); // Call the action after retrieving the API key
d.action(d3_event, d, _qaItem);
});
} else {
d.action(d3_event, d);
d.action(d3_event, d, _qaItem);
}
mapRouletteMenu.close();
})
Expand All @@ -102,7 +101,7 @@ export function uiMapRouletteMenu(context) {
utilHighlightEntities(d.relatedEntityIds(), false, context);
});

buttonsEnter.append('div')
buttonsEnter.append('div')
.attr('class', 'icon-wrap')
.call(uiIcon('', 'operation'));

Expand Down Expand Up @@ -177,16 +176,19 @@ export function uiMapRouletteMenu(context) {
}
}

function fixedIt(d3_event, d) {
if (_qaItem) {
_qaItem._status = 1;
_actionTaken = 'FIXED';
submitTask(d3_event, _qaItem);
} else {

function fixedIt(d3_event, d, _qaItem) {
if (!_qaItem) {
console.error('No task selected');
return;
}
console.log('Current d in fixedIt:', d); // Debugging log
_qaItem._status = 1; // Update the status of the task
_actionTaken = 'FIXED'; // Set the action taken
submitTask(d3_event, _qaItem); // Submit the task with the updated status
}


function cantComplete(d3_event, d) {
if (_qaItem) {
_qaItem._status = 6;
Expand Down Expand Up @@ -217,38 +219,33 @@ export function uiMapRouletteMenu(context) {
}
}

function submitTask(d3_event, task) {

function submitTask(d3_event, d) {
if (!d) {
console.error('No task to submit');
return;
}
const osm = context.services.osm;
const userID = osm._userDetails.id;
if (maproulette) {
console.log('task', task);
task.taskStatus = task._status;
task.mapRouletteApiKey = _mapRouletteApiKey;
// Check if the element exists and get its value, otherwise use an empty string
const commentInput = d3_select('.new-comment-input');
task.comment = commentInput.empty() ? '' : commentInput.property('value').trim();
// Ensure taskId is correctly set
if (!task.id) {
console.error('Task ID is missing');
return;
}
task.taskId = task.id;
task.userId = userID;
maproulette.postUpdate(task, (err, item) => {
d.taskStatus = d._status;
d.mapRouletteApiKey = _mapRouletteApiKey;
d.comment = d3_select('.new-comment-input').property('value').trim();
d.taskId = d.id;
d.userId = userID;
maproulette.postUpdate(d, (err, item) => {
if (err) {
console.error(err); // eslint-disable-line no-console
return;
}
dispatch.call('change', item);
// Fly to a nearby task if the feature is enabled, after the update
if (maproulette.nearbyTaskEnabled) {
maproulette.flyToNearbyTask(task);
maproulette.flyToNearbyTask(d);
}
});
}
}


function getMapRouletteApiKey(context, callback) {
const osm = context.services.osm;
osm.loadMapRouletteKey((err, preferences) => {
Expand Down Expand Up @@ -285,7 +282,6 @@ export function uiMapRouletteMenu(context) {
mapRouletteMenu.error = function(val) {
if (!arguments.length) return _qaItem;
_qaItem = val;
console.log('Task selected:', _qaItem);
_actionTaken = '';
return mapRouletteMenu;
};
Expand Down

0 comments on commit 2ced05c

Please sign in to comment.