From 69ce5ee9643204d15c8f870e7412156b4ed0678d Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 3 Jan 2019 00:07:55 -0500 Subject: [PATCH] Remove user details and auth and adjust button texts for commenting The user details and auth are not needed because KeepRight accepts only anonymous updating --- data/core.yaml | 11 +-- dist/locales/en.json | 11 +-- modules/services/keepRight.js | 12 +-- modules/ui/keepRight_editor.js | 162 ++++++--------------------------- 4 files changed, 43 insertions(+), 153 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 165bded6d..eaf6a52dd 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -654,12 +654,11 @@ en: detail_description: Description comment: Comment comment_placeholder: Enter a comment to share with other users. - upload_explanation: Your comments will be publicly visible on KeepRight. - upload_explanation_with_user: "Your comments as {user} will be publicly visible on KeepRight." - resolve_comment: Comment and Resolve - ignore_comment: Comment and Ignore - resolve: Resolve - ignore: Ignore + close: Close (Error Fixed) + ignore: Ignore (Not an Error) + save_comment: Save Comment + close_comment: Close and Comment + ignore_comment: Ignore and Comment entities: node: "Node {id}" way: "Way {id}" diff --git a/dist/locales/en.json b/dist/locales/en.json index 302354360..65609b06d 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -794,12 +794,11 @@ "detail_description": "Description", "comment": "Comment", "comment_placeholder": "Enter a comment to share with other users.", - "upload_explanation": "Your comments will be publicly visible on KeepRight.", - "upload_explanation_with_user": "Your comments as {user} will be publicly visible on KeepRight.", - "resolve_comment": "Comment and Resolve", - "ignore_comment": "Comment and Ignore", - "resolve": "Resolve", - "ignore": "Ignore", + "close": "Close (Error Fixed)", + "ignore": "Ignore (Not an Error)", + "save_comment": "Save Comment", + "close_comment": "Close and Comment", + "ignore_comment": "Ignore and Comment", "entities": { "node": "Node {id}", "way": "Way {id}", diff --git a/modules/services/keepRight.js b/modules/services/keepRight.js index 35318a370..d83a66bb7 100644 --- a/modules/services/keepRight.js +++ b/modules/services/keepRight.js @@ -10,7 +10,6 @@ import { request as d3_request } from 'd3-request'; import { geoExtent, geoVecAdd } from '../geo'; import { krError } from '../osm'; -import { services } from './index'; import { t } from '../util/locale'; import { utilRebind, utilTiler, utilQsString } from '../util'; @@ -326,19 +325,15 @@ export default { postKeepRightUpdate: function(update, callback) { - if (!services.osm.authenticated()) { - return callback({ message: 'Not Authenticated', status: -3 }, update); - } if (_krCache.inflight[update.id]) { - return callback( - { message: 'Error update already inflight', status: -2 }, update); + return callback({ message: 'Error update already inflight', status: -2 }, update); } var path = apibase + 'comment.php?'; if (update.state) { path += '&st=' + update.state; } - if (update.newComment) { + if (update.newComment !== undefined) { path += '&' + utilQsString({ co: update.newComment }); } @@ -372,11 +367,13 @@ export default { }); }, + // get a single error from the cache getError: function(id) { return _krCache.keepRight[id]; }, + // replace a single error in the cache replaceError: function(error) { if (!(error instanceof krError) || !error.id) return; @@ -386,6 +383,7 @@ export default { return error; }, + // remove a single error from the cache removeError: function(error) { if (!(error instanceof krError) || !error.id) return; diff --git a/modules/ui/keepRight_editor.js b/modules/ui/keepRight_editor.js index f8b9d7687..5d73e0ddf 100644 --- a/modules/ui/keepRight_editor.js +++ b/modules/ui/keepRight_editor.js @@ -1,8 +1,5 @@ import { dispatch as d3_dispatch } from 'd3-dispatch'; -import { - event as d3_event, - select as d3_select -} from 'd3-selection'; +import { select as d3_select } from 'd3-selection'; import { t } from '../util/locale'; import { services } from '../services'; @@ -96,7 +93,7 @@ export function uiKeepRightEditor(context) { .attr('class', 'new-comment-input') .attr('placeholder', t('QA.keepRight.comment_placeholder')) .attr('maxlength', 1000) - .property('value', function(d) { return d.comment; }) + .property('value', function(d) { return d.newComment || d.comment; }) .call(utilNoAuto) .on('input', changeInput) .on('blur', changeInput); @@ -104,16 +101,19 @@ export function uiKeepRightEditor(context) { // update saveSection = saveSectionEnter .merge(saveSection) - .call(userDetails) .call(keepRightSaveButtons); function changeInput() { var input = d3_select(this); - var val = input.property('value').trim() || undefined; + var val = input.property('value').trim(); + + if (val === _error.comment) { + val = undefined; + } // store the unsaved comment with the error itself - _error = _error.update({ newComment: val, comment: val }); + _error = _error.update({ newComment: val }); var keepRight = services.keepRight; if (keepRight) { @@ -126,100 +126,7 @@ export function uiKeepRightEditor(context) { } - function userDetails(selection) { - var detailSection = selection.selectAll('.detail-section') - .data([0]); - - detailSection = detailSection.enter() - .append('div') - .attr('class', 'detail-section') - .merge(detailSection); - - var osm = services.osm; - if (!osm) return; - - // Add warning if user is not logged in - var hasAuth = osm.authenticated(); - var authWarning = detailSection.selectAll('.auth-warning') - .data(hasAuth ? [] : [0]); - - authWarning.exit() - .transition() - .duration(200) - .style('opacity', 0) - .remove(); - - var authEnter = authWarning.enter() - .insert('div', '.tag-reference-body') - .attr('class', 'field-warning auth-warning') - .style('opacity', 0); - - authEnter - .call(svgIcon('#iD-icon-alert', 'inline')); - - authEnter - .append('span') - .text(t('note.login')); - - authEnter - .append('a') - .attr('target', '_blank') - .call(svgIcon('#iD-icon-out-link', 'inline')) - .append('span') - .text(t('login')) - .on('click.error-login', function() { - d3_event.preventDefault(); - osm.authenticate(); - }); - - authEnter - .transition() - .duration(200) - .style('opacity', 1); - - - var prose = detailSection.selectAll('.error-save-prose') - .data(hasAuth ? [0] : []); - - prose.exit() - .remove(); - - prose = prose.enter() - .append('p') - .attr('class', 'error-save-prose') - .text(t('QA.keepRight.upload_explanation')) - .merge(prose); - - osm.userDetails(function(err, user) { - if (err) return; - - var userLink = d3_select(document.createElement('div')); - - if (user.image_url) { - userLink - .append('img') - .attr('src', user.image_url) - .attr('class', 'icon pre-text user-icon'); - } - - userLink - .append('a') - .attr('class', 'user-info') - .text(user.display_name) - .attr('href', osm.userURL(user.display_name)) - .attr('tabindex', -1) - .attr('target', '_blank'); - - prose - .html(t('QA.keepRight.upload_explanation_with_user', { user: userLink.html() })); - }); - } - - function keepRightSaveButtons(selection) { - var osm = services.osm; - var hasAuth = osm && osm.authenticated(); - var isSelected = (_error && _error.id === context.selectedErrorID()); var buttonSection = selection.selectAll('.buttons') .data((isSelected ? [_error] : []), function(d) { return d.status + d.id; }); @@ -235,41 +142,43 @@ export function uiKeepRightEditor(context) { buttonEnter .append('button') - .attr('class', 'button resolve-button action'); + .attr('class', 'button comment-button action') + .text(t('QA.keepRight.save_comment')); + + buttonEnter + .append('button') + .attr('class', 'button close-button action'); buttonEnter .append('button') .attr('class', 'button ignore-button action'); - buttonEnter - .append('button') - .attr('class', 'button comment-button action') - .text(t('note.comment')); - // update buttonSection = buttonSection .merge(buttonEnter); - buttonSection.select('.cancel-button') // select and propagate data - .on('click.cancel', function(d) { + buttonSection.select('.comment-button') // select and propagate data + .attr('disabled', function(d) { + return d.newComment === undefined ? true : null; + }) + .on('click.comment', function(d) { this.blur(); // avoid keeping focus on the button - #4641 var keepRight = services.keepRight; if (keepRight) { - keepRight.removeError(d); + keepRight.postKeepRightUpdate(d, function(err, error) { + dispatch.call('change', error); + }); } - context.enter(modeBrowse(context)); - dispatch.call('change'); }); - buttonSection.select('.resolve-button') // select and propagate data - .attr('disabled', (hasAuth ? null : true)) + buttonSection.select('.close-button') // select and propagate data .text(function(d) { // NOTE: no state is available because keepRight export only exports open errors - var andComment = (d.newComment ? '_comment' : ''); - return t('QA.keepRight.resolve' + andComment); + var andComment = (d.newComment !== undefined ? '_comment' : ''); + return t('QA.keepRight.close' + andComment); }) - .on('click.state', function(d) { + .on('click.close', function(d) { this.blur(); // avoid keeping focus on the button - #4641 var keepRight = services.keepRight; if (keepRight) { @@ -282,12 +191,11 @@ export function uiKeepRightEditor(context) { }); buttonSection.select('.ignore-button') // select and propagate data - .attr('disabled', (hasAuth ? null : true)) .text(function(d) { - var andComment = (d.newComment ? '_comment' : ''); + var andComment = (d.newComment !== undefined ? '_comment' : ''); return t('QA.keepRight.ignore' + andComment); }) - .on('click.state', function(d) { + .on('click.ignore', function(d) { this.blur(); // avoid keeping focus on the button - #4641 var keepRight = services.keepRight; if (keepRight) { @@ -297,20 +205,6 @@ export function uiKeepRightEditor(context) { }); } }); - - buttonSection.select('.comment-button') // select and propagate data - .attr('disabled', function(d) { - return (hasAuth && d.newComment) ? null : true; - }) - .on('click.comment', function(d) { - this.blur(); // avoid keeping focus on the button - #4641 - var keepRight = services.keepRight; - if (keepRight) { - keepRight.postKeepRightUpdate(d, function(err, error) { - dispatch.call('change', error); - }); - } - }); }