From 42a3f773a958c43a6ed1229ab2be70912986e7c1 Mon Sep 17 00:00:00 2001 From: lkrsnik Date: Tue, 13 Feb 2024 15:19:22 +0100 Subject: [PATCH] Added new updates acording to log. --- app.py | 23 ++++++++++++++-- static/css/style.css | 29 +++++++++++++++++--- static/js/init.js | 47 +++++++++++++++++++++++++++++--- static/js/result.js | 2 +- templates/about.html | 2 +- templates/index.html | 62 ++++++++++++++++++++++++++++++++++--------- templates/result.html | 6 ++--- 7 files changed, 144 insertions(+), 27 deletions(-) diff --git a/app.py b/app.py index 398027e..41c9e0e 100755 --- a/app.py +++ b/app.py @@ -8,6 +8,7 @@ import time import requests from flask import Flask, render_template, request, send_file, redirect, url_for +from flask_headers import headers from werkzeug.utils import secure_filename from stark import run @@ -134,6 +135,7 @@ def create_app(): return render_template('result.html', head_row=displayed_head, content=displayed_content_dict) @app.route('/', methods=['GET', 'POST']) + # @headers({'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'}) def index(): if request.method == 'POST': form = request.form @@ -240,6 +242,14 @@ def create_app(): configs['detailed_results_file'] = None configs['frequency_threshold'] = 0 + if 'frequency_threshold' in form and form['frequency_threshold']: + try: + int(form['frequency_threshold']) + except ValueError: + validation['frequency_threshold'] = f'Please insert an Integer.' + else: + configs['frequency_threshold'] = int(form['frequency_threshold']) + configs['lines_threshold'] = None configs['continuation_processing'] = False @@ -256,14 +266,23 @@ def create_app(): name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=60)) configs['output'] = os.path.join('media', name) if len(validation) > 0: + a = request.args.get('noreload') + b = request.args + c = request return render_template('index.html', validation=validation) try: run(configs) except Exception as e: - validation['general'] = 'Processing failed! Please recheck your settings.' + validation['general'] = 'Processing failed! Please recheck your settings, e.g. input format or head node description.' if len(validation) > 0: return render_template('index.html', validation=validation) - return redirect(url_for('result', result_id=name)) + # check if there are no results + with open(os.path.join('media', name), 'r') as rf: + content = list(csv.reader(rf, delimiter='\t')) + if len(content) == 1: + validation['results'] = False + return render_template('index.html', validation=validation) + return redirect(url_for('result', result_id=name, order_by='Frequency ', order_type='desc')) return render_template('index.html') return app diff --git a/static/css/style.css b/static/css/style.css index b6090a7..963cc6c 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -55,11 +55,11 @@ label { } table { - table-layout: fixed; + table-layout: auto; } th { - width: 300px; + max-width: 300px; padding: 10px 0 10px; background-color: #cccccc; text-align: center; @@ -69,7 +69,7 @@ th { } td { - width: 300px; + max-width: 300px; padding: 10px 0 10px; text-align: center; border-right: solid 1px #bbbbbb; @@ -81,7 +81,7 @@ td { color: #F44336; position: relative; min-height: 18px; - font-size: 12px; + font-size: 1.1rem; } @media only screen and (min-width: 993px) { @@ -89,3 +89,24 @@ td { width: 60%; } } + +.input-field .helper-text { + font-size: 1.1rem; +} + +.input-field > label:not(.label-icon).active { + -webkit-transform: translateY(-14px); + transform: translateY(-14px); +} + +.file-field .file-path-wrapper { + height: 75px; +} + +#advanced-tree-expand { + color: rgba(0, 0, 0, 0.87); +} + +.wider-container { + width: 80%; +} diff --git a/static/js/init.js b/static/js/init.js index dfa8df0..2734280 100644 --- a/static/js/init.js +++ b/static/js/init.js @@ -1,6 +1,6 @@ // Global array to store input names -var globalInputList = ['tree_size_min', 'tree_size_max', 'file', 'association_measures', 'labeled_trees', 'node_type_upos', 'fixed_order', 'input_url', 'node_type_lemma', 'root_restriction', 'node_type_form']; - +var globalInputList = ['tree_size_min', 'tree_size_max', 'file', 'association_measures', 'labeled_trees', 'node_type_upos', 'fixed_order', 'input_url', 'node_type_lemma', 'root_restriction', 'node_type_form', 'frequency_threshold']; +//const URLSearchParams = window.URLSearchParams; // Function to store values to local storage function storeValuesToLocalstorage() { globalInputList.forEach(function(inputName) { @@ -30,6 +30,9 @@ function readValuesFromLocalstorage() { // set label to active $("label[for='" + inputElement.attr('id') + "']").addClass('active'); } + if (inputName === 'frequency_threshold' && text_val === null) { + text_val = '1' + } inputElement.val(text_val); } else if (inputType === 'checkbox') { @@ -50,7 +53,7 @@ function readValuesFromLocalstorage() { document.addEventListener("DOMContentLoaded", function(event) { tree_size = readValuesFromLocalstorage() - var valuesForSlider = [2,3,4,5]; + var valuesForSlider = [1,2,3,4,5]; var format = { to: function(value) { @@ -72,6 +75,40 @@ document.addEventListener("DOMContentLoaded", function(event) { }, format: format }); + /* + // OLD VERSION + var perfEntries = performance.getEntriesByType("navigation"); + + for (var i = 0; i < perfEntries.length; i++) { + if (perfEntries[i].type === 'back_forward') { + window.location.href = '?noreload=true' + return; + } + } + var urlParams = new URLSearchParams(window.location.search); + if (!urlParams.has('noreload')) { + if (Object.keys(localStorage).length > 1) { + localStorage.clear(); + window.location.href = '?noreload=true' + } + + }*/ + var perfEntries = performance.getEntriesByType("navigation"); + for (var i = 0; i < perfEntries.length; i++) { + if (perfEntries[i].type === 'back_forward') { + window.location.href = '/' + return; + } + } + + var urlParams = new URLSearchParams(window.location.search); + if (urlParams.has('reload')) { +// if (Object.keys(localStorage).length > 1) { + localStorage.clear(); + window.location.href = '/' +// } + + } }); (function($){ @@ -81,6 +118,10 @@ document.addEventListener("DOMContentLoaded", function(event) { }); // end of document ready $(document).ready(function(){ + $('.modal').modal(); +// var instance = M.Modal.getInstance(elem); +// instance.open(); + $('.input-field input[type="checkbox"]').on('change', function() { var isChecked = $('.input-field input[type="checkbox"]:checked').length > 0; $('#node-type-error').hide(); diff --git a/static/js/result.js b/static/js/result.js index c8f4709..e7d22a5 100644 --- a/static/js/result.js +++ b/static/js/result.js @@ -21,7 +21,7 @@ $(document).ready(function() { $(".table-wrapper tbody tr").click(function() { var url = $(this).data("href"); if (url) { - window.location.href = url; + window.open(url, '_blank'); } }); $(".th-desc").hide(); diff --git a/templates/about.html b/templates/about.html index 3ea2d7d..fa5b591 100644 --- a/templates/about.html +++ b/templates/about.html @@ -13,7 +13,7 @@