g3w-admin-processing 1.2.1b1.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. g3w_admin_processing-1.2.1b1.dev1.dist-info/METADATA +258 -0
  2. g3w_admin_processing-1.2.1b1.dev1.dist-info/RECORD +80 -0
  3. g3w_admin_processing-1.2.1b1.dev1.dist-info/WHEEL +5 -0
  4. g3w_admin_processing-1.2.1b1.dev1.dist-info/licenses/LICENSE +373 -0
  5. g3w_admin_processing-1.2.1b1.dev1.dist-info/top_level.txt +1 -0
  6. qprocessing/__init__.py +7 -0
  7. qprocessing/admin.py +21 -0
  8. qprocessing/api/__init__.py +0 -0
  9. qprocessing/api/permissions.py +41 -0
  10. qprocessing/api/views/__init__.py +4 -0
  11. qprocessing/api/views/actions.py +84 -0
  12. qprocessing/api/views/admin.py +76 -0
  13. qprocessing/api/views/models.py +219 -0
  14. qprocessing/api/views/upload.py +177 -0
  15. qprocessing/apiurls.py +64 -0
  16. qprocessing/apps.py +38 -0
  17. qprocessing/configs.py +131 -0
  18. qprocessing/forms.py +133 -0
  19. qprocessing/migrations/0001_initial.py +24 -0
  20. qprocessing/migrations/0002_auto_20230615_1609.py +23 -0
  21. qprocessing/migrations/0003_qprocessinginputupload.py +32 -0
  22. qprocessing/migrations/0004_auto_20230809_0920.py +26 -0
  23. qprocessing/migrations/0005_alter_qprocessinginputupload_user.py +21 -0
  24. qprocessing/migrations/__init__.py +0 -0
  25. qprocessing/models.py +143 -0
  26. qprocessing/receivers.py +100 -0
  27. qprocessing/sitetrees.py +31 -0
  28. qprocessing/static/qprocessing/js/components/DrawInputVectorFeatures.js +180 -0
  29. qprocessing/static/qprocessing/js/components/InputFieldChooser.js +226 -0
  30. qprocessing/static/qprocessing/js/components/InputPrjRasterLayer.js +135 -0
  31. qprocessing/static/qprocessing/js/components/InputPrjVectorLayer.js +415 -0
  32. qprocessing/static/qprocessing/js/components/ModelPanel.js +496 -0
  33. qprocessing/static/qprocessing/js/components/ModelResults.js +73 -0
  34. qprocessing/static/qprocessing/js/components/OutputFile.js +63 -0
  35. qprocessing/static/qprocessing/js/components/OutputRasterLayer.js +63 -0
  36. qprocessing/static/qprocessing/js/components/OutputVectorLayer.js +115 -0
  37. qprocessing/static/qprocessing/js/components/UploadVectorFile.js +53 -0
  38. qprocessing/static/qprocessing/js/i18n/en.js +33 -0
  39. qprocessing/static/qprocessing/js/i18n/index.js +7 -0
  40. qprocessing/static/qprocessing/js/i18n/it.js +33 -0
  41. qprocessing/static/qprocessing/js/plugin.js +122 -0
  42. qprocessing/tasks.py +136 -0
  43. qprocessing/templates/qprocessing/project_form.html +70 -0
  44. qprocessing/templates/qprocessing/projects_list.html +72 -0
  45. qprocessing/tests/__init__.py +0 -0
  46. qprocessing/tests/base.py +104 -0
  47. qprocessing/tests/data/models/qbuffer.model3 +233 -0
  48. qprocessing/tests/data/models/qintersection.model3 +288 -0
  49. qprocessing/tests/data/models/qpointspolygons.model3 +222 -0
  50. qprocessing/tests/data/models/test.model3 +321 -0
  51. qprocessing/tests/data/models/test_buffer_all_inputs.model3 +269 -0
  52. qprocessing/tests/data/models/test_buffer_layer1.model3 +201 -0
  53. qprocessing/tests/data/project_data/buildings.geojson +15 -0
  54. qprocessing/tests/data/project_data/qprocessing.gpkg +0 -0
  55. qprocessing/tests/data/qprocessing_qprocessing.qgs +2813 -0
  56. qprocessing/tests/data/qprocessing_qprocessing_attachments.zip +0 -0
  57. qprocessing/tests/data/test_qgis_328.qgs +954 -0
  58. qprocessing/tests/data/test_qgis_328_attachments.zip +0 -0
  59. qprocessing/tests/data/upload/fail_shp_to_upload.zip +0 -0
  60. qprocessing/tests/data/upload/linestring_to_upload.geojson +9 -0
  61. qprocessing/tests/data/upload/point_to_upload.geojson +10 -0
  62. qprocessing/tests/data/upload/point_to_upload_espg4326.geojson +10 -0
  63. qprocessing/tests/data/upload/point_to_upload_espg4326.qmd +26 -0
  64. qprocessing/tests/data/upload/polygon_to_upload.geojson +9 -0
  65. qprocessing/tests/data/upload/shp_to_upload.cpg +1 -0
  66. qprocessing/tests/data/upload/shp_to_upload.dbf +0 -0
  67. qprocessing/tests/data/upload/shp_to_upload.prj +1 -0
  68. qprocessing/tests/data/upload/shp_to_upload.qix +0 -0
  69. qprocessing/tests/data/upload/shp_to_upload.shp +0 -0
  70. qprocessing/tests/data/upload/shp_to_upload.shx +0 -0
  71. qprocessing/tests/data/upload/shp_to_upload.zip +0 -0
  72. qprocessing/tests/test_algorithm.py +52 -0
  73. qprocessing/tests/test_api.py +173 -0
  74. qprocessing/tests/test_api_models.py +459 -0
  75. qprocessing/urls.py +33 -0
  76. qprocessing/utils/__init__.py +0 -0
  77. qprocessing/utils/data.py +283 -0
  78. qprocessing/utils/exceptions.py +20 -0
  79. qprocessing/utils/formtypes.py +521 -0
  80. qprocessing/views.py +96 -0
@@ -0,0 +1,415 @@
1
+ import UploadVectorFile from "./UploadVectorFile.js";
2
+ import DrawInputVectorFeatures from "./DrawInputVectorFeatures.js";
3
+
4
+ const { GUI } = g3wsdk.gui;
5
+ const { selectMixin } = g3wsdk.gui.vue.Mixins;
6
+ const { isSameBaseGeometryType } = g3wsdk.core.geoutils;
7
+ const { ProjectsRegistry } = g3wsdk.core.project;
8
+
9
+ export default ({
10
+
11
+ // language=html
12
+ template: /* html */ `
13
+ <div
14
+ v-if = "state.visible"
15
+ class = "form-group prj-vector-layer"
16
+ >
17
+
18
+ <slot name="label">
19
+ <label :for="state.name" v-disabled="!state.editable" class="col-sm-12">
20
+ {{ state.label }}
21
+ <span v-if="state.validate && state.validate.required">*</span>
22
+ </label>
23
+ </slot>
24
+
25
+ <div class="col-sm-12">
26
+
27
+ <section v-if="showUploadFile" class="vector-tools-context" v-disabled="upload">
28
+ <section class="vector-tools">
29
+ <upload-vector-file :upload="upload" @add-layer="addLayer" />
30
+ <draw-input-vector-features :upload="upload" @toggled-tool="toggleTempLayer" :datatypes="state.input.options.datatypes" @add-layer="addLayer" />
31
+ </section>
32
+ <section class="vector-tools-message">
33
+ <div v-if="errorUpload" class="error-upload"> Errore </div>
34
+ </section>
35
+ </section>
36
+
37
+ <slot name="body">
38
+ <select
39
+ v-select2 = "'value'"
40
+ :id = "state.name"
41
+ ref = "select_layer"
42
+ style = "width:100%;"
43
+ class = "form-control"
44
+ >
45
+ <option
46
+ v-for = "value in state.input.options.values"
47
+ :key = "value.value"
48
+ :value = "value.value">{{ value.key }}
49
+ </option>
50
+ </select>
51
+ <div
52
+ v-if = "isSelectedFeatures"
53
+ v-disabled = "selected_features_disabled"
54
+ class = "prjvectorlayerfeature-only-selected-features"
55
+ >
56
+ <input
57
+ style = "width:100%;"
58
+ class = "magic-checkbox"
59
+ v-model = "selected_features_checked"
60
+ type = "checkbox"
61
+ :id = "state.name + '_checkbox'"
62
+ />
63
+ <label
64
+ style = "margin-top: 10px;"
65
+ :for = "state.name + '_checkbox'"
66
+ v-t-plugin = "'qprocessing.inputs.prjvectorlayerfeature.selected_features'">
67
+ </label>
68
+ </div>
69
+ </slot>
70
+
71
+ <slot name="message">
72
+ <p
73
+ v-if = "notvalid"
74
+ class = "g3w-long-text error-input-message"
75
+ style = "margin: 0"
76
+ v-html = "state.validate.message">
77
+ </p>
78
+ <p
79
+ v-else-if = "state.info"
80
+ style = "margin: 0 "
81
+ v-html = "state.info"
82
+ ></p>
83
+ </slot>
84
+
85
+ <div
86
+ v-if="state.help && this.state.help.visible"
87
+ v-html="state.help.message"
88
+ class="g3w_input_help skin-background-color extralighten">
89
+ </div>
90
+
91
+ </div>
92
+ </div>
93
+ `,
94
+
95
+ name: "InputPrjVectorLayer",
96
+ mixins: [selectMixin],
97
+ components: {
98
+ UploadVectorFile,
99
+ DrawInputVectorFeatures,
100
+ },
101
+ props: {
102
+ modelId: {
103
+ type: Number,
104
+ required: true,
105
+ },
106
+ state: {
107
+ type: Object,
108
+ required: true
109
+ }
110
+ },
111
+ data(){
112
+ return {
113
+ upload: false,
114
+ errorUpload: false,
115
+ value: null,
116
+ selected_features_checked: false,
117
+ selected_features_disabled: true
118
+ }
119
+ },
120
+ computed: {
121
+ /**
122
+ * Check if datatypes contain geometries values
123
+ * @returns Boolean
124
+ */
125
+ showUploadFile(){
126
+ return !!this.state.input.options.datatypes.find(datatype => (datatype === 'anygeometry') || (['point', 'line', 'polygon'].indexOf(datatype) !== -1));
127
+ },
128
+ //check if it can take in account of selected features
129
+ isSelectedFeatures(){
130
+ return 'prjvectorlayerfeature' === this.state.input.type;
131
+ },
132
+ //check if is no valid
133
+ notvalid() {
134
+ return false === this.state.validate.valid;
135
+ }
136
+ },
137
+ methods: {
138
+ /*
139
+ * Show/hide temp tool
140
+ * */
141
+ toggleTempLayer(bool){
142
+ this.addTempLayer.setVisible(bool);
143
+ },
144
+ async addLayer({file, features=[]}={}){
145
+ //set initial reactive properties
146
+ this.upload = true;
147
+ this.errorUpload = false;
148
+ try {
149
+ const qprocessing = g3wsdk.core.plugin.PluginsRegistry.getPlugin('qprocessing');
150
+ const {key, value} = await qprocessing.uploadFile({
151
+ file,
152
+ inputName: this.state.name,
153
+ modelId: this.modelId,
154
+ });
155
+ //need to add only one external file
156
+ this.state.input.options.values = this.state.input.options.values.filter(({key, value}) => !value.startsWith('file:'));
157
+
158
+ //handle temp layer
159
+
160
+ this.addTempLayer.getSource().clear(); //clear all eventually previous features
161
+ this.addTempLayer.getSource().addFeatures(features); //add eventually features
162
+ this.addTempLayer.setVisible(true); //visible true
163
+
164
+ this.state.input.options.values.push({
165
+ key,
166
+ value
167
+ });
168
+
169
+ await this.$nextTick();
170
+ this.value = value;
171
+ //set current select item
172
+ $(this.$refs.select_layer)
173
+ .select2()
174
+ .val(value)
175
+ .trigger('change');
176
+ } catch(e) {
177
+ this.errorUpload = true;
178
+ }
179
+ this.upload = false;
180
+ },
181
+
182
+ /**
183
+ * Check if a layer has selected features
184
+ *
185
+ * @param layerId
186
+ * @returns {*}
187
+ */
188
+ getLayerSelectedFeaturesIds(layerId) {
189
+ return GUI.getService('map').defaultsLayers.selectionLayer.getSource().getFeatures().filter(f => f.__layerId === layerId).map(f => f.getId());
190
+ },
191
+
192
+ /**
193
+ * @TODO
194
+ * @param layerId
195
+ */
196
+ setDisabledSelectFeaturesCheckbox(layerId){
197
+ this.selected_features_disabled = this.getLayerSelectedFeaturesIds(layerId).length === 0;
198
+ //in case go disabled, uncheck checkbox
199
+ if (true === this.selected_features_disabled) {
200
+ this.selected_features_checked = false;
201
+ }
202
+ },
203
+ /**
204
+ *Set input layer value based on selected feature id or not
205
+ * @param checked
206
+ */
207
+ setInputValueFromSelectedFeatures(checked) {
208
+ const currentLayerFeatureSelectedIds = this.getLayerSelectedFeaturesIds(this.value);
209
+ if (true === checked && currentLayerFeatureSelectedIds.length > 0) {
210
+ this.state.value = `${this.value}:${currentLayerFeatureSelectedIds.join(',')}`
211
+ } else {
212
+ this.state.value = this.value;
213
+ }
214
+
215
+ this.$emit('changeinput', this.state);
216
+ },
217
+
218
+ /**
219
+ *
220
+ * @param layer external layer Object
221
+ * @param datatypes Array
222
+ * @returns {boolean}
223
+ */
224
+ isExternalLayerValidForInputDatatypes({ layer, datatypes=[] }={}) {
225
+ return (
226
+ undefined !== datatypes.find(type => 'anygeometry' === type) ||
227
+ undefined !== datatypes.map(type => ({ 'point': 'Point', 'line': 'LineString', 'polygon': 'Polygon' })[type]).filter(Boolean).find(type => isSameBaseGeometryType(type, layer.geometryType))
228
+ )
229
+ },
230
+
231
+ /**
232
+ * Get all Project Vector Layers that has geometry types
233
+ * @param datatypes <Array> of String
234
+ * 'nogeometry',
235
+ * 'point',
236
+ * 'line',
237
+ * 'polygon',
238
+ * 'anygeometry'
239
+ * return <Array>
240
+ */
241
+ getInputPrjVectorLayerData(datatypes=[]) {
242
+ const layers = [];
243
+
244
+ //check if any geometry layer type is request
245
+ const anygeometry = undefined !== datatypes.find(data_type => data_type === 'anygeometry');
246
+ //check if no geometry layer type is request
247
+ const nogeometry = undefined !== datatypes.find(data_type => data_type === 'nogeometry');
248
+
249
+ //get geometry_types only from data_types array
250
+ const geometry_types = datatypes.map(type => ({ 'point': 'Point', 'line': 'LineString', 'polygon': 'Polygon' })[type]).filter(Boolean);
251
+
252
+ ProjectsRegistry.getCurrentProject().getLayers()
253
+ //exclude base layer
254
+ .filter(layer => !layer.baselayer)
255
+ .forEach(layer => {
256
+ const key = layer.name;
257
+ const value = layer.id;
258
+ //get layer if it has no geometry
259
+ if (true === nogeometry) {
260
+ if (
261
+ (true === nogeometry) &&
262
+ (undefined === layer.geometrytype || "NoGeometry" === layer.geometrytype)
263
+ ) {
264
+ layers.push({key, value})
265
+ return;
266
+ }
267
+ }
268
+
269
+ if (
270
+ (null !== layer.geometrytype) &&
271
+ (undefined !== layer.geometrytype) &&
272
+ ("NoGeometry" !== layer.geometrytype)
273
+ ) {
274
+ // in the case of any geometry type
275
+ if (true === anygeometry) {
276
+ layers.push({key, value})
277
+ } else {
278
+ if (geometry_types.length > 0) {
279
+ if (undefined !== geometry_types.find(geometry_type => isSameBaseGeometryType(geometry_type, layer.geometrytype))) {
280
+ layers.push({key, value})
281
+ }
282
+ }
283
+ }
284
+ }
285
+ })
286
+
287
+ //check for external
288
+ if (anygeometry || geometry_types.length > 0) {
289
+ //get external layers from catalog
290
+ GUI.getService('catalog').getExternalLayers({
291
+ type: 'vector'
292
+ }).forEach(layer => {
293
+ if (this.isExternalLayerValidForInputDatatypes({
294
+ layer,
295
+ datatypes
296
+ })) {
297
+ layers.push({
298
+ key:layer.name,
299
+ value: `__g3w__external__:${layer.id}`
300
+ })
301
+ }
302
+ })
303
+ }
304
+
305
+ return layers;
306
+ }
307
+ },
308
+
309
+ watch: {
310
+ //listen change of value (input select)
311
+ 'value'(value) {
312
+ if (true === this.isSelectedFeatures) {
313
+ this.setDisabledSelectFeaturesCheckbox(value);
314
+ }
315
+ this.state.value = value;
316
+ this.state.validate.valid = ![undefined, null].includes(value);
317
+ this.$emit('changeinput', this.state);
318
+ },
319
+ //Listen selected feature checkbox event change
320
+ 'selected_features_checked'(checked) {
321
+ this.setInputValueFromSelectedFeatures(checked);
322
+ }
323
+ },
324
+
325
+ created() {
326
+ const qprocessing = g3wsdk.core.plugin.PluginsRegistry.getPlugin('qprocessing');
327
+
328
+ //set initial values
329
+ this.state.input.options.values = this.getInputPrjVectorLayerData(this.state.input.options.datatypes);
330
+
331
+ if (this.state.input.options.values.length > 0) {
332
+ this.value = this.state.input.options.values[0].value;
333
+ this.state.validate.valid = true;
334
+ }
335
+
336
+ //In case of selected features
337
+ if (null !== this.value && this.isSelectedFeatures) {
338
+ this.selected_features_id = []; // create array of selected id features
339
+ //register
340
+ qprocessing.registersSelectedFeatureLayersEvent();
341
+ qprocessing.on('change-selected-features', () => {
342
+ this.setDisabledSelectFeaturesCheckbox(this.value);
343
+ this.setInputValueFromSelectedFeatures(this.selected_features_checked);
344
+ });
345
+ }
346
+
347
+ /**
348
+ * temporary layer filled by upload or draw tools
349
+ */
350
+
351
+ this.addTempLayer = new ol.layer.Vector({
352
+ source: new ol.source.Vector()
353
+ })
354
+
355
+ //add to map
356
+ GUI.getService('map').getMap().addLayer(this.addTempLayer);
357
+
358
+ //set initial visibility to false
359
+ this.addTempLayer.setVisible(false);
360
+
361
+ //listen add external Layer
362
+ this.keyAddExternal =
363
+
364
+ GUI.getService('catalog').onafter('addExternalLayer', ({ type, layer }) =>{
365
+ if ('vector' !== type) {
366
+ return;
367
+ }
368
+ if (this.isExternalLayerValidForInputDatatypes({ layer, datatypes: this.state.input.options.datatypes })) {
369
+ this.state.input.options.values.push({
370
+ key:layer.name,
371
+ value: `__g3w__external__:${layer.id}`
372
+ });
373
+ }
374
+ })
375
+
376
+ },
377
+ async mounted(){
378
+ await this.$nextTick();
379
+ this.select2 = $(this.$refs.select_layer);
380
+ //need to emit add input to validate
381
+ this.$emit('addinput', this.state);
382
+ this.$emit('changeinput', this.state);
383
+ },
384
+ beforeDestroy() {
385
+
386
+ const qprocessing = g3wsdk.core.plugin.PluginsRegistry.getPlugin('qprocessing');
387
+
388
+ if (this.isSelectedFeatures) {
389
+ qprocessing.unregistersSelectedFeatureLayersEvent();
390
+ qprocessing.removeAllListeners('change-selected-features');
391
+ }
392
+
393
+ //remove temp layer
394
+ this.addTempLayer.getSource().clear();
395
+ GUI.getService('map').getMap().removeLayer(this.addTempLayer);
396
+ this.addTempLayer = null;
397
+
398
+ ///remove external layer
399
+ GUI.getService('catalog').un('addExternalLayer', this.keyAddExternal);
400
+
401
+ }
402
+ });
403
+
404
+ document.head.insertAdjacentHTML(
405
+ 'beforeend',
406
+ /* css */`
407
+ <style>
408
+ /* Replicate same scoped style in InputBase.vue */
409
+ .prj-vector-layer label { text-align: left !important; padding-top: 0 !important; margin-bottom: 3px; }
410
+ .vector-tools-context { margin-bottom: 5px; }
411
+ .vector-tools { display: flex; justify-content: space-between; }
412
+ .vector-tools-message { margin: 3px; }
413
+ .vector-tools-message .error-upload { font-weight: bold; color: red; }
414
+ </style>`,
415
+ );