Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download changes link #4350

Merged
merged 6 commits into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions css/80_app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,7 @@ img.tile-removing {
border: 1px solid #ccc;
border-radius: 4px;
background: #fff;
margin-bottom: 10px;
}

.mode-save .warning-section {
Expand Down
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ en:
save: Upload
cancel: Cancel
changes: "{count} Changes"
download_changes: Download OsmChange file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard spelling for OSC files is "osmChange"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll change it. I was going off of the osm wiki - should we change it there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wiki page titles have to begin with a capital character.

warnings: Warnings
modified: Modified
deleted: Deleted
Expand Down
1 change: 1 addition & 0 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"save": "Upload",
"cancel": "Cancel",
"changes": "{count} Changes",
"download_changes": "Download OsmChange file",
"warnings": "Warnings",
"modified": "Modified",
"deleted": "Deleted",
Expand Down
7 changes: 1 addition & 6 deletions modules/modes/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import _ from 'lodash';

import { d3keybinding } from '../lib/d3.keybinding.js';
import { t } from '../util/locale';
import { JXON } from '../util/jxon';

import {
actionDiscardTags,
Expand Down Expand Up @@ -248,11 +247,7 @@ export function modeSave(context) {

selection.call(uiConflicts(context)
.list(conflicts)
.on('download', function() {
var data = JXON.stringify(changeset.update({ id: 'CHANGEME' }).osmChangeJXON(origChanges)),
win = window.open('data:text/xml,' + encodeURIComponent(data), '_blank');
win.focus();
})
.origChanges(origChanges)
.on('cancel', function() {
history.pop();
selection.remove();
Expand Down
40 changes: 39 additions & 1 deletion modules/ui/commit_changes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as d3 from 'd3';
import { t } from '../util/locale';
import { JXON } from '../util/jxon';
import { actionDiscardTags } from '../actions';
import { osmChangeset } from '../osm';
import { svgIcon } from '../svg';
import { utilDetect } from '../util/detect';

import {
utilDisplayName,
utilDisplayType,
Expand All @@ -9,10 +14,13 @@ import {


export function uiCommitChanges(context) {
var detected = utilDetect();


function commitChanges(selection) {

var summary = context.history().difference().summary();
var history = context.history(),
summary = history.difference().summary();

var container = selection.selectAll('.modal-section.commit-section')
.data([0]);
Expand Down Expand Up @@ -85,6 +93,36 @@ export function uiCommitChanges(context) {
.on('click', zoomToEntity);


// Download changeset link
var changeset = new osmChangeset({ id: 'CHANGEME' }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally for downloading you don't want to supply anything for changeset ID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check this for me? I'm really not sure what other tools need.

It currently ends up generating something kind of like this, but we can remove the changeset="CHANGEME" stuff if needed:

<osmChange version="0.6" generator="iD">
  <create/>
  <modify>
    <node id="105439801" lon="-74.53666020842094" lat="40.663296528227306" version="2" changeset="CHANGEME"/>
    <node id="105439798" lon="-74.53607265426908" lat="40.66309431604051" version="2" changeset="CHANGEME"/>
  </modify>
  <delete if-unused="true">
    <node id="5106517631" lon="-74.5367492" lat="40.6633484" version="1" changeset="CHANGEME"/>
  </delete>
</osmChange>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the changeset="CHANGEME" and it looks okay. I'm not 100% sure what programs support reading osmChange for uploads.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, thanks!

changes = history.changes(actionDiscardTags(history.difference())),
data = JXON.stringify(changeset.osmChangeJXON(changes)),
uri = 'data:text/xml,' + encodeURIComponent(data);

var downloadLink = container.selectAll('.download-changes')
.data([0]);

var enter = downloadLink.enter()
.append('a')
.attr('class', 'download-changes')
.attr('href', uri) // no IE11 ?
.attr('download', 'changes.osc') // no IE11 ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard way is with Content-Disposition: attachment; filename="changes.osc" header for downloading content to a file, and I think that works for IE, but I'm not sure what you do when generating a file on the browser to save.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is different in client side javascript, see stack overflow. That's why we are using the download attribute here, which is now finally supported in all modern browsers.

I'm going to test today what happens in IE11, but I think we should be able to fallback to the previous behavior, which is opening a new tab with the data:// uri contents in it (this trick no longer works after Chrome 59, so that's why I had to figure something out quickly - the existing download link on the conflict resolution screen no longer works).

// .attr('target', '_blank') // maybe IE11 ?
.call(svgIcon('#icon-load', 'inline'));

enter
.append('span')
.text(t('commit.download_changes'));

downloadLink
.merge(enter)
.on('click.download', function() {
if (!detected.ie) return; // yes IE11 ?
var win = window.open(uri, '_blank');
win.focus();
});


function mouseover(d) {
if (d.entity) {
context.surface().selectAll(
Expand Down
53 changes: 39 additions & 14 deletions modules/ui/conflicts.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import * as d3 from 'd3';
import { t } from '../util/locale';
import { geoExtent } from '../geo/index';
import { svgIcon } from '../svg/index';
import { utilEntityOrMemberSelector } from '../util/index';
import { JXON } from '../util/jxon';
import { geoExtent } from '../geo';
import { osmChangeset } from '../osm';
import { svgIcon } from '../svg';
import { utilDetect } from '../util/detect';
import { utilEntityOrMemberSelector } from '../util';
import { utilRebind } from '../util/rebind';


export function uiConflicts(context) {
var dispatch = d3.dispatch('download', 'cancel', 'save'),
list;
var dispatch = d3.dispatch('cancel', 'save'),
origChanges,
conflictList;


function conflicts(selection) {
Expand All @@ -30,14 +34,28 @@ export function uiConflicts(context) {
.append('div')
.attr('class', 'body fillL');


// Download changes link
var detected = utilDetect(),
changeset = new osmChangeset({ id: 'CHANGEME' }),
data = JXON.stringify(changeset.osmChangeJXON(origChanges)),
uri = 'data:text/xml,' + encodeURIComponent(data);

body
.append('div')
.attr('class', 'conflicts-help')
.text(t('save.conflict.help'))
.append('a')
.attr('class', 'conflicts-download')
.attr('href', uri) // no IE11 ?
.attr('download', 'changes.osc') // no IE11 ?
// .attr('target', '_blank') // maybe IE11 ?
.text(t('save.conflict.download_changes'))
.on('click.download', function() { dispatch.call('download'); });
.on('click.download', function() {
if (!detected.ie) return; // yes IE11 ?
var win = window.open(uri, '_blank');
win.focus();
});

body
.append('div')
Expand All @@ -57,7 +75,7 @@ export function uiConflicts(context) {

buttons
.append('button')
.attr('disabled', list.length > 1)
.attr('disabled', conflictList.length > 1)
.attr('class', 'action conflicts-button col6')
.text(t('save.title'))
.on('click.try_again', function() { dispatch.call('save'); });
Expand All @@ -71,12 +89,12 @@ export function uiConflicts(context) {


function showConflict(selection, index) {
if (index < 0 || index >= list.length) return;
if (index < 0 || index >= conflictList.length) return;

var parent = d3.select(selection.node().parentNode);

// enable save button if this is the last conflict being reviewed..
if (index === list.length - 1) {
if (index === conflictList.length - 1) {
window.setTimeout(function() {
parent.select('.conflicts-button')
.attr('disabled', null);
Expand All @@ -90,7 +108,7 @@ export function uiConflicts(context) {

var item = selection
.selectAll('.conflict')
.data([list[index]]);
.data([conflictList[index]]);

var enter = item.enter()
.append('div')
Expand All @@ -99,7 +117,7 @@ export function uiConflicts(context) {
enter
.append('h4')
.attr('class', 'conflict-count')
.text(t('save.conflict.count', { num: index + 1, total: list.length }));
.text(t('save.conflict.count', { num: index + 1, total: conflictList.length }));

enter
.append('a')
Expand Down Expand Up @@ -141,7 +159,7 @@ export function uiConflicts(context) {
.attr('class', 'conflict-nav-button action col6')
.attr('disabled', function(d, i) {
return (i === 0 && index === 0) ||
(i === 1 && index === list.length - 1) || null;
(i === 1 && index === conflictList.length - 1) || null;
})
.on('click', function(d, i) {
var container = parent.select('.conflict-container'),
Expand Down Expand Up @@ -252,8 +270,15 @@ export function uiConflicts(context) {
// ]
// }
conflicts.list = function(_) {
if (!arguments.length) return list;
list = _;
if (!arguments.length) return conflictList;
conflictList = _;
return conflicts;
};


conflicts.origChanges = function(_) {
if (!arguments.length) return origChanges;
origChanges = _;
return conflicts;
};

Expand Down