From 960b53229cd5d93ffff4331cc59ebaa7d5708d15 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Tue, 7 May 2019 16:36:40 -0400 Subject: [PATCH 01/33] working on removing changeset error when editing w/ 2 layer in map --- css/80_app.css | 23 ++++++ modules/Hoot/managers/layerManager.js | 1 + modules/Hoot/ui/sidebar/layerAdd.js | 15 +++- modules/Hoot/ui/sidebar/sidebar.js | 73 +++++++++++++++++- modules/services/osm.js | 106 +++++++++++++++++++++----- 5 files changed, 197 insertions(+), 21 deletions(-) diff --git a/css/80_app.css b/css/80_app.css index 037a8d16e6..6827b9db8e 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -334,6 +334,18 @@ button.disabled { border-radius: 4px 0 0 4px; } +.select-active-layer { + width: -webkit-fill-available; + font-weight: bold; +} + +.select-active-button:active, +.select-active-button:focus +.select-active-button:target { + background: #cccccc; + color: #888; +} + /* Action buttons */ button.action { @@ -359,6 +371,17 @@ button[disabled].action:hover { cursor: not-allowed; } +.disable-non-active, +.disable-non-active:hover { + background: #cccccc; + color: #888; + cursor: not-allowed; +} + +.no-click { + pointer-events: none; +} + /* Icons ------------------------------------------------------- */ diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index de02df0a31..3da2b54f03 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -143,6 +143,7 @@ export default class Layers { let layer = { name: params.name, id: params.id, + activeLayer: params.activeLayer, refType: params.refType, color: params.color, merged: params.merged || false, diff --git a/modules/Hoot/ui/sidebar/layerAdd.js b/modules/Hoot/ui/sidebar/layerAdd.js index 9b52f32915..770854f7b4 100644 --- a/modules/Hoot/ui/sidebar/layerAdd.js +++ b/modules/Hoot/ui/sidebar/layerAdd.js @@ -18,7 +18,8 @@ export default class LayerAdd extends SidebarForm { this.selectedLayer = { name: null, - id: null + id: null, + activeLayer: true }; } @@ -201,6 +202,7 @@ export default class LayerAdd extends SidebarForm { name: d ? d.name : this.selectedLayer.name, id: d ? d.id : this.selectedLayer.id, refType: this.formMeta.refType, + activeLayer: d ? this.checkActiveLayers() : this.selectedLayer.activeLayer, color }; @@ -211,6 +213,17 @@ export default class LayerAdd extends SidebarForm { Hoot.events.emit( 'load-layer' ); // return this.checkForReview( layer ); + this.checkActiveLayers(); + } + + checkActiveLayers() { + let activeLayer = this.selectedLayer.activeLayer; + if (this.formMeta.refType === 'secondary') { + activeLayer = false; + } else { + activeLayer = true; + } + return activeLayer; } /** diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index dc49eef8f2..1e31355717 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -126,7 +126,7 @@ export default class Sidebar { form.controller.update(); form.loadingLayerName = null; - + this.saveChanges(); this.conflateCheck(); } } ); @@ -168,6 +168,77 @@ export default class Sidebar { this.adjustSize(); } + saveChanges() { + let loadedLayers = Object.values(Hoot.layers.loadedLayers); + if (loadedLayers.length === 2) { + let selectReference = d3.selectAll('#reference'); + let selectSecondary = d3.selectAll('#secondary'); + let referenceActive = loadedLayers[1]; + let secondaryActive = loadedLayers[0]; + let changeActive = new LayerAdd(); + let referenceState; + let secondaryState; + + selectReference + .append('button') + .classed('select-active-layer', true) + .text('Set as active layer') + .on('click', function() { + d3.selectAll('#secondary div.controller') + .classed('disable-non-active', true); + d3.selectAll('#reference div.controller') + .classed('disable-non-active', false); + d3.selectAll('#secondary button.delete-button') + .classed('disable-non-active', true) + .classed('no-click', true); + d3.selectAll('#reference button.delete-button') + .classed('disable-non-active', false) + .classed('no-click', false); + + referenceState = referenceActive; + + if (secondaryState) { + secondaryState.activeLayer = true; + referenceState.activeLayer = false; + } + else { + referenceState.activeLayer = false; + } + changeActive.selectedLayer = referenceState; + }); + + selectSecondary + .append('button') + .classed('select-active-layer', true) + .text('Set as active layer') + .on('click', function() { + d3.selectAll('#reference div.controller') + .classed('disable-non-active', true); + d3.selectAll('#secondary div.controller') + .classed('disable-non-active', false); + d3.selectAll('#reference button.delete-button') + .classed('disable-non-active', true) + .classed('no-click', true); + d3.selectAll('#secondary button.delete-button') + .classed('disable-non-active', false) + .classed('no-click', false); + + secondaryState = secondaryActive; + + if (referenceState) { + secondaryState.activeLayer = false; + referenceState.activeLayer = true; + } + else { + referenceState.activeLayer = true; + } + + changeActive.selectedLayer = referenceState; + + }); + } + } + conflateCheck() { let loadedLayers = Object.values( Hoot.layers.loadedLayers ), addControllers = d3.selectAll( '.add-controller' ); diff --git a/modules/services/osm.js b/modules/services/osm.js index ae7f135a9a..cf1c3f901a 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -8,6 +8,7 @@ import _flatten from 'lodash-es/flatten'; import _groupBy from 'lodash-es/groupBy'; import _isEmpty from 'lodash-es/isEmpty'; import _map from 'lodash-es/map'; +import _matches from 'lodash-es/matches'; import _throttle from 'lodash-es/throttle'; import _uniq from 'lodash-es/uniq'; import _values from 'lodash-es/values'; @@ -41,6 +42,7 @@ import { } from '../util'; import { baseUrl as hootBaseUrl } from '../Hoot/config/apiConfig'; +import { all } from 'q'; var tiler = utilTiler(); var dispatch = d3_dispatch('authLoading', 'authDone', 'change', 'loading', 'loaded', 'loadedNotes'); @@ -632,14 +634,21 @@ export default { filterChanges: function( changes ) { let ways = _filter( _flatten( _map( changes, featArr => featArr ) ), feat => feat.type !== 'node' ), visLayers = _map( _filter( _values( Hoot.layers.loadedLayers ), layer => layer.visible ), layer => layer.id ), - defaultMapId; + primaryMapId, + secondaryMapId; // Make sure there is only one layer visible. Otherwise, return a falsy value to prevent save. if (visLayers.length === 1 || changes.created.length === 0){ - defaultMapId = visLayers[0]; - } else { + primaryMapId = visLayers[0]; + } + else { return false; } + if (visLayers.length === 2) { + secondaryMapId = visLayers[1]; + return ({ message: 'Select layer for saving chagnes', status: -2 }, secondaryMapId); + + } return _reduce( changes, ( obj, featArr, type ) => { let changeTypes = { @@ -649,7 +658,30 @@ export default { }; _forEach( featArr, feat => { - let mapId = defaultMapId; + if (visLayers.length === 2) { + let allIds = [primaryMapId, secondaryMapId]; + for (let i = 0; i < allIds.length; i++) { + if ( feat.isNew() && feat.type === 'node' ) { + let parent = _find( ways, way => _includes( way.nodes, feat.id ) ); + if ( parent && parent.mapId ) { + allIds[i] = parent.mapId; + } + } + // create map ID key if not yet exists + if ( !obj[ allIds[i] ] ) { + obj[ allIds[i] ] = {}; + } + // create change type key if not yet exists + if ( !obj[ allIds[i] ][ type ] ) { + obj[ allIds[i] ][ type ] = []; + } + // merge object into default types array so that the final result + // will contain all keys in case change type is empty + obj[ allIds[i] ] = Object.assign( changeTypes, obj[ allIds[i] ] ); + } + } + else { + let mapId = primaryMapId; if ( feat.isNew() && feat.type === 'node' ) { let parent = _find( ways, way => _includes( way.nodes, feat.id ) ); @@ -674,8 +706,8 @@ export default { // merge object into default types array so that the final result // will contain all keys in case change type is empty obj[ mapId ] = Object.assign( changeTypes, obj[ mapId ] ); + } } ); - return obj; }, {} ); }, @@ -696,21 +728,57 @@ export default { return createdChangeset.call(this, null, _changeset.open); } else { // Open a new changeset.. - _forEach( changesArr, ( changes, mapId ) => { - let path = '/api/0.6/changeset/create'; - path += mapId ? `?mapId=${ mapId }` : ''; + if ( Object.keys(Hoot.layers.loadedLayers).length === 2 ) { + let allLayers = _map( _filter( _values( Hoot.layers.loadedLayers ), layer => layer.visible ), layer => layer.id ); + console.log(allLayers); + console.log(changesArr); + //let mapId = [allLayers[0], allLayers[1]]; + _map( _forEach( changesArr === allLayers), layer => { + let path = '/api/0.6/changeset/create'; + path += layer ? `?mapId=${layer}` : ''; + var options = { + method: 'PUT', + path: path, + options: { header: { 'Content-Type': 'text/xml' } }, + content: JXON.stringify(changeset.asJXON()) + }; + _changeset.inflight = oauth.xhr( + options, + wrapcb(this, createdChangeset, cid, layer) + ); + }); + // _forEach( changesArr, (changes, allLayers) => { + // let path = '/api/0.6/changeset/create'; + // path += allLayers++ ? `?mapId=${allLayers++}` : ''; + // var options = { + // method: 'PUT', + // path: path, + // options: { header: { 'Content-Type': 'text/xml' } }, + // content: JXON.stringify(changeset.asJXON()) + // }; + // _changeset.inflight = oauth.xhr( + // options, + // wrapcb(this, createdChangeset, cid, allLayers++) + // ); + // }); + } else { + _forEach( changesArr, ( changes, mapId ) => { + let path = '/api/0.6/changeset/create'; + path += mapId ? `?mapId=${ mapId }` : ''; + + var options = { + method: 'PUT', + path: path, + options: { header: { 'Content-Type': 'text/xml' } }, + content: JXON.stringify(changeset.asJXON()) + }; + _changeset.inflight = oauth.xhr( + options, + wrapcb(this, createdChangeset, cid, mapId) + ); + } ); + } - var options = { - method: 'PUT', - path: path, - options: { header: { 'Content-Type': 'text/xml' } }, - content: JXON.stringify(changeset.asJXON()) - }; - _changeset.inflight = oauth.xhr( - options, - wrapcb(this, createdChangeset, cid, mapId) - ); - } ); } From eb95c0b9082eac703125482805ef3761494423c6 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Wed, 8 May 2019 13:39:05 -0400 Subject: [PATCH 02/33] can create new &/or edit existing features then save to selected layer --- css/80_app.css | 48 ++++++++++++++--- modules/Hoot/ui/sidebar/layerAdd.js | 2 +- modules/Hoot/ui/sidebar/sidebar.js | 60 +++++++++++++++++---- modules/services/osm.js | 81 ++++------------------------- 4 files changed, 101 insertions(+), 90 deletions(-) diff --git a/css/80_app.css b/css/80_app.css index 6827b9db8e..74f1fbaf46 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -339,13 +339,10 @@ button.disabled { font-weight: bold; } -.select-active-button:active, -.select-active-button:focus -.select-active-button:target { - background: #cccccc; - color: #888; -} +.button-active { + background: #e6e3e3; +} /* Action buttons */ button.action { @@ -373,11 +370,46 @@ button[disabled].action:hover { .disable-non-active, .disable-non-active:hover { - background: #cccccc; - color: #888; cursor: not-allowed; } +.active-pulse { + border-radius: 50%; + background: #cccccc; + cursor: pointer; + box-shadow: 0 0 0 rgba(136,136,136, 0.4); + animation: active-pulse 2.5s infinite; + } + .active-pulse:hover { + animation: none; + } + + @-webkit-keyframes active-pulse { + 0% { + -webkit-box-shadow: 0 0 0 0 rgba(136,136,136, 0.4); + } + 70% { + -webkit-box-shadow: 0 0 0 10px rgba(136,136,136, 0); + } + 100% { + -webkit-box-shadow: 0 0 0 0 rgba(136,136,136, 0); + } + } + @keyframes active-pulse { + 0% { + -moz-box-shadow: 0 0 0 0 rgba(136,136,136, 0.4); + box-shadow: 0 0 0 0 rgba(136,136,136, 0.4); + } + 70% { + -moz-box-shadow: 0 0 0 10px rgba(136,136,136, 0); + box-shadow: 0 0 0 10px rgba(136,136,136, 0); + } + 100% { + -moz-box-shadow: 0 0 0 0 rgba(136,136,136, 0); + box-shadow: 0 0 0 0 rgba(136,136,136, 0); + } + } + .no-click { pointer-events: none; } diff --git a/modules/Hoot/ui/sidebar/layerAdd.js b/modules/Hoot/ui/sidebar/layerAdd.js index 770854f7b4..d2d54f1ce2 100644 --- a/modules/Hoot/ui/sidebar/layerAdd.js +++ b/modules/Hoot/ui/sidebar/layerAdd.js @@ -19,7 +19,7 @@ export default class LayerAdd extends SidebarForm { this.selectedLayer = { name: null, id: null, - activeLayer: true + activeLayer: null }; } diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index 1e31355717..1eff6fa2e9 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -15,6 +15,7 @@ import { utilQsString, utilStringQs } from '../../../util'; +import { diff3MergeIndices } from 'node-diff3'; /** * Create the sidebar @@ -173,8 +174,8 @@ export default class Sidebar { if (loadedLayers.length === 2) { let selectReference = d3.selectAll('#reference'); let selectSecondary = d3.selectAll('#secondary'); - let referenceActive = loadedLayers[1]; - let secondaryActive = loadedLayers[0]; + let referenceActive = loadedLayers[0]; + let secondaryActive = loadedLayers[1]; let changeActive = new LayerAdd(); let referenceState; let secondaryState; @@ -184,25 +185,46 @@ export default class Sidebar { .classed('select-active-layer', true) .text('Set as active layer') .on('click', function() { + + d3.event.preventDefault(); + + d3.select('#reference') + .classed('active-pulse', true); + + d3.select('#secondary') + .classed('active-pulse', false); + + d3.select('#reference button.select-active-layer') + .text('Active Layer') + .classed('button-active', true); + + d3.select('#secondary button.select-active-layer') + .text('Set as active layer') + .classed('button-active', false); + d3.selectAll('#secondary div.controller') .classed('disable-non-active', true); + d3.selectAll('#reference div.controller') .classed('disable-non-active', false); + d3.selectAll('#secondary button.delete-button') .classed('disable-non-active', true) .classed('no-click', true); + d3.selectAll('#reference button.delete-button') .classed('disable-non-active', false) .classed('no-click', false); + referenceState = referenceActive; if (secondaryState) { - secondaryState.activeLayer = true; - referenceState.activeLayer = false; + secondaryState.activeLayer = false; + referenceState.activeLayer = true; } else { - referenceState.activeLayer = false; + referenceState.activeLayer = true; } changeActive.selectedLayer = referenceState; }); @@ -212,13 +234,33 @@ export default class Sidebar { .classed('select-active-layer', true) .text('Set as active layer') .on('click', function() { + + d3.event.preventDefault(); + + d3.select('#secondary') + .classed('active-pulse', true); + + d3.select('#reference') + .classed('active-pulse', false); + + d3.select('#secondary button.select-active-layer') + .text('Active Layer') + .classed('button-active', true); + + d3.select('#reference button.select-active-layer') + .text('Set as active layer') + .classed('button-active', false); + d3.selectAll('#reference div.controller') .classed('disable-non-active', true); + d3.selectAll('#secondary div.controller') .classed('disable-non-active', false); + d3.selectAll('#reference button.delete-button') .classed('disable-non-active', true) .classed('no-click', true); + d3.selectAll('#secondary button.delete-button') .classed('disable-non-active', false) .classed('no-click', false); @@ -226,14 +268,14 @@ export default class Sidebar { secondaryState = secondaryActive; if (referenceState) { - secondaryState.activeLayer = false; - referenceState.activeLayer = true; + secondaryState.activeLayer = true; + referenceState.activeLayer = false; } else { - referenceState.activeLayer = true; + secondaryState.activeLayer = true; } - changeActive.selectedLayer = referenceState; + changeActive.selectedLayer = secondaryState; }); } diff --git a/modules/services/osm.js b/modules/services/osm.js index cf1c3f901a..a50a09cae6 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -633,22 +633,20 @@ export default { filterChanges: function( changes ) { let ways = _filter( _flatten( _map( changes, featArr => featArr ) ), feat => feat.type !== 'node' ), - visLayers = _map( _filter( _values( Hoot.layers.loadedLayers ), layer => layer.visible ), layer => layer.id ), - primaryMapId, - secondaryMapId; + checkLayers = Hoot.layers.loadedLayers, + visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), + activeLayer = _find(checkLayers, function(a, b) { return a.activeLayer === true ? a : null; }), + defaultMapId; // Make sure there is only one layer visible. Otherwise, return a falsy value to prevent save. if (visLayers.length === 1 || changes.created.length === 0){ - primaryMapId = visLayers[0]; + defaultMapId = activeLayer.id; } - else { + else if (visLayers.length === 2) { + defaultMapId = activeLayer.id; + } else { return false; } - if (visLayers.length === 2) { - secondaryMapId = visLayers[1]; - return ({ message: 'Select layer for saving chagnes', status: -2 }, secondaryMapId); - - } return _reduce( changes, ( obj, featArr, type ) => { let changeTypes = { @@ -658,30 +656,7 @@ export default { }; _forEach( featArr, feat => { - if (visLayers.length === 2) { - let allIds = [primaryMapId, secondaryMapId]; - for (let i = 0; i < allIds.length; i++) { - if ( feat.isNew() && feat.type === 'node' ) { - let parent = _find( ways, way => _includes( way.nodes, feat.id ) ); - if ( parent && parent.mapId ) { - allIds[i] = parent.mapId; - } - } - // create map ID key if not yet exists - if ( !obj[ allIds[i] ] ) { - obj[ allIds[i] ] = {}; - } - // create change type key if not yet exists - if ( !obj[ allIds[i] ][ type ] ) { - obj[ allIds[i] ][ type ] = []; - } - // merge object into default types array so that the final result - // will contain all keys in case change type is empty - obj[ allIds[i] ] = Object.assign( changeTypes, obj[ allIds[i] ] ); - } - } - else { - let mapId = primaryMapId; + let mapId = defaultMapId; if ( feat.isNew() && feat.type === 'node' ) { let parent = _find( ways, way => _includes( way.nodes, feat.id ) ); @@ -706,7 +681,6 @@ export default { // merge object into default types array so that the final result // will contain all keys in case change type is empty obj[ mapId ] = Object.assign( changeTypes, obj[ mapId ] ); - } } ); return obj; }, {} ); @@ -728,40 +702,6 @@ export default { return createdChangeset.call(this, null, _changeset.open); } else { // Open a new changeset.. - if ( Object.keys(Hoot.layers.loadedLayers).length === 2 ) { - let allLayers = _map( _filter( _values( Hoot.layers.loadedLayers ), layer => layer.visible ), layer => layer.id ); - console.log(allLayers); - console.log(changesArr); - //let mapId = [allLayers[0], allLayers[1]]; - _map( _forEach( changesArr === allLayers), layer => { - let path = '/api/0.6/changeset/create'; - path += layer ? `?mapId=${layer}` : ''; - var options = { - method: 'PUT', - path: path, - options: { header: { 'Content-Type': 'text/xml' } }, - content: JXON.stringify(changeset.asJXON()) - }; - _changeset.inflight = oauth.xhr( - options, - wrapcb(this, createdChangeset, cid, layer) - ); - }); - // _forEach( changesArr, (changes, allLayers) => { - // let path = '/api/0.6/changeset/create'; - // path += allLayers++ ? `?mapId=${allLayers++}` : ''; - // var options = { - // method: 'PUT', - // path: path, - // options: { header: { 'Content-Type': 'text/xml' } }, - // content: JXON.stringify(changeset.asJXON()) - // }; - // _changeset.inflight = oauth.xhr( - // options, - // wrapcb(this, createdChangeset, cid, allLayers++) - // ); - // }); - } else { _forEach( changesArr, ( changes, mapId ) => { let path = '/api/0.6/changeset/create'; path += mapId ? `?mapId=${ mapId }` : ''; @@ -777,11 +717,8 @@ export default { wrapcb(this, createdChangeset, cid, mapId) ); } ); - } - } - function createdChangeset(err, changesetID, mapId) { _changeset.inflight = null; if (err) { return callback(err, changeset); } From ce6f3cfb75b61da1a7bb982acd66ceea656db878 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Wed, 8 May 2019 15:16:18 -0400 Subject: [PATCH 03/33] updated to account for deleting and adding new layers to map --- modules/Hoot/ui/sidebar/sidebar.js | 152 +++++++++++++++-------------- 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index 1eff6fa2e9..e816d5c200 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -171,113 +171,117 @@ export default class Sidebar { saveChanges() { let loadedLayers = Object.values(Hoot.layers.loadedLayers); + let selectReference = d3.selectAll('#reference'); + let selectSecondary = d3.selectAll('#secondary'); if (loadedLayers.length === 2) { - let selectReference = d3.selectAll('#reference'); - let selectSecondary = d3.selectAll('#secondary'); let referenceActive = loadedLayers[0]; let secondaryActive = loadedLayers[1]; let changeActive = new LayerAdd(); let referenceState; let secondaryState; - selectReference - .append('button') - .classed('select-active-layer', true) - .text('Set as active layer') - .on('click', function() { - d3.event.preventDefault(); + if (d3.select('#reference button.select-active-layer').empty()) { + selectReference + .append('button') + .classed('select-active-layer', true) + .text('Set as active layer') + .on('click', function () { - d3.select('#reference') - .classed('active-pulse', true); + d3.event.preventDefault(); - d3.select('#secondary') - .classed('active-pulse', false); + d3.select('#reference') + .classed('active-pulse', true); - d3.select('#reference button.select-active-layer') - .text('Active Layer') - .classed('button-active', true); + d3.select('#secondary') + .classed('active-pulse', false); - d3.select('#secondary button.select-active-layer') - .text('Set as active layer') - .classed('button-active', false); + d3.select('#reference button.select-active-layer') + .text('Active Layer') + .classed('button-active', true); - d3.selectAll('#secondary div.controller') - .classed('disable-non-active', true); + d3.select('#secondary button.select-active-layer') + .text('Set as active layer') + .classed('button-active', false); - d3.selectAll('#reference div.controller') - .classed('disable-non-active', false); + d3.selectAll('#secondary div.controller') + .classed('disable-non-active', true); - d3.selectAll('#secondary button.delete-button') - .classed('disable-non-active', true) - .classed('no-click', true); + d3.selectAll('#reference div.controller') + .classed('disable-non-active', false); - d3.selectAll('#reference button.delete-button') - .classed('disable-non-active', false) - .classed('no-click', false); + d3.selectAll('#secondary button.delete-button') + .classed('disable-non-active', true) + .classed('no-click', true); + d3.selectAll('#reference button.delete-button') + .classed('disable-non-active', false) + .classed('no-click', false); - referenceState = referenceActive; - if (secondaryState) { - secondaryState.activeLayer = false; - referenceState.activeLayer = true; - } - else { - referenceState.activeLayer = true; - } - changeActive.selectedLayer = referenceState; - }); + referenceState = referenceActive; - selectSecondary - .append('button') - .classed('select-active-layer', true) - .text('Set as active layer') - .on('click', function() { + if (secondaryState) { + secondaryState.activeLayer = false; + referenceState.activeLayer = true; + } + else { + referenceState.activeLayer = true; + } + changeActive.selectedLayer = referenceState; + }); + } - d3.event.preventDefault(); + if (d3.select('#secondary button.select-active-layer').empty()) { + selectSecondary + .append('button') + .classed('select-active-layer', true) + .text('Set as active layer') + .on('click', function () { - d3.select('#secondary') - .classed('active-pulse', true); + d3.event.preventDefault(); + d3.select('#secondary') + .classed('active-pulse', true); - d3.select('#reference') - .classed('active-pulse', false); + d3.select('#reference') + .classed('active-pulse', false); - d3.select('#secondary button.select-active-layer') - .text('Active Layer') - .classed('button-active', true); + d3.select('#secondary button.select-active-layer') + .text('Active Layer') + .classed('button-active', true); - d3.select('#reference button.select-active-layer') - .text('Set as active layer') - .classed('button-active', false); + d3.select('#reference button.select-active-layer') + .text('Set as active layer') + .classed('button-active', false); - d3.selectAll('#reference div.controller') - .classed('disable-non-active', true); + d3.selectAll('#reference div.controller') + .classed('disable-non-active', true); - d3.selectAll('#secondary div.controller') - .classed('disable-non-active', false); + d3.selectAll('#secondary div.controller') + .classed('disable-non-active', false); - d3.selectAll('#reference button.delete-button') - .classed('disable-non-active', true) - .classed('no-click', true); + d3.selectAll('#reference button.delete-button') + .classed('disable-non-active', true) + .classed('no-click', true); - d3.selectAll('#secondary button.delete-button') - .classed('disable-non-active', false) - .classed('no-click', false); + d3.selectAll('#secondary button.delete-button') + .classed('disable-non-active', false) + .classed('no-click', false); - secondaryState = secondaryActive; + secondaryState = secondaryActive; - if (referenceState) { - secondaryState.activeLayer = true; - referenceState.activeLayer = false; - } - else { - secondaryState.activeLayer = true; - } + if (referenceState) { + secondaryState.activeLayer = true; + referenceState.activeLayer = false; + } + else { + secondaryState.activeLayer = true; + } - changeActive.selectedLayer = secondaryState; + changeActive.selectedLayer = secondaryState; - }); + }); + } } } From 8d9ab103fb72365accf113db5af5282432d65f29 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 13 May 2019 10:10:40 -0400 Subject: [PATCH 04/33] working on suppressing drawing for non-active layer --- modules/Hoot/ui/sidebar/layerAdd.js | 4 ++-- modules/Hoot/ui/sidebar/sidebar.js | 6 ++--- modules/behavior/draw.js | 34 ++++++++++++++++++++--------- modules/services/osm.js | 2 +- modules/ui/raw_membership_editor.js | 2 -- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/modules/Hoot/ui/sidebar/layerAdd.js b/modules/Hoot/ui/sidebar/layerAdd.js index d2d54f1ce2..881422d942 100644 --- a/modules/Hoot/ui/sidebar/layerAdd.js +++ b/modules/Hoot/ui/sidebar/layerAdd.js @@ -202,7 +202,7 @@ export default class LayerAdd extends SidebarForm { name: d ? d.name : this.selectedLayer.name, id: d ? d.id : this.selectedLayer.id, refType: this.formMeta.refType, - activeLayer: d ? this.checkActiveLayers() : this.selectedLayer.activeLayer, + activeLayer: d ? d.activeLayer : this.selectedLayer.activeLayer, color }; @@ -213,7 +213,7 @@ export default class LayerAdd extends SidebarForm { Hoot.events.emit( 'load-layer' ); // return this.checkForReview( layer ); - this.checkActiveLayers(); + //this.checkActiveLayers(); } checkActiveLayers() { diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index e816d5c200..651db7d991 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -222,11 +222,11 @@ export default class Sidebar { referenceState = referenceActive; if (secondaryState) { - secondaryState.activeLayer = false; - referenceState.activeLayer = true; + secondaryState.activeLayer = false; + referenceState.activeLayer = true; } else { - referenceState.activeLayer = true; + referenceState.activeLayer = true; } changeActive.selectedLayer = referenceState; }); diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index 3081d21534..9653523664 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -12,13 +12,13 @@ import { behaviorHover } from './hover'; import { behaviorTail } from './tail'; import { geoChooseEdge, geoVecLength } from '../geo'; import { utilKeybinding, utilRebind } from '../util'; +import _find from 'lodash-es/find'; var _usedTails = {}; var _disableSpace = false; var _lastSpace = null; - export function behaviorDraw(context) { var dispatch = d3_dispatch( 'move', 'click', 'clickWay', 'clickNode', 'undo', 'cancel', 'finish' @@ -124,19 +124,33 @@ export function behaviorDraw(context) { function click() { var d = datum(); var target = d && d.properties && d.properties.entity; + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true ? a : null; }); if (target && target.type === 'node') { // Snap to a node - dispatch.call('clickNode', this, target, d); - return; + if (_activeLayer.id === Number(target.mapId)) { + console.log(target.name + ' (' + target.id + ')' + ' is an active layer' ); + dispatch.call('clickNode', this, target, d); + return; + } else { + return ({ message: 'Selected layer is not active', status: -2 }, target.name); + } + // dispatch.call('clickNode', this, target, d); + // return; } else if (target && target.type === 'way') { // Snap to a way - var choice = geoChooseEdge( - context.childNodes(target), context.mouse(), context.projection, context.activeID() - ); - if (choice) { - var edge = [target.nodes[choice.index - 1], target.nodes[choice.index]]; - dispatch.call('clickWay', this, choice.loc, edge, d); - return; + // eslint-disable-next-line radix + if (_activeLayer.id === Number(target.mapId)) { + console.log(target.id + ' is an active layer' ); + var choice = geoChooseEdge( + context.childNodes(target), context.mouse(), context.projection, context.activeID() + ); + if (choice) { + var edge = [target.nodes[choice.index - 1], target.nodes[choice.index]]; + dispatch.call('clickWay', this, choice.loc, edge, d); + return; + } + } else { + return ({ message: 'Selected layer is not active', status: -2 }, target.name); } } dispatch.call('click', this, context.map().mouseCoordinates(), d); diff --git a/modules/services/osm.js b/modules/services/osm.js index a50a09cae6..c1ab7d0bf6 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -634,7 +634,7 @@ export default { filterChanges: function( changes ) { let ways = _filter( _flatten( _map( changes, featArr => featArr ) ), feat => feat.type !== 'node' ), checkLayers = Hoot.layers.loadedLayers, - visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), + visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), activeLayer = _find(checkLayers, function(a, b) { return a.activeLayer === true ? a : null; }), defaultMapId; diff --git a/modules/ui/raw_membership_editor.js b/modules/ui/raw_membership_editor.js index be2b8b3a2a..d0ae3ad254 100644 --- a/modules/ui/raw_membership_editor.js +++ b/modules/ui/raw_membership_editor.js @@ -25,13 +25,11 @@ import { svgIcon } from '../svg'; import { uiDisclosure } from './disclosure'; import { utilDisplayName, utilNoAuto, utilHighlightEntity } from '../util'; - export function uiRawMembershipEditor(context) { var taginfo = services.taginfo; var _entityID; var _showBlank; - function selectRelation(d) { d3_event.preventDefault(); From fac292550709a552f4c3f9deef1005919424d9e8 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Mon, 13 May 2019 10:26:58 -0400 Subject: [PATCH 05/33] comments... ref #1425 --- modules/behavior/draw.js | 2 ++ modules/behavior/draw_way.js | 1 + modules/behavior/hover.js | 1 + 3 files changed, 4 insertions(+) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index 9653523664..36a515ca55 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -126,6 +126,8 @@ export function behaviorDraw(context) { var target = d && d.properties && d.properties.entity; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true ? a : null; }); + // for each if/elseif statment add boolean (is _activeLayer===target.mapId)... + if (target && target.type === 'node') { // Snap to a node if (_activeLayer.id === Number(target.mapId)) { console.log(target.name + ' (' + target.id + ')' + ' is an active layer' ); diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index e99da7b326..423a5a05d3 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -73,6 +73,7 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { function move(datum) { context.surface().classed('nope-disabled', d3_event.altKey); + // add one more boolean at end, is activeLayer===mapId var targetLoc = datum && datum.properties && datum.properties.entity && datum.properties.entity.loc; var targetNodes = datum && datum.properties && datum.properties.nodes; var loc = context.map().mouseCoordinates(); diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index b7bd503de4..ecf5e078de 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -140,6 +140,7 @@ export function behaviorHover(context) { return; } + // again, boolean, is entity.mapId === activeLayerId... var suppressed = _altDisables && d3_event && d3_event.altKey; _selection.selectAll(selector) .classed(suppressed ? 'hover-suppressed' : 'hover', true); From 14cf7f2d534104654cbac2ed36ee5e02664e96bf Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Fri, 17 May 2019 10:37:45 -0400 Subject: [PATCH 06/33] working on inflight error --- modules/Hoot/managers/api.js | 26 ++++++++++++++++++++++++ modules/Hoot/managers/layerManager.js | 9 ++++++--- modules/Hoot/ui/sidebar/layerAdd.js | 16 ++++----------- modules/Hoot/ui/sidebar/sidebar.js | 6 +++--- modules/behavior/draw.js | 15 +++----------- modules/behavior/draw_way.js | 4 +++- modules/osm/entity.js | 29 ++++++++++++++++++--------- modules/services/osm.js | 2 +- 8 files changed, 66 insertions(+), 41 deletions(-) diff --git a/modules/Hoot/managers/api.js b/modules/Hoot/managers/api.js index 8baef83c1b..00a3e28abe 100644 --- a/modules/Hoot/managers/api.js +++ b/modules/Hoot/managers/api.js @@ -327,6 +327,32 @@ export default class API { } ); } + + /** + * Get all id's necessary to create new map features + * + * @param {Promise|array} mapId + changesetId, nodeId, wayId, relationId + */ + getAllIds( mapId ) { + const params = { + path: `/osm/api/0.6/map/${ mapId }/startingIndex`, + method: 'GET' + }; + + return this.request( params ) + .then( resp => { + + let activeIds = {}; + activeIds = resp.data; + return activeIds; + } ) + .catch( err => { + const message = this.internalError( err ) || 'Unable to retrieve all map ids'; + + return Promise.reject( message ); + } ); + } + /** * Get all layer links from the database * diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index 3da2b54f03..bcd975ee05 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -39,6 +39,7 @@ export default class Layers { this.allLayers = []; this.loadedLayers = {}; this.hashLayers = {}; + this.allIds = {}; this.recentlyUsedLayers = null; this.mergedLayer = null; this.mergedConflicts = null; @@ -136,14 +137,16 @@ export default class Layers { async loadLayer( params ) { try { - let mapId = params.id, - tags = await this.hoot.api.getMapTags( mapId ), - layerExtent = await this.layerExtent( mapId ); + let mapId = params.id, + tags = await this.hoot.api.getMapTags( mapId ), + layerExtent = await this.layerExtent( mapId ), + activeIds = await Hoot.api.getAllIds( mapId ); let layer = { name: params.name, id: params.id, activeLayer: params.activeLayer, + activeIds: activeIds, refType: params.refType, color: params.color, merged: params.merged || false, diff --git a/modules/Hoot/ui/sidebar/layerAdd.js b/modules/Hoot/ui/sidebar/layerAdd.js index 881422d942..a13e1eb876 100644 --- a/modules/Hoot/ui/sidebar/layerAdd.js +++ b/modules/Hoot/ui/sidebar/layerAdd.js @@ -6,6 +6,7 @@ import _map from 'lodash-es/map'; import _reject from 'lodash-es/reject'; +import _find from 'lodash-es/find'; import FolderTree from '../../tools/folderTree'; import SidebarForm from './sidebarForm'; @@ -19,7 +20,8 @@ export default class LayerAdd extends SidebarForm { this.selectedLayer = { name: null, id: null, - activeLayer: null + activeLayer: null, + activeIds: null }; } @@ -203,6 +205,7 @@ export default class LayerAdd extends SidebarForm { id: d ? d.id : this.selectedLayer.id, refType: this.formMeta.refType, activeLayer: d ? d.activeLayer : this.selectedLayer.activeLayer, + activeIds: d ? d.activeIds : this.selectedLayer.activeIds, color }; @@ -213,17 +216,6 @@ export default class LayerAdd extends SidebarForm { Hoot.events.emit( 'load-layer' ); // return this.checkForReview( layer ); - //this.checkActiveLayers(); - } - - checkActiveLayers() { - let activeLayer = this.selectedLayer.activeLayer; - if (this.formMeta.refType === 'secondary') { - activeLayer = false; - } else { - activeLayer = true; - } - return activeLayer; } /** diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index 651db7d991..0175a5b193 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -170,13 +170,13 @@ export default class Sidebar { } saveChanges() { - let loadedLayers = Object.values(Hoot.layers.loadedLayers); + let loadedLayers = Object.values(Hoot.layers.loadedLayers); let selectReference = d3.selectAll('#reference'); let selectSecondary = d3.selectAll('#secondary'); if (loadedLayers.length === 2) { let referenceActive = loadedLayers[0]; let secondaryActive = loadedLayers[1]; - let changeActive = new LayerAdd(); + let changeActive = new LayerAdd(); let referenceState; let secondaryState; @@ -271,8 +271,8 @@ export default class Sidebar { secondaryState = secondaryActive; if (referenceState) { - secondaryState.activeLayer = true; referenceState.activeLayer = false; + secondaryState.activeLayer = true; } else { secondaryState.activeLayer = true; diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index 36a515ca55..792c10ecd0 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -124,24 +124,18 @@ export function behaviorDraw(context) { function click() { var d = datum(); var target = d && d.properties && d.properties.entity; - var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true ? a : null; }); + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); // for each if/elseif statment add boolean (is _activeLayer===target.mapId)... - if (target && target.type === 'node') { // Snap to a node - if (_activeLayer.id === Number(target.mapId)) { + if (target && target.type === 'node' && _activeLayer.id === Number(target.mapId)) { // Snap to a node console.log(target.name + ' (' + target.id + ')' + ' is an active layer' ); dispatch.call('clickNode', this, target, d); return; - } else { - return ({ message: 'Selected layer is not active', status: -2 }, target.name); - } // dispatch.call('clickNode', this, target, d); // return; - } else if (target && target.type === 'way') { // Snap to a way - // eslint-disable-next-line radix - if (_activeLayer.id === Number(target.mapId)) { + } else if (target && target.type === 'way' && _activeLayer.id === Number(target.mapId)) { // Snap to a way console.log(target.id + ' is an active layer' ); var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() @@ -151,9 +145,6 @@ export function behaviorDraw(context) { dispatch.call('clickWay', this, choice.loc, edge, d); return; } - } else { - return ({ message: 'Selected layer is not active', status: -2 }, target.name); - } } dispatch.call('click', this, context.map().mouseCoordinates(), d); } diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 423a5a05d3..42e71132c7 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -16,6 +16,7 @@ import { geoChooseEdge, geoHasSelfIntersections } from '../geo'; import { modeBrowse, modeSelect } from '../modes'; import { osmNode } from '../osm'; import { utilKeybinding } from '../util'; +import _find from 'lodash-es/find'; export function behaviorDrawWay(context, wayId, index, mode, startGraph) { @@ -73,7 +74,8 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { function move(datum) { context.surface().classed('nope-disabled', d3_event.altKey); - // add one more boolean at end, is activeLayer===mapId + // add one more boolean at end, is activeLayer===mapId + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); var targetLoc = datum && datum.properties && datum.properties.entity && datum.properties.entity.loc; var targetNodes = datum && datum.properties && datum.properties.nodes; var loc = context.map().mouseCoordinates(); diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 8a4e031f9c..62ee036a36 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -3,40 +3,51 @@ import _keys from 'lodash-es/keys'; import _toPairs from 'lodash-es/toPairs'; import _union from 'lodash-es/union'; import _without from 'lodash-es/without'; +import _find from 'lodash-es/find'; import { debug } from '../index'; import { osmIsInterestingTag } from './tags'; import { dataDeprecated } from '../../data/index'; - export function osmEntity(attrs) { // For prototypal inheritance. if (this instanceof osmEntity) return; // Create the appropriate subtype. if (attrs && attrs.type) { - return osmEntity[attrs.type].apply(this, arguments); - } else if (attrs && attrs.id) { - return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments); - } + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); + if (_activeLayer && _activeLayer.id) { + console.log(attrs); + console.log(attrs.id); + //attrs.id = attrs.id + '_' + _activeLayer.id; + return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments); + } else { + return osmEntity[attrs.type].apply(this, arguments); + } + } // Initialize a generic Entity (used only in tests). return (new osmEntity()).initialize(arguments); } - osmEntity.id = function(type) { - return osmEntity.id.fromOSM(type, osmEntity.id.next[type]--); + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); + let allIds = {}; + allIds = _activeLayer.activeIds; + var id = osmEntity.id.fromOSM(type, allIds[type]--); + if (_activeLayer && _activeLayer.id) { + id = id + '_' + _activeLayer.id; + } + return id; }; - osmEntity.id.next = { changeset: -1, node: -1, way: -1, relation: -1 }; osmEntity.id.fromOSM = function(type, id) { - return type[0] + id; + return type[0] + id; }; diff --git a/modules/services/osm.js b/modules/services/osm.js index c1ab7d0bf6..c7debc498b 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -635,7 +635,7 @@ export default { let ways = _filter( _flatten( _map( changes, featArr => featArr ) ), feat => feat.type !== 'node' ), checkLayers = Hoot.layers.loadedLayers, visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), - activeLayer = _find(checkLayers, function(a, b) { return a.activeLayer === true ? a : null; }), + activeLayer = _find(checkLayers, function(a, b) { return a.activeLayer === true; }), defaultMapId; // Make sure there is only one layer visible. Otherwise, return a falsy value to prevent save. From 70c4f1d303ba5442631284d56564816cbb8eb2a2 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Tue, 21 May 2019 15:07:43 -0400 Subject: [PATCH 07/33] can now add or edit layers /w 2 in map when proper active layer selected --- modules/Hoot/managers/api.js | 7 +----- modules/Hoot/managers/layerManager.js | 2 +- modules/Hoot/ui/sidebar/sidebar.js | 32 +++++++++++---------------- modules/behavior/draw.js | 10 ++------- modules/behavior/draw_way.js | 17 +++++++++----- modules/osm/entity.js | 14 ++++-------- 6 files changed, 33 insertions(+), 49 deletions(-) diff --git a/modules/Hoot/managers/api.js b/modules/Hoot/managers/api.js index 00a3e28abe..739e8d7ebf 100644 --- a/modules/Hoot/managers/api.js +++ b/modules/Hoot/managers/api.js @@ -340,12 +340,7 @@ export default class API { }; return this.request( params ) - .then( resp => { - - let activeIds = {}; - activeIds = resp.data; - return activeIds; - } ) + .then( resp => resp.data ) .catch( err => { const message = this.internalError( err ) || 'Unable to retrieve all map ids'; diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index bcd975ee05..93cf5c548a 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -145,7 +145,7 @@ export default class Layers { let layer = { name: params.name, id: params.id, - activeLayer: params.activeLayer, + activeLayer: params.activeLayer === undefined ? null : params.activeLayer, activeIds: activeIds, refType: params.refType, color: params.color, diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index 0175a5b193..fe6c0a0f1d 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -6,6 +6,7 @@ import _filter from 'lodash-es/filter'; import _forEach from 'lodash-es/forEach'; +import _find from 'lodash-es/find'; import LayerAdd from './layerAdd'; import LayerConflate from './layerConflate'; @@ -15,7 +16,6 @@ import { utilQsString, utilStringQs } from '../../../util'; -import { diff3MergeIndices } from 'node-diff3'; /** * Create the sidebar @@ -174,11 +174,9 @@ export default class Sidebar { let selectReference = d3.selectAll('#reference'); let selectSecondary = d3.selectAll('#secondary'); if (loadedLayers.length === 2) { - let referenceActive = loadedLayers[0]; - let secondaryActive = loadedLayers[1]; + let referenceActive = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); + let secondaryActive = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); let changeActive = new LayerAdd(); - let referenceState; - let secondaryState; if (d3.select('#reference button.select-active-layer').empty()) { @@ -219,16 +217,14 @@ export default class Sidebar { .classed('no-click', false); - referenceState = referenceActive; - - if (secondaryState) { - secondaryState.activeLayer = false; - referenceState.activeLayer = true; + if (secondaryActive.activeLayer !== null) { + secondaryActive.activeLayer = false; + referenceActive.activeLayer = true; } else { - referenceState.activeLayer = true; + referenceActive.activeLayer = true; } - changeActive.selectedLayer = referenceState; + changeActive.selectedLayer = referenceActive; }); } @@ -268,17 +264,15 @@ export default class Sidebar { .classed('disable-non-active', false) .classed('no-click', false); - secondaryState = secondaryActive; - - if (referenceState) { - referenceState.activeLayer = false; - secondaryState.activeLayer = true; + if (referenceActive.activeLayer !== null) { + referenceActive.activeLayer = false; + secondaryActive.activeLayer = true; } else { - secondaryState.activeLayer = true; + secondaryActive.activeLayer = true; } - changeActive.selectedLayer = secondaryState; + changeActive.selectedLayer = secondaryActive; }); } diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index 792c10ecd0..c7d563d8f3 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -126,17 +126,11 @@ export function behaviorDraw(context) { var target = d && d.properties && d.properties.entity; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - // for each if/elseif statment add boolean (is _activeLayer===target.mapId)... - - if (target && target.type === 'node' && _activeLayer.id === Number(target.mapId)) { // Snap to a node - console.log(target.name + ' (' + target.id + ')' + ' is an active layer' ); + if (target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node dispatch.call('clickNode', this, target, d); return; - // dispatch.call('clickNode', this, target, d); - // return; - } else if (target && target.type === 'way' && _activeLayer.id === Number(target.mapId)) { // Snap to a way - console.log(target.id + ' is an active layer' ); + } else if (target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() ); diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 42e71132c7..e06551889a 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -17,6 +17,7 @@ import { modeBrowse, modeSelect } from '../modes'; import { osmNode } from '../osm'; import { utilKeybinding } from '../util'; import _find from 'lodash-es/find'; +import { data } from '../../data'; export function behaviorDrawWay(context, wayId, index, mode, startGraph) { @@ -74,9 +75,9 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { function move(datum) { context.surface().classed('nope-disabled', d3_event.altKey); - // add one more boolean at end, is activeLayer===mapId - var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); var targetLoc = datum && datum.properties && datum.properties.entity && datum.properties.entity.loc; + //&& datum.properties.entity.id.includes(String(_activeLayer.id)); var targetNodes = datum && datum.properties && datum.properties.nodes; var loc = context.map().mouseCoordinates(); @@ -95,14 +96,12 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { checkGeometry(false); } - - // Check whether this edit causes the geometry to break. - // If so, class the surface with a nope cursor. // `finishDraw` - Only checks the relevant line segments if finishing drawing function checkGeometry(finishDraw) { var nopeDisabled = context.surface().classed('nope-disabled'); var isInvalid = isInvalidGeometry(end, context.graph(), finishDraw); + if (nopeDisabled) { context.surface() .classed('nope', false) @@ -121,6 +120,12 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { for (var i = 0; i < parents.length; i++) { var parent = parents[i]; var nodes = parent.nodes.map(function(nodeID) { return graph.entity(nodeID); }); + // var getId = origWay.id.split('_')[1]; + // var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); + + // if (getId === String(_activeLayer.id)) { + // finishDraw = true; + // } if (origWay.isClosed()) { // Check if Area if (finishDraw) { @@ -282,6 +287,8 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { // Connect the way to an existing node and continue drawing. drawWay.addNode = function(node, d) { + console.log(node); + console.log(d); if ((d && d.properties && d.properties.nope) || context.surface().classed('nope')) { return; // can't click here } diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 62ee036a36..85e8921a4a 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -14,17 +14,11 @@ export function osmEntity(attrs) { if (this instanceof osmEntity) return; // Create the appropriate subtype. + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); if (attrs && attrs.type) { - - var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - if (_activeLayer && _activeLayer.id) { - console.log(attrs); - console.log(attrs.id); - //attrs.id = attrs.id + '_' + _activeLayer.id; - return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments); - } else { - return osmEntity[attrs.type].apply(this, arguments); - } + return osmEntity[attrs.type].apply(this, arguments); + } else if (attrs && attrs.id && attrs.id.includes(String(_activeLayer.id))) { + return osmEntity[osmEntity.id.type(attrs.id).apply(this, arguments)]; } // Initialize a generic Entity (used only in tests). return (new osmEntity()).initialize(arguments); From 7e89286e0e45b4711162c1e267a766001f31e711 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Fri, 31 May 2019 12:20:48 -0400 Subject: [PATCH 08/33] working on synchronizing all draw behaviors with new activeLayer setup --- css/80_app.css | 9 ++- modules/Hoot/config/domMetadata.js | 11 +-- modules/Hoot/ui/sidebar/sidebar.js | 117 +++++++++++++++-------------- modules/behavior/draw_way.js | 10 --- modules/behavior/hover.js | 25 +++--- modules/behavior/select.js | 10 ++- modules/modes/drag_node.js | 12 +-- modules/modes/save.js | 37 ++++++++- modules/services/osm.js | 57 ++++++++------ 9 files changed, 171 insertions(+), 117 deletions(-) diff --git a/css/80_app.css b/css/80_app.css index 74f1fbaf46..7261a7f696 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -370,8 +370,9 @@ button[disabled].action:hover { .disable-non-active, .disable-non-active:hover { - cursor: not-allowed; -} + background-color: #fff; +} /* cursor: not-allowed; */ + .active-pulse { border-radius: 50%; @@ -410,9 +411,9 @@ button[disabled].action:hover { } } -.no-click { +/* .no-click { pointer-events: none; -} +} */ /* Icons diff --git a/modules/Hoot/config/domMetadata.js b/modules/Hoot/config/domMetadata.js index dcacea486a..67d26f72f1 100644 --- a/modules/Hoot/config/domMetadata.js +++ b/modules/Hoot/config/domMetadata.js @@ -27,8 +27,8 @@ export function layerConflateForm( data ) { id: 'conflateFolderPath', class: 'path-name', inputType: 'combobox', - value: this.defaultFolder.name, - _value: this.defaultFolder.id, + value: this.defaultFolder ? this.defaultFolder.name : 'root', + _value: this.defaultFolder ? this.defaultFolder.id : 0, data: this.folderList, itemKey: 'path', _valueKey: 'id', @@ -243,14 +243,14 @@ export function importMultiForm() { export function addFolderForm() { return [ { - label: 'Folder Name', + label: 'Name', id: 'addFolderName', class: 'new-folder-name', inputType: 'text', onChange: d => this.validateTextInput( d ) }, { - label: 'Folder Visibility', + label: 'Public', id: 'addFolderVisibility', inputType: 'checkbox', value: 'Public', @@ -260,6 +260,7 @@ export function addFolderForm() { ]; } + export function modifyDatasetForm() { return [ { @@ -289,7 +290,7 @@ export function modifyDatasetForm() { onChange: d => this.validateTextInput( d ) }, { - label: 'Visibility', + label: 'Public', id: 'modifyVisibility', inputType: 'checkbox', value: 'Public', diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index fe6c0a0f1d..3ca0f1fb05 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -173,58 +173,81 @@ export default class Sidebar { let loadedLayers = Object.values(Hoot.layers.loadedLayers); let selectReference = d3.selectAll('#reference'); let selectSecondary = d3.selectAll('#secondary'); + let refClickCount = 0; + let secClickCount = 0; if (loadedLayers.length === 2) { let referenceActive = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); let secondaryActive = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); let changeActive = new LayerAdd(); + // eslint-disable-next-line no-inner-declarations + function updateButton(active, inactive) { - if (d3.select('#reference button.select-active-layer').empty()) { - selectReference - .append('button') - .classed('select-active-layer', true) - .text('Set as active layer') - .on('click', function () { + if (active) { + d3.select(`#${active}`) + .classed('active-pulse', true); - d3.event.preventDefault(); + d3.select(`#${active} button.select-active-layer`) + .text('Active Layer') + .classed('button-active', true); - d3.select('#reference') - .classed('active-pulse', true); + d3.select(`#${active} div.controller`) + .classed('disable-non-active', false); - d3.select('#secondary') - .classed('active-pulse', false); + d3.select(`#${active} button.delete-button`) + .classed('disable-non-active', false); + //.classed('no-click', false); + } - d3.select('#reference button.select-active-layer') - .text('Active Layer') - .classed('button-active', true); + if (inactive) { + d3.select(`#${inactive}`) + .classed('active-pulse', false); - d3.select('#secondary button.select-active-layer') - .text('Set as active layer') - .classed('button-active', false); + d3.select(`#${inactive} button.select-active-layer`) + .text('Set as active layer') + .classed('button-active', false); - d3.selectAll('#secondary div.controller') - .classed('disable-non-active', true); + d3.select(`#${inactive} div.controller`) + .classed('disable-non-active', true); - d3.selectAll('#reference div.controller') - .classed('disable-non-active', false); + d3.select(`#${inactive} button.delete-button`) + .classed('disable-non-active', true); + //.classed('no-click', true); + } - d3.selectAll('#secondary button.delete-button') - .classed('disable-non-active', true) - .classed('no-click', true); + } - d3.selectAll('#reference button.delete-button') - .classed('disable-non-active', false) - .classed('no-click', false); + if (d3.select('#reference button.select-active-layer').empty()) { + selectReference + .append('button') + .classed('select-active-layer', true) + .text('Set as active layer') + .on('click', function () { + + d3.event.preventDefault(); + + updateButton('reference', 'secondary'); if (secondaryActive.activeLayer !== null) { - secondaryActive.activeLayer = false; + secondaryActive.activeLayer = null; referenceActive.activeLayer = true; } + else if (refClickCount === 1 && referenceActive.activeLayer === true) { + refClickCount++; + } else { + refClickCount++; referenceActive.activeLayer = true; } + while ( refClickCount === 2 ) { + updateButton(null, 'reference'); + referenceActive.activeLayer = null; + refClickCount = 0; + } + changeActive.selectedLayer = referenceActive; + }); } @@ -236,41 +259,25 @@ export default class Sidebar { .on('click', function () { d3.event.preventDefault(); - d3.select('#secondary') - .classed('active-pulse', true); - - d3.select('#reference') - .classed('active-pulse', false); - d3.select('#secondary button.select-active-layer') - .text('Active Layer') - .classed('button-active', true); - - d3.select('#reference button.select-active-layer') - .text('Set as active layer') - .classed('button-active', false); - - d3.selectAll('#reference div.controller') - .classed('disable-non-active', true); - - d3.selectAll('#secondary div.controller') - .classed('disable-non-active', false); - - d3.selectAll('#reference button.delete-button') - .classed('disable-non-active', true) - .classed('no-click', true); - - d3.selectAll('#secondary button.delete-button') - .classed('disable-non-active', false) - .classed('no-click', false); + updateButton('secondary', 'reference'); if (referenceActive.activeLayer !== null) { - referenceActive.activeLayer = false; + referenceActive.activeLayer = null; secondaryActive.activeLayer = true; } + else if (secClickCount === 1 && secondaryActive.activeLayer === true) { + secClickCount++; + } else { + secClickCount++; secondaryActive.activeLayer = true; } + while ( secClickCount === 2 ) { + updateButton(null, 'secondary'); + secondaryActive.activeLayer = null; + secClickCount = 0; + } changeActive.selectedLayer = secondaryActive; diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index e06551889a..48248e4cb9 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -75,9 +75,7 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { function move(datum) { context.surface().classed('nope-disabled', d3_event.altKey); - var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); var targetLoc = datum && datum.properties && datum.properties.entity && datum.properties.entity.loc; - //&& datum.properties.entity.id.includes(String(_activeLayer.id)); var targetNodes = datum && datum.properties && datum.properties.nodes; var loc = context.map().mouseCoordinates(); @@ -120,12 +118,6 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { for (var i = 0; i < parents.length; i++) { var parent = parents[i]; var nodes = parent.nodes.map(function(nodeID) { return graph.entity(nodeID); }); - // var getId = origWay.id.split('_')[1]; - // var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); - - // if (getId === String(_activeLayer.id)) { - // finishDraw = true; - // } if (origWay.isClosed()) { // Check if Area if (finishDraw) { @@ -287,8 +279,6 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { // Connect the way to an existing node and continue drawing. drawWay.addNode = function(node, d) { - console.log(node); - console.log(d); if ((d && d.properties && d.properties.nope) || context.surface().classed('nope')) { return; // can't click here } diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index ecf5e078de..b381411e14 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -8,6 +8,8 @@ import { import { osmEntity, osmNote } from '../osm'; import { utilKeybinding, utilRebind } from '../util'; +import _find from 'lodash-es/find'; + /* The hover behavior adds the `.hover` class on mouseover to all elements to which @@ -117,18 +119,19 @@ export function behaviorHover(context) { selector = '.note-' + datum.id; } else if (datum instanceof osmEntity) { - entity = datum; - selector = '.' + entity.id; - if (entity.type === 'relation') { - entity.members.forEach(function(member) { selector += ', .' + member.id; }); - } + entity = datum; + selector = '.' + entity.id; + if (entity.type === 'relation') { + entity.members.forEach(function(member) { selector += ', .' + member.id; }); + } } else if (datum && datum.properties && (datum.properties.entity instanceof osmEntity)) { - entity = datum.properties.entity; - selector = '.' + entity.id; - if (entity.type === 'relation') { - entity.members.forEach(function(member) { selector += ', .' + member.id; }); - } + entity = datum.properties.entity; + selector = '.' + entity.id; + if (entity.type === 'relation') { + entity.members.forEach(function(member) { selector += ', .' + member.id; }); + } + } // Update hover state and dispatch event @@ -139,8 +142,6 @@ export function behaviorHover(context) { _newId = entity.id; return; } - - // again, boolean, is entity.mapId === activeLayerId... var suppressed = _altDisables && d3_event && d3_event.altKey; _selection.selectAll(selector) .classed(suppressed ? 'hover-suppressed' : 'hover', true); diff --git a/modules/behavior/select.js b/modules/behavior/select.js index bbb6df526f..0dc19bef9b 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -1,4 +1,5 @@ import _without from 'lodash-es/without'; +import _find from 'lodash-es/find'; import { event as d3_event, @@ -118,8 +119,11 @@ export function behaviorSelect(context) { var isMultiselect = d3_event.shiftKey || d3_select('#surface .lasso').node(); var isShowAlways = +context.storage('edit-menu-show-always') === 1; var datum = d3_event.target.__data__ || (lastMouse && lastMouse.target.__data__); + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); var mode = context.mode(); + + var entity = datum && datum.properties && datum.properties.entity; if (entity) datum = entity; @@ -132,14 +136,16 @@ export function behaviorSelect(context) { context.selectedNoteID(null); if (!isMultiselect) { - if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways)) { + if (Number(datum.id.split('_')[1]) !== _activeLayer.id) { + mode.suppressMenu(false).reselect(); + } + else if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways)) { // multiple things already selected, just show the menu... mode.suppressMenu(false).reselect(); } else { // select a single thing.. context.enter(modeSelect(context, [datum.id]).suppressMenu(suppressMenu)); } - } else { if (selectedIDs.indexOf(datum.id) !== -1) { // clicked entity is already in the selectedIDs list.. diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 9753f8e1e1..15267e39b2 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -52,6 +52,7 @@ export function modeDragNode(context) { var _activeEntity; var _startLoc; var _lastLoc; + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); function startNudge(entity, nudge) { @@ -187,6 +188,7 @@ export function modeDragNode(context) { var currMouse = geoVecSubtract(currPoint, nudge); var loc = context.projection.invert(currMouse); + if (!_nudgeInterval) { // If not nudging at the edge of the viewport, try to snap.. // related code // - `mode/drag_node.js` `doMode()` @@ -198,10 +200,9 @@ export function modeDragNode(context) { var targetNodes = d && d.properties && d.properties.nodes; var edge; - if (targetLoc) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - - } else if (targetNodes) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (edge) { loc = edge.loc; @@ -340,6 +341,7 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; + if ( _activeLayer === undefined || _activeLayer.id !== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey); @@ -368,7 +370,7 @@ export function modeDragNode(context) { _actionBounceBack(entity.id, _startLoc) ); - } else if (target && target.type === 'way') { + } else if (target && target.type === 'way' && Number(target.id.split('_')[1]) === _activeLayer.id) { var choice = geoChooseEdge(context.childNodes(target), context.mouse(), context.projection, entity.id); context.replace( actionAddMidpoint({ @@ -378,7 +380,7 @@ export function modeDragNode(context) { connectAnnotation(entity, target) ); - } else if (target && target.type === 'node') { + } else if (target && target.type === 'node' && Number(target.id.split('_')[1]) === _activeLayer.id) { context.replace( actionConnect([target.id, entity.id]), connectAnnotation(entity, target) diff --git a/modules/modes/save.js b/modules/modes/save.js index 07cd515117..6fed3e0cca 100644 --- a/modules/modes/save.js +++ b/modules/modes/save.js @@ -1,5 +1,6 @@ import _clone from 'lodash-es/clone'; import _filter from 'lodash-es/filter'; +import _find from 'lodash-es/find'; import _map from 'lodash-es/map'; import _reduce from 'lodash-es/reduce'; import _union from 'lodash-es/union'; @@ -44,6 +45,9 @@ import { } from '../util'; import { osmEntity } from '../osm/index'; +import { create } from 'domain'; +import { pseudoRandomBytes } from 'crypto'; +import { async } from 'q'; var _isSaving = false; @@ -287,7 +291,6 @@ export function modeSave(context) { } } - function upload(changeset) { var osm = context.connection(); if (!osm) { @@ -305,7 +308,36 @@ export function modeSave(context) { var changes = history.changes(actionDiscardTags(history.difference())); if (changes.modified.length || changes.created.length || changes.deleted.length) { //loadLocation(); // so it is ready when we display the save screen - osm.putChangeset(changeset, changes, uploadCallback); + + var getMapIds = Object.keys(Hoot.layers.loadedLayers); + var idToNum = getMapIds.map(parseFloat); + let changesetArray = []; + + var mapChanges = idToNum.map(function(mapId) { + var created = changes.created.filter(function(created) { return Number(created.id.split('_')[1]) === mapId; }); + var modified = changes.modified.filter(function(modified) { return Number(modified.id.split('_')[1]) === mapId; }); + var deleted = changes.deleted.filter(function(deleted) { return Number(deleted.id.split('_')[1]) === mapId; }); + return { + mapId: mapId, + changes: { + created: created, + modified: modified, + deleted: deleted + } + }; + }); + + mapChanges.forEach( + function (changes) { + if (changes.changes.created.length === 0 && changes.changes.modified.length === 0 && changes.changes.deleted.length === 0) { + return; + } + else if (changes.changes.created.length > 0 || changes.changes.modified.length > 0 || changes.changes.deleted.length > 0) { + changesetArray.push(changes); + } + osm.putChangeset(changeset, changes.changes ,uploadCallback, changesetArray, changes.mapId); + } + ); } else { // changes were insignificant or reverted by user d3_select('.inspector-wrap *').remove(); loading.close(); @@ -316,7 +348,6 @@ export function modeSave(context) { } } - function uploadCallback(err, changeset) { if (err) { if (err.status === 409) { // 409 Conflicts diff --git a/modules/services/osm.js b/modules/services/osm.js index c7debc498b..c5f581c4ad 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -8,7 +8,6 @@ import _flatten from 'lodash-es/flatten'; import _groupBy from 'lodash-es/groupBy'; import _isEmpty from 'lodash-es/isEmpty'; import _map from 'lodash-es/map'; -import _matches from 'lodash-es/matches'; import _throttle from 'lodash-es/throttle'; import _uniq from 'lodash-es/uniq'; import _values from 'lodash-es/values'; @@ -42,7 +41,6 @@ import { } from '../util'; import { baseUrl as hootBaseUrl } from '../Hoot/config/apiConfig'; -import { all } from 'q'; var tiler = utilTiler(); var dispatch = d3_dispatch('authLoading', 'authDone', 'change', 'loading', 'loaded', 'loadedNotes'); @@ -74,6 +72,7 @@ var _userCache = { toLoad: {}, user: {} }; var _changeset = {}; var _connectionID = 1; +var _multiCIDs = []; var _tileZoom = 16; var _noteZoom = 12; var _rateLimitError; @@ -639,10 +638,8 @@ export default { defaultMapId; // Make sure there is only one layer visible. Otherwise, return a falsy value to prevent save. - if (visLayers.length === 1 || changes.created.length === 0){ - defaultMapId = activeLayer.id; - } - else if (visLayers.length === 2) { + + if ( activeLayer.activeLayer === true ){ defaultMapId = activeLayer.id; } else { return false; @@ -688,35 +685,40 @@ export default { // Create, upload, and close a changeset // PUT /api/0.6/changeset/create - // POST /api/0.6/changeset/#id/upload + // POST /api/0.6/changeset/#i/upload // PUT /api/0.6/changeset/#id/close - putChangeset: function(changeset, changes, callback ) { + putChangeset: function(changeset, changes, callback, changesetArray, mapId ) { var cid = _connectionID; + _multiCIDs.push(cid); - let changesArr = this.filterChanges( changes ); + //let changesArr = this.filterChanges(changes); - if (_changeset.inflight || !changesArr) { - return callback({ message: 'Changeset already inflight', status: -2 }, changeset); + if (_changeset.inflight) { + if (changesetArray.length === 2) { + changesetArray.forEach(function (multiple) { + var err; + var result; + uploadedChangeset(err, result, multiple.mapId); + }); + } else { + return callback({ message: 'Changeset already inflight', status: -2 }, changeset); + } } else if (_changeset.open) { // reuse existing open changeset.. - return createdChangeset.call(this, null, _changeset.open); + return createdChangeset.call(this, null, _changeset.open, mapId); } else { // Open a new changeset.. - _forEach( changesArr, ( changes, mapId ) => { - let path = '/api/0.6/changeset/create'; - path += mapId ? `?mapId=${ mapId }` : ''; - - var options = { + let path = `/api/0.6/changeset/create/?mapId=${ mapId }`; + var options = { method: 'PUT', path: path, options: { header: { 'Content-Type': 'text/xml' } }, content: JXON.stringify(changeset.asJXON()) }; - _changeset.inflight = oauth.xhr( + _changeset.inflight = oauth.xhr( options, wrapcb(this, createdChangeset, cid, mapId) ); - } ); } function createdChangeset(err, changesetID, mapId) { @@ -762,7 +764,7 @@ export default { } ); let path = '/api/0.6/changeset/' + changesetID + '/upload'; - path += mapId ? `?mapId=${ mapId }` : ''; + path += `?mapId=${ mapId }`; // Upload the changeset.. var options = { @@ -789,7 +791,20 @@ export default { // At this point, we don't really care if the connection was switched.. // Only try to close the changeset if we're still talking to the same server. - if (this.getConnectionId() === cid) { + if (_multiCIDs.length === 2) { + _multiCIDs.forEach(function (id) { + let path = '/api/0.6/changeset/' + changeset.id + '/close'; + path += mapId ? `?mapId=${mapId}` : ''; + + // Still attempt to close changeset, but ignore response because #2667 + oauth.xhr({ + method: 'PUT', + path: path, + options: { header: { 'Content-Type': 'text/xml' } } + }, function () { return true; }); + }); + } + else { let path = '/api/0.6/changeset/' + changeset.id + '/close'; path += mapId ? `?mapId=${ mapId }` : ''; From bd72f6722549dea9cbc13e94fcb091e0b47d377d Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Fri, 31 May 2019 16:31:28 -0400 Subject: [PATCH 09/33] can now successfully upload changes made to two separate map layers --- modules/modes/save.js | 90 ++++++++++++++++++++++++++++------------- modules/services/osm.js | 31 ++------------ 2 files changed, 66 insertions(+), 55 deletions(-) diff --git a/modules/modes/save.js b/modules/modes/save.js index 6fed3e0cca..d83395545c 100644 --- a/modules/modes/save.js +++ b/modules/modes/save.js @@ -66,6 +66,7 @@ export function modeSave(context) { var _toCheck = []; var _toLoad = []; + var _changesetArray = []; var _loaded = {}; var _toLoadCount = 0; var _toLoadTotal = 0; @@ -311,33 +312,54 @@ export function modeSave(context) { var getMapIds = Object.keys(Hoot.layers.loadedLayers); var idToNum = getMapIds.map(parseFloat); - let changesetArray = []; - - var mapChanges = idToNum.map(function(mapId) { - var created = changes.created.filter(function(created) { return Number(created.id.split('_')[1]) === mapId; }); - var modified = changes.modified.filter(function(modified) { return Number(modified.id.split('_')[1]) === mapId; }); - var deleted = changes.deleted.filter(function(deleted) { return Number(deleted.id.split('_')[1]) === mapId; }); - return { - mapId: mapId, - changes: { - created: created, - modified: modified, - deleted: deleted + + idToNum.forEach(function (mapId) { + var created = changes.created.filter(function (created) { return Number(created.id.split('_')[1]) === mapId; }); + var modified = changes.modified.filter(function (modified) { return Number(modified.id.split('_')[1]) === mapId; }); + var deleted = changes.deleted.filter(function (deleted) { return Number(deleted.id.split('_')[1]) === mapId; }); + if (created.length > 0 || modified.length > 0 || deleted.length > 0) { + _changesetArray.push( + { + mapId: mapId, + changes: { + created: created, + modified: modified, + deleted: deleted + } } - }; - }); + ); - mapChanges.forEach( - function (changes) { - if (changes.changes.created.length === 0 && changes.changes.modified.length === 0 && changes.changes.deleted.length === 0) { - return; - } - else if (changes.changes.created.length > 0 || changes.changes.modified.length > 0 || changes.changes.deleted.length > 0) { - changesetArray.push(changes); - } - osm.putChangeset(changeset, changes.changes ,uploadCallback, changesetArray, changes.mapId); + return; } - ); + }); + + osm.putChangeset(changeset, _changesetArray[0].changes, uploadCallback, _changesetArray[0].mapId); + + // var mapChanges = idToNum.map(function(mapId) { + // var created = changes.created.filter(function(created) { return Number(created.id.split('_')[1]) === mapId; }); + // var modified = changes.modified.filter(function(modified) { return Number(modified.id.split('_')[1]) === mapId; }); + // var deleted = changes.deleted.filter(function(deleted) { return Number(deleted.id.split('_')[1]) === mapId; }); + // return { + // mapId: mapId, + // changes: { + // created: created, + // modified: modified, + // d deleted: deleted + // } + // }; + // }); + + // mapChanges.forEach( + // function (changes) { + // if (changes.changes.created.length === 0 && changes.changes.modified.length === 0 && changes.changes.deleted.length === 0) { + // return; + // } + // else if (changes.changes.created.length > 0 || changes.changes.modified.length > 0 || changes.changes.deleted.length > 0) { + // _changesetArray.push(changes); + // } + // osm.putChangeset(changeset, changes.changes ,uploadCallback, _changesetArray, changes.mapId); + // } + // ); } else { // changes were insignificant or reverted by user d3_select('.inspector-wrap *').remove(); loading.close(); @@ -348,7 +370,7 @@ export function modeSave(context) { } } - function uploadCallback(err, changeset) { + function uploadCallback(err, changeset, mapId) { if (err) { if (err.status === 409) { // 409 Conflicts save(changeset, true, true); // tryAgain = true, checkConflicts = true @@ -362,7 +384,7 @@ export function modeSave(context) { } else { context.history().clearSaved(); - success(changeset); + success(changeset, mapId); // Add delay to allow for postgres replication #1646 #2678 window.setTimeout(function() { d3_select('.inspector-wrap *').remove(); @@ -494,11 +516,23 @@ export function modeSave(context) { } - function success(changeset) { + function success(changeset, mapId) { + + var cID = Number(mapId); + _changesetArray = _changesetArray.filter( function(changes) { return cID !== changes.mapId; } ); + + if (_changesetArray.length > 0) { + var osm = context.connection(); + if (osm) { + osm.putChangeset(changeset, _changesetArray[0].changes, uploadCallback, _changesetArray[0].mapId); + return; + } + } + commit.reset(); // commented out to prevent success UI from showing - //var ui = uiSuccess(context) + // var ui = uiSuccess(context) // .changeset(changeset) // .location(_location) // .on('cancel', function() { context.ui().sidebar.hide(); }); diff --git a/modules/services/osm.js b/modules/services/osm.js index c5f581c4ad..8d983df950 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -72,7 +72,6 @@ var _userCache = { toLoad: {}, user: {} }; var _changeset = {}; var _connectionID = 1; -var _multiCIDs = []; var _tileZoom = 16; var _noteZoom = 12; var _rateLimitError; @@ -687,22 +686,13 @@ export default { // PUT /api/0.6/changeset/create // POST /api/0.6/changeset/#i/upload // PUT /api/0.6/changeset/#id/close - putChangeset: function(changeset, changes, callback, changesetArray, mapId ) { + putChangeset: function(changeset, changes, callback, mapId ) { var cid = _connectionID; - _multiCIDs.push(cid); //let changesArr = this.filterChanges(changes); if (_changeset.inflight) { - if (changesetArray.length === 2) { - changesetArray.forEach(function (multiple) { - var err; - var result; - uploadedChangeset(err, result, multiple.mapId); - }); - } else { - return callback({ message: 'Changeset already inflight', status: -2 }, changeset); - } + return callback({ message: 'Changeset already inflight', status: -2 }, changeset); } else if (_changeset.open) { // reuse existing open changeset.. return createdChangeset.call(this, null, _changeset.open, mapId); @@ -786,25 +776,12 @@ export default { // Upload was successful, safe to call the callback. // Add delay to allow for postgres replication #1646 #2678 - window.setTimeout(function() { callback(null, changeset); }, 500); + window.setTimeout(function() { callback(null, changeset, mapId); }, 500); _changeset.open = null; // At this point, we don't really care if the connection was switched.. // Only try to close the changeset if we're still talking to the same server. - if (_multiCIDs.length === 2) { - _multiCIDs.forEach(function (id) { - let path = '/api/0.6/changeset/' + changeset.id + '/close'; - path += mapId ? `?mapId=${mapId}` : ''; - - // Still attempt to close changeset, but ignore response because #2667 - oauth.xhr({ - method: 'PUT', - path: path, - options: { header: { 'Content-Type': 'text/xml' } } - }, function () { return true; }); - }); - } - else { + if (this.getConnectionId() === cid) { let path = '/api/0.6/changeset/' + changeset.id + '/close'; path += mapId ? `?mapId=${ mapId }` : ''; From 7faae877f80616a2c2bcfa2b38c66bfa140b340f Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 3 Jun 2019 08:27:03 -0400 Subject: [PATCH 10/33] updated datum and activeLayer id checks in select.js class --- modules/behavior/select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/behavior/select.js b/modules/behavior/select.js index 0dc19bef9b..6a919b4656 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -136,7 +136,7 @@ export function behaviorSelect(context) { context.selectedNoteID(null); if (!isMultiselect) { - if (Number(datum.id.split('_')[1]) !== _activeLayer.id) { + if (Number(datum.id.split('_')[1]) !== Number(_activeLayer.id)) { mode.suppressMenu(false).reselect(); } else if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways)) { From ae33772102e81bc99cdc9d2a392f886e5f70c8de Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 3 Jun 2019 10:13:28 -0400 Subject: [PATCH 11/33] updating draw methods accounting for single layer editing w new activeLayer --- modules/behavior/draw.js | 4 ++-- modules/behavior/draw_way.js | 5 +++-- modules/behavior/select.js | 3 ++- modules/modes/drag_node.js | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index c7d563d8f3..bffdad0d46 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -126,11 +126,11 @@ export function behaviorDraw(context) { var target = d && d.properties && d.properties.entity; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - if (target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node + if (target && target.type === 'node' && Hoot.layers.loadedLayers === 1 || target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node dispatch.call('clickNode', this, target, d); return; - } else if (target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way + } else if (target && target.type === 'way' && Hoot.layers.loadedLayers === 1 || target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() ); diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 48248e4cb9..e691d0d0bb 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -77,12 +77,13 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { var targetLoc = datum && datum.properties && datum.properties.entity && datum.properties.entity.loc; var targetNodes = datum && datum.properties && datum.properties.nodes; + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); var loc = context.map().mouseCoordinates(); - if (targetLoc) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Hoot.layers.loadedLayers === 1 || targetLoc && Number(datum.id.split('_')[1]) === _activeLayer.id ) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Hoot.layers.loadedLayers === 1 || targetNodes && Number(datum.id.split('_')[1]) === _activeLayer.id ) { // snap to way - a line target with `.nodes` var choice = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (choice) { loc = choice.loc; diff --git a/modules/behavior/select.js b/modules/behavior/select.js index 6a919b4656..3575f957d4 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -136,7 +136,8 @@ export function behaviorSelect(context) { context.selectedNoteID(null); if (!isMultiselect) { - if (Number(datum.id.split('_')[1]) !== Number(_activeLayer.id)) { + + if ( Hoot.layers.loadedLayers > 1 && Number(datum.id.split('_')[1]) !== Number(_activeLayer.id)) { mode.suppressMenu(false).reselect(); } else if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways)) { diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 15267e39b2..5a764f5fdd 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -200,9 +200,9 @@ export function modeDragNode(context) { var targetNodes = d && d.properties && d.properties.nodes; var edge; - if (targetLoc && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Hoot.layers.loadedLayers === 1 || targetLoc && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Hoot.layers.loadedLayers === 1 || targetNodes && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (edge) { loc = edge.loc; From 16e099ab08a790a058d943ad67999b5f7e49e877 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Tue, 4 Jun 2019 14:40:15 -0400 Subject: [PATCH 12/33] behaviors added to include activeLayer settings when only 1 layer in map --- modules/Hoot/ui/sidebar/layerAdd.js | 22 +++++ modules/Hoot/ui/sidebar/sidebar.js | 135 ++++++++++++++++++++-------- modules/behavior/draw_way.js | 2 - modules/behavior/hover.js | 3 - modules/behavior/select.js | 14 ++- modules/modes/add_line.js | 1 - modules/modes/select.js | 1 + modules/osm/changeset.js | 3 +- 8 files changed, 130 insertions(+), 51 deletions(-) diff --git a/modules/Hoot/ui/sidebar/layerAdd.js b/modules/Hoot/ui/sidebar/layerAdd.js index a13e1eb876..159f8e806d 100644 --- a/modules/Hoot/ui/sidebar/layerAdd.js +++ b/modules/Hoot/ui/sidebar/layerAdd.js @@ -215,9 +215,31 @@ export default class LayerAdd extends SidebarForm { Hoot.events.emit( 'load-layer' ); + if ( Object.keys(Hoot.layers.loadedLayers).length === 1 ) { + await this.setActiveLayer(d); + } + // return this.checkForReview( layer ); } + async setActiveLayer ( d ) { + + let changeActive = new LayerAdd(); + + let loadedLayers = Object.values(Hoot.layers.loadedLayers); + + let referenceLayer = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); + let secondaryLayer = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); + + if (Object.keys(Hoot.layers.loadedLayers).length === 1 && referenceLayer ) { + referenceLayer.activeLayer = true; + changeActive.selectedLayer = referenceLayer; + } else { + secondaryLayer.activeLayer = true; + changeActive.selectedLayer = secondaryLayer; + } + } + /** * Listen for events */ diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index 3ca0f1fb05..ffb34f815f 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -196,7 +196,6 @@ export default class Sidebar { d3.select(`#${active} button.delete-button`) .classed('disable-non-active', false); - //.classed('no-click', false); } if (inactive) { @@ -219,70 +218,136 @@ export default class Sidebar { if (d3.select('#reference button.select-active-layer').empty()) { + selectReference .append('button') .classed('select-active-layer', true) - .text('Set as active layer') - .on('click', function () { + .text('Set as active layer'); - d3.event.preventDefault(); + if (referenceActive.activeLayer === true && refClickCount === 0) { + d3.select('#reference button.select-active-layer') + .classed('select-active-layer', true) + .text('Active Layer'); - updateButton('reference', 'secondary'); + updateButton('reference', 'secondary'); - if (secondaryActive.activeLayer !== null) { - secondaryActive.activeLayer = null; - referenceActive.activeLayer = true; - } - else if (refClickCount === 1 && referenceActive.activeLayer === true) { - refClickCount++; - } - else { - refClickCount++; - referenceActive.activeLayer = true; - } - while ( refClickCount === 2 ) { - updateButton(null, 'reference'); - referenceActive.activeLayer = null; - refClickCount = 0; - } + } - changeActive.selectedLayer = referenceActive; + selectReference.on('click', function () { - }); + d3.event.preventDefault(); + + if (secondaryActive.activeLayer !== null) { + secondaryActive.activeLayer = null; + referenceActive.activeLayer = true; + updateButton('reference', 'secondary'); + } + else if (refClickCount === 1 && referenceActive.activeLayer === true) { + refClickCount++; + } + else { + refClickCount++; + referenceActive.activeLayer = true; + d3.select('#reference button.select-active-layer') + .classed('select-active-layer', true) + .text('Active Layer'); + updateButton('reference', 'secondary'); + } + while (refClickCount === 2) { + updateButton(null, 'reference'); + referenceActive.activeLayer = null; + refClickCount = 0; + } + + changeActive.selectedLayer = referenceActive; + }); } if (d3.select('#secondary button.select-active-layer').empty()) { + selectSecondary - .append('button') + .append('button') + .classed('select-active-layer', true) + .text('Set as active layer'); + + + if ( secondaryActive.activeLayer === true && secClickCount === 0 ) { + + d3.select('#secondary button.select-active-layer') .classed('select-active-layer', true) - .text('Set as active layer') - .on('click', function () { + .text('Active Layer'); - d3.event.preventDefault(); + updateButton('secondary', 'reference'); + } - updateButton('secondary', 'reference'); + selectSecondary + .on('click', function () { + d3.event.preventDefault(); + //updateButton(null, 'reference'); if (referenceActive.activeLayer !== null) { - referenceActive.activeLayer = null; - secondaryActive.activeLayer = true; + referenceActive.activeLayer = null; + secondaryActive.activeLayer = true; + updateButton('secondary', 'reference'); } else if (secClickCount === 1 && secondaryActive.activeLayer === true) { secClickCount++; } else { secClickCount++; - secondaryActive.activeLayer = true; + secondaryActive.activeLayer = true; + d3.select('#reference button.select-active-layer') + .classed('select-active-layer', true) + .text('Active Layer'); + updateButton('secondary', 'reference'); + } - while ( secClickCount === 2 ) { + while ( secClickCount === 2 ) { updateButton(null, 'secondary'); - secondaryActive.activeLayer = null; + secondaryActive.activeLayer = null; secClickCount = 0; } changeActive.selectedLayer = secondaryActive; - }); - } + + } + + // else if ( secondaryActive.activeLayer === null && secClickCount === 0 ) { + + // selectSecondary + // .append('button') + // .classed('select-active-layer', true) + // .text('Set as active layer') + // .on('click', function () { + + // d3.event.preventDefault(); + + // //updateButton('reference', 'secondary'); + + // if (referenceActive.activeLayer !== null) { + // referenceActive.activeLayer = null; + // secondaryActive.activeLayer = true; + // } + // else if (secClickCount === 1 && secondaryActive.activeLayer === true) { + // secClickCount++; + // } + // else { + // secClickCount++; + // secondaryActive.activeLayer = true; + // } + // while ( secClickCount === 2 ) { + // updateButton(null, 'secondary'); + // secondaryActive.activeLayer = null; + // secClickCount = 0; + // } + + // changeActive.selectedLayer = referenceActive; + + // }); + + // } + } } diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index e691d0d0bb..8d702b8f5a 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -17,8 +17,6 @@ import { modeBrowse, modeSelect } from '../modes'; import { osmNode } from '../osm'; import { utilKeybinding } from '../util'; import _find from 'lodash-es/find'; -import { data } from '../../data'; - export function behaviorDrawWay(context, wayId, index, mode, startGraph) { var origWay = context.entity(wayId); diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index b381411e14..586418dc2b 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -8,9 +8,6 @@ import { import { osmEntity, osmNote } from '../osm'; import { utilKeybinding, utilRebind } from '../util'; -import _find from 'lodash-es/find'; - - /* The hover behavior adds the `.hover` class on mouseover to all elements to which the identical datum is bound, and removes it on mouseout. diff --git a/modules/behavior/select.js b/modules/behavior/select.js index 3575f957d4..011739d3f1 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -20,6 +20,7 @@ import { osmEntity, osmNote } from '../osm'; +import { createSecurePair } from 'tls'; export function behaviorSelect(context) { @@ -136,18 +137,16 @@ export function behaviorSelect(context) { context.selectedNoteID(null); if (!isMultiselect) { - - if ( Hoot.layers.loadedLayers > 1 && Number(datum.id.split('_')[1]) !== Number(_activeLayer.id)) { - mode.suppressMenu(false).reselect(); - } - else if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways)) { - // multiple things already selected, just show the menu... + if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways) ) { mode.suppressMenu(false).reselect(); + } else if (Number(datum.id.split('_')[1]) !== Number(_activeLayer.id)) { + selectedIDs = []; } else { // select a single thing.. context.enter(modeSelect(context, [datum.id]).suppressMenu(suppressMenu)); } - } else { + } + else { if (selectedIDs.indexOf(datum.id) !== -1) { // clicked entity is already in the selectedIDs list.. if (!suppressMenu && !isShowAlways) { @@ -164,7 +163,6 @@ export function behaviorSelect(context) { context.enter(modeSelect(context, selectedIDs).suppressMenu(suppressMenu)); } } - } else if (datum && datum.__featurehash__ && !isMultiselect) { // clicked Data.. context .selectedNoteID(null) diff --git a/modules/modes/add_line.js b/modules/modes/add_line.js index bd4e6c4829..8ce55e4f64 100644 --- a/modules/modes/add_line.js +++ b/modules/modes/add_line.js @@ -9,7 +9,6 @@ import { behaviorAddWay } from '../behavior'; import { modeDrawLine } from './index'; import { osmNode, osmWay } from '../osm'; - export function modeAddLine(context) { var mode = { id: 'add-line', diff --git a/modules/modes/select.js b/modules/modes/select.js index add5b64798..67c8391bca 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -1,4 +1,5 @@ import _intersection from 'lodash-es/intersection'; +import _find from 'lodash-es/find'; import _map from 'lodash-es/map'; import _uniq from 'lodash-es/uniq'; import _values from 'lodash-es/values'; diff --git a/modules/osm/changeset.js b/modules/osm/changeset.js index 31deeeca34..d77e2f0b7d 100644 --- a/modules/osm/changeset.js +++ b/modules/osm/changeset.js @@ -8,7 +8,6 @@ import _values from 'lodash-es/values'; import { osmEntity } from './entity'; import { geoExtent } from '../geo'; - export function osmChangeset() { if (!(this instanceof osmChangeset)) { return (new osmChangeset()).initialize(arguments); @@ -55,6 +54,7 @@ _extend(osmChangeset.prototype, { // Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange) // XML. Returns a string. osmChangeJXON: function(changes) { + var changeset_id = this.id; function nest(x, order) { @@ -123,7 +123,6 @@ _extend(osmChangeset.prototype, { function rep(entity) { return entity.asJXON(changeset_id); } - return { osmChange: { '@version': 0.6, From 16b2fd8c3e18e39e7ed2e7e8e2b6bd5b678a75aa Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Wed, 5 Jun 2019 15:47:30 -0400 Subject: [PATCH 13/33] updated behaviors to prevent unwanted hovering over non-active layers --- modules/behavior/draw.js | 4 +-- modules/behavior/draw_way.js | 4 +-- modules/behavior/hover.js | 8 ++++-- modules/modes/drag_node.js | 6 ++-- modules/svg/areas.js | 10 +++++-- modules/svg/lines.js | 12 +++++--- modules/svg/vertices.js | 54 ++++++++++++++++++++---------------- 7 files changed, 58 insertions(+), 40 deletions(-) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index bffdad0d46..c7d563d8f3 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -126,11 +126,11 @@ export function behaviorDraw(context) { var target = d && d.properties && d.properties.entity; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - if (target && target.type === 'node' && Hoot.layers.loadedLayers === 1 || target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node + if (target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node dispatch.call('clickNode', this, target, d); return; - } else if (target && target.type === 'way' && Hoot.layers.loadedLayers === 1 || target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way + } else if (target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() ); diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 8d702b8f5a..4cd1084ad6 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -78,10 +78,10 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); var loc = context.map().mouseCoordinates(); - if (targetLoc && Hoot.layers.loadedLayers === 1 || targetLoc && Number(datum.id.split('_')[1]) === _activeLayer.id ) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Number(datum.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Hoot.layers.loadedLayers === 1 || targetNodes && Number(datum.id.split('_')[1]) === _activeLayer.id ) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Number(datum.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to way - a line target with `.nodes` var choice = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (choice) { loc = choice.loc; diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index 586418dc2b..c981c1e745 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -8,6 +8,8 @@ import { import { osmEntity, osmNote } from '../osm'; import { utilKeybinding, utilRebind } from '../util'; +import _find from 'lodash-es/find'; + /* The hover behavior adds the `.hover` class on mouseover to all elements to which the identical datum is bound, and removes it on mouseout. @@ -97,6 +99,8 @@ export function behaviorHover(context) { function enter(datum) { + + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); if (datum === _target) return; _target = datum; @@ -115,7 +119,7 @@ export function behaviorHover(context) { entity = datum; selector = '.note-' + datum.id; - } else if (datum instanceof osmEntity) { + } else if (datum instanceof osmEntity && Number(datum.id.split('_')[1]) === Number(_activeLayer.id)) { entity = datum; selector = '.' + entity.id; if (entity.type === 'relation') { @@ -132,7 +136,7 @@ export function behaviorHover(context) { } // Update hover state and dispatch event - if (entity && entity.id !== _newId) { + if (entity && entity.id !== _newId && Number(entity.id.split('_')[1]) === Number(_activeLayer.id)) { // If drawing a way, don't hover on a node that was just placed. #3974 var mode = context.mode() && context.mode().id; if ((mode === 'draw-line' || mode === 'draw-area') && !_newId && entity.type === 'node') { diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 5a764f5fdd..ff5833aee5 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -200,9 +200,9 @@ export function modeDragNode(context) { var targetNodes = d && d.properties && d.properties.nodes; var edge; - if (targetLoc && Hoot.layers.loadedLayers === 1 || targetLoc && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Hoot.layers.loadedLayers === 1 || targetNodes && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (edge) { loc = edge.loc; @@ -341,7 +341,7 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; - if ( _activeLayer === undefined || _activeLayer.id !== Number(entity.id.split('_')[1])) return; + if (_activeLayer.id !== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey); diff --git a/modules/svg/areas.js b/modules/svg/areas.js index ca80419232..f4b1453fe3 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -1,5 +1,6 @@ import _map from 'lodash-es/map'; import _values from 'lodash-es/values'; +import _find from 'lodash-es/find'; import { bisector as d3_bisector } from 'd3-array'; @@ -126,14 +127,17 @@ export function svgAreas(projection, context) { var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor '; var getPath = svgPath(projection).geojson; var activeID = context.activeID(); + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; } ); // The targets and nopes will be MultiLineString sub-segments of the ways var data = { targets: [], nopes: [] }; entities.forEach(function(way) { - var features = svgSegmentWay(way, graph, activeID); - data.targets.push.apply(data.targets, features.passive); - data.nopes.push.apply(data.nopes, features.active); + if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { + var features = svgSegmentWay(way, graph, activeID); + data.targets.push.apply(data.targets, features.passive); + data.nopes.push.apply(data.nopes, features.active); + } }); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index 6e0eb11836..cbae8cf0c0 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -3,6 +3,7 @@ import _filter from 'lodash-es/filter'; import _flatten from 'lodash-es/flatten'; import _forOwn from 'lodash-es/forOwn'; import _map from 'lodash-es/map'; +import _find from 'lodash-es/map'; import { range as d3_range } from 'd3-array'; @@ -42,14 +43,17 @@ export function svgLines(projection, context) { var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor '; var getPath = svgPath(projection).geojson; var activeID = context.activeID(); + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; } ); // The targets and nopes will be MultiLineString sub-segments of the ways var data = { targets: [], nopes: [] }; - entities.forEach(function(way) { - var features = svgSegmentWay(way, graph, activeID); - data.targets.push.apply(data.targets, features.passive); - data.nopes.push.apply(data.nopes, features.active); + entities.forEach(function (way) { + if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { + var features = svgSegmentWay(way, graph, activeID); + data.targets.push.apply(data.targets, features.passive); + data.nopes.push.apply(data.nopes, features.active); + } }); diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 689a95d984..9cdef7e04a 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -1,5 +1,6 @@ import _assign from 'lodash-es/assign'; import _values from 'lodash-es/values'; +import _find from 'lodash-es/find'; import { select as d3_select } from 'd3-selection'; @@ -196,33 +197,38 @@ export function svgVertices(projection, context) { var getTransform = svgPointTransform(projection).geojson; var activeID = context.activeID(); var data = { targets: [], nopes: [] }; + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; } ); entities.forEach(function(node) { - if (activeID === node.id) return; // draw no target on the activeID - - var vertexType = svgPassiveVertex(node, graph, activeID); - if (vertexType !== 0) { // passive or adjacent - allow to connect - data.targets.push({ - type: 'Feature', - id: node.id, - properties: { - target: true, - entity: node - }, - geometry: node.asGeoJSON() - }); - } else { - data.nopes.push({ - type: 'Feature', - id: node.id + '-nope', - properties: { - nope: true, - target: true, - entity: node - }, - geometry: node.asGeoJSON() - }); + if (Number(node.id.split('_')[1]) === Number(_activeLayer.id)) { + if (activeID === node.id ) return; // draw no target on the activeID + + var vertexType = svgPassiveVertex(node, graph, activeID); + if (vertexType !== 0) { // passive or adjacent - allow to connect + data.targets.push({ + type: 'Feature', + id: node.id, + properties: { + target: true, + entity: node + }, + geometry: node.asGeoJSON() + }); + } else { + data.nopes.push({ + type: 'Feature', + id: node.id + '-nope', + properties: { + nope: true, + target: true, + entity: node + }, + geometry: node.asGeoJSON() + }); + } + } + }); From 7a390cbfe28bc9f0d67aaff604b2f1e5ee34ab76 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Thu, 6 Jun 2019 15:57:38 -0400 Subject: [PATCH 14/33] fixed active node dragging, updated highlighting, now only active layer --- modules/modes/drag_node.js | 1 + modules/svg/areas.js | 7 ++--- modules/svg/lines.js | 12 ++++----- modules/svg/vertices.js | 55 +++++++++++++++++--------------------- 4 files changed, 34 insertions(+), 41 deletions(-) diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index ff5833aee5..cca9f95110 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -341,6 +341,7 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); if (_activeLayer.id !== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); diff --git a/modules/svg/areas.js b/modules/svg/areas.js index f4b1453fe3..ba057956c2 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -127,15 +127,16 @@ export function svgAreas(projection, context) { var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor '; var getPath = svgPath(projection).geojson; var activeID = context.activeID(); - var _activeLayer = _find(Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; } ); + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); // The targets and nopes will be MultiLineString sub-segments of the ways var data = { targets: [], nopes: [] }; entities.forEach(function(way) { - if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { - var features = svgSegmentWay(way, graph, activeID); + var features = svgSegmentWay(way, graph, activeID); + if (Number(way.id.split('_')[1]) === _activeLayer.id) { data.targets.push.apply(data.targets, features.passive); + } else { data.nopes.push.apply(data.nopes, features.active); } }); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index cbae8cf0c0..207421343d 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -43,17 +43,15 @@ export function svgLines(projection, context) { var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor '; var getPath = svgPath(projection).geojson; var activeID = context.activeID(); - var _activeLayer = _find(Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; } ); + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); // The targets and nopes will be MultiLineString sub-segments of the ways var data = { targets: [], nopes: [] }; - entities.forEach(function (way) { - if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { - var features = svgSegmentWay(way, graph, activeID); - data.targets.push.apply(data.targets, features.passive); - data.nopes.push.apply(data.nopes, features.active); - } + entities.forEach(function(way) { + var features = svgSegmentWay(way, graph, activeID); + data.targets.push.apply(data.targets, features.passive); + data.nopes.push.apply(data.nopes, features.active); }); diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 9cdef7e04a..bc8c8abb61 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -1,7 +1,5 @@ import _assign from 'lodash-es/assign'; import _values from 'lodash-es/values'; -import _find from 'lodash-es/find'; - import { select as d3_select } from 'd3-selection'; import { geoScaleToZoom } from '../geo'; @@ -197,38 +195,33 @@ export function svgVertices(projection, context) { var getTransform = svgPointTransform(projection).geojson; var activeID = context.activeID(); var data = { targets: [], nopes: [] }; - var _activeLayer = _find(Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; } ); entities.forEach(function(node) { - if (Number(node.id.split('_')[1]) === Number(_activeLayer.id)) { - if (activeID === node.id ) return; // draw no target on the activeID - - var vertexType = svgPassiveVertex(node, graph, activeID); - if (vertexType !== 0) { // passive or adjacent - allow to connect - data.targets.push({ - type: 'Feature', - id: node.id, - properties: { - target: true, - entity: node - }, - geometry: node.asGeoJSON() - }); - } else { - data.nopes.push({ - type: 'Feature', - id: node.id + '-nope', - properties: { - nope: true, - target: true, - entity: node - }, - geometry: node.asGeoJSON() - }); - } - + if (activeID === node.id) return; // draw no target on the activeID + + var vertexType = svgPassiveVertex(node, graph, activeID); + if (vertexType !== 0) { // passive or adjacent - allow to connect + data.targets.push({ + type: 'Feature', + id: node.id, + properties: { + target: true, + entity: node + }, + geometry: node.asGeoJSON() + }); + } else { + data.nopes.push({ + type: 'Feature', + id: node.id + '-nope', + properties: { + nope: true, + target: true, + entity: node + }, + geometry: node.asGeoJSON() + }); } - }); From 5c988cb60492a13b7bfb5cfa1ade0b30999c3319 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Thu, 6 Jun 2019 17:10:57 -0400 Subject: [PATCH 15/33] conditional fix for way's finishDraw methods Signed-off-by: Jack Grossman --- modules/behavior/draw.js | 4 ++-- modules/behavior/draw_way.js | 2 +- modules/modes/drag_node.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index c7d563d8f3..d547a58cda 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -126,11 +126,11 @@ export function behaviorDraw(context) { var target = d && d.properties && d.properties.entity; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - if (target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node + if (target && target.type === 'node' && Number(_activeLayer.id) === Number(target.id.split('_')[1])) { // Snap to a node dispatch.call('clickNode', this, target, d); return; - } else if (target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way + } else if (target && target.type === 'way' && Number(_activeLayer.id) === Number(target.id.split('_')[1])) { // Snap to a way var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() ); diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 4cd1084ad6..51dff229bd 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -81,7 +81,7 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { if (targetLoc && Number(datum.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Number(datum.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Number(datum.properties.entity.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to way - a line target with `.nodes` var choice = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (choice) { loc = choice.loc; diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index cca9f95110..bf60855d80 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -341,8 +341,8 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; - var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); - if (_activeLayer.id !== Number(entity.id.split('_')[1])) return; + // var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); + // if (_activeLayer.id !== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey); From 875eac7b588391c1f7930143cb36e5e12637e8f9 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Fri, 7 Jun 2019 10:03:04 -0400 Subject: [PATCH 16/33] css switching update --- modules/svg/areas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/svg/areas.js b/modules/svg/areas.js index ba057956c2..8a13b1387c 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -134,7 +134,7 @@ export function svgAreas(projection, context) { entities.forEach(function(way) { var features = svgSegmentWay(way, graph, activeID); - if (Number(way.id.split('_')[1]) === _activeLayer.id) { + if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { data.targets.push.apply(data.targets, features.passive); } else { data.nopes.push.apply(data.nopes, features.active); From d7182f423f178e97e417477946dd30e009d641d2 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Fri, 7 Jun 2019 14:49:47 -0400 Subject: [PATCH 17/33] added activeLayer check when removing layers, updated verticies svg check --- modules/Hoot/managers/layerManager.js | 24 ++++++++++ modules/Hoot/ui/sidebar/sidebar.js | 63 +++++++++------------------ modules/modes/drag_node.js | 8 ++-- modules/svg/lines.js | 10 +++-- modules/svg/vertices.js | 4 +- 5 files changed, 59 insertions(+), 50 deletions(-) diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index 93cf5c548a..d2786dda69 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -19,6 +19,7 @@ import { rgb as d3_rgb } from 'd3-color'; import { geoExtent as GeoExtent } from '../../geo/index'; import { utilDetect } from '../../util/detect'; import colorPalette from '../config/colorPalette'; +import LayerAdd from '../ui/sidebar/layerAdd'; import { osmChangeset } from '../../osm'; @@ -320,9 +321,32 @@ export default class Layers { this.hoot.context.flush(); } + + if ( Object.keys(Hoot.layers.loadedLayers).length === 1 ) { + this.resetActiveLayers(); + } this.hoot.events.emit( 'loaded-layer-removed' ); } + async resetActiveLayers() { + + let changeActive = new LayerAdd(); + + let loadedLayers = Object.values(Hoot.layers.loadedLayers); + + let referenceLayer = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); + let secondaryLayer = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); + + if (Object.keys(Hoot.layers.loadedLayers).length === 1 && referenceLayer ) { + referenceLayer.activeLayer = true; + changeActive.selectedLayer = referenceLayer; + } else { + secondaryLayer.activeLayer = true; + changeActive.selectedLayer = secondaryLayer; + } + + } + removeAllLoadedLayers() { _forEach( this.loadedLayers, layer => { this.hoot.context.background().removeSource( layer.id ); diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index ffb34f815f..16507d8dc8 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -156,10 +156,21 @@ export default class Sidebar { Hoot.layers.mergedLayer = null; delete this.forms[ d.id ]; this.reset(); - } else { + } + else { this.forms[ d.id ].render( d ); this.conflateCheck(); + if (Object.keys(Hoot.layers.loadedLayers).length === 1) { + let loadedLayers = Object.values(Hoot.layers.loadedLayers); + let referenceActive = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); + if (referenceActive) { + d3.select('#reference button.select-active-layer').remove(); + } else { + d3.select('#secondary button.select-active-layer').remove(); + } + } + //update url hash var q = utilStringQs(window.location.hash.substring(1)); delete q[d.refType]; @@ -173,11 +184,12 @@ export default class Sidebar { let loadedLayers = Object.values(Hoot.layers.loadedLayers); let selectReference = d3.selectAll('#reference'); let selectSecondary = d3.selectAll('#secondary'); + let referenceActive = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); + let secondaryActive = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); let refClickCount = 0; let secClickCount = 0; + if (loadedLayers.length === 2) { - let referenceActive = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); - let secondaryActive = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); let changeActive = new LayerAdd(); // eslint-disable-next-line no-inner-declarations @@ -216,7 +228,6 @@ export default class Sidebar { } - if (d3.select('#reference button.select-active-layer').empty()) { selectReference @@ -253,7 +264,7 @@ export default class Sidebar { .text('Active Layer'); updateButton('reference', 'secondary'); } - while (refClickCount === 2) { + while (refClickCount === 2 && Object.keys(Hoot.layers.loadedLayers).length > 1) { updateButton(null, 'reference'); referenceActive.activeLayer = null; refClickCount = 0; @@ -280,6 +291,10 @@ export default class Sidebar { updateButton('secondary', 'reference'); } + if ( Object.keys(Hoot.layers.loadedLayers).length === 1 ) { + d3.select('#secondary button').remove(); + } + selectSecondary .on('click', function () { @@ -302,7 +317,7 @@ export default class Sidebar { updateButton('secondary', 'reference'); } - while ( secClickCount === 2 ) { + while ( secClickCount === 2 && Object.keys(Hoot.layers.loadedLayers).length > 1 ) { updateButton(null, 'secondary'); secondaryActive.activeLayer = null; secClickCount = 0; @@ -312,42 +327,6 @@ export default class Sidebar { }); } - - // else if ( secondaryActive.activeLayer === null && secClickCount === 0 ) { - - // selectSecondary - // .append('button') - // .classed('select-active-layer', true) - // .text('Set as active layer') - // .on('click', function () { - - // d3.event.preventDefault(); - - // //updateButton('reference', 'secondary'); - - // if (referenceActive.activeLayer !== null) { - // referenceActive.activeLayer = null; - // secondaryActive.activeLayer = true; - // } - // else if (secClickCount === 1 && secondaryActive.activeLayer === true) { - // secClickCount++; - // } - // else { - // secClickCount++; - // secondaryActive.activeLayer = true; - // } - // while ( secClickCount === 2 ) { - // updateButton(null, 'secondary'); - // secondaryActive.activeLayer = null; - // secClickCount = 0; - // } - - // changeActive.selectedLayer = referenceActive; - - // }); - - // } - } } diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index bf60855d80..1afec80c02 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -200,9 +200,9 @@ export function modeDragNode(context) { var targetNodes = d && d.properties && d.properties.nodes; var edge; - if (targetLoc && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to way - a line target with `.nodes` edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (edge) { loc = edge.loc; @@ -341,8 +341,8 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; - // var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); - // if (_activeLayer.id !== Number(entity.id.split('_')[1])) return; + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); + if (Number(_activeLayer.id) !== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index 207421343d..2ba13c5086 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -3,7 +3,7 @@ import _filter from 'lodash-es/filter'; import _flatten from 'lodash-es/flatten'; import _forOwn from 'lodash-es/forOwn'; import _map from 'lodash-es/map'; -import _find from 'lodash-es/map'; +import _find from 'lodash-es/find'; import { range as d3_range } from 'd3-array'; @@ -50,8 +50,12 @@ export function svgLines(projection, context) { entities.forEach(function(way) { var features = svgSegmentWay(way, graph, activeID); - data.targets.push.apply(data.targets, features.passive); - data.nopes.push.apply(data.nopes, features.active); + if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { + data.targets.push.apply(data.targets, features.passive); + } + else { + data.nopes.push.apply(data.nopes, features.active); + } }); diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index bc8c8abb61..31baef74d4 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -1,5 +1,6 @@ import _assign from 'lodash-es/assign'; import _values from 'lodash-es/values'; +import _find from 'lodash-es/find'; import { select as d3_select } from 'd3-selection'; import { geoScaleToZoom } from '../geo'; @@ -195,12 +196,13 @@ export function svgVertices(projection, context) { var getTransform = svgPointTransform(projection).geojson; var activeID = context.activeID(); var data = { targets: [], nopes: [] }; + var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); entities.forEach(function(node) { if (activeID === node.id) return; // draw no target on the activeID var vertexType = svgPassiveVertex(node, graph, activeID); - if (vertexType !== 0) { // passive or adjacent - allow to connect + if (vertexType !== 0 || Number(node.id.split('_')[1]) === Number(_activeLayer.id) ) { // passive or adjacent - allow to connect data.targets.push({ type: 'Feature', id: node.id, From 87d9353af43771bb0c4e0d1760d2c85e1b0bd6ef Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 10 Jun 2019 09:30:06 -0400 Subject: [PATCH 18/33] added null check, revert to defaultFolder in domMetadata --- modules/Hoot/config/domMetadata.js | 10 +++++----- modules/modes/drag_node.js | 4 ++-- modules/svg/vertices.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/Hoot/config/domMetadata.js b/modules/Hoot/config/domMetadata.js index 67d26f72f1..5fd98bc644 100644 --- a/modules/Hoot/config/domMetadata.js +++ b/modules/Hoot/config/domMetadata.js @@ -27,8 +27,8 @@ export function layerConflateForm( data ) { id: 'conflateFolderPath', class: 'path-name', inputType: 'combobox', - value: this.defaultFolder ? this.defaultFolder.name : 'root', - _value: this.defaultFolder ? this.defaultFolder.id : 0, + value: this.defaultFolder.name, + _value: this.defaultFolder.id, data: this.folderList, itemKey: 'path', _valueKey: 'id', @@ -243,14 +243,14 @@ export function importMultiForm() { export function addFolderForm() { return [ { - label: 'Name', + label: 'Folder Name', id: 'addFolderName', class: 'new-folder-name', inputType: 'text', onChange: d => this.validateTextInput( d ) }, { - label: 'Public', + label: 'Folder Visibility', id: 'addFolderVisibility', inputType: 'checkbox', value: 'Public', @@ -290,7 +290,7 @@ export function modifyDatasetForm() { onChange: d => this.validateTextInput( d ) }, { - label: 'Public', + label: 'Visiblity', id: 'modifyVisibility', inputType: 'checkbox', value: 'Public', diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 1afec80c02..4ea8e39de0 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -371,7 +371,7 @@ export function modeDragNode(context) { _actionBounceBack(entity.id, _startLoc) ); - } else if (target && target.type === 'way' && Number(target.id.split('_')[1]) === _activeLayer.id) { + } else if (target && target.type === 'way') { // && Number(target.id.split('_')[1]) === _activeLayer.id var choice = geoChooseEdge(context.childNodes(target), context.mouse(), context.projection, entity.id); context.replace( actionAddMidpoint({ @@ -381,7 +381,7 @@ export function modeDragNode(context) { connectAnnotation(entity, target) ); - } else if (target && target.type === 'node' && Number(target.id.split('_')[1]) === _activeLayer.id) { + } else if (target && target.type === 'node' ) { //&& Number(target.id.split('_')[1]) === _activeLayer.id context.replace( actionConnect([target.id, entity.id]), connectAnnotation(entity, target) diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 31baef74d4..7572045954 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -202,7 +202,7 @@ export function svgVertices(projection, context) { if (activeID === node.id) return; // draw no target on the activeID var vertexType = svgPassiveVertex(node, graph, activeID); - if (vertexType !== 0 || Number(node.id.split('_')[1]) === Number(_activeLayer.id) ) { // passive or adjacent - allow to connect + if (vertexType !== 0 && node.id && _activeLayer.id && Number(node.id.split('_')[1]) === Number(_activeLayer.id) ) { // passive or adjacent - allow to connect data.targets.push({ type: 'Feature', id: node.id, From fd82f8fba19660e750fa83ed67170aa8ee7a60d2 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 10 Jun 2019 14:20:08 -0400 Subject: [PATCH 19/33] updating svg classes for proper activeLayer checking --- modules/behavior/hover.js | 4 +-- modules/behavior/select.js | 8 ++---- modules/modes/drag_node.js | 10 +++---- modules/modes/save.js | 35 ++---------------------- modules/modes/select.js | 1 - modules/osm/entity.js | 4 +-- modules/services/osm.js | 56 -------------------------------------- modules/svg/areas.js | 3 +- modules/svg/lines.js | 3 +- modules/svg/vertices.js | 4 ++- 10 files changed, 20 insertions(+), 108 deletions(-) diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index c981c1e745..ac22b0df5f 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -119,7 +119,7 @@ export function behaviorHover(context) { entity = datum; selector = '.note-' + datum.id; - } else if (datum instanceof osmEntity && Number(datum.id.split('_')[1]) === Number(_activeLayer.id)) { + } else if (datum instanceof osmEntity && _activeLayer && _activeLayer.id && Number(datum.id.split('_')[1]) === Number(_activeLayer.id)) { entity = datum; selector = '.' + entity.id; if (entity.type === 'relation') { @@ -136,7 +136,7 @@ export function behaviorHover(context) { } // Update hover state and dispatch event - if (entity && entity.id !== _newId && Number(entity.id.split('_')[1]) === Number(_activeLayer.id)) { + if (entity && entity.id !== _newId && _activeLayer && _activeLayer.id && Number(entity.id.split('_')[1]) === Number(_activeLayer.id)) { // If drawing a way, don't hover on a node that was just placed. #3974 var mode = context.mode() && context.mode().id; if ((mode === 'draw-line' || mode === 'draw-area') && !_newId && entity.type === 'node') { diff --git a/modules/behavior/select.js b/modules/behavior/select.js index 011739d3f1..ae89d7bde0 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -20,8 +20,6 @@ import { osmEntity, osmNote } from '../osm'; -import { createSecurePair } from 'tls'; - export function behaviorSelect(context) { var lastMouse = null; @@ -139,9 +137,9 @@ export function behaviorSelect(context) { if (!isMultiselect) { if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways) ) { mode.suppressMenu(false).reselect(); - } else if (Number(datum.id.split('_')[1]) !== Number(_activeLayer.id)) { - selectedIDs = []; - } else { + } else if (Number(datum.id.split('_')[1]) === Number(_activeLayer.id)) { + // selectedIDs = []; + // } else { // select a single thing.. context.enter(modeSelect(context, [datum.id]).suppressMenu(suppressMenu)); } diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 4ea8e39de0..efbcec382e 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -200,9 +200,9 @@ export function modeDragNode(context) { var targetNodes = d && d.properties && d.properties.nodes; var edge; - if (targetLoc && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to way - a line target with `.nodes` + } else if (targetNodes && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to way - a line target with `.nodes` edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (edge) { loc = edge.loc; @@ -342,7 +342,7 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); - if (Number(_activeLayer.id) !== Number(entity.id.split('_')[1])) return; + if (_activeLayer && _activeLayer.id && Number(_activeLayer.id) !== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey); @@ -371,7 +371,7 @@ export function modeDragNode(context) { _actionBounceBack(entity.id, _startLoc) ); - } else if (target && target.type === 'way') { // && Number(target.id.split('_')[1]) === _activeLayer.id + } else if (target && target.type === 'way' && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === _activeLayer.id) { var choice = geoChooseEdge(context.childNodes(target), context.mouse(), context.projection, entity.id); context.replace( actionAddMidpoint({ @@ -381,7 +381,7 @@ export function modeDragNode(context) { connectAnnotation(entity, target) ); - } else if (target && target.type === 'node' ) { //&& Number(target.id.split('_')[1]) === _activeLayer.id + } else if (target && target.type === 'node' && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === _activeLayer.id) { context.replace( actionConnect([target.id, entity.id]), connectAnnotation(entity, target) diff --git a/modules/modes/save.js b/modules/modes/save.js index d83395545c..908d641d59 100644 --- a/modules/modes/save.js +++ b/modules/modes/save.js @@ -44,11 +44,6 @@ import { utilKeybinding } from '../util'; -import { osmEntity } from '../osm/index'; -import { create } from 'domain'; -import { pseudoRandomBytes } from 'crypto'; -import { async } from 'q'; - var _isSaving = false; @@ -310,8 +305,8 @@ export function modeSave(context) { if (changes.modified.length || changes.created.length || changes.deleted.length) { //loadLocation(); // so it is ready when we display the save screen - var getMapIds = Object.keys(Hoot.layers.loadedLayers); - var idToNum = getMapIds.map(parseFloat); + var getMapIds = Object.keys(Hoot.layers.loadedLayers); + var idToNum = getMapIds.map(parseFloat); idToNum.forEach(function (mapId) { var created = changes.created.filter(function (created) { return Number(created.id.split('_')[1]) === mapId; }); @@ -334,32 +329,6 @@ export function modeSave(context) { }); osm.putChangeset(changeset, _changesetArray[0].changes, uploadCallback, _changesetArray[0].mapId); - - // var mapChanges = idToNum.map(function(mapId) { - // var created = changes.created.filter(function(created) { return Number(created.id.split('_')[1]) === mapId; }); - // var modified = changes.modified.filter(function(modified) { return Number(modified.id.split('_')[1]) === mapId; }); - // var deleted = changes.deleted.filter(function(deleted) { return Number(deleted.id.split('_')[1]) === mapId; }); - // return { - // mapId: mapId, - // changes: { - // created: created, - // modified: modified, - // d deleted: deleted - // } - // }; - // }); - - // mapChanges.forEach( - // function (changes) { - // if (changes.changes.created.length === 0 && changes.changes.modified.length === 0 && changes.changes.deleted.length === 0) { - // return; - // } - // else if (changes.changes.created.length > 0 || changes.changes.modified.length > 0 || changes.changes.deleted.length > 0) { - // _changesetArray.push(changes); - // } - // osm.putChangeset(changeset, changes.changes ,uploadCallback, _changesetArray, changes.mapId); - // } - // ); } else { // changes were insignificant or reverted by user d3_select('.inspector-wrap *').remove(); loading.close(); diff --git a/modules/modes/select.js b/modules/modes/select.js index 67c8391bca..add5b64798 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -1,5 +1,4 @@ import _intersection from 'lodash-es/intersection'; -import _find from 'lodash-es/find'; import _map from 'lodash-es/map'; import _uniq from 'lodash-es/uniq'; import _values from 'lodash-es/values'; diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 85e8921a4a..b901685ba7 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -26,9 +26,7 @@ export function osmEntity(attrs) { osmEntity.id = function(type) { var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - let allIds = {}; - allIds = _activeLayer.activeIds; - var id = osmEntity.id.fromOSM(type, allIds[type]--); + var id = osmEntity.id.fromOSM(type, _activeLayer.activeIds[type]--); if (_activeLayer && _activeLayer.id) { id = id + '_' + _activeLayer.id; } diff --git a/modules/services/osm.js b/modules/services/osm.js index e861bbe504..f59c7a8405 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -628,60 +628,6 @@ export default { return oauth.authenticated(); }, - - filterChanges: function( changes ) { - let ways = _filter( _flatten( _map( changes, featArr => featArr ) ), feat => feat.type !== 'node' ), - checkLayers = Hoot.layers.loadedLayers, - visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), - activeLayer = _find(checkLayers, function(a, b) { return a.activeLayer === true; }), - defaultMapId; - - // Make sure there is only one layer visible. Otherwise, return a falsy value to prevent save. - - if ( activeLayer.activeLayer === true ){ - defaultMapId = activeLayer.id; - } else { - return false; - } - - return _reduce( changes, ( obj, featArr, type ) => { - let changeTypes = { - created: [], - deleted: [], - modified: [] - }; - - _forEach( featArr, feat => { - let mapId = defaultMapId; - - if ( feat.isNew() && feat.type === 'node' ) { - let parent = _find( ways, way => _includes( way.nodes, feat.id ) ); - - if ( parent && parent.mapId ) { - mapId = parent.mapId; - } - } - - // create map ID key if not yet exists - if ( !obj[ mapId ] ) { - obj[ mapId ] = {}; - } - - // create change type key if not yet exists - if ( !obj[ mapId ][ type ] ) { - obj[ mapId ][ type ] = []; - } - - obj[ mapId ][ type ].push( feat ); - - // merge object into default types array so that the final result - // will contain all keys in case change type is empty - obj[ mapId ] = Object.assign( changeTypes, obj[ mapId ] ); - } ); - return obj; - }, {} ); - }, - // Create, upload, and close a changeset // PUT /api/0.6/changeset/create // POST /api/0.6/changeset/#i/upload @@ -689,8 +635,6 @@ export default { putChangeset: function(changeset, changes, callback, mapId ) { var cid = _connectionID; - //let changesArr = this.filterChanges(changes); - if (_changeset.inflight) { return callback({ message: 'Changeset already inflight', status: -2 }, changeset); diff --git a/modules/svg/areas.js b/modules/svg/areas.js index 8a13b1387c..3f4fd545c7 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -134,7 +134,8 @@ export function svgAreas(projection, context) { entities.forEach(function(way) { var features = svgSegmentWay(way, graph, activeID); - if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { + var activeLayerCheck = _activeLayer ? way.id && _activeLayer.id && Number(way.id.split('_')[1]) === Number(_activeLayer.id) : true; + if (activeLayerCheck) { data.targets.push.apply(data.targets, features.passive); } else { data.nopes.push.apply(data.nopes, features.active); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index d679a0597c..67e5204bc2 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -50,7 +50,8 @@ export function svgLines(projection, context) { entities.forEach(function(way) { var features = svgSegmentWay(way, graph, activeID); - if (Number(way.id.split('_')[1]) === Number(_activeLayer.id)) { + var activeLayerCheck = _activeLayer ? way.id && _activeLayer.id && Number(way.id.split('_')[1]) === Number(_activeLayer.id) : true; + if (activeLayerCheck) { data.targets.push.apply(data.targets, features.passive); } else { diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 726da97280..9d5407a6c7 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -202,7 +202,9 @@ export function svgVertices(projection, context) { if (activeID === node.id) return; // draw no target on the activeID var vertexType = svgPassiveVertex(node, graph, activeID); - if (vertexType !== 0 && node.id && _activeLayer.id && Number(node.id.split('_')[1]) === Number(_activeLayer.id) ) { // passive or adjacent - allow to connect + var activeLayerCheck = _activeLayer ? node.id && _activeLayer.id && Number(node.id.split('_')[1]) === Number(_activeLayer.id) : true; + // if active layer isn't set, identify it, otherwise push targets and nopes + if (vertexType !== 0 && activeLayerCheck) { // passive or adjacent - allow to connect data.targets.push({ type: 'Feature', id: node.id, From ba9dda24ba3fd04f6e215f4e802211cf7a3be775 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 10 Jun 2019 14:55:43 -0400 Subject: [PATCH 20/33] removed parsing of active layer id --- modules/Hoot/managers/layerManager.js | 2 +- modules/Hoot/ui/sidebar/sidebar.js | 6 ++---- modules/behavior/draw.js | 4 ++-- modules/behavior/draw_way.js | 4 ++-- modules/behavior/hover.js | 5 +++-- modules/behavior/select.js | 4 +--- modules/modes/drag_node.js | 6 +++--- modules/svg/areas.js | 3 ++- modules/svg/lines.js | 3 ++- modules/svg/vertices.js | 5 +++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index f4ee3f6b23..1c58256c72 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -183,7 +183,7 @@ export default class Layers { let layer = { name: params.name, id: params.id, - activeLayer: params.activeLayer === undefined ? null : params.activeLayer, + activeLayer: params.activeLayer === undefined ? null : Number(params.activeLayer), activeIds: activeIds, refType: params.refType, color: params.color, diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index 641402b9d8..bf14f00d6e 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -187,8 +187,6 @@ export default class Sidebar { let selectSecondary = d3.selectAll('#secondary'); let referenceActive = _find(loadedLayers, function(a, b) { return a.refType === 'primary'; }); let secondaryActive = _find(loadedLayers, function(a, b) { return a.refType === 'secondary'; }); - let refClickCount = 0; - let secClickCount = 0; if (loadedLayers.length === 2) { let changeActive = new LayerAdd(); @@ -262,7 +260,7 @@ export default class Sidebar { .classed('select-active-layer', true) .text('Set as active layer'); - if (referenceActive.activeLayer === true && refClickCount === 0) { + if (referenceActive.activeLayer === true) { d3.select('#reference button.select-active-layer') .classed('select-active-layer', true) .text('Active Layer'); @@ -282,7 +280,7 @@ export default class Sidebar { .text('Set as active layer'); - if (secondaryActive.activeLayer === true && secClickCount === 0) { + if (secondaryActive.activeLayer === true) { d3.select('#secondary button.select-active-layer') .classed('select-active-layer', true) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index d547a58cda..c7d563d8f3 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -126,11 +126,11 @@ export function behaviorDraw(context) { var target = d && d.properties && d.properties.entity; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); - if (target && target.type === 'node' && Number(_activeLayer.id) === Number(target.id.split('_')[1])) { // Snap to a node + if (target && target.type === 'node' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a node dispatch.call('clickNode', this, target, d); return; - } else if (target && target.type === 'way' && Number(_activeLayer.id) === Number(target.id.split('_')[1])) { // Snap to a way + } else if (target && target.type === 'way' && _activeLayer.id === Number(target.id.split('_')[1])) { // Snap to a way var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() ); diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 51dff229bd..cc1bf1ba28 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -78,10 +78,10 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer; }); var loc = context.map().mouseCoordinates(); - if (targetLoc && Number(datum.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && Number(datum.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && Number(datum.properties.entity.id.split('_')[1]) === Number(_activeLayer.id) ) { // snap to way - a line target with `.nodes` + } else if (targetNodes && Number(datum.properties.entity.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` var choice = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (choice) { loc = choice.loc; diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index ac22b0df5f..39b29183c2 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -101,6 +101,7 @@ export function behaviorHover(context) { function enter(datum) { var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); + if (datum === _target) return; _target = datum; @@ -119,7 +120,7 @@ export function behaviorHover(context) { entity = datum; selector = '.note-' + datum.id; - } else if (datum instanceof osmEntity && _activeLayer && _activeLayer.id && Number(datum.id.split('_')[1]) === Number(_activeLayer.id)) { + } else if (datum instanceof osmEntity && _activeLayer && _activeLayer.id && Number(datum.id.split('_')[1]) === _activeLayer.id) { entity = datum; selector = '.' + entity.id; if (entity.type === 'relation') { @@ -136,7 +137,7 @@ export function behaviorHover(context) { } // Update hover state and dispatch event - if (entity && entity.id !== _newId && _activeLayer && _activeLayer.id && Number(entity.id.split('_')[1]) === Number(_activeLayer.id)) { + if (entity && entity.id !== _newId && _activeLayer && _activeLayer.id && Number(entity.id.split('_')[1]) === _activeLayer.id) { // If drawing a way, don't hover on a node that was just placed. #3974 var mode = context.mode() && context.mode().id; if ((mode === 'draw-line' || mode === 'draw-area') && !_newId && entity.type === 'node') { diff --git a/modules/behavior/select.js b/modules/behavior/select.js index ae89d7bde0..725fe440aa 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -137,9 +137,7 @@ export function behaviorSelect(context) { if (!isMultiselect) { if (selectedIDs.length > 1 && (!suppressMenu && !isShowAlways) ) { mode.suppressMenu(false).reselect(); - } else if (Number(datum.id.split('_')[1]) === Number(_activeLayer.id)) { - // selectedIDs = []; - // } else { + } else if (Number(datum.id.split('_')[1]) === _activeLayer.id) { // select a single thing.. context.enter(modeSelect(context, [datum.id]).suppressMenu(suppressMenu)); } diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index efbcec382e..ee37251f59 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -200,9 +200,9 @@ export function modeDragNode(context) { var targetNodes = d && d.properties && d.properties.nodes; var edge; - if (targetLoc && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to node/vertex - a point target with `.loc` + if (targetLoc && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to node/vertex - a point target with `.loc` loc = targetLoc; - } else if (targetNodes && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === Number(_activeLayer.id)) { // snap to way - a line target with `.nodes` + } else if (targetNodes && _activeLayer && _activeLayer.id && Number(target.id.split('_')[1]) === _activeLayer.id) { // snap to way - a line target with `.nodes` edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); if (edge) { loc = edge.loc; @@ -342,7 +342,7 @@ export function modeDragNode(context) { function move(entity) { if (_isCancelled) return; var _activeLayer = _find( Hoot.layers.loadedLayers, function(a,b) { return a.activeLayer; }); - if (_activeLayer && _activeLayer.id && Number(_activeLayer.id) !== Number(entity.id.split('_')[1])) return; + if (_activeLayer && _activeLayer.id && _activeLayer.id!== Number(entity.id.split('_')[1])) return; d3_event.sourceEvent.stopPropagation(); context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey); diff --git a/modules/svg/areas.js b/modules/svg/areas.js index 3f4fd545c7..3b9ec4039d 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -128,13 +128,14 @@ export function svgAreas(projection, context) { var getPath = svgPath(projection).geojson; var activeID = context.activeID(); var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); + var noActiveLayer = !_activeLayer; // The targets and nopes will be MultiLineString sub-segments of the ways var data = { targets: [], nopes: [] }; entities.forEach(function(way) { var features = svgSegmentWay(way, graph, activeID); - var activeLayerCheck = _activeLayer ? way.id && _activeLayer.id && Number(way.id.split('_')[1]) === Number(_activeLayer.id) : true; + var activeLayerCheck = noActiveLayer ? true : Number(way.id.split('_')[1]) === _activeLayer.id; if (activeLayerCheck) { data.targets.push.apply(data.targets, features.passive); } else { diff --git a/modules/svg/lines.js b/modules/svg/lines.js index 67e5204bc2..fa2c7f205f 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -44,13 +44,14 @@ export function svgLines(projection, context) { var getPath = svgPath(projection).geojson; var activeID = context.activeID(); var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); + var noActiveLayer = !_activeLayer; // The targets and nopes will be MultiLineString sub-segments of the ways var data = { targets: [], nopes: [] }; entities.forEach(function(way) { var features = svgSegmentWay(way, graph, activeID); - var activeLayerCheck = _activeLayer ? way.id && _activeLayer.id && Number(way.id.split('_')[1]) === Number(_activeLayer.id) : true; + var activeLayerCheck = noActiveLayer ? true : Number(way.id.split('_')[1]) === _activeLayer.id; if (activeLayerCheck) { data.targets.push.apply(data.targets, features.passive); } diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 9d5407a6c7..4259420667 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -197,14 +197,15 @@ export function svgVertices(projection, context) { var activeID = context.activeID(); var data = { targets: [], nopes: [] }; var _activeLayer = _find(Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true; }); + var noActiveLayer = !_activeLayer; entities.forEach(function(node) { if (activeID === node.id) return; // draw no target on the activeID var vertexType = svgPassiveVertex(node, graph, activeID); - var activeLayerCheck = _activeLayer ? node.id && _activeLayer.id && Number(node.id.split('_')[1]) === Number(_activeLayer.id) : true; + var isActiveLayer = noActiveLayer ? true : Number(node.id.split('_')[1]) === _activeLayer.id; // if active layer isn't set, identify it, otherwise push targets and nopes - if (vertexType !== 0 && activeLayerCheck) { // passive or adjacent - allow to connect + if (vertexType !== 0 && isActiveLayer) { // passive or adjacent - allow to connect data.targets.push({ type: 'Feature', id: node.id, From 1f0ec99717b3b33e2b702357118156d2983a7ea1 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 10 Jun 2019 15:42:52 -0400 Subject: [PATCH 21/33] updating for failing jenkins tests --- modules/modes/save.js | 1 - test/spec/spec_helpers.js | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/modes/save.js b/modules/modes/save.js index 908d641d59..abcf92ef94 100644 --- a/modules/modes/save.js +++ b/modules/modes/save.js @@ -1,6 +1,5 @@ import _clone from 'lodash-es/clone'; import _filter from 'lodash-es/filter'; -import _find from 'lodash-es/find'; import _map from 'lodash-es/map'; import _reduce from 'lodash-es/reduce'; import _union from 'lodash-es/union'; diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index 8459786cdb..88870f4c21 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -23,6 +23,23 @@ mocha.setup({ expect = chai.expect; window.d3 = iD.d3; // TODO: remove +window.Hoot = { + layers: { + loadedLayers: { + 50: { + name: 'a', + id: '50', + activeIds: { + node: 0, + way: 0, + relation: 0, + changeset: 0 + }, + refType: 'primary' + } + } + } +}; // Array.find polyfill (For PhantomJS / IE11) From 42af31c28fb4ce149b45fddcb2757dcbed3c48d3 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 10:34:11 -0400 Subject: [PATCH 22/33] fix behabior test #1425 --- test/index.html | 10 +++++----- test/spec/behavior/hover.js | 20 ++++++++++---------- test/spec/spec_helpers.js | 3 ++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/index.html b/test/index.html index d52e9fad38..6d48266e74 100644 --- a/test/index.html +++ b/test/index.html @@ -32,7 +32,7 @@ - + - + + - + --> diff --git a/test/spec/behavior/hover.js b/test/spec/behavior/hover.js index 4dbc5ac9a1..4811bbb718 100644 --- a/test/spec/behavior/hover.js +++ b/test/spec/behavior/hover.js @@ -32,8 +32,8 @@ describe('iD.behaviorHover', function() { describe('mouseover', function () { it('adds the .hover class to all elements to which the same datum is bound', function () { - var a = iD.osmNode({id: 'a'}); - var b = iD.osmNode({id: 'b'}); + var a = iD.osmNode({id: 'a_50'}); + var b = iD.osmNode({id: 'b_50'}); _graph = iD.coreGraph([a, b]); _container.selectAll('span') @@ -41,15 +41,15 @@ describe('iD.behaviorHover', function() { .enter().append('span').attr('class', function(d) { return d.id; }); _container.call(iD.behaviorHover(_context)); - iD.utilTriggerEvent(_container.selectAll('.a'), 'mouseover'); + iD.utilTriggerEvent(_container.selectAll('.a_50'), 'mouseover'); - expect(_container.selectAll('.a.hover').nodes()).to.have.length(2); - expect(_container.selectAll('.b.hover').nodes()).to.have.length(0); + expect(_container.selectAll('.a_50.hover').nodes()).to.have.length(2); + expect(_container.selectAll('.b_50.hover').nodes()).to.have.length(0); }); it('adds the .hover class to all members of a relation', function() { - var a = iD.osmRelation({id: 'a', members: [{id: 'b'}]}); - var b = iD.osmNode({id: 'b'}); + var a = iD.osmRelation({id: 'a_50', members: [{id: 'b_50'}]}); + var b = iD.osmNode({id: 'b_50'}); _graph = iD.coreGraph([a, b]); _container.selectAll('span') @@ -57,10 +57,10 @@ describe('iD.behaviorHover', function() { .enter().append('span').attr('class', function(d) { return d.id; }); _container.call(iD.behaviorHover(_context)); - iD.utilTriggerEvent(_container.selectAll('.a'), 'mouseover'); + iD.utilTriggerEvent(_container.selectAll('.a_50'), 'mouseover'); - expect(_container.selectAll('.a.hover').nodes()).to.have.length(1); - expect(_container.selectAll('.b.hover').nodes()).to.have.length(1); + expect(_container.selectAll('.a_50.hover').nodes()).to.have.length(1); + expect(_container.selectAll('.b_50.hover').nodes()).to.have.length(1); }); }); diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index 88870f4c21..a8f34b8e41 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -28,7 +28,8 @@ window.Hoot = { loadedLayers: { 50: { name: 'a', - id: '50', + id: 50, + activeLayer: true, activeIds: { node: 0, way: 0, From 21d821966ef7e10a92c985d2f5109c07f168c04c Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 11:39:40 -0400 Subject: [PATCH 23/33] fix history tests #1425 --- modules/osm/entity.js | 2 +- package.json | 1 + test/spec/core/history.js | 56 +++++++++++++++++++-------------------- test/spec/spec_helpers.js | 20 +++++++------- 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/modules/osm/entity.js b/modules/osm/entity.js index b901685ba7..db552a034c 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -18,7 +18,7 @@ export function osmEntity(attrs) { if (attrs && attrs.type) { return osmEntity[attrs.type].apply(this, arguments); } else if (attrs && attrs.id && attrs.id.includes(String(_activeLayer.id))) { - return osmEntity[osmEntity.id.type(attrs.id).apply(this, arguments)]; + return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments); } // Initialize a generic Entity (used only in tests). return (new osmEntity()).initialize(arguments); diff --git a/package.json b/package.json index 5cd0593573..a16dcb85c9 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "all": "npm-run-all -s clean build dist", "build": "webpack --env.NODE_ENV=prod", "build:analyze": "webpack --env.NODE_ENV=analyze", + "build:dev": "webpack --env.NODE_ENV=dev", "clean": "shx rm -f dist/*.js dist/*.map dist/*.css dist/img/*.svg", "dist": "npm-run-all -p dist:**", "dist:mapillary": "shx mkdir -p dist/mapillary-js && shx cp -R node_modules/mapillary-js/dist/* dist/mapillary-js/", diff --git a/test/spec/core/history.js b/test/spec/core/history.js index 467e48d5fa..38d32da6cd 100644 --- a/test/spec/core/history.js +++ b/test/spec/core/history.js @@ -391,13 +391,13 @@ describe('iD.History', function () { var json = { 'stack': [ {'entities': {}}, - {'entities': {'n-1': {'loc': [1, 2], 'id': 'n-1'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'} + {'entities': {'n-1_50': {'loc': [1, 2], 'id': 'n-1_50'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'} ], 'nextIDs': {'node': -2, 'way': -1, 'relation': -1}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]})); + expect(history.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', loc: [1, 2]})); expect(history.undoAnnotation()).to.eql('Added a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1}); @@ -407,14 +407,14 @@ describe('iD.History', function () { var json = { 'stack': [ {'entities': {}}, - {'entities': {'n-1': {'loc': [1, 2], 'id': 'n-1'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'}, - {'entities': {'n-1': {'loc': [2, 3], 'id': 'n-1', 'v': 1}}, 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'} + {'entities': {'n-1_50': {'loc': [1, 2], 'id': 'n-1_50'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'}, + {'entities': {'n-1_50': {'loc': [2, 3], 'id': 'n-1_50', 'v': 1}}, 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'} ], 'nextIDs': {'node': -2, 'way': -1, 'relation': -1}, 'index': 2 }; history.fromJSON(JSON.stringify(json)); - expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [2, 3], v: 1})); + expect(history.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', loc: [2, 3], v: 1})); expect(history.undoAnnotation()).to.eql('Moved a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1}); @@ -424,14 +424,14 @@ describe('iD.History', function () { var json = { 'stack': [ {'entities': {}}, - {'entities': {'n1': 'undefined'}, 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'} + {'entities': {'n1_50': 'undefined'}, 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'} ], 'nextIDs': {'node': -1, 'way': -2, 'relation': -3}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - history.merge([iD.Node({id: 'n1'})]); - expect(history.graph().hasEntity('n1')).to.be.undefined; + history.merge([iD.Node({id: 'n1_50'})]); + expect(history.graph().hasEntity('n1_50')).to.be.undefined; expect(history.undoAnnotation()).to.eql('Deleted a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -1, way: -2, relation: -3}); @@ -441,17 +441,17 @@ describe('iD.History', function () { var json = { 'version': 2, 'entities': [ - {'loc': [1, 2], 'id': 'n-1'} + {'loc': [1, 2], 'id': 'n-1_50'} ], 'stack': [ {}, - {'modified': ['n-1v0'], 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'} + {'modified': ['n-1_50v0'], 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'} ], 'nextIDs': {'node': -2, 'way': -1, 'relation': -1}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]})); + expect(history.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', loc: [1, 2]})); expect(history.undoAnnotation()).to.eql('Added a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1}); @@ -462,18 +462,18 @@ describe('iD.History', function () { var json = { 'version': 2, 'entities': [ - {'loc': [2, 3], 'id': 'n1', 'v': 1} + {'loc': [2, 3], 'id': 'n1_50', 'v': 1} ], 'stack': [ {}, - {'modified': ['n1v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'} + {'modified': ['n1_50v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'} ], 'nextIDs': {'node': -2, 'way': -1, 'relation': -1}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - history.merge([iD.Node({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135) - expect(history.graph().entity('n1')).to.eql(iD.Node({id: 'n1', loc: [2, 3], v: 1})); + history.merge([iD.Node({id: 'n1_50'})]); // Shouldn't be necessary; flaw in v2 format (see #2135) + expect(history.graph().entity('n1_50')).to.eql(iD.Node({id: 'n1_50', loc: [2, 3], v: 1})); expect(history.undoAnnotation()).to.eql('Moved a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1}); @@ -486,14 +486,14 @@ describe('iD.History', function () { 'entities': [], 'stack': [ {}, - {'deleted': ['n1'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'} + {'deleted': ['n1_50'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'} ], 'nextIDs': {'node': -1, 'way': -2, 'relation': -3}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - history.merge([iD.Node({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135) - expect(history.graph().hasEntity('n1')).to.be.undefined; + history.merge([iD.Node({id: 'n1_50'})]); // Shouldn't be necessary; flaw in v2 format (see #2135) + expect(history.graph().hasEntity('n1_50')).to.be.undefined; expect(history.undoAnnotation()).to.eql('Deleted a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -1, way: -2, relation: -3}); @@ -504,18 +504,18 @@ describe('iD.History', function () { var json = { 'version': 3, 'entities': [ - {'loc': [1, 2], 'id': 'n-1'} + {'loc': [1, 2], 'id': 'n-1_50'} ], 'baseEntities': [], 'stack': [ {}, - {'modified': ['n-1v0'], 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'} + {'modified': ['n-1_50v0'], 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'} ], 'nextIDs': {'node': -2, 'way': -1, 'relation': -1}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]})); + expect(history.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', loc: [1, 2]})); expect(history.undoAnnotation()).to.eql('Added a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1}); @@ -526,18 +526,18 @@ describe('iD.History', function () { var json = { 'version': 3, 'entities': [ - {'loc': [2, 3], 'id': 'n1', 'v': 1} + {'loc': [2, 3], 'id': 'n1_50', 'v': 1} ], - 'baseEntities': [{'loc': [1, 2], 'id': 'n1'}], + 'baseEntities': [{'loc': [1, 2], 'id': 'n1_50'}], 'stack': [ {}, - {'modified': ['n1v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'} + {'modified': ['n1_50v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'} ], 'nextIDs': {'node': -2, 'way': -1, 'relation': -1}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - expect(history.graph().entity('n1')).to.eql(iD.Node({id: 'n1', loc: [2, 3], v: 1})); + expect(history.graph().entity('n1_50')).to.eql(iD.Node({id: 'n1_50', loc: [2, 3], v: 1})); expect(history.undoAnnotation()).to.eql('Moved a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1}); @@ -548,16 +548,16 @@ describe('iD.History', function () { var json = { 'version': 3, 'entities': [], - 'baseEntities': [{'loc': [1, 2], 'id': 'n1'}], + 'baseEntities': [{'loc': [1, 2], 'id': 'n1_50'}], 'stack': [ {}, - {'deleted': ['n1'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'} + {'deleted': ['n1_50'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'} ], 'nextIDs': {'node': -1, 'way': -2, 'relation': -3}, 'index': 1 }; history.fromJSON(JSON.stringify(json)); - expect(history.graph().hasEntity('n1')).to.be.undefined; + expect(history.graph().hasEntity('n1_50')).to.be.undefined; expect(history.undoAnnotation()).to.eql('Deleted a point.'); expect(history.imageryUsed()).to.eql(['Bing']); expect(iD.Entity.id.next).to.eql({node: -1, way: -2, relation: -3}); diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index a8f34b8e41..71c989b472 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -27,16 +27,16 @@ window.Hoot = { layers: { loadedLayers: { 50: { - name: 'a', - id: 50, - activeLayer: true, - activeIds: { - node: 0, - way: 0, - relation: 0, - changeset: 0 - }, - refType: 'primary' + name: 'a', + id: 50, + activeLayer: true, + activeIds: { + node: 0, + way: 0, + relation: 0, + changeset: 0 + }, + refType: 'primary' } } } From 76fabe0b5a0446a2f661a3715c86ee5d92e4352a Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 12:05:06 -0400 Subject: [PATCH 24/33] fix entity tests ref #1425 --- test/spec/osm/entity.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/spec/osm/entity.js b/test/spec/osm/entity.js index 93b9b1f67a..2fedd634b8 100644 --- a/test/spec/osm/entity.js +++ b/test/spec/osm/entity.js @@ -3,9 +3,9 @@ describe('iD.osmEntity', function () { expect(iD.Entity({type: 'node'})).be.an.instanceOf(iD.Node); expect(iD.Entity({type: 'way'})).be.an.instanceOf(iD.Way); expect(iD.Entity({type: 'relation'})).be.an.instanceOf(iD.Relation); - expect(iD.Entity({id: 'n1'})).be.an.instanceOf(iD.Node); - expect(iD.Entity({id: 'w1'})).be.an.instanceOf(iD.Way); - expect(iD.Entity({id: 'r1'})).be.an.instanceOf(iD.Relation); + expect(iD.Entity({id: 'n1_50'})).be.an.instanceOf(iD.Node); + expect(iD.Entity({id: 'w1_50'})).be.an.instanceOf(iD.Way); + expect(iD.Entity({id: 'r1_50'})).be.an.instanceOf(iD.Relation); }); if (iD.debug) { @@ -65,12 +65,12 @@ describe('iD.osmEntity', function () { }); it('resets \'id\', \'user\', and \'version\' properties', function () { - var n = iD.Entity({id: 'n', version: 10, user: 'user'}), + var n = iD.Entity({id: 'n_50', version: 10, user: 'user'}), copies = {}; n.copy(null, copies); - expect(copies.n.isNew()).to.be.ok; - expect(copies.n.version).to.be.undefined; - expect(copies.n.user).to.be.undefined; + expect(copies.n_50.isNew()).to.be.ok; + expect(copies.n_50.version).to.be.undefined; + expect(copies.n_50.user).to.be.undefined; }); it('copies tags', function () { From 305efc55db74dfe804c4206c262a64a285a61ab2 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 13:07:49 -0400 Subject: [PATCH 25/33] fix some intersection/svglines test refs #1425 --- test/spec/osm/intersection.js | 17 +++++++++-------- test/spec/spec_helpers.js | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/test/spec/osm/intersection.js b/test/spec/osm/intersection.js index ecb23a265c..0fc00c0205 100644 --- a/test/spec/osm/intersection.js +++ b/test/spec/osm/intersection.js @@ -127,7 +127,7 @@ describe('iD.osmIntersection', function() { expect(turns[1].u).to.be.true; expect(turns[2]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[2].key).to.match(/^-\_\*\_w-\d+$/); // new way + expect(turns[2].key).to.match(/^-\_\*\_w-\d_\d+$/); // new way expect(turns[2].u).to.be.not.ok; }); @@ -158,7 +158,7 @@ describe('iD.osmIntersection', function() { expect(turns[1].u).to.be.not.ok; expect(turns[2]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[2].key).to.match(/^=\_\*\_w-\d+$/); // new way + expect(turns[2].key).to.match(/^=\_\*\_w-\d+_\d+$/); // new way expect(turns[2].u).to.be.not.ok; }); @@ -403,7 +403,7 @@ describe('iD.osmIntersection', function() { expect(turns[1].u).to.be.true; expect(turns[2]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[2].key).to.match(/^=\_\*\_w-\d+$/); // new way + expect(turns[2].key).to.match(/^=\_\*\_w-\d+_\d+$/); // new way expect(turns[2].u).to.be.not.ok; }); @@ -435,7 +435,7 @@ describe('iD.osmIntersection', function() { expect(turns[1].u).to.be.not.ok; expect(turns[2]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[2].key).to.match(/^-\_\*\_w-\d+$/); // new way + expect(turns[2].key).to.match(/^-\_\*\_w-\d+_\d+$/); // new way expect(turns[2].u).to.be.not.ok; }); @@ -479,7 +479,7 @@ describe('iD.osmIntersection', function() { iD.osmNode({id: 'c'}), iD.osmNode({id: '*'}), iD.osmNode({id: 'u'}), - iD.osmWay({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: '-1'}}), + iD.osmWay({id: '-_50', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: '-1'}}), iD.osmWay({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}}) ]); @@ -487,7 +487,7 @@ describe('iD.osmIntersection', function() { expect(turns.length).to.eql(2); expect(turns[0]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[0].key).to.eql('=_*_-'); + expect(turns[0].key).to.eql('=_*_-_50'); expect(turns[0].u).to.be.not.ok; expect(turns[1]).to.be.an.instanceOf(iD.osmTurn); @@ -512,7 +512,8 @@ describe('iD.osmIntersection', function() { ]); var intersection = iD.osmIntersection(graph, '*'); - var newWay = intersection.ways.find(function(w) { return /^w-\d+$/.test(w.id); }); + intersection.actions.forEach(function (a) { a(graph); }); + var newWay = intersection.ways.find(function(w) { return /^w-\d+_\d+$/.test(w.id); }); var turns = iD.osmIntersection(graph, '*').turns(newWay.id); expect(turns.length).to.eql(2); @@ -542,7 +543,7 @@ describe('iD.osmIntersection', function() { ]); var intersection = iD.osmIntersection(graph, '*'); - var newWay = intersection.ways.find(function(w) { return /^w-\d+$/.test(w.id); }); + var newWay = intersection.ways.find(function(w) { return /^w-\d+_\d+$/.test(w.id); }); var turns = iD.osmIntersection(graph, '*').turns(newWay.id); expect(turns.length).to.eql(2); diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index 71c989b472..48148772ff 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -38,7 +38,8 @@ window.Hoot = { }, refType: 'primary' } - } + }, + getTopLayer: function(){} } }; From 2b2693b8f76f4d722dfba00d592b5975ef712f3d Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 13:53:55 -0400 Subject: [PATCH 26/33] don't comment out all the tests! ref #1425 --- test/index.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/index.html b/test/index.html index 6d48266e74..bbe10dd0e4 100644 --- a/test/index.html +++ b/test/index.html @@ -32,7 +32,7 @@ - + - + From 7e8a0deee9ac1addc6ef8fa6fae3c9ecb05324dc Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 14:03:49 -0400 Subject: [PATCH 27/33] keep using same intersection ref #1425 --- test/spec/osm/intersection.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/spec/osm/intersection.js b/test/spec/osm/intersection.js index 0fc00c0205..41826bdfd9 100644 --- a/test/spec/osm/intersection.js +++ b/test/spec/osm/intersection.js @@ -479,7 +479,7 @@ describe('iD.osmIntersection', function() { iD.osmNode({id: 'c'}), iD.osmNode({id: '*'}), iD.osmNode({id: 'u'}), - iD.osmWay({id: '-_50', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: '-1'}}), + iD.osmWay({id: '-', nodes: ['*', 'a', 'b', 'c', '*'], tags: {highway: 'residential', oneway: '-1'}}), iD.osmWay({id: '=', nodes: ['*', 'u'], tags: {highway: 'residential'}}) ]); @@ -487,7 +487,7 @@ describe('iD.osmIntersection', function() { expect(turns.length).to.eql(2); expect(turns[0]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[0].key).to.eql('=_*_-_50'); + expect(turns[0].key).to.eql('=_*_-'); expect(turns[0].u).to.be.not.ok; expect(turns[1]).to.be.an.instanceOf(iD.osmTurn); @@ -512,9 +512,8 @@ describe('iD.osmIntersection', function() { ]); var intersection = iD.osmIntersection(graph, '*'); - intersection.actions.forEach(function (a) { a(graph); }); var newWay = intersection.ways.find(function(w) { return /^w-\d+_\d+$/.test(w.id); }); - var turns = iD.osmIntersection(graph, '*').turns(newWay.id); + var turns = intersection.turns(newWay.id); expect(turns.length).to.eql(2); expect(turns[0]).to.be.an.instanceOf(iD.osmTurn); @@ -544,7 +543,7 @@ describe('iD.osmIntersection', function() { var intersection = iD.osmIntersection(graph, '*'); var newWay = intersection.ways.find(function(w) { return /^w-\d+_\d+$/.test(w.id); }); - var turns = iD.osmIntersection(graph, '*').turns(newWay.id); + var turns = intersection.turns(newWay.id); expect(turns.length).to.eql(2); expect(turns[0]).to.be.an.instanceOf(iD.osmTurn); From 2f78207d7c5329badb6573520193fb7c8f59a190 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 14:29:44 -0400 Subject: [PATCH 28/33] update intersection regexc ref #1425 --- test/spec/osm/intersection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/osm/intersection.js b/test/spec/osm/intersection.js index 41826bdfd9..b593408746 100644 --- a/test/spec/osm/intersection.js +++ b/test/spec/osm/intersection.js @@ -127,7 +127,7 @@ describe('iD.osmIntersection', function() { expect(turns[1].u).to.be.true; expect(turns[2]).to.be.an.instanceOf(iD.osmTurn); - expect(turns[2].key).to.match(/^-\_\*\_w-\d_\d+$/); // new way + expect(turns[2].key).to.match(/^-\_\*\_w-\d+_\d+$/); // new way expect(turns[2].u).to.be.not.ok; }); From 73f53a4e9dda5e26a54efc28936272d956fcbda5 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 12 Jun 2019 14:58:45 -0400 Subject: [PATCH 29/33] remove timeout ref #1425 --- test/spec/ui/fields/wikipedia.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/spec/ui/fields/wikipedia.js b/test/spec/ui/fields/wikipedia.js index 9daa382d60..a4667788a9 100644 --- a/test/spec/ui/fields/wikipedia.js +++ b/test/spec/ui/fields/wikipedia.js @@ -110,7 +110,7 @@ describe('iD.uiFieldWikipedia', function() { expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('Deutsch'); }); - it('does not set delayed wikidata tag if graph has changed', function(done) { + it('does not set delayed wikidata tag if graph has changed', function (done) { var wikipedia = iD.uiFieldWikipedia(field, context).entity(entity); wikipedia.on('change', changeTags); selection.call(wikipedia); @@ -135,7 +135,7 @@ describe('iD.uiFieldWikipedia', function() { createServer({ autoRespond: true, autoRespondAfter: 60 }); // t30: graph change - Set title to "Title" - window.setTimeout(function() { + window.setTimeout(function () { iD.utilGetSetValue(selection.selectAll('.wiki-title'), 'Title'); happen.once(selection.selectAll('.wiki-title').node(), { type: 'change' }); happen.once(selection.selectAll('.wiki-title').node(), { type: 'blur' }); @@ -144,14 +144,14 @@ describe('iD.uiFieldWikipedia', function() { // t60: at t0 + 60ms (delay), wikidata SHOULD NOT be set because graph has changed. // t70: check that wikidata unchanged - window.setTimeout(function() { + window.setTimeout(function () { expect(context.entity(entity.id).tags.wikidata).to.be.undefined; }, 70); // t90: at t30 + 60ms (delay), wikidata SHOULD be set because graph is unchanged. // t100: check that wikidata has changed - window.setTimeout(function() { + window.setTimeout(function () { expect(context.entity(entity.id).tags.wikidata).to.equal('Q216353'); expect(spy.callCount).to.equal(4); @@ -162,6 +162,6 @@ describe('iD.uiFieldWikipedia', function() { done(); }, 200); - }) - .timeout(200); + }); + // .timeout(200); }); From 44371a1a1fe5ee6739a10c8817c40a2ba3c53ebf Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Fri, 14 Jun 2019 16:15:01 -0400 Subject: [PATCH 30/33] merged hoot2x --- modules/Hoot/managers/api.js | 322 +++++++++++++++++++++++------------ 1 file changed, 214 insertions(+), 108 deletions(-) diff --git a/modules/Hoot/managers/api.js b/modules/Hoot/managers/api.js index 63a1bc01b5..07b6c2e1fc 100644 --- a/modules/Hoot/managers/api.js +++ b/modules/Hoot/managers/api.js @@ -101,6 +101,9 @@ export default class API { if ( status === 'complete' ) { clearInterval( this.intervals[ jobId ] ); res( { data, type: 'success', status: 200, jobId } ); + } else if ( status === 'cancelled' ) { + clearInterval( this.intervals[ jobId ] ); + res( { data, type: 'warn', status: 200 } ); } else if ( status === 'failed' ) { clearInterval( this.intervals[ jobId ] ); rej( { data, type: 'error', status: 500 } ); @@ -201,7 +204,12 @@ export default class API { }; return this.request( params ) - .then( resp => resp.data ); + .then( resp => resp.data ) + .catch( err => { + if (!err.message) err.message = 'Unable to retrieve job status'; + + return Promise.reject( err ); + } ); } getJobError( id ) { @@ -341,7 +349,7 @@ export default class API { * * @returns {Promise|array} - links */ - getLinks() { + getLinks() { const params = { path: '/osm/api/0.6/map/folders/linked', method: 'GET' @@ -504,7 +512,7 @@ export default class API { return this.request( params ) .then( resp => resp.data ) - .catch( err => { + .catch( () => { return { 'minlon': -180, 'minlat': -90, @@ -631,32 +639,13 @@ export default class API { TRANSLATION: data.TRANSLATION, INPUT_TYPE: data.INPUT_TYPE, INPUT_NAME: data.INPUT_NAME, - NONE_TRANSLATION: data.NONE_TRANSLATION + NONE_TRANSLATION: data.NONE_TRANSLATION, + FOLDER_ID: data.folderId }, data: data.formData }; - return this.request( params ) - .then( resp => this.statusInterval( resp.data[ 0 ].jobid ) ) - .then( resp => { - return { - data: resp.data, - message: 'Dataset successfully imported', - status: 200, - type: resp.type, - jobId: resp.jobId - }; - } ) - .catch( err => { - return Promise.reject( { - data: { - details: err.data.commandDetail[ 0 ].stderr - }, - message: 'Failed to import dataset!', - status: err.status, - type: err.type - } ); - } ); + return this.request( params ); } modify( { mapId, modName, inputType } ) { @@ -703,19 +692,19 @@ export default class API { exportDataset( data ) { data.tagoverrides = JSON.stringify( Object.assign(data.tagoverrides || {}, { - 'error:circular':'', - 'hoot:building:match':'', - 'hoot:status':'', - 'hoot:review:members':'', - 'hoot:review:score':'', - 'hoot:review:note':'', - 'hoot:review:sort_order':'', - 'hoot:review:type':'', - 'hoot:review:needs':'', - 'hoot:score:match':'', - 'hoot:score:miss':'', - 'hoot:score:review':'', - 'hoot:score:uuid':'' + // 'error:circular':'', + // 'hoot:building:match':'', + // 'hoot:status':'', + // 'hoot:review:members':'', + // 'hoot:review:score':'', + // 'hoot:review:note':'', + // 'hoot:review:sort_order':'', + // 'hoot:review:type':'', + // 'hoot:review:needs':'', + // 'hoot:score:match':'', + // 'hoot:score:miss':'', + // 'hoot:score:review':'', + // 'hoot:score:uuid':'' }) ); @@ -728,8 +717,7 @@ export default class API { 'outputtype', 'tagoverrides', 'textstatus' , - 'translation', - 'userId' + 'translation' ]; if (!requiredKeys.every( k => data.hasOwnProperty(k) )) { @@ -746,29 +734,7 @@ export default class API { params.path = `${params.path}?ext=zip`; } - let jobId; - - return this.request( params ) - .then( (resp) => { jobId = resp.data.jobid; } ) - .then( () => this.statusInterval( jobId ) ) - .then( () => this.saveDataset( jobId, data.outputname ) ) - .then( () => { - const dataType = data.inputType === 'Folder' ? 'folder' : 'Dataset'; - return { - message: `'${data.outputname}' ${dataType} Exported`, - status: 200, - type: 'success' - }; - } ) - .catch( (err) => { - console.log( err ); - - return { - message: `Failed to export dataset: ${ data.input }`, - status: 500, - type: 'success' - }; - } ); + return this.request( params ); } updateFolder( { folderId, parentId } ) { @@ -829,32 +795,7 @@ export default class API { data }; - return this.request( params ) - .then( resp => this.statusInterval( resp.data.jobId ) ) - .then( resp => { - return { - data: resp.data, - message: 'Schema data uploaded', - status: 200, - type: resp.type, - jobId: resp.jobId - }; - } ) - .catch( err => { - window.console.log( err ); - let message, status, type; - - status = err.status; - type = err.type; - - if ( status >= 500 ) { - message = 'Error during conflation! Please try again later.'; - } else { - message = 'Error while uploading schema data!'; - } - - return Promise.reject( { message, status, type } ); - } ); + return this.request( params ); } uploadBasemap( data ) { @@ -929,7 +870,7 @@ export default class API { } updateMapFolderLinks( { mapId, folderId } ) { - if ( !mapId || folderId < 0 ) return; + if ( !mapId || folderId < 0 ) return Promise.resolve( 'Map or folder id invalid' ); const params = { path: `/osm/api/0.6/map/${ mapId }/move/${ folderId }`, @@ -1080,23 +1021,7 @@ export default class API { data }; - return this.request( params ) - .then( resp => this.statusInterval( resp.data.jobid ) ) - .then( resp => { - return { - data: resp.data, - message: 'Clip job complete', - status: 200, - type: resp.type - }; - } ) - .catch( err => { - const message = err.data, - status = err.status, - type = err.type; - - return Promise.reject( { message, status, type } ); - } ); + return this.request( params ); } /** @@ -1134,7 +1059,6 @@ export default class API { return { data: resp.data, message: 'Review has successfully been saved. It can be viewed in Manage Panel -> Review Bookmarks', - status: 200, type: 'success' }; } ) @@ -1142,6 +1066,188 @@ export default class API { return { data: err.data, message: 'Error saving review!', + type: 'error' + }; + } ); + } + + grailPullOverpassToDb( data ) { + const params = { + path: `/grail/pulloverpasstodb?bbox=${ data.BBOX }`, + method: 'GET' + }; + + return this.request( params ) + .then( resp => this.statusInterval( resp.data.jobid ) ) + .then( resp => { + return { + data: resp.data, + message: 'Pull from Overpass API has succeeded.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + return { + data: err.data, + message: 'Error doing pull!', + status: err.status, + type: 'error' + }; + } ); + } + + + grailPullRailsPortToDb( data ) { + const params = { + path: `/grail/pullrailsporttodb?bbox=${ data.BBOX }`, + method: 'GET' + }; + + return this.request( params ) + .then( resp => this.statusInterval( resp.data.jobid ) ) + .then( resp => { + return { + data: resp.data, + message: 'Pull from Rails Port API has succeeded.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + return { + data: err.data, + message: 'Error doing pull!', + status: err.status, + type: 'error' + }; + } ); + } + + createDifferential( data ) { + const params = { + path: '/grail/createdifferential', + method: 'POST', + data + }; + + return this.request( params ) + .then( resp => this.statusInterval( resp.data.jobid ) ) + .then( resp => { + return { + data: resp.data, + message: 'Differential for selected region created.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + const message = err.data, + status = err.status, + type = err.type; + + return Promise.reject( { message, status, type } ); + } ); + } + + differentialStats( jobId, includeTags ) { + const params = { + path: `/grail/differentialstats?jobId=${ jobId }&includeTags=${ includeTags }`, + method: 'GET' + }; + + return this.request( params ) + .then( resp => { + return { + data: resp.data, + message: 'Differential stats retrieved.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + const message = err.data, + status = err.status, + type = err.type; + + return Promise.reject( { message, status, type } ); + } ); + } + + differentialPush( data ) { + const params = { + path: '/grail/differentialpush', + method: 'POST', + data + }; + + return this.request( params ) + .then( resp => this.statusInterval( resp.data.jobid ) ) + .then( resp => { + return { + data: resp.data, + message: 'Differential push complete.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + const message = err.data, + status = err.status, + type = err.type; + + return Promise.reject( { message, status, type } ); + } ); + } + + conflateDifferential( data ) { + const params = { + path: '/grail/conflatedifferential', + method: 'POST', + data + }; + + return this.request( params ) + .then( resp => this.statusInterval( resp.data.jobid ) ) + .then( resp => { + return { + data: resp.data, + message: 'Conflate differential has succeeded.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + return { + data: err.data, + message: 'Error doing Conflate differential!', + status: err.status, + type: 'error' + }; + } ); + } + + conflationUpload( data ) { + const params = { + path: '/grail/conflatepush', + method: 'POST', + data + }; + + return this.request( params ) + .then( resp => this.statusInterval( resp.data.jobid ) ) + .then( resp => { + return { + data: resp.data, + message: 'Conflation Upload has succeeded.', + status: 200, + type: 'success' + }; + } ) + .catch( err => { + return { + data: err.data, + message: 'Error doing Conflation Upload!', status: err.status, type: 'error' }; From 3819c61881d2871fed923d0caa5a663a820b46cd Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 17 Jun 2019 12:14:47 -0400 Subject: [PATCH 31/33] updated sidebar to prevent page from refreshing when switching active lyrs --- modules/Hoot/managers/layerManager.js | 8 ++++---- modules/Hoot/ui/sidebar/sidebar.js | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index 835fe293c0..dfbb389e6b 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -191,8 +191,8 @@ export default class Layers { let layer = { name: params.name, - id: params.id, - activeLayer: params.activeLayer === undefined ? null : Number(params.activeLayer), + id: Number(params.id), + activeLayer: !params.activeLayer ? null : Number(params.activeLayer), activeIds: activeIds, refType: params.refType, color: params.color, @@ -380,9 +380,9 @@ export default class Layers { async resetActiveLayers() { - let changeActive = new LayerAdd(); + let changeActive = new LayerAdd(); - let loadedLayer = Object.values(Hoot.layers.loadedLayers); + let loadedLayer = Object.values(Hoot.layers.loadedLayers); loadedLayer[0].activeLayer = true; diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index bf14f00d6e..494e7e5ea1 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -248,6 +248,7 @@ export default class Sidebar { updateButton(null, currentLayer.layerName); updateButton(null, currentLayer.otherLayer); } + d3.event.preventDefault(); activeButton.text(setAsActive ? 'Active Layer': 'Set as active layer'); }; From 1e3bda44a2c38a56a92ca336ca99b54f11f5c445 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Wed, 19 Jun 2019 09:00:40 -0400 Subject: [PATCH 32/33] updated layer keys in layerManager --- modules/Hoot/managers/layerManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Hoot/managers/layerManager.js b/modules/Hoot/managers/layerManager.js index dfbb389e6b..944a04374f 100644 --- a/modules/Hoot/managers/layerManager.js +++ b/modules/Hoot/managers/layerManager.js @@ -192,7 +192,7 @@ export default class Layers { let layer = { name: params.name, id: Number(params.id), - activeLayer: !params.activeLayer ? null : Number(params.activeLayer), + activeLayer: !params.activeLayer ? null : params.activeLayer, activeIds: activeIds, refType: params.refType, color: params.color, From e2179dfaedb356b9cb2ec820a8b54b0d2ded527f Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Thu, 20 Jun 2019 15:16:10 -0400 Subject: [PATCH 33/33] removed unused vars --- modules/Hoot/managers/api.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/Hoot/managers/api.js b/modules/Hoot/managers/api.js index 07b6c2e1fc..d3389e49de 100644 --- a/modules/Hoot/managers/api.js +++ b/modules/Hoot/managers/api.js @@ -4,10 +4,6 @@ * @author Matt Putipong on 3/2/18 *******************************************************************************************************/ -import _assign from 'lodash-es/assign'; -import _find from 'lodash-es/find'; -import _map from 'lodash-es/map'; - import axios from 'axios/dist/axios'; import { apiConfig } from '../config/apiConfig'; import { saveAs } from 'file-saver';