From 916d22caf71efa4cc71357c8d105d8b99bbca410 Mon Sep 17 00:00:00 2001 From: Eric F Date: Wed, 1 Dec 2021 13:01:03 +0100 Subject: [PATCH] =?utf8?q?D=C3=A9but=20de=20gestion=20des=20validit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- testFlask/mdm.py | 32 +++-- testFlask/templates/base.html | 83 ++++++------ testFlask/templates/commandes_2.html | 180 ++++++++++++++++++--------- 3 files changed, 188 insertions(+), 107 deletions(-) diff --git a/testFlask/mdm.py b/testFlask/mdm.py index 4501c786..45948332 100755 --- a/testFlask/mdm.py +++ b/testFlask/mdm.py @@ -137,6 +137,11 @@ def index(): ) # etape = str(escape(request.args.get("etape", ""))) +## WebApp -> Eficas (signaux) : +# Pour SIMP : Ajoute, Supprime (MC facultatif), Change la valeur +# Pour FACT : Ajoute, Supprime +# Pour PROC : Ajoute, Supprime +# Pour OPER : Ajoute, Supprime, Nomme, Renomme # @app.route('/post/') @app.route("/updateSimp", methods=['POST']) def updateSimp(): @@ -147,23 +152,34 @@ def updateSimp(): # Print the dictionary print(req) print(req['id']) - id,data=req.values() - data=str(data) #Oups PN - r=monConnecteur.changeValeur(id,data); - print (r) + id,data = req.values() + data = str(data) #Oups PN + #comments,changeIsAccepted = monConnecteur.changeValeur(id,data); + changeDone = monConnecteur.changeValeur(id,data); + changeDone = False + print ("changeDone : ",changeDone) + # Ne pas récupérer le noeud dans le cas du SIMP (le changeDone et l''ancienne valeur ds la WebApp suffit + node = monConnecteur.getDicoForFancy(monConnecteur.monEditeur.getNodeById(id)) + print("node :",node) # myTreeDico=monConnecteur.getDicoObjetsCompletsPourTree(req['id']) # print("myTreeDico :",myTreeDico) # return jsonify([myTreeDico]) # return make_response(json.dumps([myTreeDico])) - return make_response(json.dumps([monConnecteur.getDicoObjetsCompletsPourTree(monConnecteur.monEditeur.tree.racine)])) - # return make_response(json.dumps([monConnecteur.getDicoObjetsCompletsPourTree(monConnecteur.monEditeur.getNodeById(req['id']))])) + #return make_response(json.dumps([monConnecteur.getDicoObjetsCompletsPourTree(monConnecteur.monEditeur.tree.racine)])) + return make_response(json.dumps( {'source':node, 'changeIsAccepted' : changeDone} )) # # Return a string along with an HTTP status code # return "JSON received!", 200 - else: # The request body wasn't JSON so return a 400 HTTP status code return "Request was not JSON", 400 - + +## SSE from Eficas signals : +# - Validite +# - Ajouter un noeud (et ses enfants) +# - Supprimer un noeud (et ses enfants), +# - ReAffichage d'un noeud (et ses enfants) +# - Changement d'un nom de mot-clé référencé + @app.route("/forward/", methods=['POST']) def move_forward(): #Moving forward code diff --git a/testFlask/templates/base.html b/testFlask/templates/base.html index 3dfe9e13..69d63fa7 100644 --- a/testFlask/templates/base.html +++ b/testFlask/templates/base.html @@ -8,6 +8,7 @@ + @@ -84,48 +85,48 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testFlask/templates/commandes_2.html b/testFlask/templates/commandes_2.html index 4d5ab161..66688544 100644 --- a/testFlask/templates/commandes_2.html +++ b/testFlask/templates/commandes_2.html @@ -54,9 +54,9 @@

-

Searchable Tree

+

MyDataModel : Testing the WebAPP approach

-

Input

+

Searching

@@ -85,7 +85,7 @@
-

Tree

+

My dataset

@@ -149,21 +149,22 @@ return {{ mcTraiteJson|tojson }}; - + //Doublon cf. base.html var glyph_opts = { preset: "bootstrap3", map: { } }; - $(function(){ - $("#tree1").fancytree({ - //extensions: ["dnd5", "edit", "glyph", "wide", "table", "gridnav"], - extensions: [ "glyph", "table", "ariagrid"], - checkbox: true, - - selectMode: 1, - dnd5: { + $(function(){ + $("#tree1").fancytree({ + //extensions: ["dnd5", "edit", "glyph", "wide", "table", "gridnav"], + extensions: [ "glyph", "table", "ariagrid"], + //extensions: [ "glyph", "table", "gridnav"], + checkbox: true, // Activate the use of checkboxes next to the nodes + + selectMode: 1, + dnd5: { dragStart: function(node, data) { return true; }, dragEnter: function(node, data) { return true; }, dragDrop: function(node, data) { data.otherNode.copyTo(node, data.hitMode); } @@ -176,42 +177,84 @@ return {{ mcTraiteJson|tojson }}; // labelSpacing: "0.1em", // Adjust this if padding between icon and label != "3px" // levelOfs: "1.5em" // Adjust this if ul padding != "16px" //}, - icon: function(event, data){ + icon: function(event, data) { if( data.node.isFolder() ) { return "glyphicon glyphicon-book"; } }, - table: { - checkboxColumnIdx: 1, - nodeColumnIdx: 2 + table: { // Options for the table extension + checkboxColumnIdx: 1, // Tree Nodes Checkboxes are rendered at column #1 (numbered from #0) + nodeColumnIdx: 2, // Tree Nodes are rendered at column #2 + indentation : 10 // Tree Nodes indentation between levels }, gridnav: { autofocusInput: true, // Focus first embedded input if node gets activated handleCursorKeys: true // Allow UP/DOWN in inputs to move to prev/next node }, + ariagrid: { + cellFocus: 'allow' + }, //lazyLoad: function(event, data) { // data.result = {url: "ajax-sub2.json", debugDelay: 1000}; //} + renderColumns: function(event, data) { -//var tree=$.ui.fancytree.getTree("#tree1") -//p1=tree.getNodeByKey('8304986a334211ec853cac220bca9aa6') -//$(p1.tr).find(">td") + + //var tree=$.ui.fancytree.getTree("#tree1") + //p1=tree.getNodeByKey('8304986a334211ec853cac220bca9aa6') + //$(p1.tr).find(">td") + var node = data.node, $tdList = $(node.tr).find(">td"); + var _attr='' + + //Render Column #0 $tdList.eq(0).text(node.getIndexHier()); - //$tdList.eq(3).text(!!node.folder); -//$tdList.eq(3).text(node.data.wValue); -//if ( $tdList.eq(3).hasClass("EFC_SIMP") ) - //if ( node.data.class ~ "EFC_SIMP" ) -// if ( node.title === "param1" ) { + + //Render Column #3 + // Jaune Eficas #ffff00 + // Rouge Eficas #ff0000 + // Vert Eficas #00ff00 if (node.data.classeAccas == "MCSIMP") { -// $tdList.eq(3).html(""); - $tdList.eq(3).html("
Valid.
Please fill out this field.
"); -//$tdList.eq(3).css('color','black') //td - $tdList.eq(3).find("input").css('color','black') + //VALIDATION STATES - Bootstrap includes validation styles for error, warning, and success messages. + //To use, add .has-warning, .has-error, or .has-success to the parent element + if( node.data.validite ) { + _attr='has-success'; + // $(".fancytree-exp-n > td:nth-child(2) span").filter(".fancytree-checkbox").css('background-color','blue') + $tdList.eq(1).find("span").filter(".fancytree-checkbox").css('background-color','#00ff00'); // Update the checkbox validation state TODO: create a CSS class + } else { + _attr='has-error'; + //$tdList.eq(1).css('background-color','red'); // Update the checkbox validation state TODO: create a CSS class + $tdList.eq(1).find("span").filter(".fancytree-checkbox").css('background-color','#ff0000'); // Update the checkbox validation state TODO: create a CSS class + } //TODO: paramétrer l'attribut/framework + //console.log("node.data.validite, _attr :"+node.data.validite+" , "+_attr); + // $tdList.eq(3).html(""); + $tdList.eq(3) + .html( + ""+ //'was-validated' ?? + "
" + + // "
" + + // "
" + + ""+ + //"
Valid.
"+ + //"
Please fill out this field.
"+ + "
"+ + "" + ) + .addClass(_attr) + .find("input").css('color','black'); //TODO : A placer ds le CSS + //$tdList.eq(1).css('back-ground,'green') // Update the checkbox validation state TODO: create a CSS class + + //$tdList.eq(3).css('color','black') //td + //$tdList.eq(3).find("input").css('color','black') - } + } else { + $tdList.eq(2).prop("colspan", 3).nextAll().remove(); + return; + } }, + icon: function(event, data) { if( data.node.type ) { return "ft-ico-" + data.node.type; @@ -220,40 +263,61 @@ return {{ mcTraiteJson|tojson }}; activate: function(event, data) { console.log("event.type, data :"+event.type+" , "+data); }, + focusTree: function(event, data) { + console.log("event.type, data :"+event.type+" , "+data); + }, activateCell: function(event, data) { console.log("event.type, data :"+event.type+" , "+data); }, defaultGridAction: function( event, data ) { var node = data.node - input=$(node.tr).find('input') - // Called when ENTER is pressed in cell-mode. - // Return false to prevent default - console.log("event.type, data :"+event.type+" , "+data); - if( !data.activeTd ) { - alert( "Custom default action for row: " + data.node.title ); - // we don't return false, so default action is applied: - } else if ( data.colIdx != 3 ) { - // eslint-disable-next-line no-alert - alert( "Custom default action: " + data.node.title ); - return false; - }; - $.ajax({ - type: "POST", - url: "{{ url_for('updateSimp') }}", - data: JSON.stringify({id: node.key, data:input.val() }), -// data: JSON.stringify({id: 5}), - contentType: "application/json; charset=utf-8", - dataType: "json", - // The callback function when the web service return success. - success: function(data, status) { - alert("Data: " + data + "\nStatus: " + status +"\nId :", $(this).attr("id") ); - console.log( {'data': data } ); - }, - // The callback function when the web service return fail. - failure: function(errMsg) { - alert(errMsg); - } - }); + var rValue,rValidite + + if (node.data.classeAccas == "MCSIMP") { + $input=$(node.tr).find('input') + value=$input.val() + + // Called when ENTER is pressed in cell-mode. + // Return false to prevent default + console.log("event.type, data :"+event.type+" , "+data); + if( !data.activeTd ) { + alert( "Custom default action for row: " + data.node.title ); + // we don't return false, so default action is applied: + } else if ( data.colIdx != 3 ) { + // eslint-disable-next-line no-alert + alert( "Custom default action: " + data.node.title ); + return false; + }; + + $.ajax({ + type : "POST", + url : "{{ url_for('updateSimp') }}", + data : JSON.stringify({id: node.key, data:value }), + contentType : "application/json; charset=utf-8", + dataType : "json", + // The callback function when the web service return success. + success: function(data, status) { + alert("Data: " + data + "\nStatus: " + status +"\ndata.changeIsAccepted :" +data.changeIsAccepted ); + rValue=data.source['wValue']; rValidite=data.source['validite']; + console.log( {'data': data } ); + console.log( {'rValue': rValue } ); + console.log( {'rValidite': rValidite } ); +//node.fromDict() +//source=JSON.parse(getTree1()) +node.data.wValue = rValue +node.data.validite = rValidite +console.log('rValue : '+rValue); +console.log('rValidite : '+rValidite); +node.render(true,false); //force rendering the node (not parents nor descendants) + }, + // The callback function when the web service return fail. + failure: function(errMsg) { + alert(errMsg); + } + }) +//node.render(true,false); //force rendering the node (not parents nor descendants) +//node.renderStatus(); //CSS element updates + } }, lazyLoad: function(event, data) { var node = data.node; -- 2.39.2