updated comment UI, added stub for POST; TODO: finish links & POST

This commit is contained in:
Thomas Hervey
2018-08-10 11:01:31 -06:00
committed by Bryan Housel
parent b5a316df48
commit d095de08fe
9 changed files with 83 additions and 124 deletions
+7
View File
@@ -175,6 +175,13 @@
}
/* KeepRight */
.kr_error-comment-container,
.kr_error-details-container {
background: #ececec;
padding: 10px 10px;
border-radius: 8px;
margin-top: 20px;
}
.kr_error_type_30 {
color: #ddb87d;
+4 -1
View File
@@ -931,8 +931,11 @@ en:
title: Edit Error
detail_title: Error
detail_description: Description
inputPlaceholder: Enter a comment to share with other users.
comment_header: Comment
newInputPlaceholder: Enter a comment to share with other users.
updateInputPlaceholder: Update the comment above to share with other users.
newComment: New Comment
updateComment: Update Comment
upload_explanation: Your comments will be publicly visible to all keepRight.at users.
upload_explanation_with_user: "Your comments as {user} will be publicly visible to all keepRight.at users."
resolve_comment: Comment and Resolve
+4 -1
View File
@@ -1138,8 +1138,11 @@
"title": "Edit Error",
"detail_title": "Error",
"detail_description": "Description",
"inputPlaceholder": "Enter a comment to share with other users.",
"comment_header": "Comment",
"newInputPlaceholder": "Enter a comment to share with other users.",
"updateInputPlaceholder": "Update the comment above to share with other users.",
"newComment": "New Comment",
"updateComment": "Update Comment",
"upload_explanation": "Your comments will be publicly visible to all keepRight.at users.",
"upload_explanation_with_user": "Your comments as {user} will be publicly visible to all keepRight.at users.",
"resolve_comment": "Comment and Resolve",
+28 -1
View File
@@ -26,7 +26,7 @@ var _keepRightCache = { loaded: {}, inflight: {}, keepRight: {}, rtree: rbush()}
var _off;
var _keepRightZoom = 16;
var apiBase = 'https://www.keepright.at/export.php?';
var apiBase = 'https://www.keepright.at/';
function abortRequest(i) {
@@ -91,6 +91,7 @@ export default {
var that = this;
var path = apiBase +
'export.php?' +
'format=' + options.format +
'&ch=' + options.ch.join() + '&';
@@ -185,6 +186,32 @@ export default {
});
},
postKeepRightUpdate: function(d, callback) {
// TODO: check if a user is authenticated
// if (!this.authenticated()) {
// return callback({ message: 'Not Authenticated', status: -3 }, d);
// }
// if (_keepRightCache.inflightPost[d.id]) {
// return callback({ message: 'Error update already inflight', status: -2 }, d);
// }
var path = apiBase + 'comment.php?';
if (d.state) { path += '&st=' + d.state; }
if (d.newComment) { path += '&' + utilQsString({'co': d.newComment }); }
path += '&schema=' + d.schema + '&id=' + d.error_id;
d3_request(path)
.mimeType('application/json')
.response(function(xhr) {
return JSON.parse(xhr.responseText);
})
.post(function(err, data) {
console.log('error:', err);
console.log('data: ', data);
});
},
// get all cached errors covering the viewport
keepRight: function(projection) {
var viewport = projection.clipExtent();
+8 -87
View File
@@ -15,98 +15,19 @@ export function uiKeepRightComment() {
var comment = selection.selectAll('.comments-container')
.data([0]);
comment = comment.enter()
var comment_details = comment.enter()
.append('div')
.attr('class', 'comments-container')
.merge(comment);
.attr('class', 'kr_error-comment-container');
var commentEnter = comment.selectAll('.comment')
.data(_error.comment)
.enter()
comment_details
.append('h4')
.text(t('QA.keepRight.comment_header'));
comment_details
.append('div')
.attr('class', 'comment');
commentEnter
.append('div')
.attr('class', function(d) { return 'comment-avatar user-' + d.uid; })
.call(svgIcon('#iD-icon-avatar', 'comment-avatar-icon'));
var mainEnter = commentEnter
.append('div')
.attr('class', 'comment-main');
var metadataEnter = mainEnter
.append('div')
.attr('class', 'comment-metadata');
metadataEnter
.append('div')
.attr('class', 'comment-author')
.each(function(d) {
var selection = d3_select(this);
var osm = services.osm;
if (osm && d.user) {
selection = selection
.append('a')
.attr('class', 'comment-author-link')
.attr('href', osm.userURL(d.user))
.attr('tabindex', -1)
.attr('target', '_blank');
}
selection
.text(function(d) { return d.user || t('note.anonymous'); });
});
metadataEnter
.append('div')
.attr('class', 'comment-date')
.text(function(d) { return d.action + ' ' + localeDateString(d.date); });
mainEnter
.append('div')
.attr('class', 'comment-text')
.html(function(d) { return d.html; });
comment
.call(replaceAvatars);
.text(_error.comment);
}
function replaceAvatars(selection) {
var osm = services.osm;
if (!osm) return;
var uids = {}; // gather uids in the comment thread
_error.comment.forEach(function(d) {
if (d.uid) uids[d.uid] = true;
});
Object.keys(uids).forEach(function(uid) {
osm.loadUser(uid, function(err, user) {
if (!user || !user.image_url) return;
selection.selectAll('.comment-avatar.user-' + uid)
.html('')
.append('img')
.attr('class', 'icon comment-avatar-icon')
.attr('src', user.image_url)
.attr('alt', user.display_name);
});
});
}
function localeDateString(s) {
if (!s) return null;
var detected = utilDetect();
var options = { day: 'numeric', month: 'short', year: 'numeric' };
s = s.replace(/-/g, '/'); // fix browser-specific Date() issues
var d = new Date(s);
if (isNaN(d.getTime())) return null;
return d.toLocaleDateString(detected.locale, options);
}
keepRightComment.error = function(_) {
if (!arguments.length) return _error;
_error = _;
+1
View File
@@ -98,6 +98,7 @@ export function uiKeepRightDetails(context) {
return t(_titleBase + _templateErrorType + '.tooltip', parseErrorDescriptions(d));
});
// var description_text = d3_select('.kr_error-details-description-text').text();
// TODO: add links to ids in description
// d3_select('.kr_error-details-description-text').enter()
// .append('span')
+20 -33
View File
@@ -68,8 +68,8 @@ export function uiKeepRightEditor(context) {
.attr('class', 'modal-section keepRight-editor')
.merge(editor)
.call(keepRightHeader.error(_error))
// .call(keepRightComment.error(_error))
.call(keepRightDetails.error(_error))
.call(keepRightComment.error(_error))
.call(errorSaveSection);
@@ -101,14 +101,16 @@ export function uiKeepRightEditor(context) {
errorSaveEnter
.append('h4')
.attr('class', '.error-save-header')
.text(function() {
return t('QA.keepRight.newComment');
.text(function(d) {
return d.comment ? t('QA.keepRight.updateComment') : t('QA.keepRight.newComment');
});
errorSaveEnter
.append('textarea')
.attr('class', 'new-comment-input')
.attr('placeholder', t('QA.keepRight.inputPlaceholder'))
.attr('placeholder', function(d) {
return d.comment ? t('QA.keepRight.updateInputPlaceholder') : t('QA.keepRight.newInputPlaceholder');
})
.attr('maxlength', 1000)
.property('value', function(d) { return d.newComment; })
.call(utilNoAuto)
@@ -276,35 +278,21 @@ export function uiKeepRightEditor(context) {
dispatch.call('change');
});
buttonSection.select('.save-button') // select and propagate data
.attr('disabled', function(d) {
return (hasAuth && d.status === 'open' && d.newComment) ? null : true;
})
.on('click.save', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var keepRight = services.keepRight;
if (keepRight) {
// TODO: handle posting updates
// keepRight.postKeepRightCreate(d, function(err, error) {
// dispatch.call('change', error);
// });
}
});
buttonSection.select('.resolve-button') // select and propagate data
.attr('disabled', (hasAuth ? null : true))
.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);
})
.on('click.status', function(d) {
.on('click.state', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var keepRight = services.keepRight;
if (keepRight) {
// TODO: handle posting updates
// keepRight.postKeepRightUpdate(d, function(err, error) {
// dispatch.call('change', error);
// });
d.state = 'ignore_t';
keepRight.postKeepRightUpdate(d, function(err, error) {
dispatch.call('change', error);
});
}
});
@@ -314,14 +302,14 @@ export function uiKeepRightEditor(context) {
var andComment = (d.newComment ? '_comment' : '');
return t('QA.keepRight.ignore' + andComment);
})
.on('click.status', function(d) {
.on('click.state', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var keepRight = services.keepRight;
if (keepRight) {
// TODO: handle posting updates
// keepRight.postKeepRightUpdate(d, function(err, error) {
// dispatch.call('change', error);
// });
d.state = 'ignore';
keepRight.postKeepRightUpdate(d, function(err, error) {
dispatch.call('change', error);
});
}
});
@@ -333,10 +321,9 @@ export function uiKeepRightEditor(context) {
this.blur(); // avoid keeping focus on the button - #4641
var keepRight = services.keepRight;
if (keepRight) {
// TODO: handle posting updates
// keepRight.postKeepRightUpdate(d, function(err, error) {
// dispatch.call('change', error);
// });
keepRight.postKeepRightUpdate(d, function(err, error) {
dispatch.call('change', error);
});
}
});
}
+1 -1
View File
@@ -59,7 +59,7 @@ export function uiKeepRightHeader(context) {
var iconEnter = headerEnter
.append('div')
.attr('class', function(d) { return 'kr_error-header-icon '; })
.attr('class', 'kr_error-header-icon')
.classed('new', function(d) { return d.id < 0; });
iconEnter
+10
View File
@@ -52,6 +52,8 @@ var keepRightSchemaFromWeb = {
export function parseErrorDescriptions(entity) {
if (!(entity instanceof krError)) return;
var _links = [];
// find the matching template from the error schema
var errorType = '_' + entity.error_type;
var matchingTemplate = errorTypes.errors[errorType] || errorTypes.warnings[errorType];
@@ -79,6 +81,13 @@ export function parseErrorDescriptions(entity) {
if (errorDescriptions[i] !== nextWord) {
var currWord = errorDescriptions[i];
// strip leading # if present
if (currWord.charAt(0) === '#') {
currWord = currWord.slice(1, currWord.length);
// and add index to list of links
_links.push(currWord);
}
// if any variables contain common words, like node, way, relation, translate those
if (commonEntities.includes(currWord)) {
currWord = t('QA.keepRight.entities.' + currWord);
@@ -94,6 +103,7 @@ export function parseErrorDescriptions(entity) {
return {
links: _links,
var1: parsedDescriptions[0] || '',
var2: parsedDescriptions[1] || '',
var3: parsedDescriptions[2] || '',