From e4db4d76339ee7d39d9450dadc6e41735d61194b Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 27 Oct 2017 10:53:27 +0100 Subject: [PATCH 1/5] Catch error from server when invalid Regular Expression used in Text Filter --- main/webapp/modules/core/scripts/project.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main/webapp/modules/core/scripts/project.js b/main/webapp/modules/core/scripts/project.js index 65d99904e..c67fc6e17 100644 --- a/main/webapp/modules/core/scripts/project.js +++ b/main/webapp/modules/core/scripts/project.js @@ -425,9 +425,15 @@ Refine.fetchRows = function(start, limit, onDone, sorting) { } $.post( - "command/core/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }) + "&callback=?", + "command/core/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }), body, function(data) { + if(data.code === 'error') { + data = theProject.rowModel; + //maybe change the data to zero? + data.rows = []; + data.filtered = 0; + } theProject.rowModel = data; // Un-pool objects @@ -445,7 +451,7 @@ Refine.fetchRows = function(start, limit, onDone, sorting) { onDone(); } }, - "jsonp" + "json" ); }; From 178e4e5bca918395682766bfdb5bb099133968cd Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 27 Oct 2017 10:55:32 +0100 Subject: [PATCH 2/5] On invalid regular expression, keep all current rows displayed in data-table view --- main/webapp/modules/core/scripts/project.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/main/webapp/modules/core/scripts/project.js b/main/webapp/modules/core/scripts/project.js index c67fc6e17..e6dd2391c 100644 --- a/main/webapp/modules/core/scripts/project.js +++ b/main/webapp/modules/core/scripts/project.js @@ -430,9 +430,6 @@ Refine.fetchRows = function(start, limit, onDone, sorting) { function(data) { if(data.code === 'error') { data = theProject.rowModel; - //maybe change the data to zero? - data.rows = []; - data.filtered = 0; } theProject.rowModel = data; From e4bdca9c95f7645fb4e206031f73bd70e284bae3 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 27 Oct 2017 10:59:03 +0100 Subject: [PATCH 3/5] Catch and display errors on compute-facet --- .../core/scripts/project/browsing-engine.js | 17 +++++++++++++++-- .../modules/core/styles/project/sidebar.less | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/main/webapp/modules/core/scripts/project/browsing-engine.js b/main/webapp/modules/core/scripts/project/browsing-engine.js index 04bc571b2..a96738dc8 100644 --- a/main/webapp/modules/core/scripts/project/browsing-engine.js +++ b/main/webapp/modules/core/scripts/project/browsing-engine.js @@ -101,6 +101,7 @@ BrowsingEngine.prototype._initializeUI = function() { '

'+$.i18n._('core-project')["not-sure"]+'
'+$.i18n._('core-project')["watch-cast"]+'

' + '' + '
' + + '
' + '
' + ' '+$.i18n._('core-project')["refreshing-facet"]+'' + '
' + @@ -240,19 +241,31 @@ BrowsingEngine.prototype.update = function(onDone) { this._elmts.header.show(); this._elmts.controls.css("visibility", "hidden"); - this._elmts.indicator.css("visibility", "visible"); + this._elmts.indicator.css("display", "block"); $.post( "command/core/compute-facets?" + $.param({ project: theProject.id }), { engine: JSON.stringify(this.getJSON(true)) }, function(data) { + if(data.code === 'error') { + var clearErr = $('#err-text').remove(); + var err = $('
') + .text(data.message) + .appendTo(self._elmts.errors); + self._elmts.errors.css("display", "block"); + if (onDone) { + onDone(); + } + return; + } var facetData = data.facets; for (var i = 0; i < facetData.length; i++) { self._facets[i].facet.updateState(facetData[i]); } - self._elmts.indicator.css("visibility", "hidden"); + self._elmts.indicator.css("display", "none"); + self._elmts.errors.css("display", "none"); if (self._facets.length > 0) { self._elmts.header.show(); self._elmts.controls.css("visibility", "visible"); diff --git a/main/webapp/modules/core/styles/project/sidebar.less b/main/webapp/modules/core/styles/project/sidebar.less index 482fe93e8..9d8c36d4b 100644 --- a/main/webapp/modules/core/styles/project/sidebar.less +++ b/main/webapp/modules/core/styles/project/sidebar.less @@ -38,9 +38,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. display: none; } +.browsing-panel-errors { + display: none; + position: relative; + height: auto; + margin: 5px; + text-align: center; + background: #fff0f4; + color: #c51244; + padding: 4px 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + border: 1px solid #ccc; + } + .browsing-panel-indicator { - visibility: hidden; - position: absolute; + display: none; + position: relative; width: 50%; margin: 5px; top: 0em; From f5e4420af9e4c4034388aeec6b019895d34f7e39 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 27 Oct 2017 11:47:59 +0100 Subject: [PATCH 4/5] Minor syntax change for Codacy --- main/webapp/modules/core/scripts/project.js | 2 +- main/webapp/modules/core/scripts/project/browsing-engine.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/webapp/modules/core/scripts/project.js b/main/webapp/modules/core/scripts/project.js index e6dd2391c..b8714db8d 100644 --- a/main/webapp/modules/core/scripts/project.js +++ b/main/webapp/modules/core/scripts/project.js @@ -178,7 +178,7 @@ Refine.reinitializeProjectData = function(f, fError) { $.getJSON( "command/core/get-project-metadata?" + $.param({ project: theProject.id }), null, function(data) { - if (data.status == 'error') { + if (data.status == "error") { alert(data.message); if (fError) { fError(); diff --git a/main/webapp/modules/core/scripts/project/browsing-engine.js b/main/webapp/modules/core/scripts/project/browsing-engine.js index a96738dc8..d9e18bcd4 100644 --- a/main/webapp/modules/core/scripts/project/browsing-engine.js +++ b/main/webapp/modules/core/scripts/project/browsing-engine.js @@ -247,7 +247,7 @@ BrowsingEngine.prototype.update = function(onDone) { "command/core/compute-facets?" + $.param({ project: theProject.id }), { engine: JSON.stringify(this.getJSON(true)) }, function(data) { - if(data.code === 'error') { + if(data.code === "error") { var clearErr = $('#err-text').remove(); var err = $('
') .text(data.message) From 98f37905d7d2fcb533d606c3f29fd0ba99ae1db6 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 27 Oct 2017 12:22:01 +0100 Subject: [PATCH 5/5] More minor syntax changes to make Codacy a little happier --- main/webapp/modules/core/scripts/project.js | 4 ++-- main/webapp/modules/core/scripts/project/browsing-engine.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main/webapp/modules/core/scripts/project.js b/main/webapp/modules/core/scripts/project.js index b8714db8d..ab86a449a 100644 --- a/main/webapp/modules/core/scripts/project.js +++ b/main/webapp/modules/core/scripts/project.js @@ -220,7 +220,7 @@ Refine._renameProject = function() { data: { "project" : theProject.id, "name" : name }, dataType: "json", success: function (data) { - if (data && typeof data.code != 'undefined' && data.code == "ok") { + if (data && typeof data.code != "undefined" && data.code == "ok") { theProject.metadata.name = name; Refine.setTitle(); } else { @@ -428,7 +428,7 @@ Refine.fetchRows = function(start, limit, onDone, sorting) { "command/core/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }), body, function(data) { - if(data.code === 'error') { + if(data.code === "error") { data = theProject.rowModel; } theProject.rowModel = data; diff --git a/main/webapp/modules/core/scripts/project/browsing-engine.js b/main/webapp/modules/core/scripts/project/browsing-engine.js index d9e18bcd4..d75a097a4 100644 --- a/main/webapp/modules/core/scripts/project/browsing-engine.js +++ b/main/webapp/modules/core/scripts/project/browsing-engine.js @@ -33,7 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. function BrowsingEngine(div, facetConfigs) { this._div = div; - this._mode = theProject.recordModel.hasRecords ? 'record-based' : 'row-based'; + this._mode = theProject.recordModel.hasRecords ? "record-based" : "row-based"; this._facets = []; this._initializeUI();