From 9404e9b0925b51cfca40921d5efeae5af8c2377c Mon Sep 17 00:00:00 2001 From: Eric Fayolle Date: Fri, 15 Mar 2024 16:14:19 +0100 Subject: [PATCH] =?utf8?q?Pr=C3=A9paration=20vers=20la=20gestion=20des=20d?= =?utf8?q?emande=20de=20nvx=20datasets=20=C3=A0=20la=20demande?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Web/mdm3.py | 78 ++++++++++++++++++++++------------ Web/templates/commandes_2.html | 42 ++++++++++-------- 2 files changed, 76 insertions(+), 44 deletions(-) mode change 100644 => 100755 Web/mdm3.py diff --git a/Web/mdm3.py b/Web/mdm3.py old mode 100644 new mode 100755 index 11643ef2..f8cdf46d --- a/Web/mdm3.py +++ b/Web/mdm3.py @@ -256,39 +256,65 @@ def newDataset(): req = request.get_json() # Print the dictionary print(__file__+"/newDataset : ",req); - catalogName=req['catalogName'];datasetName=req['datasetName']; - #QUESAKO code ? - - #TODO: pour l'instant un seul connecteur mono utilisateur - # il faudra gérer les différents utilisateurs avec la session Flask et - # disposer de plusieurs connecteurs par utilisateur. - #try { ? - # monConnecteur=createConnecteur(app,catalogName,datasetName) - # ou - monConnecteur = createConnecteur(app,catalogFile=os.path.join('data',catalogName)) - #monConnecteur.litFichierComm(datasetName) - myFancyTreeDico= monConnecteur.getDicoForFancy(monConnecteur.monEditeur.tree.racine) - myFancyTreeJS = json.dumps([myFancyTreeDico],indent=4) #TODO : remove indent if not DEBUG - pprint( myFancyTreeJS) - commands = monConnecteur.getListeCommandes(); - #TODO: Gérer le titre - # return make_response(json.dumps( {'source':myFancyTreeJS, 'commands':commands, 'titre':code} )) - - # TODO : Envoyer un evenement de création de JDD au javascript qui gèrera les onglets... - # et ne relancera pas le render - # return render_template('commandes_2.html', - # titre=code, - # listeCommandes = monConnecteur.getListeCommandes(), - # tree=myFancyTreeJS, - # ) - + cataFile =req['catalogName']; + dataSeFile =req['datasetName']; + cataFile = os.path.abspath('../Codes/WebTest/cata_essai.py') + dataSetFile = os.path.abspath('../Codes/WebTest/web_tres_simple_avec_2Fact.comm') else: # The request body wasn't JSON so return a 400 HTTP status code return "Request was not JSON", 400 #return make_response(jsonify({"message": "Request body must be JSON"}), 400) + + (editorId, errorCode, errorMessage, messageInfo) = eficasAppli.getWebEditor(session['canalId'], cataFile, dataSetFile) + debug = 1 + if debug : + print ('apres getWebEditor : canalId, : ', session['canalId'], ' editorId, : ', editorId, + ' code Erreur : ', errorCode,'message : ', errorMessage, 'messageInfo ', messageInfo) + + if not errorCode : + if debug : + print ('_______________________________________________') + print ('canalId', session['canalId']) + print ('editorId', editorId) + print ('_______________________________________________') + #La session est ouvert par le service /index session['canalId'] = canalId + session['externEditorId'] = editorId; + else : + # Il faudrait gerer les erreurs + return make_response(jsonify({"message": errorMessage, "code": errorCode}), 400) + + if debug : print ('idEditor = ', session['externEditorId']) + (eficasEditor, errorCode, errorMessage) = eficasAppli.getWebEditorById(session['canalId'],editorId) + if errorCode: + return make_response(jsonify({"message": errorMessage, "code": errorCode}), 400) + + + fancyTreeDict=eficasEditor.getDicoForFancy(eficasEditor.tree.racine) #TODO: changer le nom Dico en Dict + #fancyTreeJS=json.dumps([fancyTreeDict],indent=4) #TODO : remove indent if not DEBUG + + #print("---- myFancyTreeDico ----") + #pprint(myFancyTreeDico) + #print("---- myFancyTreeJS ----") + #pprint( myFancyTreeJS) + commands = eficasEditor.getListeCommandes(); #TODO: Renommer la fonction + + title = os.path.basename(cataFile)+'/'+os.path.basename(dataSetFile) + if debug : print ( 'liste des commandes', eficasEditor.getListeCommandes()) + return make_response(json.dumps( {'source': [fancyTreeDict], 'commands':commands, 'title':title,} )) + @app.route('/') def index(): + + # tree4Fancy = """ [ + # {"title": "Node 1", "key": "1"}, + # {"title": "Folder 2", "key": "2", "folder": true, "children": [ + # {"title": "Node 2.1", "key": "3"}, + # {"title": "Node 2.2", "key": "4"} + # ]} + # ] + # """.replace('\n','') + print ('_______________________________________________') #(canalId, codeErreur, message) = eficasAppli.getSessionId() #debug=1 diff --git a/Web/templates/commandes_2.html b/Web/templates/commandes_2.html index 400695d8..1b2391e7 100644 --- a/Web/templates/commandes_2.html +++ b/Web/templates/commandes_2.html @@ -485,15 +485,18 @@ function sendNewDataset( catalogName, datasetName) { // Tester data == NULL ! const source = data.source; const commands = data.commands; - const titre = data.titre; - const rMessage = data.message + const title = data.title; + const rMessage = data.message; + console.log(source); // TODO: détacher la constuction des options fancytree de #tree1 ! //tree.destroy(); let message = "New Dataset has been loaded ("+rMessage+")"; tree.clear(); //Remove all the nodes but keep the configuration tree.setOption('source', source); - tree.reload().done( ()=>treeMessage(_msgCssSelStr,"alert-success",message)); + + //?? FAIT BUGGER tree.reload().done( ()=>treeMessage(_msgCssSelStr,"alert-success",message)); + //TODO : Gérer les commandes //TODO : Gérer le titre/code @@ -529,7 +532,7 @@ function sendNewDataset( catalogName, datasetName) { //GESTION DES EVENEMENTS PROVENANT DU SERVEUR - const source = new EventSource("{{ url_for('sse.stream' , channel=efi_update_channel ) }}"); +const source = new EventSource("{{ url_for('sse.stream' , channel=efi_update_channel ) }}"); source.addEventListener('error', function(event) { alert("Failed to connect to event stream. Is Redis running?"); @@ -689,18 +692,20 @@ source.addEventListener('message', function(event) { -function getTree1() { +function getTree() { // Some logic to retrieve, or generate tree structure return {{ tree|tojson }}; -} - +}; +$(function(){ + 'use strict'; + $("#tree1").fancytree(efiFancytreeOptions()); + //sendNewDataset("",""); +}); // $("#tree1").fancytree({ source: [ {title: "Node 1", key: "1000"},{title: "Folder 2", key: "2", folder: true, children: [ {title: "Node 2.1", key: "3000"},{title: "Node 2.2", key: "44"} ]} ], }) // $("#tree1").fancytree({ source: JSON.parse(getTree1()), }) - - //Doublon cf. base.html var glyph_opts = { preset: "bootstrap3", @@ -728,16 +733,17 @@ function efiIconRendering(event, data) { }; }; -$(function(){ - 'use strict'; - $("#tree1").fancytree({ +//créer une fonction pour changer l'appel à getTree +let efiFancytreeOptions=function(){ + 'use strict'; + return { //focusOnSelect:true, - debug:4, //if null: use global setting $.ui.fancytree.debugLevel + debug:4, //if null: use global setting $.ui.fancytree.debugLevel debuLevel:4, //if null: use global setting $.ui.fancytree.debugLevel //extensions: ["dnd5", "edit", "glyph", "wide", "table", "gridnav"], extensions: [ "glyph", "table", "ariagrid"], // https://github.com/mar10/fancytree/wiki/ExtTable - //extensions: [ "glyph", "table", "gridnav"], + //extensions: [ "glyph", "table", "gridnav"], // utilisation d'ariagrid et non de gridnav checkbox: true, // Activate the use of checkboxes next to the nodes // selectMode: 1: single selection @@ -754,7 +760,7 @@ $(function(){ dragDrop : function(node, data) { data.otherNode.copyTo(node, data.hitMode); } }, glyph: glyph_opts, - source: JSON.parse(getTree1()), //TODO: Vérifier que la transformation JSON n'est pas double avec Flask + source: JSON.parse(getTree()), //TODO: Vérifier que la transformation JSON n'est pas double avec Flask //wide: { // iconWidth: "1em", // Adjust this if @fancy-icon-width != "16px" // iconSpacing: "0.5em", // Adjust this if @fancy-icon-spacing != "3px" @@ -1176,9 +1182,9 @@ $(function(){ renderNode: function(event, data) { console.log("event.type, data :"+event.type+" , "+data); }, - - }); -}); + }; +}; + function efiDefaultGridAction(event, data) { //(used by ext-aria) The user hit enter on the active row or cell. //return true; -- 2.39.2