From 658721a15067b217ed6236bd0e3d084f58d8ae75 Mon Sep 17 00:00:00 2001 From: Thomas Hervey Date: Sat, 21 Jul 2018 19:36:13 -0400 Subject: [PATCH] WIP: added note category, TODO: update input --- css/65_data.css | 4 ++ data/presets.yaml | 16 ++++++++ data/presets/fields.json | 1 + data/presets/fields/category.json | 21 +++++++++++ data/taginfo.json | 25 ++++++++++++ dist/locales/en.json | 11 ++++++ modules/modes/add_note.js | 2 +- modules/modes/drag_note.js | 2 +- modules/modes/select_note.js | 1 - modules/ui/note_category.js | 63 +++++++++++++++++++++++++++++++ modules/ui/note_comments.js | 2 +- modules/ui/note_editor.js | 6 +++ 12 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 data/presets/fields/category.json create mode 100644 modules/ui/note_category.js diff --git a/css/65_data.css b/css/65_data.css index 7deaba72a..a8367e1fe 100644 --- a/css/65_data.css +++ b/css/65_data.css @@ -93,6 +93,10 @@ border-radius: 5px 0 0 5px; } +.note-category { + margin: 20px 0px; +} + .comments-container { background: #ececec; padding: 1px 10px; diff --git a/data/presets.yaml b/data/presets.yaml index a5c716a72..e9bd42092 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -304,6 +304,22 @@ en: castle_type: # castle_type=* label: Type + category: + # 'none=*, option1=*, option2=*, option3=*, option4=*' + label: Category + options: + # none=yes + none: None + # option1=yes + option1: Option1 + # option2=yes + option2: Option2 + # option3=yes + option3: Option3 + # option4=yes + option4: Option4 + # category field placeholder + placeholder: Unknown clothes: # clothes=* label: Clothes diff --git a/data/presets/fields.json b/data/presets/fields.json index d295ff913..7296ec5fe 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -49,6 +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"}}}, "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 new file mode 100644 index 000000000..7eeb9747c --- /dev/null +++ b/data/presets/fields/category.json @@ -0,0 +1,21 @@ +{ + "type": "radio", + "keys": [ + "none", + "option1", + "option2", + "option3", + "option4" + ], + "label": "Category", + "placeholder": "Unknown", + "strings": { + "options": { + "none": "None", + "option1": "Option1", + "option2": "Option2", + "option3": "Option3", + "option4": "Option4" + } + } +} diff --git a/data/taginfo.json b/data/taginfo.json index 50d522098..e73652fc6 100644 --- a/data/taginfo.json +++ b/data/taginfo.json @@ -6375,6 +6375,31 @@ {"key": "capacity", "description": "Capacity"}, {"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": "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 7f6489a73..972409ee3 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1667,6 +1667,17 @@ "castle_type": { "label": "Type" }, + "category": { + "label": "Category", + "placeholder": "Unknown", + "options": { + "none": "None", + "option1": "Option1", + "option2": "Option2", + "option3": "Option3", + "option4": "Option4" + } + }, "clothes": { "label": "Clothes" }, diff --git a/modules/modes/add_note.js b/modules/modes/add_note.js index f0ab36571..685dcf3c7 100644 --- a/modules/modes/add_note.js +++ b/modules/modes/add_note.js @@ -39,7 +39,7 @@ export function modeAddNote(context) { context .selectedNoteID(note.id) - .enter(modeSelectNote(context, [note.id]).newFeature(true)); + .enter(modeSelectNote(context, note.id).newFeature(true)); } diff --git a/modules/modes/drag_note.js b/modules/modes/drag_note.js index 602fac67e..8437300c2 100644 --- a/modules/modes/drag_note.js +++ b/modules/modes/drag_note.js @@ -223,7 +223,7 @@ export function modeDragNote(context) { mode.selectedNoteID = function() { - if (!arguments.length) return _activeEntity ? [_activeEntity.id] : []; + if (!arguments.length) return _activeEntity ? _activeEntity.id : []; // no assign return mode; }; diff --git a/modules/modes/select_note.js b/modules/modes/select_note.js index 7fe0c6e7d..61fe78891 100644 --- a/modules/modes/select_note.js +++ b/modules/modes/select_note.js @@ -129,7 +129,6 @@ export function modeSelectNote(context, selectedNoteID) { context.ui().sidebar .hide(); - context.selectedNoteID(null); }; diff --git a/modules/ui/note_category.js b/modules/ui/note_category.js new file mode 100644 index 000000000..5f43a3e2f --- /dev/null +++ b/modules/ui/note_category.js @@ -0,0 +1,63 @@ +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_comments.js b/modules/ui/note_comments.js index ccf3d5537..87649782c 100644 --- a/modules/ui/note_comments.js +++ b/modules/ui/note_comments.js @@ -11,7 +11,7 @@ export function uiNoteComments() { function noteComments(selection) { - if (_note.isNew()) { return; } + if (_note.isNew()) return; // don't draw .comments-container var comments = selection.selectAll('.comments-container') .data([0]); diff --git a/modules/ui/note_editor.js b/modules/ui/note_editor.js index 2a50f8891..b0bcc7812 100644 --- a/modules/ui/note_editor.js +++ b/modules/ui/note_editor.js @@ -20,11 +20,13 @@ 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 _note; @@ -107,6 +109,10 @@ export function uiNoteEditor(context) { .append('div') .attr('class', 'note-save save-section cf'); + if (_note.isNew()) { + noteSaveEnter.call(noteCategory.note(_note)); + } + noteSaveEnter .append('h4') .attr('class', '.note-save-header')