From 8c9aae1499697c7a0e98eab539c4993b279ab7c5 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 14 Sep 2017 17:35:06 -0400 Subject: [PATCH] Add download changes link to uiCommitChanges summary (WIP: still need to check IE11 and fix download on conflict screen) --- css/80_app.css | 1 + data/core.yaml | 1 + dist/locales/en.json | 1 + modules/modes/save.js | 1 + modules/ui/commit_changes.js | 40 +++++++++++++++++++++++++++++++++++- 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/css/80_app.css b/css/80_app.css index e652cbecf..d050ec313 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -3532,6 +3532,7 @@ img.tile-removing { border: 1px solid #ccc; border-radius: 4px; background: #fff; + margin-bottom: 10px; } .mode-save .warning-section { diff --git a/data/core.yaml b/data/core.yaml index 82df21868..797f01354 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -260,6 +260,7 @@ en: save: Upload cancel: Cancel changes: "{count} Changes" + download_changes: Download OsmChange file warnings: Warnings modified: Modified deleted: Deleted diff --git a/dist/locales/en.json b/dist/locales/en.json index 526b80556..63343b1e8 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -334,6 +334,7 @@ "save": "Upload", "cancel": "Cancel", "changes": "{count} Changes", + "download_changes": "Download OsmChange file", "warnings": "Warnings", "modified": "Modified", "deleted": "Deleted", diff --git a/modules/modes/save.js b/modules/modes/save.js index 391fe2f47..e071056c5 100644 --- a/modules/modes/save.js +++ b/modules/modes/save.js @@ -249,6 +249,7 @@ export function modeSave(context) { selection.call(uiConflicts(context) .list(conflicts) .on('download', function() { + // FIXME: var data = JXON.stringify(changeset.update({ id: 'CHANGEME' }).osmChangeJXON(origChanges)), win = window.open('data:text/xml,' + encodeURIComponent(data), '_blank'); win.focus(); diff --git a/modules/ui/commit_changes.js b/modules/ui/commit_changes.js index e47fd81b2..7e7dac177 100644 --- a/modules/ui/commit_changes.js +++ b/modules/ui/commit_changes.js @@ -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, @@ -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]); @@ -85,6 +93,36 @@ export function uiCommitChanges(context) { .on('click', zoomToEntity); + // Download changeset link + var changeset = new osmChangeset({ id: 'CHANGEME' }), + 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 ? + // .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(