# gérer un appel register callback
app.fromConnecteur=fromConnecteur
+## 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-cle reference
+
def propageValide(id, valid):
- #print ('dans propageValide: ', id, valid)
+ #print ('Flask/propageValide: ', id, valid)
sse.publish( {'id':id, 'valid':valid, 'message': "Hello from propageValide!"}, type='propageValide')
def appendChildren(id, fcyTreeJson, pos):
- print ('dans appendChildren: ', fcyTreeJson, pos)
+ print ('Flask/appendChildren: ', id, fcyTreeJson, pos)
sse.publish( {'id':id, 'fcyTreeSrc':fcyTreeJson, 'pos':pos, 'message': "Hello from appendChildren!"}, type='appendChildren')
def deleteChildren(idList):
- #print ('dans deleteChildren: ', idList)
+ #print ('Flask/deleteChildren: ', idList)
sse.publish( {'idList':idList,'message': "Hello from deleteChildren!"}, type='deleteChildren')
# # Pour test curl
)
# etape = str(escape(request.args.get("etape", "")))
-## WebApp -> Eficas (signaux) :
+## WebApp -> Eficas :
# Pour SIMP : Ajoute, Supprime (MC facultatif), Change la valeur
# Pour FACT : Ajoute, Supprime
# Pour PROC : Ajoute, Supprime
print(req)
print(req['id'])
id=req['id'];value=req['value']
- # id, value = req.values() # Dangereux correspondance implicite
- value = str(value) #Oups PN
+ # id, value = req.values() # Dangereux correspondance implicite
+ value = str(value) #On peut écrire Pi
rId,message,changeDone = monConnecteur.changeValeur(id,value);
assert(rId==id)
#changeDone = True
return "Request was not JSON", 400
#return make_response(jsonify({"message": "Request body must be 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-cle reference
+
+@app.route("/appendChild", methods=['POST'])
+def appendChild():
+ # Validate the request body contains JSON
+ if request.is_json:
+ # Parse the JSON into a Python dictionary
+ req = request.get_json()
+ # Print the dictionary
+ print(req);print(req['id'])
+ id=req['id'];name=req['name'];pos=req['pos'];
+ # id, value = req.values() # Dangereux correspondance implicite
+ #rId,message,changeDone = monConnecteur.appendChild(id,name,pos);
+ newId = monConnecteur.appendChild(id,name,'last'); #pos
+ print ("/appendChild : newId : ",newId)
+
+ return make_response(json.dumps( {'id':newId} ))
+ # return make_response(json.dumps( {'source':node, 'changeIsAccepted' : changeDone, 'message': message} ))
+ # 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
+ #return make_response(jsonify({"message": "Request body must be JSON"}), 400)
+
@app.route("/forward/", methods=['POST'])
def move_forward():
</head>
+ <!-- <nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="10"> -->
+ <nav class="navbar navbar-inverse" >
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">MDM/Eficas</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <!-- <li class="active"><a href="#">File</a></li> -->
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">File<span class="caret"></span></a>
+ <ul class="dropdown-menu">
+ <!-- <li class="active"><a href="#">File</a></li> -->
+ <li>
+ <form action="">
+ <div class="input-group">
+ <input type="file" class="form-control" name="toto">
+ <div class="input-group-btn">
+ <button class="btn btn-default" type="submit">Set the current catalog</button>
+ </div>
+ </div>
+ </form>
+ <!-- <form action=""> -->
+ <!-- <div class="form-group"> -->
+ <!-- <\!-- <label for="catalog">Set the current catalog </label> -\-> -->
+ <!-- <button type="file" class="btn btn-default" multiple="false" id="catalog" value="Set the current catalog"></button> -->
+ <!-- </div> -->
+ <!-- </form> -->
+ </li>
+ <li><a href="#">Set Catalog</a></li>
+ <li><a href="#">Open Dataset</a></li>
+ </ul>
+ </li>
+ <li><a href="#">Editor</a></li>
+ <li><a href="#">Dataset</a></li>
+ <li><a href="#">Help</a></li>
+ </ul>
+ </div>
+ </nav>
+
<div class="container-fluid">
{% block content %} {% endblock %}
</div>
</html>
+
+<!-- e=tree.findFirst((e)=>{return e.title == "param1";}) -->
+<!-- e=tree.findFirst((e)=>{return e.key == "02acc78472e011ec8e9f64c901d49bcd";}) -->
<div class="row">
<!-- <hr> -->
- <h2>MyDataModel : Testing the WebAPP approach</h2>
+ <!-- <h2>MyDataModel : Testing the WebAPP approach</h2> -->
+
<!-- <div class="col-sm-4"> -->
<!-- <h2>Searching</h2> -->
<!-- <\!-- <form> -\-> -->
</div>
<div class="row">
<div class="col-sm-12">
- <h2>Choose Object to add</h2>
+ <!-- <h2>Choose Object to add</h2> -->
+
<!-- <h1>Choose command to add </h1> -->
<!-- <h2>Commandes en ligne </h2> -->
<!-- <ul> -->
{% for commande in listeCommandes %}
<!-- PN : pourquoi peut-il avoir plusieurs cheched -> à cause de name -->
- <div class="btn-group" data-toggle="buttons">
+ <div class="btn-group" data-toggle="buttons" onclick="clickOnCommand( '#tree1','#tree1-messages', '{{ commande }}' )">
<!-- <input type="radio" name={{ commande }} id={{ commande }} > -->
<!-- <input type="radio" class="form-check-input" name='Etapes' id={{ commande }} > -->
<label class="btn btn-primary activate" for={{ commande }}> {{ commande }}</label><!-- <br> -->
</div>
</div>
<div class="row">
- <h2>Messages</h2>
- <div id="tree1-messages" class="col-sm-12" >Ouuuu
- </div>
+ <h2>Messages</h2>
+ <div id="tree1-messages" class="col-sm-12 alert alert-success" >....</div>
+ <!-- alert alert-success alert-info alert-warning alert-danger -->
</div>
<!-- <style type="text/css"> -->
<!-- #treetable { -->
<!-- </style> -->
<script>
+
+ // APPELS EXPLICITES AU SERVER
+ function clickOnCommand(treeCssSelStr, msgCssSelStr, cmdName ) {
+ tree = $.ui.fancytree.getTree("#tree1");
+ activeNode = tree.activeNode;
+ if ( activeNode == null) {
+ index=0;
+ } else {
+ parentList = activeNode.getParentList();
+ if ( parentList.length < 2) {
+ index=0; // le root node est actuellement le nom de code !
+ } else {
+ activeCommandKey = parentList[1].key; //activeNode.getParentList()[0] is always the root node so [1] is always the first level, the eficas command level (the code name by now)
+ // commandList = tree.rootNode.getChildren() // le root node est actuellement le nom de code !
+ commandList = tree.rootNode.getChildren()[0].getChildren(); // le root node est actuellement le nom de code !
+ index = commandList.findIndex(function(n){return n.key == activeCommandKey;})
+ }
+ }
+ console.log("clickOnCommand : index = "+index);
+
+ let success=function(data, status) {
+ console.log("Successfully appendChild message for command " + cmdName + " sent: " + "\nStatus: " + status +"\ndata :" +data );
+ // rChangeIsAccepted = data.changeIsAccepted;
+ rId = data['id'];
+ // rValidite = data['validite'];
+ console.log( {'data': data } );
+ console.log( {'rId': rId } );
+ //console.log( {'rValidite': rValidite } );
+ //console.log( {'rChangeIsAccepted': rChangeIsAccepted } );
+ if ( rId == null ) {
+ let message = "Unsuccessfull appendChild for command " + cmdName + ". appendChild has returned a null id."
+ console.log(message);
+ $(msgCssSelStr).text(message);
+ //Créer une fonction pour désactiver toutes les classes d'alert pour positionner une seule
+ $(msgCssSelStr).removeClass("alert-success alert-info alert-warning alert-danger");
+ $(msgCssSelStr).addClass("alert-danger");
+ }
+ // if ( rChangeIsAccepted ) {
+ // node.data.wValue = rValue
+ // node.data.validite = rValidite
+ // //node.data = data.source ?? Essayer de remplacer la source complète du noeud
+ // console.log('rValue : '+rValue);
+ // console.log('rValidite : '+rValidite);
+ // } else {
+ // // Gérer le input pour laisser le focus et passer en rouge
+ // };
+ // node.render(true,false); //force rendering the node (not parents nor descendants)
+ // //node.renderStatus(); //CSS element updates
+ };
+
+ $.ajax({
+ type : "POST",
+ url : "{{ url_for('appendChild') }}",
+ data : JSON.stringify({id: tree.rootNode.children[0].key, name:cmdName, pos:index }),
+ contentType : "application/json; charset=utf-8",
+ dataType : "json",
+ success : success,
+ failure : function(errMsg) { alert(errMsg); }
+ })
+
+ };
+ //GESTION DES EVENEMENTS PROVENANT DU SERVEUR
var source = new EventSource("{{ url_for('sse.stream') }}");
-
+
+ // --- propageValid ---
source.addEventListener('propageValide', function(event) {
- const data = JSON.parse(event.data);
- var id = data.id;
- var valid = data.valid;
- var message = data.message;
+ const data = JSON.parse(event.data);
+ var id = data.id;
+ var valid = data.valid;
+ var message = data.message;
// alert("The server says " + data.message);
console.log("The server says " + data.message +" , id: "+id);
$("#tree1-messages").text(message);
//});
}, false);
+ // --- appendChildren ---
(function (treeCssSelStr, msgCssSelStr) {
let _treeCssSelStr = treeCssSelStr; //inutile
let _msgCssSelStr = msgCssSelStr; //inutile
var id = data.id;
const source = data.fcyTreeSrc;
var pos = data.pos;
- var message = data.message;
+ var message = data.message;
- //alert("The server says " + data.message);
console.log("The server says " + data.message);
$(_msgCssSelStr).text(message);
//var activeNode = tree.getActiveNode();
console.log("_tree : "+ _tree); //?
- var tree = $.ui.fancytree.getTree(_treeCssSelStr);
- node=tree.getNodeByKey(id)
- node.addChildren(source,pos);
+ var tree = $.ui.fancytree.getTree(_treeCssSelStr);
+ node = tree.getNodeByKey(id);
+ countChildren = node.countChildren(false);
+ console.log("countChildren : "+ countChildren);
+ console.log("pos : "+ pos);
+ if ( pos >= countChildren) {
+ node.addChildren(source);
+ } else {
+ node.addChildren(source,pos);
+ }
<!-- node.addChildren({ -->
<!-- title: "Document using a custom icon", -->
<!-- icon: "customdoc1.gif" -->
}, false);
})('#tree1','#tree1-messages');
+ // --- deleteChildren ---
source.addEventListener('deleteChildren', function(event) {
const data = JSON.parse(event.data);
<!-- const keySet = new Set(data.idList); -->
return false;
};
- $.ajax({
- type : "POST",
- url : "{{ url_for('updateSimp') }}",
- data : JSON.stringify({id: node.key, value:value }),
- contentType : "application/json; charset=utf-8",
- dataType : "json",
- // The callback function when the web service return success.
- success: function(data, status) {
+ let success=function(data, status) {
<!-- alert("Successfully Value Sent: " + value + "\nStatus: " + status +"\ndata.changeIsAccepted :" +data.changeIsAccepted ); -->
console.log("Successfully Value Sent: " + value + "\nStatus: " + status +"\ndata.changeIsAccepted :" +data.changeIsAccepted );
rChangeIsAccepted = data.changeIsAccepted;
};
node.render(true,false); //force rendering the node (not parents nor descendants)
//node.renderStatus(); //CSS element updates
- },
+ };
+
+ $.ajax({
+ type : "POST",
+ url : "{{ url_for('updateSimp') }}",
+ data : JSON.stringify({id: node.key, value:value }),
+ contentType : "application/json; charset=utf-8",
+ dataType : "json",
+ // The callback function when the web service return success.
+ success: success,
// The callback function when the web service return fail.
failure: function(errMsg) {
alert(errMsg);