From c21310e99a2586e068cac92e19a20f2d0e8e717e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 13 Jan 2020 02:52:17 +0100 Subject: [PATCH 1/2] FEATURE: Make collection export option dynamic Resolves #522 --- Gruntfile.js | 6 +++--- dist/leaflet.distortableimage.js | 18 +++++++++++++++++- src/edit/DistortableCollection.Edit.js | 18 +++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index b2d7e0e13..7e22f70b3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -151,9 +151,9 @@ module.exports = function(grunt) { grunt.registerTask('default', ['karma:development:start', 'watch']); grunt.registerTask('build', [ - 'jshint', - 'karma:development:start', - 'coverage', + // 'jshint', + // 'karma:development:start', + // 'coverage', 'concat:dist', ]); diff --git a/dist/leaflet.distortableimage.js b/dist/leaflet.distortableimage.js index b546b443e..335aec5d6 100644 --- a/dist/leaflet.distortableimage.js +++ b/dist/leaflet.distortableimage.js @@ -3040,6 +3040,10 @@ L.DistortableCollection.Edit = L.Handler.extend({ }, cancelExport: function() { + if (!this.customCollection) { + this._exportOpts.collection = undefined; + } + clearInterval(this.updateInterval); }, @@ -3116,6 +3120,11 @@ L.DistortableCollection.Edit = L.Handler.extend({ if (data.status === 'complete') { clearInterval(self.updateInterval); + + if (!self.customCollection) { + self._exportOpts.collection = undefined; + } + resolve(); if (data.jpg !== null) { alert('Export succeeded. ' + opts.exportUrl + data.jpg); @@ -3158,7 +3167,14 @@ L.DistortableCollection.Edit = L.Handler.extend({ }); } - opts.collection = opts.collection || this._group.generateExportJson(); + // If the user has passed collection property + if (opts.collection) { + self.customCollection = true; + } else { + self.customCollection = false; + opts.collection = this._group.generateExportJson(); + } + opts.frequency = opts.frequency || 3000; opts.scale = opts.scale || 100; // switch it to _getAvgCmPerPixel ! opts.updater = opts.updater || _defaultUpdater; diff --git a/src/edit/DistortableCollection.Edit.js b/src/edit/DistortableCollection.Edit.js index f346245ff..a9e3ab3a7 100644 --- a/src/edit/DistortableCollection.Edit.js +++ b/src/edit/DistortableCollection.Edit.js @@ -199,6 +199,10 @@ L.DistortableCollection.Edit = L.Handler.extend({ }, cancelExport: function() { + if (!this.customCollection) { + this._exportOpts.collection = undefined; + } + clearInterval(this.updateInterval); }, @@ -275,6 +279,11 @@ L.DistortableCollection.Edit = L.Handler.extend({ if (data.status === 'complete') { clearInterval(self.updateInterval); + + if (!self.customCollection) { + self._exportOpts.collection = undefined; + } + resolve(); if (data.jpg !== null) { alert('Export succeeded. ' + opts.exportUrl + data.jpg); @@ -317,7 +326,14 @@ L.DistortableCollection.Edit = L.Handler.extend({ }); } - opts.collection = opts.collection || this._group.generateExportJson(); + // If the user has passed collection property + if (opts.collection) { + self.customCollection = true; + } else { + self.customCollection = false; + opts.collection = this._group.generateExportJson(); + } + opts.frequency = opts.frequency || 3000; opts.scale = opts.scale || 100; // switch it to _getAvgCmPerPixel ! opts.updater = opts.updater || _defaultUpdater; From c7684d9d0ae09aefaa4fce7fb47bf371ec108f60 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 13 Jan 2020 08:10:09 +0100 Subject: [PATCH 2/2] REFACTOR: Minor changes Changes: - New version 0.11.2 - Rollback Gruntfile changes - .images call from JSON.stringify(opts.collection.images) attached to generateExportJson --- Gruntfile.js | 6 +++--- dist/leaflet.distortableimage.js | 4 ++-- package-lock.json | 2 +- package.json | 2 +- src/edit/DistortableCollection.Edit.js | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 7e22f70b3..b2d7e0e13 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -151,9 +151,9 @@ module.exports = function(grunt) { grunt.registerTask('default', ['karma:development:start', 'watch']); grunt.registerTask('build', [ - // 'jshint', - // 'karma:development:start', - // 'coverage', + 'jshint', + 'karma:development:start', + 'coverage', 'concat:dist', ]); diff --git a/dist/leaflet.distortableimage.js b/dist/leaflet.distortableimage.js index 335aec5d6..02e374e8a 100644 --- a/dist/leaflet.distortableimage.js +++ b/dist/leaflet.distortableimage.js @@ -3159,7 +3159,7 @@ L.DistortableCollection.Edit = L.Handler.extend({ crossDomain: true, type: 'POST', data: { - collection: JSON.stringify(opts.collection.images), + collection: JSON.stringify(opts.collection), scale: opts.scale, upload: true, }, @@ -3172,7 +3172,7 @@ L.DistortableCollection.Edit = L.Handler.extend({ self.customCollection = true; } else { self.customCollection = false; - opts.collection = this._group.generateExportJson(); + opts.collection = this._group.generateExportJson().images; } opts.frequency = opts.frequency || 3000; diff --git a/package-lock.json b/package-lock.json index 9239b55a4..ca356187d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "leaflet-distortableimage", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e6f023a19..d42d44f37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leaflet-distortableimage", - "version": "0.11.1", + "version": "0.11.2", "description": "Leaflet plugin enabling image overlays to be distorted, stretched, and warped (built for Public Lab's MapKnitter: http://publiclab.org).", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/src/edit/DistortableCollection.Edit.js b/src/edit/DistortableCollection.Edit.js index a9e3ab3a7..18917155e 100644 --- a/src/edit/DistortableCollection.Edit.js +++ b/src/edit/DistortableCollection.Edit.js @@ -318,7 +318,7 @@ L.DistortableCollection.Edit = L.Handler.extend({ crossDomain: true, type: 'POST', data: { - collection: JSON.stringify(opts.collection.images), + collection: JSON.stringify(opts.collection), scale: opts.scale, upload: true, }, @@ -331,7 +331,7 @@ L.DistortableCollection.Edit = L.Handler.extend({ self.customCollection = true; } else { self.customCollection = false; - opts.collection = this._group.generateExportJson(); + opts.collection = this._group.generateExportJson().images; } opts.frequency = opts.frequency || 3000;