diff --git a/CHANGELOG.md b/CHANGELOG.md index ce88fd59f067c7bd4d3f92d6a9e3fb8f6fa04377..abef83eb8fa754e5d87f6c3e97718160c9335ee9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ * **XML configuration format is changed: if you update from previous version you will lost your previous configuration.** * Both new users and custom UCDs can now be added using the GUI. * Added "Rebuild UCD" functionality on the UCD insertion dialog. +* Fixed bug on consistency checking when a schema is missing +* Added warning in case of possible wrong source credentials selection (this is shown when consistency checking detect only the TAP_SCHEMA itself). +* Avoided connection timeout on the webapp when loading big TAP_SCHEMA schemas. ## Version 1.0.4 diff --git a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java index c64f11404c08a10e86aeaeee23057243828ab756..d20ae585cb1221ea6273f816b0721022a77d5e7b 100644 --- a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java +++ b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java @@ -73,6 +73,9 @@ public class SchemaSelectionBean implements Serializable { private String tapSchemaName; private List<String> allSchemas; private List<String> selectedSchemas; + private boolean loading; + private TapSchema loadedTapSchema; + private String loadingError; @PostConstruct public void init() { @@ -145,8 +148,10 @@ public class SchemaSelectionBean implements Serializable { } public void setSelectedTAPSchema(String selectedTAPSchema) { - this.selectedTAPSchema = selectedTAPSchema; - + this.selectedTAPSchema = selectedTAPSchema; + } + + public void selectedTAPSchemaChanged() { try { loadExposedSchemas(); } catch (SQLException e) { @@ -162,38 +167,58 @@ public class SchemaSelectionBean implements Serializable { this.selectedSchemas = selectedSchemas; } - private String loadTapSchema(TapSchema tapSchema) { - tapSchemaEditingBean.setTapSchema(tapSchema); - return "tapSchemaEditing.xhtml?faces-redirect=true"; + public String openLoaded() { + if (loadedTapSchema.getConsistencyChecks().isInconsistent()) { + consistencyChecksBean.setDbWrapper(dbWrapper); + consistencyChecksBean.setTapSchema(loadedTapSchema); + return "consistencyChecks.xhtml?faces-redirect=true"; + } else { + tapSchemaEditingBean.setTapSchema(loadedTapSchema); + return "tapSchemaEditing.xhtml?faces-redirect=true"; + } } - public String edit() { - try { - TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, selectedTAPSchema, true); - if (tapSchema.getConsistencyChecks().isInconsistent()) { - consistencyChecksBean.setDbWrapper(dbWrapper); - consistencyChecksBean.setTapSchema(tapSchema); - return "consistencyChecks.xhtml?faces-redirect=true"; - } else { - return loadTapSchema(tapSchema); + public void edit() { + + loadedTapSchema = null; + loading = true; + loadingError = null; + + new Thread(new Runnable() { + @Override + public void run() { + try { + loadedTapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, selectedTAPSchema, true); + } catch (Throwable e) { + loadingError = e.getMessage(); + } + loading = false; } - } catch (SQLException e) { - throw new RuntimeException(e); - } + }).start(); } - public String create() { - try { - TapSchema tapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, tapSchemaName, false); - for (String schemaName : selectedSchemas) { - tapSchema.addChild(schemaName); + public void create() { + + loadedTapSchema = null; + loading = true; + loadingError = null; + + new Thread(new Runnable() { + @Override + public void run() { + try { + loadedTapSchema = TapSchemaFactory.getTapSchema(TapSchemaVersion.TAP_SCHEMA_1_IA2, dbWrapper, tapSchemaName, false); + for (String schemaName : selectedSchemas) { + loadedTapSchema.addChild(schemaName); + } + } catch (Throwable e) { + loadingError = e.getMessage(); + } + loading = false; } - return loadTapSchema(tapSchema); - } catch (SQLException e) { - throw new RuntimeException(e); - } + }).start(); } - + public String getTapSchemaName() { return tapSchemaName; } @@ -226,4 +251,23 @@ public class SchemaSelectionBean implements Serializable { throw new ValidatorException(new FacesMessage(validatorMessage)); } } + + /** + * This boolean is true when a TapSchema instance is loading. + */ + public boolean isLoading() { + return loading; + } + + /** + * This String is not null when an error happens while a TapSchema is + * loading. + */ + public String getLoadingError() { + return loadingError; + } + + public TapSchema getLoadedTapSchema() { + return loadedTapSchema; + } } diff --git a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java index f8df2e948030bff94fde2caaa5725c86a339d590..a61ddc719d55994b95654be69424ce88480a0b0e 100644 --- a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java +++ b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java @@ -400,17 +400,18 @@ public class TapSchemaEditingBean implements Serializable { }); } - public String reload() { + public void reload() { if (schemaSelection.getSelectedRadioOption().equals("edit")) { - return schemaSelection.edit(); + schemaSelection.edit(); } else { if (tapSchema.exists()) { schemaSelection.setSelectedRadioOption("edit"); schemaSelection.setSelectedTAPSchema(tapSchema.getName()); - return schemaSelection.edit(); + schemaSelection.selectedTAPSchemaChanged(); + schemaSelection.edit(); } else { - return schemaSelection.create(); + schemaSelection.create(); } } } diff --git a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoaderResource.java b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoaderResource.java new file mode 100644 index 0000000000000000000000000000000000000000..7a7b0c984d0bba4bd87eaf0250719d0746769177 --- /dev/null +++ b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoaderResource.java @@ -0,0 +1,54 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2017 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.webapp; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.json.Json; +import javax.json.JsonObjectBuilder; + +/** + * REST Web Service + * + * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} + */ +@Path("tap_schema") +@RequestScoped +public class TapSchemaLoaderResource { + + @Inject + private SchemaSelectionBean schemaSelection; + + @GET + @Path("status") + public String getStatus() { + JsonObjectBuilder job = Json.createObjectBuilder(); + job.add("loading", schemaSelection.isLoading()); + if (schemaSelection.getLoadingError() != null) { + job.add("error", schemaSelection.getLoadingError()); + } + return job.build().toString(); + } +} diff --git a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java index a6b768bd93f21d17eb5668178f54ee871dd7be82..c3259e8797ebf5d0992879f65c724fb7882d87e0 100644 --- a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java +++ b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java @@ -46,6 +46,7 @@ public class ApplicationConfig extends Application { */ private void addRestResourceClasses(Set<Class<?>> resources) { resources.add(it.inaf.ia2.tsm.webapp.CredentialsDialogResource.class); + resources.add(it.inaf.ia2.tsm.webapp.TapSchemaLoaderResource.class); resources.add(it.inaf.ia2.tsm.webapp.env.KeepAliveResource.class); } } diff --git a/TASMAN-webapp/src/main/webapp/WEB-INF/templates/master.xhtml b/TASMAN-webapp/src/main/webapp/WEB-INF/templates/master.xhtml index 86b90bd1ca80a0c3443eb3fec976c0b01ef1965e..cd18cfc594d5e5c448e80605e095a0053b92ea56 100644 --- a/TASMAN-webapp/src/main/webapp/WEB-INF/templates/master.xhtml +++ b/TASMAN-webapp/src/main/webapp/WEB-INF/templates/master.xhtml @@ -19,7 +19,8 @@ <h:outputStylesheet library="css" name="style.css"></h:outputStylesheet> <h:outputScript library="js" name="lib/jquery-1.11.3.min.js"></h:outputScript> <h:outputScript library="js" name="lib/bootstrap.min.js"></h:outputScript> - <h:outputScript library="js" name="script.js"></h:outputScript> + <h:outputScript library="js" name="common.js"></h:outputScript> + <script>TSM.init('${config.restPath}', '${keepalive.windowId}');</script> <ui:insert name="scripts"></ui:insert> </h:head> @@ -34,6 +35,31 @@ TASMAN ${config.version} – Powered by IA2 </footer> + <div class="modal fade" tabindex="-1" role="dialog" id="errorModal" data-backdrop="static"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"> + <h4 class="modal-title text-danger"> + <span class="glyphicon glyphicon-alert"></span> + Error + </h4> + </div> + <div class="modal-body"> + <p>An error occurred. The page will be reloaded.</p> + <div class="alert alert-danger" role="alert"> + <p><strong class="errorName"></strong></p> + <p class="errorMessage"></p> + </div> + </div> + <div class="modal-footer"> + <h:form> + <h:commandLink class="btn btn-primary">Ok</h:commandLink> + </h:form> + </div> + </div> + </div> + </div> + <div class="loading hide"> <div class="icon-wrapper"> <span class="glyphicon glyphicon-refresh animate-spin"></span> diff --git a/TASMAN-webapp/src/main/webapp/consistencyChecks.xhtml b/TASMAN-webapp/src/main/webapp/consistencyChecks.xhtml index bcc7ddf804a5c6fbb60622030319984b485d9525..ef601900d3fb9fa0600fabd2f60cfa6c0a9f97ea 100644 --- a/TASMAN-webapp/src/main/webapp/consistencyChecks.xhtml +++ b/TASMAN-webapp/src/main/webapp/consistencyChecks.xhtml @@ -6,10 +6,6 @@ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"> <ui:define name="title">Consistency problems for #{consistency.tapSchema.name}</ui:define> - <ui:define name="scripts"> - <h:outputScript library="js" name="keepalive.js"></h:outputScript> - <script>startKeepAlive('${config.restPath}', '${keepalive.windowId}');</script> - </ui:define> <ui:define name="content"> <f:event listener="#{loggedInChecker.checkFromNonIndex()}" type="preRenderView" /> <div class="container"> diff --git a/TASMAN-webapp/src/main/webapp/credentialsEditing.xhtml b/TASMAN-webapp/src/main/webapp/credentialsEditing.xhtml index 9e1659ef7a09a3ae2e21180eef6fe51a241ac8b1..77a80ccf5b6561a052e8bbb2519ba8a579a7d160 100644 --- a/TASMAN-webapp/src/main/webapp/credentialsEditing.xhtml +++ b/TASMAN-webapp/src/main/webapp/credentialsEditing.xhtml @@ -9,7 +9,6 @@ <ui:define name="scripts"> <h:outputScript library="js" name="credentials.js"></h:outputScript> <h:outputScript library="js" name="ucd-editor.js"></h:outputScript> - <script>credentials.init('#{config.restPath}', '#{keepalive.windowId}');</script> </ui:define> <ui:define name="content"> <f:event listener="#{loggedInChecker.checkFromNonIndex()}" type="preRenderView" /> diff --git a/TASMAN-webapp/src/main/webapp/resources/js/async-loader.js b/TASMAN-webapp/src/main/webapp/resources/js/async-loader.js new file mode 100644 index 0000000000000000000000000000000000000000..5409768d0148f5342ba2c6d2e5ba6c143a5ebee8 --- /dev/null +++ b/TASMAN-webapp/src/main/webapp/resources/js/async-loader.js @@ -0,0 +1,43 @@ +(function ($, TSM) { + + var loading; + + function periodicCheck() { + showWaiting(); + setTimeout(function () { + $.get(TSM.getRestPath('tap_schema/status'), function (res) { + var status = JSON.parse(res); + if (status.loading) { + periodicCheck(); + } else { + if (status.error) { + hideWaiting(); + TSM.showError(status.error); + } else { + // Perform redirect trick + $('#async-loader\\:open-loaded').click(); + } + } + }); + }, 500); + } + + TSM.asyncLoader = { + + init: function (l) { + loading = l; + }, + startChecking: function (event) { + if (event.status === 'success') { + periodicCheck(); + } + } + }; + + $(document).ready(function () { + if (loading) { + periodicCheck(); + } + }); + +})(jQuery, window.TSM); \ No newline at end of file diff --git a/TASMAN-webapp/src/main/webapp/resources/js/common.js b/TASMAN-webapp/src/main/webapp/resources/js/common.js new file mode 100644 index 0000000000000000000000000000000000000000..f6612216fd73d1039a4b95926f196f3a6dbe04de --- /dev/null +++ b/TASMAN-webapp/src/main/webapp/resources/js/common.js @@ -0,0 +1,70 @@ +(function ($) { + + window.showWaiting = function () { + $('.loading').removeClass('hide'); + }; + window.hideWaiting = function () { + $('.loading').addClass('hide'); + }; + + var restPath, windowId; + + TSM = { + init: function (path, wid) { + restPath = path; + windowId = wid; + }, + getRestPath: function (action) { + path = restPath + '/' + action; + if (path.indexOf("?") !== -1) { + path += '&'; + } else { + path += '?'; + } + return path + 'dswid=' + windowId; + }, + showError: function (errorMessage) { + $('#errorModal .errorName').text(""); + $('#errorModal .errorMessage').text(errorMessage); + $('#errorModal').modal('show'); + } + }; + + $(document).ready(function () { + // Starting keep alive + if (window.name && window.name !== '') { + setInterval(function () { + $.get(TSM.getRestPath('keepalive')); + }, 60000); + } + + if (jsf) { + jsf.ajax.addOnError(function (error) { + $('#errorModal .errorName').text(error.errorName); + $('#errorModal .errorMessage').text(error.errorMessage); + if (error.errorName.indexOf('ViewExpiredException') !== -1) { + // If view has expired reload the page to display error message + location.reload(); + } else { + $('#errorModal').modal('show'); + } + }); + + // Setup loading animation + jsf.ajax.addOnEvent(function (data) { + if ($(data.source).is('input[type="text"]')) { + return; // special case + } + switch (data.status) { + case "begin": + showWaiting(); + break; + case "complete": + hideWaiting(); + break; + } + }); + } + }); + +})(jQuery); diff --git a/TASMAN-webapp/src/main/webapp/resources/js/credentials.js b/TASMAN-webapp/src/main/webapp/resources/js/credentials.js index f5c2ae171c18178927924a1b0b5217fca058d1c6..068ce3357502a22565588f8b1cc5df3aafaf7395 100644 --- a/TASMAN-webapp/src/main/webapp/resources/js/credentials.js +++ b/TASMAN-webapp/src/main/webapp/resources/js/credentials.js @@ -1,12 +1,6 @@ (function () { - var restPath, windowId; - window.credentials = { - init: function (path, wid) { - restPath = path; - windowId = wid; - }, editClicked: function (event) { if (event.status === 'success') { $('#credentials-modal').modal('show'); @@ -23,10 +17,10 @@ $(document).ready(function () { $('body').on('shown.bs.modal', '#credentials-modal', function ( ) { - $.post(restPath + "/credentialsDialog?opened=true&dswid=" + windowId); + $.post(TSM.getRestPath("credentialsDialog?opened=true")); }); $('body').on('hidden.bs.modal', '#credentials-modal', function ( ) { - $.post(restPath + "/credentialsDialog?opened=false&dswid=" + windowId); + $.post(TSM.getRestPath("credentialsDialog?opened=false")); }); $('body').on('keyup', '#credentials-modal input', function (event) { @@ -34,6 +28,6 @@ $('#main\\:save-credentials').click(); event.preventDefault(); } - }) + }); }); })(); diff --git a/TASMAN-webapp/src/main/webapp/resources/js/edit-tapschema.js b/TASMAN-webapp/src/main/webapp/resources/js/edit-tapschema.js index b161c9c86a51309da8d92355c8d4db67d72e69b2..38b2c0850daf4458415fb33db21d5fdeeea515c0 100644 --- a/TASMAN-webapp/src/main/webapp/resources/js/edit-tapschema.js +++ b/TASMAN-webapp/src/main/webapp/resources/js/edit-tapschema.js @@ -1,4 +1,4 @@ -(function ($) { +(function ($, TSM) { // Function factory to handle custom communications between the backing bean and JavaScript functions function eventHandlerFactory(handler, componentId) { @@ -38,124 +38,95 @@ var COLUMNS_COMPONENT_ID = 'main:columns-list'; - window.TSM = { -// validateManualUCD: function (event) { -// $clientValidationMessage = $('#ucd_search_form\\:ucd_validation_result'); -// -// var valid = UCDRegExp.test(event.target.value); -// if (valid) { -// $clientValidationMessage.empty(); -// } else { -// $clientValidationMessage.text('Invalid UCD!'); -// } -// -// $('#ucd_search_form\\:save_ucd').prop('disabled', !valid); -// }, - displayUpdateOperations: eventHandlerFactory(function (srcElement, jsupdate) { - $('#updateOperationsModal').modal('show'); - }), - saveUCDCalled: eventHandlerFactory(function (srcElement, jsupdate) { - if (jsupdate !== null) { - $('#searchUCDModal').modal('hide'); - } - // Hide loading + TSM.displayUpdateOperations = eventHandlerFactory(function (srcElement, jsupdate) { + $('#updateOperationsModal').modal('show'); + }); + + TSM.saveUCDCalled = eventHandlerFactory(function (srcElement, jsupdate) { + if (jsupdate !== null) { + $('#searchUCDModal').modal('hide'); + } + // Hide loading + $('.loading').addClass('hide'); + }); + + TSM.textInputChanged = eventHandlerFactory(function (srcElement, jsupdate) { + $(srcElement).toggleClass('changed', jsupdate === 'true'); + }); + + TSM.stopPropagation = function (event) { + event.stopPropagation(); + event.preventDefault(); + return false; + }; + + TSM.columnChanged = function (event) { + if (event.status === 'success') { + var $li = $(event.source).closest('li'); + $li.closest('ul').find('li').removeClass('active'); + $li.addClass('active'); + } + }; + + TSM.columnRemoved = eventHandlerFactory(function (srcElement, jsupdate, htmlupdate) { + jsupdate = JSON.parse(jsupdate); + var $ul = $(srcElement).closest('ul'); + $(srcElement).closest('a').find('span').addClass('strikeout'); + $(srcElement).prop('disabled', true); + + if (jsupdate.selectedColumn !== undefined) { + $ul.find('li').removeClass('active'); + $ul.find('li:nth-child(' + (jsupdate.selectedColumn + 1) + ')').addClass('active'); + } + }, COLUMNS_COMPONENT_ID); + + TSM.columnRemovalUndo = eventHandlerFactory(function (srcElement, jsupdate) { + var $a = $('#main\\:columns-list\\:' + jsupdate + '\\:column-selector'); + $a.find('input').prop('disabled', false); + $a.find('.strikeout').removeClass('strikeout'); + $a.removeClass('strikeout'); + }, COLUMNS_COMPONENT_ID); + + TSM.ucdTextKeyDown = function (event) { + if (event.keyCode === 13) { + $('#ucd_search_form\\:search_UCD_btn').click(); + } + }; + + TSM.openAddablesModal = function (event) { + if (event.status === 'success') { + $('#addablesModal').modal('show'); + } + }; + + TSM.entitiesAdded = function (event) { + if (event.status === 'success') { + $('#addablesModal').modal('hide'); + } + }; + + TSM.openSearchUCDModal = function (event) { + if (event.status === 'success') { $('.loading').addClass('hide'); - }), - textInputChanged: eventHandlerFactory(function (srcElement, jsupdate) { - $(srcElement).toggleClass('changed', jsupdate === 'true'); - }), - stopPropagation: function (event) { - event.stopPropagation(); - event.preventDefault(); - return false; - }, - columnChanged: function (event) { - if (event.status === 'success') { - var $li = $(event.source).closest('li'); - $li.closest('ul').find('li').removeClass('active'); - $li.addClass('active'); - } - }, - columnRemoved: eventHandlerFactory(function (srcElement, jsupdate, htmlupdate) { - jsupdate = JSON.parse(jsupdate); - var $ul = $(srcElement).closest('ul'); - $(srcElement).closest('a').find('span').addClass('strikeout'); - $(srcElement).prop('disabled', true); - - if (jsupdate.selectedColumn !== undefined) { - $ul.find('li').removeClass('active'); - $ul.find('li:nth-child(' + (jsupdate.selectedColumn + 1) + ')').addClass('active'); - } - }, COLUMNS_COMPONENT_ID), - columnRemovalUndo: eventHandlerFactory(function (srcElement, jsupdate) { - var $a = $('#main\\:columns-list\\:' + jsupdate + '\\:column-selector'); - $a.find('input').prop('disabled', false); - $a.find('.strikeout').removeClass('strikeout'); - $a.removeClass('strikeout'); - }, COLUMNS_COMPONENT_ID), - ucdTextKeyDown: function (event) { - if (event.keyCode === 13) { - $('#ucd_search_form\\:search_UCD_btn').click(); - } - }, - openAddablesModal: function (event) { - if (event.status === 'success') { - $('#addablesModal').modal('show'); - } - }, - entitiesAdded: function (event) { - if (event.status === 'success') { - $('#addablesModal').modal('hide'); - } - }, - openSearchUCDModal: function (event) { - if (event.status === 'success') { - $('.loading').addClass('hide'); - $('#searchUCDModal').modal('show'); - } - }, - closeSearchUCDModal: function (event) { - if (event.status === 'success') { - $('#searchUCDModal').modal('hide'); - } - }, - notifyUpdate: function (event) { - if (event.status === 'success' && $(event.responseXML).find('error').length === 0) { - $('#updateSuccessModal').modal('show'); - } - }, - updateFromModal: function () { - $('#updateOperationsModal').modal('hide'); - $('#main\\:update-btn').click(); + $('#searchUCDModal').modal('show'); } }; - $(document).ready(function () { - jsf.ajax.addOnError(function (error) { - $('#errorModal .errorName').text(error.errorName); - $('#errorModal .errorMessage').text(error.errorMessage); - if (error.errorName.indexOf('ViewExpiredException') !== -1) { - // If view has expired reload the page to display error message - location.reload(); - } else { - $('#errorModal').modal('show'); - } - }); + TSM.closeSearchUCDModal = function (event) { + if (event.status === 'success') { + $('#searchUCDModal').modal('hide'); + } + }; - // Setup loading animation - jsf.ajax.addOnEvent(function (data) { - if ($(data.source).is('input[type="text"]')) { - return; // special case - } - switch (data.status) { - case "begin": - showWaiting(); - break; - case "complete": - hideWaiting(); - break; - } - }); - }); + TSM.notifyUpdate = function (event) { + if (event.status === 'success' && $(event.responseXML).find('error').length === 0) { + $('#updateSuccessModal').modal('show'); + } + }; + + TSM.updateFromModal = function () { + $('#updateOperationsModal').modal('hide'); + $('#main\\:update-btn').click(); + }; -})(jQuery); \ No newline at end of file +})(jQuery, TSM); \ No newline at end of file diff --git a/TASMAN-webapp/src/main/webapp/resources/js/keepalive.js b/TASMAN-webapp/src/main/webapp/resources/js/keepalive.js deleted file mode 100644 index 8c20c295068abbfcc235baaf42dba64ccc270b43..0000000000000000000000000000000000000000 --- a/TASMAN-webapp/src/main/webapp/resources/js/keepalive.js +++ /dev/null @@ -1,5 +0,0 @@ -window.startKeepAlive = function (restPath, windowId) { - setInterval(function () { - $.get(restPath + '/keepalive?dswid=' + windowId); - }, 60000); -}; diff --git a/TASMAN-webapp/src/main/webapp/resources/js/script.js b/TASMAN-webapp/src/main/webapp/resources/js/script.js deleted file mode 100644 index a20c4305fbe225811f502eb776032fdfb99aa563..0000000000000000000000000000000000000000 --- a/TASMAN-webapp/src/main/webapp/resources/js/script.js +++ /dev/null @@ -1,7 +0,0 @@ - -window.showWaiting = function () { - $('.loading').removeClass('hide'); -}; -window.hideWaiting = function () { - $('.loading').addClass('hide'); -}; diff --git a/TASMAN-webapp/src/main/webapp/schemaSelection.xhtml b/TASMAN-webapp/src/main/webapp/schemaSelection.xhtml index 02eb021af5bc9e5d00f5fcf9adde16e15944f71d..be96e137fe0769269b665230697d3b1087d36c5a 100644 --- a/TASMAN-webapp/src/main/webapp/schemaSelection.xhtml +++ b/TASMAN-webapp/src/main/webapp/schemaSelection.xhtml @@ -7,9 +7,9 @@ xmlns:tsm_components="http://xmlns.jcp.org/jsf/composite/tsm_components"> <ui:define name="title">TASMAN - Schemata selection page</ui:define> <ui:define name="scripts"> - <h:outputScript library="js" name="keepalive.js"></h:outputScript> <h:outputScript library="js" name="ucd-editor.js"></h:outputScript> - <script>startKeepAlive('${config.restPath}', '${keepalive.windowId}');</script> + <h:outputScript library="js" name="async-loader.js"></h:outputScript> + <script>TSM.asyncLoader.init(#{schemaSelection.loading});</script> </ui:define> <ui:define name="content"> @@ -49,7 +49,7 @@ <h:outputLabel for="selectedTAPSchema">Tap Schema:</h:outputLabel> <h:selectOneMenu value="#{schemaSelection.selectedTAPSchema}" id="selectedTAPSchema" class="form-control"> <f:selectItems value="#{schemaSelection.allTAPSchemas}"></f:selectItems> - <f:ajax event="change" render="main:exposedSchemas"></f:ajax> + <f:ajax event="change" render="main:exposedSchemas" listener="#{schemaSelection.selectedTAPSchemaChanged}"></f:ajax> </h:selectOneMenu> </div> <div class="form-group" id="exposedDatabasesWrapper"> @@ -60,7 +60,9 @@ </p> </div> <div class="form-group"> - <h:commandButton value="Edit Tapschema" class="btn btn-primary" action="#{schemaSelection.edit()}" onclick="showWaiting()"></h:commandButton> + <h:commandButton value="Edit Tapschema" class="btn btn-primary" action="#{schemaSelection.edit()}"> + <f:ajax execute="@form" render="@form" onevent="TSM.asyncLoader.startChecking" /> + </h:commandButton> </div> </div> </h:panelGroup> @@ -84,7 +86,9 @@ </div> <div class="form-group"> - <h:commandButton value="Create TAP_SCHEMA" class="btn btn-primary" action="#{schemaSelection.create()}" onclick="showWaiting()"></h:commandButton> + <h:commandButton value="Create TAP_SCHEMA" class="btn btn-primary" action="#{schemaSelection.create()}"> + <f:ajax execute="@form" render="@form" onevent="TSM.asyncLoader.startChecking" /> + </h:commandButton> </div> </div> </h:panelGroup> @@ -106,5 +110,9 @@ <tsm_components:ucd_editor id="ucd-editor" /> </h:form> + + <h:form id="async-loader" class="hide"> + <h:commandButton action="#{schemaSelection.openLoaded()}" id="open-loaded" /> + </h:form> </ui:define> </ui:composition> \ No newline at end of file diff --git a/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml b/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml index 0d0ea462c6702e4794bee339c6bedcb4d6943d1e..501fec053568d579d3cbb6d0639cb29bb9c7c1dd 100644 --- a/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml @@ -10,8 +10,8 @@ <ui:define name="scripts"> <h:outputScript library="js" name="edit-tapschema.js"></h:outputScript> <h:outputScript library="js" name="ucd-editor.js"></h:outputScript> - <h:outputScript library="js" name="keepalive.js"></h:outputScript> - <script>startKeepAlive('#{config.restPath}', '#{keepalive.windowId}');</script> + <h:outputScript library="js" name="async-loader.js"></h:outputScript> + <script>TSM.asyncLoader.init(#{schemaSelection.loading});</script> </ui:define> <ui:define name="content"> <f:event listener="#{loggedInChecker.checkFromNonIndex()}" type="preRenderView" /> @@ -40,6 +40,7 @@ <h:commandLink class="btn btn-info" action="#{tapSchemaEditing.reload()}" onclick="showWaiting()"> <span class="glyphicon glyphicon-refresh"></span> Reload all + <f:ajax execute="@form" render="@form" onevent="TSM.asyncLoader.startChecking" /> </h:commandLink> </div> <div class="col-sm-6 vpadding text-right"> @@ -649,31 +650,6 @@ </div> </div> - <div class="modal fade" tabindex="-1" role="dialog" id="errorModal" data-backdrop="static"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <h4 class="modal-title text-danger"> - <span class="glyphicon glyphicon-alert"></span> - Error - </h4> - </div> - <div class="modal-body"> - <p>An error occurred. The page will be reloaded.</p> - <div class="alert alert-danger" role="alert"> - <p><strong class="errorName"></strong></p> - <p class="errorMessage"></p> - </div> - </div> - <div class="modal-footer"> - <h:form> - <h:commandLink class="btn btn-primary">Ok</h:commandLink> - </h:form> - </div> - </div> - </div> - </div> - <div class="modal fade" tabindex="-1" role="dialog" id="updateSuccessModal"> <div class="modal-dialog"> <div class="modal-content"> @@ -874,5 +850,9 @@ </div> </div> </div> + + <h:form id="async-loader" class="hide"> + <h:commandButton action="#{schemaSelection.openLoaded()}" id="open-loaded" /> + </h:form> </ui:define> </ui:composition> \ No newline at end of file