Skip to content

Commit

Permalink
Merge pull request #45 from jgravois/import_discussion
Browse files Browse the repository at this point in the history
add mandatory, user editable discussion tag to changeset
  • Loading branch information
mapmeld committed Aug 9, 2017
2 parents 3c1348c + 4fb6234 commit 6a6ad18
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 15 deletions.
4 changes: 2 additions & 2 deletions modules/behavior/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export function behaviorHash(context) {
newParams.map = zoom.toFixed(2) +
'/' + center[1].toFixed(precision) +
'/' + center[0].toFixed(precision);

/*
var gsLayer = context.layers().layer('geoservice').originalURL;
var gsLayer = context.layers().layer('geoservice').layerUrl;
if (gsLayer) {
q.geoservice = gsLayer;
}
Expand Down
18 changes: 15 additions & 3 deletions modules/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function coreHistory(context) {
lock = utilSessionMutex('lock'),
duration = 150,
checkpoints = {},
stack, index, tree;
stack, index, tree, source;


// internal _act, accepts list of actions and eased time
Expand All @@ -40,7 +40,8 @@ export function coreHistory(context) {
return {
graph: graph,
annotation: annotation,
imageryUsed: imageryUsed
imageryUsed: imageryUsed,
source: source
};
}

Expand Down Expand Up @@ -285,6 +286,15 @@ export function coreHistory(context) {
}
},

source: function(sourceUrl) {
if (sourceUrl) {
source = sourceUrl;
return history;
} else {
return source;
}
},


// save the current history state
checkpoint: function(key) {
Expand Down Expand Up @@ -414,6 +424,7 @@ export function coreHistory(context) {
if (deleted.length) x.deleted = deleted;
if (i.imageryUsed) x.imageryUsed = i.imageryUsed;
if (i.annotation) x.annotation = i.annotation;
if (i.source) x.source = i.source;

return x;
});
Expand Down Expand Up @@ -516,7 +527,8 @@ export function coreHistory(context) {
return {
graph: coreGraph(stack[0].graph).load(entities),
annotation: d.annotation,
imageryUsed: d.imageryUsed
imageryUsed: d.imageryUsed,
source: d.source
};
});

Expand Down
4 changes: 2 additions & 2 deletions modules/modes/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export function modeSave(context) {
var mode = {
id: 'save'
};

if (d3.select('input[name="approvalProcess"]:checked').property('value') === 'individual') {
// when clicking the save button, filter out entities which were not approved manually
var deletions = [];
_.map(window.importedEntities, function(entity) {
try {
if ((entity.approvedForEdit !== 'approved' && entity.approvedForEdit !== 'unchanged') && context.entity(entity.id)) {
deletions.push(entity.id);
deletions.push(entity.id);
}
} catch (e) {
// entity was already deleted, can't be removed here
Expand Down
5 changes: 3 additions & 2 deletions modules/renderer/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ export function rendererBackground(context) {
.forEach(function (d) { imageryUsed.push(d.source().imageryUsed()); });

var gsLayer = context.layers().layer('geoservice');
if (gsLayer && gsLayer.enabled() && gsLayer.hasData()) {
if (gsLayer && gsLayer.hasData()) {
imageryUsed.push('GeoService');
context.history().source(gsLayer.layerUrl);
}

var gpx = context.layers().layer('gpx');
Expand Down Expand Up @@ -272,7 +273,7 @@ export function rendererBackground(context) {
background.toggleOverlayLayer(overlay);
}
});

/*
if (q.geoservice) {
setTimeout(function() {
Expand Down
6 changes: 3 additions & 3 deletions modules/svg/geoservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ export function svgGeoService(projection, context, dispatch) {
};

drawGeoService.url = function(true_url, downloadMax) {
if (!this.originalURL) {
this.originalURL = true_url;
if (!this.layerUrl) {
drawGeoService.layerUrl = true_url;
}

var fmt = drawGeoService.format() || 'json';
Expand Down Expand Up @@ -700,7 +700,7 @@ export function svgGeoService(projection, context, dispatch) {
}

var that = this;
console.log('final GeoService URL: ' + url);
// console.log('final GeoService URL: ' + url);
d3.text(url, function(err, data) {
if (err) {
console.log('GeoService URL did not load');
Expand Down
45 changes: 44 additions & 1 deletion modules/ui/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {


var changeset;
var readOnlyTags = ['created_by', 'imagery_used', 'host', 'locale'];
var readOnlyTags = ['created_by', 'imagery_used', 'host', 'locale', 'source'];


export function uiCommit(context) {
Expand All @@ -35,6 +35,13 @@ export function uiCommit(context) {
locale: detected.locale.substr(0, 255)
};

// if a GeoService was imported, pass the source url through,
// along with mandatory, user editable field for the import discussion
if (context.history().source() ){
tags.source = context.history().source();
tags.import_discussion = '';
}

changeset = new osmChangeset({ tags: tags });
}

Expand All @@ -44,6 +51,7 @@ export function uiCommit(context) {
rawTagEditor = uiRawTagEditor(context).on('change', changeTags),
comment = context.storage('comment') || '',
commentDate = +context.storage('commentDate') || 0,
importDiscussion = context.storage('importDiscussion') || '',
currDate = Date.now(),
cutoff = 2 * 86400 * 1000; // 2 days

Expand Down Expand Up @@ -87,6 +95,29 @@ export function uiCommit(context) {

commentField.node().select();

if (tags.source) {
var discussionSection = body
.append('div')
.attr('class', 'modal-section form-field commit-form');

discussionSection
.append('label')
.attr('class', 'form-label')
.text('Import Discussion');

var discussionField = discussionSection
.append('textarea')
.attr('class', 'commit-form-comment')
.attr('placeholder', 'imports@openstreetmap.org discussion thread (required)')
.attr('maxlength', 255)
.property('value', importDiscussion)
.on('input.save', change(true))
.on('change.save', change())
.on('blur.save', function() {
context.storage('importDiscussion', this.value);
});
}

context.connection().userChangesets(function (err, changesets) {
if (err) return;

Expand Down Expand Up @@ -364,6 +395,18 @@ export function uiCommit(context) {
checkComment(comment);

var changeset = updateChangeset({ comment: comment });

if (discussionField) {
var discussion = discussionField.property('value').trim();
if (!onInput) {
discussionField.property('value', discussion);
}

checkComment(discussion);

var changeset = updateChangeset({ import_discussion: discussion });
}

var expanded = !tagSection.selectAll('a.hide-toggle.expanded').empty();

tagSection
Expand Down
4 changes: 3 additions & 1 deletion modules/ui/map_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export function uiMapData(context) {
content.append('h3')
.text('Import from a GeoService by URL');


var body = content.append('div')
.attr('class', 'body');

Expand Down Expand Up @@ -540,7 +541,7 @@ export function uiMapData(context) {
.text('The url provided not recognized as a valid GeoService');
unrecognizedLabel.classed('hide', false);
return;
}
}
}

// if it just ends /0, we need to keep /0 around
Expand Down Expand Up @@ -831,6 +832,7 @@ export function uiMapData(context) {

function editGeoService() {
// window allows user to enter a GeoService layer

d3.event.preventDefault();
toggle();
}
Expand Down
1 change: 0 additions & 1 deletion modules/ui/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { uiCmd } from './cmd';
import { uiTooltipHtml } from './tooltipHtml';
import { tooltip } from '../util/tooltip';


export function uiSave(context) {
var history = context.history(),
key = uiCmd('⌘S');
Expand Down

0 comments on commit 6a6ad18

Please sign in to comment.