Skip to content

Commit

Permalink
[Fixes #12049] Adapt the SLD and XML upload forms to the new progress…
Browse files Browse the repository at this point in the history
… API (#12050)

* Adapt SLD and XML forms to the new API

* change source name and delete execution when completed
  • Loading branch information
giohappy committed Mar 20, 2024
1 parent 2a64efb commit cababa3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions geonode/geoserver/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ <h4>{% trans "Files to be uploaded" %}</h4>

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" %}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h4>{% trans "Files to be uploaded" %}</h4>

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" %}"
Expand Down
4 changes: 3 additions & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,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',\
]",
)
)
Expand Down
44 changes: 38 additions & 6 deletions geonode/static/geonode/js/upload/LayerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<img class="pull-right" src="../../static/geonode/img/loading.gif">');
var id = (new Date()).getTime();
Expand Down Expand Up @@ -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
})
}
};

Expand Down Expand Up @@ -675,8 +706,6 @@ define(function (require, exports) {
},
beforeSend: function () {
self.markStart();
self.polling = true;
self.startPolling();
},
error: function (jqXHR) {
self.polling = false;
Expand Down Expand Up @@ -713,13 +742,16 @@ define(function (require, exports) {
callback(array);
},
success: function (resp, status) {
self.logStatus({
/*self.logStatus({
msg: '<p>' + gettext('Layer files uploaded, configuring in GeoServer') + '</p>',
level: 'alert-success',
empty: 'true'
});
self.id = resp.id;
self.doStep(resp, callback, array);
*/
self.polling = true;
self.startPolling(resp.execution_id);
}
});
};
Expand Down

0 comments on commit cababa3

Please sign in to comment.