From 2e186e8edf58db42125c80078f2873a74f0339a9 Mon Sep 17 00:00:00 2001 From: Giovanni Allegri Date: Wed, 20 Mar 2024 16:02:52 +0100 Subject: [PATCH] [Fixes #12049] Adapt the SLD and XML upload forms to the new progress API (#12050) * Adapt SLD and XML forms to the new API * change source name and delete execution when completed --- geonode/geoserver/context_processors.py | 1 + .../datasets/dataset_metadata_upload.html | 1 + .../datasets/dataset_style_upload.html | 1 + geonode/settings.py | 4 +- geonode/static/geonode/js/upload/LayerInfo.js | 44 ++++++++++++++++--- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/geonode/geoserver/context_processors.py b/geonode/geoserver/context_processors.py index 464cfffa772..572a02469a1 100644 --- a/geonode/geoserver/context_processors.py +++ b/geonode/geoserver/context_processors.py @@ -30,6 +30,7 @@ def geoserver_urls(request): GEOSERVER_BASE_URL=ogc_server_settings.public_url, UPLOADER_URL=reverse("importer_upload"), LAYER_ANCILLARY_FILES_UPLOAD_URL=reverse("importer_upload"), + EXECUTION_STATUS_ENDPOINT=reverse("executionrequest-list"), MAPFISH_PRINT_ENABLED=getattr(ogc_server_settings, "MAPFISH_PRINT_ENABLED", False), PRINT_NG_ENABLED=getattr(ogc_server_settings, "PRINT_NG_ENABLED", False), GEONODE_SECURITY_ENABLED=getattr(ogc_server_settings, "GEONODE_SECURITY_ENABLED", False), diff --git a/geonode/layers/templates/datasets/dataset_metadata_upload.html b/geonode/layers/templates/datasets/dataset_metadata_upload.html index 6ef4d3d2e55..b5238bdf372 100644 --- a/geonode/layers/templates/datasets/dataset_metadata_upload.html +++ b/geonode/layers/templates/datasets/dataset_metadata_upload.html @@ -80,6 +80,7 @@

{% trans "Files to be uploaded" %}

csrf_token = "{{ csrf_token }}", form_target = "{{ LAYER_ANCILLARY_FILES_UPLOAD_URL }}", + executions_status_endpoint = "{{EXECUTION_STATUS_ENDPOINT}}", time_enabled = false, mosaic_enabled = false, userLookup = "{% url "account_ajax_lookup" %}" diff --git a/geonode/layers/templates/datasets/dataset_style_upload.html b/geonode/layers/templates/datasets/dataset_style_upload.html index 6b873fab6c4..ac90cbd9d34 100644 --- a/geonode/layers/templates/datasets/dataset_style_upload.html +++ b/geonode/layers/templates/datasets/dataset_style_upload.html @@ -81,6 +81,7 @@

{% trans "Files to be uploaded" %}

csrf_token = "{{ csrf_token }}", form_target = "{{ LAYER_ANCILLARY_FILES_UPLOAD_URL }}", + executions_status_endpoint = "{{EXECUTION_STATUS_ENDPOINT}}", time_enabled = false, mosaic_enabled = false, userLookup = "{% url "account_ajax_lookup" %}" diff --git a/geonode/settings.py b/geonode/settings.py index 2224bce108f..d42d330a2cf 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -2347,7 +2347,9 @@ def get_geonode_catalogue_service(): 'importer.handlers.shapefile.handler.ShapeFileHandler',\ 'importer.handlers.kml.handler.KMLFileHandler',\ 'importer.handlers.csv.handler.CSVFileHandler',\ - 'importer.handlers.geotiff.handler.GeoTiffFileHandler'\ + 'importer.handlers.geotiff.handler.GeoTiffFileHandler',\ + 'importer.handlers.xml.handler.XMLFileHandler',\ + 'importer.handlers.sld.handler.SLDFileHandler',\ ]", ) ) diff --git a/geonode/static/geonode/js/upload/LayerInfo.js b/geonode/static/geonode/js/upload/LayerInfo.js index 4d4c4385172..25ada87d17d 100644 --- a/geonode/static/geonode/js/upload/LayerInfo.js +++ b/geonode/static/geonode/js/upload/LayerInfo.js @@ -404,6 +404,14 @@ define(function (require, exports) { }); }; + LayerInfo.prototype.markEnd = function () { + this.logStatus({ + msg: 'Your upload was succesfull!', + level: 'alert-success', + empty: 'true' + }); + }; + LayerInfo.prototype.doResume = function (event) { $(this).text(gettext('Finalizing')).attr('disabled', 'disabled').after(''); var id = (new Date()).getTime(); @@ -479,13 +487,36 @@ define(function (require, exports) { }); }; - LayerInfo.prototype.startPolling = function() { + LayerInfo.prototype.startPolling = function(execution_id) { var self = this; + const baseUrl = siteUrl + executions_status_endpoint; if (self.polling) { - $.ajax({ url: updateUrl(siteUrl + "upload/progress", 'id', self.id), type: 'GET', success: function(data){ + $.ajax({ + url: baseUrl + "?import&filter{source}=resource_file_upload&page=1&page_size=99999", type: 'GET', success: function(data){ // TODO: Not sure we need to do anything here? //console.log('polling'); - }, dataType: "json", complete: setTimeout(function() {self.startPolling()}, 3000), timeout: 30000 }); + }, + dataType: "json", + success: function(resp, code) { + if (resp.requests && resp.requests.length>0) { + const execution_data = resp.requests.find((req) => req.exec_id === execution_id); + if (execution_data.status == 'finished'){ + self.polling = false; + self.markEnd(); + $.ajax({url: baseUrl + "/" + execution_id, type: "DELETE"}); + if (execution_data.output_params && execution_data.output_params['detail_url']) { + const detail_url = execution_data.output_params['detail_url']; + if (detail_url != '') { + window.location = detail_url; + } + } + + } + } + setTimeout(function() {self.startPolling(execution_id)}, 3000) + }, + timeout: 30000 + }) } }; @@ -675,8 +706,6 @@ define(function (require, exports) { }, beforeSend: function () { self.markStart(); - self.polling = true; - self.startPolling(); }, error: function (jqXHR) { self.polling = false; @@ -713,13 +742,16 @@ define(function (require, exports) { callback(array); }, success: function (resp, status) { - self.logStatus({ + /*self.logStatus({ msg: '

' + gettext('Layer files uploaded, configuring in GeoServer') + '

', level: 'alert-success', empty: 'true' }); self.id = resp.id; self.doStep(resp, callback, array); + */ + self.polling = true; + self.startPolling(resp.execution_id); } }); };