Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Standardize the "copy and paste from another layer" flow (layer relations) #118

Merged
merged 50 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8c63517
Clean code - spaces
volterra79 Jul 3, 2024
e414c8a
:globe_with_meridians: translation
volterra79 Jul 3, 2024
8a750c5
:sparkles: Change way to copy feature from other layer. Same way of c…
volterra79 Jul 3, 2024
cd4719a
Remove help message
volterra79 Jul 3, 2024
9b9092f
Change version to v3.9.0
volterra79 Jul 31, 2024
21f322c
Merge branch 'dev' into issue_117
volterra79 Aug 6, 2024
cf1c5e1
Merge branch 'dev' into issue_117
volterra79 Aug 8, 2024
d4abfac
Merge branch 'dev' into issue_117
volterra79 Aug 8, 2024
6120def
Merge branch 'dev' into issue_117
volterra79 Sep 2, 2024
8f1f9f8
Fix merge dev conflict
volterra79 Sep 2, 2024
7edc32a
Transform jQuery promise in ES6 Promise using promisify
volterra79 Sep 2, 2024
a600c25
Covert jQuery Promise in ES6 Promise using promisify
volterra79 Sep 2, 2024
9fad4a5
Convert jQuery Promise in ES6 Promise using promisify
volterra79 Sep 2, 2024
042bcf9
Convert jQuery Promise in ES6 Promise using promisify
volterra79 Sep 2, 2024
7120a20
Clean code - readability
volterra79 Sep 3, 2024
fe5b4bf
Replace $.Deferred with $promisify
volterra79 Sep 3, 2024
4ceb9e6
Replace $.Deferred with $promisify
volterra79 Sep 3, 2024
59b8594
Replace $.Deferred with $promisify
volterra79 Sep 3, 2024
9349e4f
Replace $.Deferred with $promisify
volterra79 Sep 3, 2024
1db1acb
Replace $.Deferred with $promisify
volterra79 Sep 3, 2024
b717db3
replace core code: `registerLeavePage`, `getOfflineItem`, `setOffline…
Raruto Sep 6, 2024
73e0663
remove unusued stuff
Raruto Sep 11, 2024
2fa40bb
missing closing tag
Raruto Sep 16, 2024
d021aed
missing class: `OlFeaturesStore`
Raruto Sep 16, 2024
b5325a6
Merge branch 'dev' into issue_117
volterra79 Sep 17, 2024
7606bd6
Fix merge conflict
volterra79 Sep 17, 2024
2a0c70d
:bug: In case of current_values has null
volterra79 Sep 17, 2024
fe64cab
Comment
volterra79 Sep 17, 2024
b1faa76
missing utils
Raruto Sep 17, 2024
8fc0314
simplify util: `getProjectLayerFeatureById`
Raruto Sep 17, 2024
ad08bc1
remove function: `getProjectLayerFeatureById`
Raruto Sep 17, 2024
088c08b
Simplify functions
volterra79 Sep 17, 2024
5b626f1
Merge remote-tracking branch 'origin/issue_117' into issue_117
volterra79 Sep 17, 2024
8eb4060
Add ;
volterra79 Sep 17, 2024
723fc56
Misspelling uniqueFieldsValue instead of uniqueFieldsValue
volterra79 Sep 17, 2024
4c11aa7
:bug: uniqueFieldsValues set empty value for each layer only
volterra79 Sep 17, 2024
4c1df1a
:bug: set selected false whe close editing panel - resetDefault
volterra79 Sep 17, 2024
03ffd2e
add from core: `utils/splitFeatures.js`
Raruto Sep 18, 2024
a9963e3
Merge branch 'issue_117' of https://github.com/g3w-suite/g3w-client-p…
Raruto Sep 18, 2024
13e8fff
add from core: `utils/isSameBaseGeometryType.js`
Raruto Sep 18, 2024
6a1919f
add from core: `utils/dissolve.js`
Raruto Sep 18, 2024
b9c3518
:bug: missing export
volterra79 Sep 18, 2024
ff04cc0
remove: `multiGeometryToSingleGeometries`, `singleGeometriesToMultiG…
Raruto Sep 18, 2024
0896664
Merge branch 'issue_117' of https://github.com/g3w-suite/g3w-client-p…
Raruto Sep 18, 2024
42eb485
space
volterra79 Sep 18, 2024
4d6afa6
Merge remote-tracking branch 'origin/issue_117' into issue_117
volterra79 Sep 18, 2024
7adabc8
Set TOC_ORDER to true to CatalogRegistry.getLayers
volterra79 Sep 18, 2024
963f29c
Clean code - space and rename variable
volterra79 Sep 23, 2024
f42eeef
Clean code - space
volterra79 Sep 23, 2024
4fb8ad5
`v-t-title` → `get_tool_title`
Raruto Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 19 additions & 183 deletions components/CopyFeaturesFromOtherLayers.vue
Original file line number Diff line number Diff line change
@@ -1,209 +1,45 @@
<template>
<div class = "editing-layers-features" >

<!-- EDIT MULTI FEATURE ATTRIBUTES -->
<div
v-if = "showEditAttributes"
v-disabled = "disabled"
class = "edit-multi-features"
>
<input
id = "g3w_edit_attributes_of_select_feature_from_layer"
type = "checkbox"
class = "magic-checkbox"
v-model = "$options.editAttributes.state"
/>
<label
for = "g3w_edit_attributes_of_select_feature_from_layer"
v-t-plugin = "'editing.modal.tools.copyfeaturefromotherlayer.edit_attributes'">
</label>
</div>

<section
class = "g3w-editing-other-layers-features"
:style = "{height: `${$data._height}px`}"
>
<div v-for =" (layerId) in Object.keys($options.layers)">

<div class = "layer-title skin-color">{{ getLayerTitle(layerId) }}</div>

<divider />

<div class = "copy-features-for-layer-content">
<div
v-for = "(feature, index) in $options.layers[layerId].features"
class = "GIVE_ME_A_NAME_1"
>

<div class = "GIVE_ME_A_NAME_2">
<section>

<!-- ZOOM TO FEATURE -->
<div
@click.stop = "zoomToFeature(feature)"
:class = "['ztf', 'skin-color', g3wtemplate.font['marker']]"
></div>
<div id = "g3w-select-editable-layers-content">
<select
id = "g3w-select-editable-layers-to-copy"
v-select2 = "'id'"
>
<option
v-for = "layer in $options.layers"
:key = "layer.id"
:value = "layer.id"
>{{ layer.name }}</option>
</select>

<!-- SELECT FEATURE -->
<div v-t-tooltip:right.create = "'plugins.editing.steps.help.select_elements'">
<input
@click.stop = "selectFeature(feature)"
:id = "`${layerId}_${index}_select_feature_from_layer`"
type = "checkbox"
class = "magic-checkbox"
/>
<label :for = "`${layerId}_${index}_select_feature_from_layer`"> {{ feature.getId() || 0 }}</label>
</div>

</div>

<div
v-for = "({ attribute, value }) in getAttributesFeature(feature, layerId)"
class = "feature-attributes"
>
<span class = "f-attr">{{ attribute }}</span>
<span class = "f-value">{{ value }}</span>
</div>

</div>
</div>
</div>

</div>
</section>
</section>

</div>
</template>

<script>
const { G3W_FID } = g3wsdk.constant;

const { GUI } = g3wsdk.gui;
const { getAlphanumericPropertiesFromFeature } = g3wsdk.core.geoutils;
const { MapLayersStoreRegistry } = g3wsdk.core.map;
const { resizeMixin } = g3wsdk.gui.vue.Mixins;

export default {

name: 'Copyfeaturesfromotherlayers',

mixins: [resizeMixin],

data() {
return {
selectedFeatures: this.$options.selectedFeatures,
disabled: true, //@since v3.7 check if we want to edit multi selected feature attributes
_height: 0,
id: this.$options.layers.find(l => l.selected).id,
};
},

computed: {
/**
* Show edit attributes only if there are at least 2 feature to select
* @since v3.7
*/
showEditAttributes() {
return Object.values(this.$options.layers).reduce((sum, { features }) => {
sum = sum + features.length;
return sum;
}, 0) > 1;
watch: {
'id'(id) {
this.$options.layers.forEach(l => l.selected = id === l.id);
}
},

methods: {
async resize() {
await this.$nextTick();
this.$data._height = window.innerHeight - 200;
},
getAttributesFeature(feature, layerId) {
const { external, fields } = this.$options.layers[layerId];
const props = getAlphanumericPropertiesFromFeature(feature.getProperties());
return props
.filter(prop => G3W_FID !== prop)
.map(attr => ({
attribute: (external ? attr : fields.find(f => f.name === attr).label),
value: feature.get(attr),
}));
},

selectFeature(feature) {
if (this.selectedFeatures.find(f => feature === f)) {
this.selectedFeatures = this.selectedFeatures.filter(f => feature !== f);
} else {
this.selectedFeatures.push(feature);
}
this.disabled = this.selectedFeatures.length < 2;
this.$options.editAttributes.state = !this.disabled && this.$options.editAttributes.state;
},

getLayerTitle(layerId) {
const layer = MapLayersStoreRegistry.getLayerById(layerId);
return layer ? layer.getTitle() : GUI.getService('map').getLayerById(layerId).get('name');
},

zoomToFeature(feature) {
GUI.getService('map').zoomToFeatures([feature] , { highlight: true, duration: 1000 });
},

},

beforeCreate() {
this.delayType = 'debounce';
},

mounted() {
GUI.closeContent();
},

};
</script>

<style scoped>
.g3w-editing-other-layers-features {
overflow: auto;
}
.edit-multi-features {
display: flex;
justify-content: flex-end
}
.edit-multi-features > label {
color: #000;
}
.layer-title {
font-weight: bold;
font-size: 1.2em;
}
.copy-features-for-layer-content {
overflow-x: auto;
}
.ztf {
padding: 0 5px 15px 5px;
font-size: 1.1em;
cursor: pointer;
margin-right: 5px;
}
.GIVE_ME_A_NAME_1 {
padding: 5px;
position: relative;
display: flex;
align-items: baseline;
border-bottom: 1px solid #eee;
}
.GIVE_ME_A_NAME_2 {
display: flex;
flex-direction: column;
border-right: 1px solid #eee;
}
.GIVE_ME_A_NAME_2 .magic-checkbox + label {
color: #FFF;
}
.feature-attributes {
display: flex;
flex-direction: column;
padding: 10px;
}
.f-attr {
font-weight: bold;
margin-bottom: 10px;
}
.f-value {
align-self: start;
}
</style>
53 changes: 22 additions & 31 deletions components/Editing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -353,34 +353,39 @@
unlock = false,
} = {}) {
return new Promise((resolve, reject) => {
const changes = ApplicationService.getOfflineItem('EDITING_CHANGES');
// get offline item
const changes = JSON.parse(window.localStorage.getItem('EDITING_CHANGES') || null);

// if you find changes offline previously
if (!changes) { return }

const promises = [];
const layerIds = [];
//FORCE TO WAIT OTHERWISE STILL OFF LINE
setTimeout(() => {
setTimeout(async () => {
for (const layerId in changes) {
layerIds.push(layerId);
const toolbox = this.service.getToolBoxById(layerId);
const commitItems = changes[layerId];
promises.push(this.service.commit({ toolbox, commitItems, modal }))
}

$.when
.apply(this.service, promises)
.then(resolve)
.fail(e => { console.warn(e); reject(e) })
.always(() => {
if (unlock) {
layerIds.forEach(layerId => this.service.getLayerById(layerId).unlock());
}
// always reset items to null
ApplicationService.setOfflineItem('EDITING_CHANGES');
})
try {
await promisify($.when.apply(this.service, promises));
resolve();
} catch(e) {
console.warn(e);
reject(e);
} finally {
if (unlock) {
layerIds.forEach(layerId => this.service.getLayerById(layerId).unlock());
}
// always reset items to null
try { window.localStorage.setItem('EDITING_CHANGES', "{}"); }
catch(e) { console.warn(e); }
}
}, 1000)
});
})
},

},
Expand Down Expand Up @@ -421,23 +426,19 @@
},

django_admin_url() {
const config = ApplicationService.getConfig();
const user = config.user;
return user.is_superuser ? new URL('/django-admin/editing/g3weditingfeaturelock/', initConfig.baseurl) : false;
return window.initConfig.user.is_superuser ? new URL('/django-admin/editing/g3weditingfeaturelock/', window.initConfig.baseurl) : false;
},

filemanager_url() {
const config = ApplicationService.getConfig();
const user = config.user;
return user.is_superuser ? new URL('/filemanager/', initConfig.baseurl) : false;
return window.initConfig.user.is_superuser ? new URL('/filemanager/', window.initConfig.baseurl) : false;
},

},

watch:{

canCommit(bool) {
ApplicationService.registerLeavePage({ bool });
window.onbeforeunload = () => bool || undefined; // register leave page
},

/**
Expand Down Expand Up @@ -494,13 +495,6 @@
this.checkOfflineChanges({ unlock: true });
}

// register "offline" event
this.unByKeys.push({
owner : ApplicationService,
setter: 'offline',
key: ApplicationService.onafter('offline', () => {})
});

// register "online" event
this.unByKeys.push({
owner : ApplicationService,
Expand Down Expand Up @@ -576,9 +570,6 @@

this.service.getToolBoxes().forEach(t => t.resetDefault());

// clear all unique values fields related to layer (after a closing editing panel).
this.state.uniqueFieldsValues = {};

// re-enable query map control
const control = GUI.getService('map').getMapControlByType({ type: 'query' });
if (control && !control.isToggled()) {
Expand Down
7 changes: 4 additions & 3 deletions components/FormRelation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
class = "magic-checkbox"
type = "checkbox">
<label :for="`select_relation__${index}`"></label>
</td>
<td>
<div style = "display: flex">
<!-- RELATION TOOLS -->
Expand Down Expand Up @@ -267,7 +268,8 @@
import { updateWorkflows } from '../utils/updateWorkflows';
import { getRelationId } from '../utils/getRelationId';
import { getFeatureTableFieldValue } from '../utils/getFeatureTableFieldValue';
import { chooseFeatureFromFeatures } from "../utils/chooseFeatureFromFeatures";
import { chooseFeatureFromFeatures } from '../utils/chooseFeatureFromFeatures';
import { isSameBaseGeometryType } from '../utils/isSameBaseGeometryType';
import { PickFeaturesInteraction } from '../interactions/pickfeaturesinteraction';
import { VM } from '../eventbus';
import {
Expand All @@ -281,8 +283,7 @@
const { ProjectsRegistry } = g3wsdk.core.project;
const { CatalogLayersStoresRegistry } = g3wsdk.core.catalog;
const { DataRouterService } = g3wsdk.core.data;
const { Geometry } = g3wsdk.core.geometry;
const { isSameBaseGeometryType } = g3wsdk.core.geoutils;
const { Geometry } = g3wsdk.core.geoutils;
const { tPlugin:t } = g3wsdk.core.i18n;
const { Layer } = g3wsdk.core.layer;
const { Feature } = g3wsdk.core.layer.features;
Expand Down
Loading
Loading