From 7dc3514e2e722b7396f8d86c8fe43d4491296b69 Mon Sep 17 00:00:00 2001 From: Erik Perrone Date: Tue, 13 Mar 2018 13:31:37 +0000 Subject: [PATCH] Maxlength attribute in the text area. Some other fix. git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@164998 82a268e6-3cf1-43bd-a215-b396298e98cf --- src/main/webapp/css/custom.css | 14 ++ src/main/webapp/index.jsp | 10 +- src/main/webapp/js/main.js | 256 +++++++++++++++++++-------------- 3 files changed, 170 insertions(+), 110 deletions(-) diff --git a/src/main/webapp/css/custom.css b/src/main/webapp/css/custom.css index 1fd0b3c..036d56a 100644 --- a/src/main/webapp/css/custom.css +++ b/src/main/webapp/css/custom.css @@ -241,12 +241,26 @@ select { margin: 2px; } +.left-side-half { + float: left; + width: 49%; + height: 3vh; + margin: 1px; +} + .right-side::after { content: ""; clear: both; display: table; } +.left-side-half::after { + content: ""; + clear: both; + display: table; +} + + .header-side { float: left; width: 100%; diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index ea27ac4..fec647a 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -72,8 +72,8 @@ -
-
@@ -95,7 +95,11 @@
-
+
+
+
+
+
diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index a3f7af3..61d361e 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -16,107 +16,109 @@ var hexLetters = '0123456789ABCDEF'; // with valid algs info. // ------------------------------------------------------------------------------------------------------ -$ - .ajax({ - url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0", - type : "GET", - async : true, - contentType : "text/plain; charset=utf-8", - success : function(data, stato) { +$(document).ready(function() { + disableExecuteButton(); + $.ajax({ + url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0", + type : "GET", + async : true, + contentType : "text/plain; charset=utf-8", + success : function(data, stato) { + $("#ner-result-container").hide(); + var lineTokens = manageCsvData(data); + getAlgorithms(lineTokens); + buildLanguageSelection(); + buildLanguageList(); + buildAnnotations(); + resizeTable(); + resizeLogo(); + + $("#back-ner-ui-button").click(function() { $("#ner-result-container").hide(); - var lineTokens = manageCsvData(data); - getAlgorithms(lineTokens); - buildLanguageSelection(); - buildLanguageList(); - buildAnnotations(); - resizeTable(); - resizeLogo(); + $("#ner-ui").show(); + $("#input-textarea").val(""); + publicLink = null; + jsonContent = null; + }); - $("#back-ner-ui-button").click(function() { - $("#ner-result-container").hide(); - $("#ner-ui").show(); - $("#input-textarea").val(""); - publicLink = null; - jsonContent = null; - }); + disableExecuteButton(); - $("#execute-button").css("background-color", pageGray); - - $("#upload-button") - .uploadFile( - { - url : "/nlphub/nlphub-uploader-servlet", - fileName : "mytxtfile", - maxFileCount : 100, - multiple : false, - maxFileSize : 1024 * 1000 * 6.14, - showFileCounter : false, - showCancel : true, - dragDropStr : "", - extErrorStr : "Error. Text file only", - sizeErrorStr : "Error. Max size: 6 Mb", - onLoad : function(obj) { - $("#file-info").remove(); - $("#reset-upload").remove(); - $("#fu-container") - .append( - "
"); - $("#right-child") - .append( - "
"); - $("#right-child") - .append( - "
Cancel
"); - $("#reset-upload").hide(); - $("#reset-upload").click( - function() { - resetExecuteButton(); - $("#file-info").empty(); - $("#reset-upload").css( - "display", "none"); - textAreaEnable(true); - }); - savedAnnotations = ""; - setEventListeners(); - }, - onSelect : function(files) { - showProgress(); - textAreaEnable(false); - $("#input-textarea").val(""); - }, - onSuccess : function(files, data, xhr) { - hideProgress(); - console.log('' + data.language); - checkLanguage(data.language); - selectAnnotationsByLanguage(); - $("#reset-upload").css("display", - "inline"); - console.log("files: " + files); - $("#file-info").empty(); - $("#file-info") - .append( - "Uploaded: " - + files - + ""); - publicLink = data.message; - $("#execute-button").css( - "background-color", pageGreen); - if (publicLink == null) { - alert("Error uploading file."); - } - }, - onError : function(files, status, errMsg, - pd) { - hideProgress(); - textAreaEnable(true); - alert(errMsg); + $("#upload-button") + .uploadFile( + { + url : "/nlphub/nlphub-uploader-servlet", + fileName : "mytxtfile", + maxFileCount : 100, + multiple : false, + maxFileSize : 1024 * 1000 * 6.14, + showFileCounter : false, + showCancel : true, + dragDropStr : "", + extErrorStr : "Error. Text file only", + sizeErrorStr : "Error. Max size: 6 Mb", + onLoad : function(obj) { + $("#file-info").remove(); + $("#reset-upload").remove(); + $("#fu-container") + .append( + "
"); + $("#right-child") + .append( + "
"); + $("#right-child") + .append( + "
Cancel
"); + $("#reset-upload").hide(); + $("#reset-upload").click( + function() { + resetExecuteButton(); + $("#file-info").empty(); + $("#reset-upload").css( + "display", "none"); + textAreaEnable(true); + }); + savedAnnotations = ""; + setEventListeners(); + }, + onSelect : function(files) { + showProgress(); + textAreaEnable(false); + $("#input-textarea").val(""); + }, + onSuccess : function(files, data, xhr) { + hideProgress(); + console.log('' + data.language); + checkLanguage(data.language); + selectAnnotationsByLanguage(); + $("#reset-upload").css("display", + "inline"); + console.log("files: " + files); + $("#file-info").empty(); + $("#file-info") + .append( + "Uploaded: " + + files + + ""); + publicLink = data.message; + enableExecuteButton(); + if (publicLink == null) { + alert("Error uploading file."); } - }); - }, - error : function(richiesta, stato, errori) { - alert("Unexpected Error. Status: " + richiesta.status); - } - }); + }, + onError : function(files, status, errMsg, + pd) { + hideProgress(); + textAreaEnable(true); + alert(errMsg); + } + }); + }, + error : function(richiesta, stato, errori) { + alert("Unexpected Error. Status: " + richiesta.status); + } + }); +}); + /* * Utility function processing the language indication returned by the language recognition service @@ -250,26 +252,61 @@ buildLanguageSelection = function() { } } +enableExecuteButton = function() { + $("#execute-button").css("background-color", pageGreen); + $("#execute-button").attr("enable", "true"); +} + +disableExecuteButton = function() { + $("#execute-button").css("background-color", pageGray); + $("#execute-button").attr("enable", "false"); +} + +isEnabled = function() { + if($("#execute-button").attr("enable") == "true") + return true; + return false; +} + +enableDisableTextArea = function() { + if ($("#input-textarea").val() == "") + disableExecuteButton(); + else + enableExecuteButton(); +} + /* * Set the listeners on the text area and the execute button */ setEventListeners = function() { $("#input-textarea").on("keyup", function() { - if ($("#input-textarea").val() == "") - $("#execute-button").css("background-color", pageGray); - else - $("#execute-button").css("background-color", pageGreen); + enableDisableTextArea(); + }); + + $("#input-textarea").change(function() { + enableDisableTextArea(); }); + window.addEventListener('contextmenu', function(e) { + //alert("You've tried to open context menu"); //here you draw your own menu + //e.preventDefault(); + enableDisableTextArea(); + }, false); + $("#execute-button") .click( function() { + if(!isEnabled()) + return; + if ((publicLink == null) && ($("#input-textarea").val() == "")) { alert("You must upload a file or write some text in the text area before submit a request."); return; } + disableExecuteButton(); + showProgress(); // if some text has been written in the text area, then // a corresponding text file @@ -286,7 +323,6 @@ setEventListeners = function() { contentType : "text/plain; charset=utf-8", success : function(data, stato) { publicLink = data.message; - // console.log(data.language); if (publicLink == null) { alert("Error uploading file."); } @@ -370,6 +406,7 @@ launchAlgorithm = function() { success : function(data, stato) { textAreaEnable(true); $("#file-info").empty(); + $("#reset-upload").css("display", "none"); if (typeof (data.response) != 'undefined') { var jsonOut = getOutputJson(data.message); } else if (typeof (data.error) != 'undefined') { @@ -444,13 +481,15 @@ showResult = function(data) { jsonContent = data; resultText = jsonContent.output.text; - $("#result-header").empty(); + $("#result-header-left").empty(); + $("#result-header-right").empty(); $("#result-params-div").empty(); $("#result-text-div").empty(); - $("#result-header").append( - "

You can download the overall result as a JSON file here

"); + $("#result-header-left").append( + "You can download the overall result as a JSON file here"); + $("#result-header-right").append(" "); var localText = resultText; localText = resultText.replace(/\n/g, "
"); $("#result-text-div").empty(); @@ -536,7 +575,10 @@ rewriteText = function(annotation, color) { var G = enhanceColor(complement.substring(2,4)); var B = enhanceColor(complement.substring(4)); complement = "#" + R + G + B; + var indices = getIndices(annotation); + $("#result-header-right").empty(); + $("#result-header-right").append("" + annotation + " occurs " + indices.length + " times."); var indexedText = ""; if ((typeof (indices) == 'undefined') || (indices.length == 0)) { @@ -636,7 +678,7 @@ mergeIndices = function(indices) { */ resetExecuteButton = function() { publicLink = null; - $("#execute-button").css("background-color", pageGray); + disableExecuteButton(); } /*