From c3fe1fedd95b94ec34b74a31bfa499e8ea129ce4 Mon Sep 17 00:00:00 2001 From: Thomas Hervey Date: Sat, 21 Jul 2018 21:09:17 -0400 Subject: [PATCH] updated categories, added category to note service --- data/presets.yaml | 22 ++++--- data/presets/fields.json | 2 +- data/presets/fields/category.json | 20 +++--- data/taginfo.json | 104 +++++++++++++++++++++++------- dist/locales/en.json | 10 +-- modules/actions/move_note.js | 1 - modules/services/osm.js | 5 +- modules/ui/note_category.js | 63 ------------------ modules/ui/note_editor.js | 47 ++++++++++++-- 9 files changed, 157 insertions(+), 117 deletions(-) delete mode 100644 modules/ui/note_category.js diff --git a/data/presets.yaml b/data/presets.yaml index e9bd42092..1061a765f 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -305,19 +305,23 @@ en: # castle_type=* label: Type category: - # 'none=*, option1=*, option2=*, option3=*, option4=*' + # 'none=*, updateDetails=*, missing=*, wrongLocation=*, groundtruth=*, doesNotExist=*, discussion=*' label: Category options: + # discussion=yes + discussion: Needs discussing + # doesNotExist=yes + doesNotExist: Does not or never existed + # groundtruth=yes + groundtruth: Ground truth or needs local confirmation + # missing=yes + missing: Something is missing # none=yes none: None - # option1=yes - option1: Option1 - # option2=yes - option2: Option2 - # option3=yes - option3: Option3 - # option4=yes - option4: Option4 + # updateDetails=yes + updateDetails: Update or add details + # wrongLocation=yes + wrongLocation: Wrong location # category field placeholder placeholder: Unknown clothes: diff --git a/data/presets/fields.json b/data/presets/fields.json index 7296ec5fe..e1018de87 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -49,7 +49,7 @@ "capacity": {"key": "capacity", "type": "number", "minValue": 0, "label": "Capacity", "placeholder": "50, 100, 200..."}, "cash_in": {"key": "cash_in", "type": "check", "label": "Cash In"}, "castle_type": {"key": "castle_type", "type": "combo", "label": "Type"}, - "category": {"type": "radio", "keys": ["none", "option1", "option2", "option3", "option4"], "label": "Category", "placeholder": "Unknown", "strings": {"options": {"none": "None", "option1": "Option1", "option2": "Option2", "option3": "Option3", "option4": "Option4"}}}, + "category": {"type": "radio", "keys": ["none", "updateDetails", "missing", "wrongLocation", "groundtruth", "doesNotExist", "discussion"], "label": "Category", "placeholder": "Unknown", "strings": {"options": {"none": "None", "updateDetails": "Update or add details", "missing": "Something is missing", "wrongLocation": "Wrong location", "groundtruth": "Ground truth or needs local confirmation", "doesNotExist": "Does not or never existed", "discussion": "Needs discussing"}}}, "clothes": {"key": "clothes", "type": "semiCombo", "label": "Clothes"}, "club": {"key": "club", "type": "typeCombo", "label": "Type"}, "collection_times": {"key": "collection_times", "type": "text", "label": "Collection Times"}, diff --git a/data/presets/fields/category.json b/data/presets/fields/category.json index 7eeb9747c..1af4a78b8 100644 --- a/data/presets/fields/category.json +++ b/data/presets/fields/category.json @@ -2,20 +2,24 @@ "type": "radio", "keys": [ "none", - "option1", - "option2", - "option3", - "option4" + "updateDetails", + "missing", + "wrongLocation", + "groundtruth", + "doesNotExist", + "discussion" ], "label": "Category", "placeholder": "Unknown", "strings": { "options": { "none": "None", - "option1": "Option1", - "option2": "Option2", - "option3": "Option3", - "option4": "Option4" + "updateDetails": "Update or add details", + "missing": "Something is missing", + "wrongLocation": "Wrong location", + "groundtruth": "Ground truth or needs local confirmation", + "doesNotExist": "Does not or never existed", + "discussion": "Needs discussing" } } } diff --git a/data/taginfo.json b/data/taginfo.json index e73652fc6..a22acfd27 100644 --- a/data/taginfo.json +++ b/data/taginfo.json @@ -6376,30 +6376,86 @@ {"key": "cash_in", "description": "Cash In"}, {"key": "castle_type", "description": "Type"}, {"key": "none", "value": "none", "description": "Category"}, - {"key": "none", "value": "option1", "description": "Category"}, - {"key": "none", "value": "option2", "description": "Category"}, - {"key": "none", "value": "option3", "description": "Category"}, - {"key": "none", "value": "option4", "description": "Category"}, - {"key": "option1", "value": "none", "description": "Category"}, - {"key": "option1", "value": "option1", "description": "Category"}, - {"key": "option1", "value": "option2", "description": "Category"}, - {"key": "option1", "value": "option3", "description": "Category"}, - {"key": "option1", "value": "option4", "description": "Category"}, - {"key": "option2", "value": "none", "description": "Category"}, - {"key": "option2", "value": "option1", "description": "Category"}, - {"key": "option2", "value": "option2", "description": "Category"}, - {"key": "option2", "value": "option3", "description": "Category"}, - {"key": "option2", "value": "option4", "description": "Category"}, - {"key": "option3", "value": "none", "description": "Category"}, - {"key": "option3", "value": "option1", "description": "Category"}, - {"key": "option3", "value": "option2", "description": "Category"}, - {"key": "option3", "value": "option3", "description": "Category"}, - {"key": "option3", "value": "option4", "description": "Category"}, - {"key": "option4", "value": "none", "description": "Category"}, - {"key": "option4", "value": "option1", "description": "Category"}, - {"key": "option4", "value": "option2", "description": "Category"}, - {"key": "option4", "value": "option3", "description": "Category"}, - {"key": "option4", "value": "option4", "description": "Category"}, + {"key": "none", "value": "updateDetails", "description": "Category"}, + {"key": "none", "value": "missing", "description": "Category"}, + {"key": "none", "value": "wrongLocation", "description": "Category"}, + {"key": "none", "value": "groundtruth", "description": "Category"}, + {"key": "none", "value": "doesNotExist", "description": "Category"}, + {"key": "none", "value": "discussion", "description": "Category"}, + {"key": "updateDetails", "value": "none", "description": "Category"}, + { + "key": "updateDetails", + "value": "updateDetails", + "description": "Category" + }, + {"key": "updateDetails", "value": "missing", "description": "Category"}, + { + "key": "updateDetails", + "value": "wrongLocation", + "description": "Category" + }, + {"key": "updateDetails", "value": "groundtruth", "description": "Category"}, + { + "key": "updateDetails", + "value": "doesNotExist", + "description": "Category" + }, + {"key": "updateDetails", "value": "discussion", "description": "Category"}, + {"key": "missing", "value": "none", "description": "Category"}, + {"key": "missing", "value": "updateDetails", "description": "Category"}, + {"key": "missing", "value": "missing", "description": "Category"}, + {"key": "missing", "value": "wrongLocation", "description": "Category"}, + {"key": "missing", "value": "groundtruth", "description": "Category"}, + {"key": "missing", "value": "doesNotExist", "description": "Category"}, + {"key": "missing", "value": "discussion", "description": "Category"}, + {"key": "wrongLocation", "value": "none", "description": "Category"}, + { + "key": "wrongLocation", + "value": "updateDetails", + "description": "Category" + }, + {"key": "wrongLocation", "value": "missing", "description": "Category"}, + { + "key": "wrongLocation", + "value": "wrongLocation", + "description": "Category" + }, + {"key": "wrongLocation", "value": "groundtruth", "description": "Category"}, + { + "key": "wrongLocation", + "value": "doesNotExist", + "description": "Category" + }, + {"key": "wrongLocation", "value": "discussion", "description": "Category"}, + {"key": "groundtruth", "value": "none", "description": "Category"}, + {"key": "groundtruth", "value": "updateDetails", "description": "Category"}, + {"key": "groundtruth", "value": "missing", "description": "Category"}, + {"key": "groundtruth", "value": "wrongLocation", "description": "Category"}, + {"key": "groundtruth", "value": "groundtruth", "description": "Category"}, + {"key": "groundtruth", "value": "doesNotExist", "description": "Category"}, + {"key": "groundtruth", "value": "discussion", "description": "Category"}, + {"key": "doesNotExist", "value": "none", "description": "Category"}, + { + "key": "doesNotExist", + "value": "updateDetails", + "description": "Category" + }, + {"key": "doesNotExist", "value": "missing", "description": "Category"}, + { + "key": "doesNotExist", + "value": "wrongLocation", + "description": "Category" + }, + {"key": "doesNotExist", "value": "groundtruth", "description": "Category"}, + {"key": "doesNotExist", "value": "doesNotExist", "description": "Category"}, + {"key": "doesNotExist", "value": "discussion", "description": "Category"}, + {"key": "discussion", "value": "none", "description": "Category"}, + {"key": "discussion", "value": "updateDetails", "description": "Category"}, + {"key": "discussion", "value": "missing", "description": "Category"}, + {"key": "discussion", "value": "wrongLocation", "description": "Category"}, + {"key": "discussion", "value": "groundtruth", "description": "Category"}, + {"key": "discussion", "value": "doesNotExist", "description": "Category"}, + {"key": "discussion", "value": "discussion", "description": "Category"}, {"key": "clothes", "description": "Clothes"}, {"key": "collection_times", "description": "Collection Times"}, {"key": "comment", "description": "Changeset Comment"}, diff --git a/dist/locales/en.json b/dist/locales/en.json index 972409ee3..49bec21b2 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1672,10 +1672,12 @@ "placeholder": "Unknown", "options": { "none": "None", - "option1": "Option1", - "option2": "Option2", - "option3": "Option3", - "option4": "Option4" + "updateDetails": "Update or add details", + "missing": "Something is missing", + "wrongLocation": "Wrong location", + "groundtruth": "Ground truth or needs local confirmation", + "doesNotExist": "Does not or never existed", + "discussion": "Needs discussing" } }, "clothes": { diff --git a/modules/actions/move_note.js b/modules/actions/move_note.js index e2179b15a..e7c1a273d 100644 --- a/modules/actions/move_note.js +++ b/modules/actions/move_note.js @@ -9,7 +9,6 @@ export function actionMoveNote(noteID, toLoc) { var note = services.osm.getNote(noteID); note.move(geoVecInterp(note.loc, toLoc, t)); - console.log('moved: ', note.loc); // TODO: update }; diff --git a/modules/services/osm.js b/modules/services/osm.js index 03cb6f0eb..d33b941b7 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -875,10 +875,13 @@ export default { if (!note.loc[0] || !note.loc[1] || !note.newComment) return; // location & description required + var comment = note.newComment; + if (note.newCategory && note.newCategory !== 'None') { comment += ' #' + note.newCategory; } var path = '/api/0.6/notes?' + 'lat=' + note.loc[1] + '&lon=' + note.loc[0] + - '&' + utilQsString({ text: note.newComment }); + '&' + utilQsString({ text: comment }); + _noteCache.inflightPost[note.id] = oauth.xhr( { method: 'POST', path: path }, wrapcb(this, done, _connectionID) diff --git a/modules/ui/note_category.js b/modules/ui/note_category.js deleted file mode 100644 index 5f43a3e2f..000000000 --- a/modules/ui/note_category.js +++ /dev/null @@ -1,63 +0,0 @@ -import { dispatch as d3_dispatch } from 'd3-dispatch'; -import { select as d3_select, selectAll as d3_selectAll } from 'd3-selection'; - -import { services } from '../services'; -import { uiField } from './field'; -import { uiFormFields } from './form_fields'; - -export function uiNoteCategory(context) { - var formFields = uiFormFields(context); - var _note; - var _fieldsArr; - - function noteCategory(selection) { - - if (!_note.isNew()) return; // don't add category - - var initial = false; - - if (!_fieldsArr) { - initial = true; - var presets = context.presets(); - - _fieldsArr = [ - uiField(context, presets.field('category'), null, { show: true, revert: false }), - ]; - - _fieldsArr.forEach(function(field) { - field - .on('change', change); - }); - } - - selection - .append('div') - .attr('class', 'note-category') - .call(formFields.fieldsArr(_fieldsArr)); - - function change() { - var val = d3_select('input[name=\'category\']:checked').property('value') || undefined; - // NOTE: perhaps there is a better way to get value, something like ... - // var input = d3_select(this); - // var val = input.property('value') || undefined; - - // store the unsaved comment with the note itself - _note = _note.update({ newCategory: val }); - - var osm = services.osm; - if (osm) { - osm.replaceNote(_note); // update note cache - } - } - - } - - noteCategory.note = function(_) { - if (!arguments.length) return _note; - _note = _; - return noteCategory; - }; - - - return noteCategory; -} \ No newline at end of file diff --git a/modules/ui/note_editor.js b/modules/ui/note_editor.js index b0bcc7812..f67cd3a28 100644 --- a/modules/ui/note_editor.js +++ b/modules/ui/note_editor.js @@ -9,6 +9,9 @@ import { services } from '../services'; import { modeBrowse } from '../modes'; import { svgIcon } from '../svg'; +import { uiField } from './field'; +import { uiFormFields } from './form_fields'; + import { uiNoteComments, uiNoteHeader, @@ -20,15 +23,17 @@ import { utilNoAuto, utilRebind } from '../util'; -import { uiNoteCategory } from './note_category'; export function uiNoteEditor(context) { var dispatch = d3_dispatch('change'); var noteComments = uiNoteComments(); - var noteCategory = uiNoteCategory(context); var noteHeader = uiNoteHeader(); + + var formFields = uiFormFields(context); + var _note; + var _fieldsArr; function noteEditor(selection) { @@ -109,8 +114,38 @@ export function uiNoteEditor(context) { .append('div') .attr('class', 'note-save save-section cf'); + // if new note, show categories to pick from if (_note.isNew()) { - noteSaveEnter.call(noteCategory.note(_note)); + var presets = context.presets(); + + // NOTE: this key isn't a age and therefore there is no documentation (yet) + _fieldsArr = [ + uiField(context, presets.field('category'), null, { show: true, revert: false }), + ]; + + _fieldsArr.forEach(function(field) { + field + .on('change', changeCategory); + }); + + noteSaveEnter + .append('div') + .attr('class', 'note-category') + .call(formFields.fieldsArr(_fieldsArr)); + } + + function changeCategory() { + // NOTE: perhaps there is a better way to get value + var val = d3_select('input[name=\'category\']:checked').property('__data__') || undefined; + + // store the unsaved category with the note itself + _note = _note.update({ newCategory: val }); + var osm = services.osm; + if (osm) { + osm.replaceNote(_note); // update note cache + } + noteSave + .call(noteSaveButtons); } noteSaveEnter @@ -127,8 +162,8 @@ export function uiNoteEditor(context) { .attr('maxlength', 1000) .property('value', function(d) { return d.newComment; }) .call(utilNoAuto) - .on('input', change) - .on('blur', change); + .on('input', changeInput) + .on('blur', changeInput); // update noteSave = noteSaveEnter @@ -137,7 +172,7 @@ export function uiNoteEditor(context) { .call(noteSaveButtons); - function change() { + function changeInput() { var input = d3_select(this); var val = input.property('value').trim() || undefined;