diff --git a/app/js/app-menu.js b/app/js/app-menu.js index 6bd75866..df72397e 100644 --- a/app/js/app-menu.js +++ b/app/js/app-menu.js @@ -12,7 +12,7 @@ var _ = require('underscore'); module.exports = function() { var dynamicResize = appUtilities.dynamicResize.bind(appUtilities); - var layoutPropertiesView, generalPropertiesView,neighborhoodQueryView, pathsBetweenQueryView, pathsFromToQueryView, commonStreamQueryView, pathsByURIQueryView, promptSaveView, promptConfirmationView, + var layoutPropertiesView, generalPropertiesView, neighborhoodQueryView, pathsBetweenQueryView, pathsFromToQueryView, commonStreamQueryView, pathsByURIQueryView, mapByWPIDQueryView, promptSaveView, promptConfirmationView, promptMapTypeView, promptInvalidTypeWarning, promtErrorPD2AF, promptInvalidFileView, promptFileConversionErrorView, promptInvalidURIWarning, reactionTemplateView, gridPropertiesView, fontPropertiesView, fileSaveView,saveUserPreferencesView, loadUserPreferencesView, sifMapWarning; function validateSBGNML(xml) { @@ -150,6 +150,7 @@ module.exports = function() { pathsFromToQueryView = appUtilities.pathsFromToQueryView = new BackboneViews.PathsFromToQueryView({el: '#query-pathsfromto-table'}); commonStreamQueryView = appUtilities.commonStreamQueryView = new BackboneViews.CommonStreamQueryView({el: '#query-commonstream-table'}); pathsByURIQueryView = appUtilities.pathsByURIQueryView = new BackboneViews.PathsByURIQueryView({el: '#query-pathsbyURI-table'}); + mapByWPIDQueryView = appUtilities.mapByWPIDQueryView = new BackboneViews.MapByWPIDQueryView({el: '#query-mapbyWPID-table'}); //promptSaveView = appUtilities.promptSaveView = new BackboneViews.PromptSaveView({el: '#prompt-save-table'}); // see PromptSaveView in backbone-views.js fileSaveView = appUtilities.fileSaveView = new BackboneViews.FileSaveView({el: '#file-save-table'}); saveUserPreferencesView = appUtilities.saveUserPreferencesView = new BackboneViews.SaveUserPreferencesView({el: '#user-preferences-save-table'}); @@ -166,7 +167,9 @@ module.exports = function() { fontPropertiesView = appUtilities.fontPropertiesView = new BackboneViews.FontPropertiesView({el: '#font-properties-table'}); infoboxPropertiesView = appUtilities.infoboxPropertiesView = new BackboneViews.InfoboxPropertiesView({el: '#infobox-properties-table'}); promptInvalidURIView = appUtilities.promptInvalidURIView = new BackboneViews.PromptInvalidURIView({el: '#prompt-invalidURI-table'}); + promptInvalidWPIDView = appUtilities.promptInvalidWPIDView = new BackboneViews.PromptInvalidWPIDView({el: '#prompt-invalidWPID-table'}); promptInvalidURIWarning = appUtilities.promptInvalidURIWarning = new BackboneViews.PromptInvalidURIWarning({el: '#prompt-invalidURI-table'}); + promptInvalidWPIDWarning = appUtilities.promptInvalidWPIDWarning = new BackboneViews.PromptInvalidWPIDWarning({el: '#prompt-invalidWPID-table'}); promptInvalidURLWarning = appUtilities.promptInvalidURLWarning = new BackboneViews.PromptInvalidURLWarning({el: '#prompt-invalidURL-table'}); promptInvalidImageWarning = appUtilities.promptInvalidImageWarning = new BackboneViews.PromptInvalidImageWarning({el: '#prompt-invalidImage-table'}); promptInvalidEdgeWarning = appUtilities.promptInvalidEdgeWarning = new BackboneViews.PromptInvalidEdgeWarning({el: '#prompt-invalidEdge-table'}); @@ -1314,6 +1317,10 @@ module.exports = function() { pathsByURIQueryView.render(); }); + $("#query-mapbyWPID").click(function (e) { + mapByWPIDQueryView.render(); + }); + $("#grid-properties").click(function (e) { gridPropertiesView.render(); }); diff --git a/app/js/app-utilities.js b/app/js/app-utilities.js index 18009587..3515276e 100644 --- a/app/js/app-utilities.js +++ b/app/js/app-utilities.js @@ -3224,14 +3224,11 @@ appUtilities.launchWithModelFile = function() { await promptConfirmationView.render(async function () { await chiseInstance.loadSBGNMLText(data.message, false, filename, cy, paramObj); }); - chiseInstance.endSpinner('paths-byURL-spinner') - + chiseInstance.endSpinner('paths-byURL-spinner'); } else { await chiseInstance.loadSBGNMLText(data.message, false, filename, cy, paramObj); - chiseInstance.endSpinner('paths-byURL-spinner') - - + chiseInstance.endSpinner('paths-byURL-spinner'); } }); } diff --git a/app/js/backbone-views.js b/app/js/backbone-views.js index ab221fe1..aefb4b74 100644 --- a/app/js/backbone-views.js +++ b/app/js/backbone-views.js @@ -3107,12 +3107,8 @@ var PathsByURIQueryView = Backbone.View.extend({ cy, "currentGeneralProperties" ); - var currentInferNestingOnLoad = - currentGeneralProperties.inferNestingOnLoad; - var currentLayoutProperties = appUtilities.getScratch( - cy, - "currentLayoutProperties" - ); + var currentInferNestingOnLoad = currentGeneralProperties.inferNestingOnLoad; + var currentLayoutProperties = appUtilities.getScratch(cy, "currentLayoutProperties"); chiseInstance.startSpinner("paths-byURI-spinner"); $.ajax({ @@ -3194,6 +3190,146 @@ var PathsByURIQueryView = Backbone.View.extend({ }, }); +/** + * Map By WPID Query view for the Sample Application. + */ +var MapByWPIDQueryView = Backbone.View.extend({ + defaultQueryParameters: { + WPID: "", + }, + currentQueryParameters: null, + initialize: function () { + var self = this; + self.copyProperties(); + self.template = _.template($("#query-mapbyWPID-template").html()); + self.template = self.template(self.currentQueryParameters); + }, + copyProperties: function () { + this.currentQueryParameters = _.clone(this.defaultQueryParameters); + }, + render: function () { + var self = this; + self.template = _.template($("#query-mapbyWPID-template").html()); + self.template = self.template(self.currentQueryParameters); + $(self.el).html(self.template); + + $(self.el).modal("show"); + + $(document) + .off("click", "#save-query-mapbyWPID") + .on("click", "#save-query-mapbyWPID", function (evt) { + // use the active chise instance + var chiseInstance = appUtilities.getActiveChiseInstance(); + + // use the associated cy instance + var cy = chiseInstance.getCy(); + + self.currentQueryParameters.WPID = document.getElementById( + "query-mapbyWPID-WPID" + ).value; + var wpid = self.currentQueryParameters.WPID.trim(); + + if (wpid.length === 0) { + document.getElementById("query-mapbyWPID-WPID").focus(); + return; + } + // wpid is cleaned up from undesired characters such as #,$,! etc. and spaces put before and after the string + wpid = wpid.replace(/[^a-zA-Z0-9:/.\-\n\t ]/g, "").trim(); + if (wpid.length === 0) { + $(self.el).modal("toggle"); + new PromptInvalidWPIDView({ el: "#prompt-invalidWPID-table" }).render(); + return; + } + + var queryURL = "https://www.wikipathways.org/wikipathways-assets/pathways/" + wpid + "/" + wpid + ".gpml"; + + var filename = ""; + + if (filename == "") { + filename = wpid; + } else { + filename = filename + "_" + wpid; + } + filename = filename + ".nwt"; + + var sendMapByWPIDQuery = function () { + var currentGeneralProperties = appUtilities.getScratch(cy, "currentGeneralProperties"); + var currentInferNestingOnLoad = currentGeneralProperties.inferNestingOnLoad; + + chiseInstance.startSpinner("map-byWPID-spinner"); + $.ajax({ + type: "get", + url: "/utilities/testURL", + data: { url: queryURL }, + success: function (data) { + if (!data.error && data.response.statusCode == 200) { + if (data.response.body !== "") { + $(document).trigger("sbgnvizLoadFile", [filename, cy]); + currentGeneralProperties.inferNestingOnLoad = false; + chiseInstance.convertGpmlToSbgnml(data.response.body, async function (data) { + chiseInstance.loadSBGNMLText(data.message, false, filename, cy); + chiseInstance.endSpinner("map-byWPID-spinner"); + }); + currentGeneralProperties.inferNestingOnLoad = currentInferNestingOnLoad; + $(document).trigger("sbgnvizLoadFileEnd", [filename, cy]); + } else { + new PromptEmptyQueryResultView({ + el: "#prompt-emptyQueryResult-table", + }).render(); + } + } else if (data.error) { + let { code } = data.error; + if (code === "ESOCKETTIMEDOUT") { + new PromptRequestTimedOutView({ + el: "#prompt-requestTimedOut-table", + }).render(); + } + chiseInstance.endSpinner("map-byWPID-spinner"); + } + else if (!data.error && data.response.statusCode == 500){ + new InternalServerError({ + el: "#prompt-internal-server-table", + }).render(); + chiseInstance.endSpinner("map-byWPID-spinner"); + } + else { + new PromptInvalidWPIDView({ + el: "#prompt-invalidWPID-table", + }).render(); + chiseInstance.endSpinner("map-byWPID-spinner"); + } + }, + error: function (xhr, options, err) { + new PromptInvalidWPIDView({ + el: "#prompt-invalidWPID-table", + }).render(); + chiseInstance.endSpinner("map-byWPID-spinner"); + }, + }); + + $(self.el).modal("toggle"); + } + + if (cy.nodes().length != 0) { + new PromptConfirmationView({ + el: "#prompt-confirmation-table", + }).render(sendMapByWPIDQuery); + } else { + sendMapByWPIDQuery(); + } + + }); + + $(document) + .off("click", "#cancel-query-mapbyWPID") + .on("click", "#cancel-query-mapbyWPID", function (evt) { + $(self.el).modal("toggle"); + }); + + return this; + }, +}); + /* There was a side effect of using this modal prompt when clicking on New. If the user would click on save, then the save box asking for the filename (FileSaveView) would appear @@ -4358,6 +4494,29 @@ var PromptInvalidURIView = Backbone.View.extend({ }, }); +var PromptInvalidWPIDView = Backbone.View.extend({ + initialize: function () { + var self = this; + self.template = _.template($("#prompt-invalidWPID-template").html()); + }, + render: function () { + var self = this; + self.template = _.template($("#prompt-invalidWPID-template").html()); + + $(self.el).html(self.template); + $(self.el).modal("show"); + + $(document) + .off("click", "#prompt-invalidWPID-confirm") + .on("click", "#prompt-invalidWPID-confirm", function (evt) { + $(self.el).modal("toggle"); + appUtilities.mapByWPIDQueryView.render(); + }); + + return this; + }, +}); + var PromptInvalidURIWarning = Backbone.View.extend({ initialize: function () { var self = this; @@ -4380,6 +4539,28 @@ var PromptInvalidURIWarning = Backbone.View.extend({ }, }); +var PromptInvalidWPIDWarning = Backbone.View.extend({ + initialize: function () { + var self = this; + self.template = _.template($("#prompt-invalidWPID-template").html()); + }, + render: function () { + var self = this; + self.template = _.template($("#prompt-invalidWPID-template").html()); + + $(self.el).html(self.template); + $(self.el).modal("show"); + + $(document) + .off("click", "#prompt-invalidWPID-confirm") + .on("click", "#prompt-invalidWPID-confirm", function (evt) { + $(self.el).modal("toggle"); + }); + + return this; + }, +}); + var PromptInvalidFileView = Backbone.View.extend({ initialize: function () { var self = this; @@ -7043,6 +7224,7 @@ module.exports = { PathsFromToQueryView: PathsFromToQueryView, CommonStreamQueryView: CommonStreamQueryView, PathsByURIQueryView: PathsByURIQueryView, + MapByWPIDQueryView: MapByWPIDQueryView, PromptSaveView: PromptSaveView, FileSaveView: FileSaveView, SaveUserPreferencesView: SaveUserPreferencesView, @@ -7062,7 +7244,9 @@ module.exports = { AnnotationListView: AnnotationListView, AnnotationElementView: AnnotationElementView, PromptInvalidURIView: PromptInvalidURIView, + PromptInvalidWPIDView: PromptInvalidWPIDView, PromptInvalidURIWarning: PromptInvalidURIWarning, + PromptInvalidWPIDWarning: PromptInvalidWPIDWarning, PromptInvalidURLWarning: PromptInvalidURLWarning, PromptInvalidImageWarning: PromptInvalidImageWarning, PromptInvalidEdgeWarning: PromptInvalidEdgeWarning, diff --git a/index.html b/index.html index 6bbd8509..4047c999 100644 --- a/index.html +++ b/index.html @@ -602,15 +602,7 @@
@@ -2355,12 +2355,7 @@ -