if self.children[pos].item.nature == 'MCBLOC' : laListe=self.children[pos].item.getDicoForFancy()
else : laListe=(self.children[pos].item.getDicoForFancy(),)
self.editor.connecteur.toWebApp('appendChildren',self.getIdUnique(),laListe,pos)
- #print (' appel appendChild',self.item.idUnique,laListe,pos)
+ print (' appel appendChild',self.item.idUnique,laListe,pos)
def onSupp(self,suppression):
#---------------------------
self.appWeb=appWeb
def toWebApp(self,fction,*args, **kwargs):
+ print ('self.appWeb.fromConnecteur', fction, *args, **kwargs)
+ print ('self.appWeb', self.appWeb)
if self.appWeb == None : # test
- #print ('self.appWeb.fromConnecteur', fction, *args, **kwargs)
return
self.appWeb.fromConnecteur(fction, *args, **kwargs)
# from flask import Flask, request, render_template, url_for, json, jsonify
import json
import pprint
-from forms import BasicForm
-from collections import OrderedDict
+from forms import BasicForm
+from collections import OrderedDict
from markupsafe import escape
from flask_sse import sse
# """Flask subclass using the custom request class"""
# request_class = MyReq
-def createConnecteur():
- monConnecteur=accasConnecteur(code, langue='ang')
+def createConnecteur(app):
+ monConnecteur=accasConnecteur(code, langue='ang',appWeb=app)
return monConnecteur
-monConnecteur=createConnecteur()
+app = Flask(__name__)
+
+monConnecteur=createConnecteur(app)
print (monConnecteur.getListeCommandes())
-app = Flask(__name__)
#Server Side Event config
app.config["REDIS_URL"] = "redis://localhost"
#app.config["REDIS_URL"] = "redis://:password@localhost"
#TODO: personaliser l'url en fonction de la session utilisateur
app.register_blueprint(sse, url_prefix='/stream')
-@app.route('/update')
-def publish_update():
- sse.publish({"message": "Hello!"}, type='update')
- return "Message sent!"
+def fromConnecteur(maFonction,*args,**kwargs):
+ print ('dans propageValidefromConnecteur: ', maFonction)
+ fnct=globals()[maFonction]
+ fnct(*args,**kwargs)
+
+#TODO : Rattacher à une session
+# gérer un appel register callback
+app.fromConnecteur=fromConnecteur
+
+def propageValide(id, valid):
+ print ('dans propageValide: ', id, valid)
+ sse.publish({"idUnique" : id, "valid":valid, "message": "Hello from propageValide!"}, type='propageValide')
+
+def appendChildren(id, nodeList, pos):
+ print ('dans appendChildren: ', nodeList, pos)
+ sse.publish({'id':id, 'nodeList':nodeList, 'pos':pos, "message": "Hello from appendChildren!"}, type='appendChildren')
+
+def deleteChildren(idList):
+ print ('dans deleteChildren: ', idList)
+ sse.publish({"idList":idList,"message": "Hello from deleteChildren!"}, type='deleteChildren')
+
+# # Pour test curl
+# @app.route('/update')
+# def publish_update():
+# sse.publish({"message": "Hello!"}, type='update')
+# return "Message sent!"
@app.route('/')
def index():
<script>
- var source = new EventSource("{{ url_for('sse.stream') }}");
- source.addEventListener('update', function(event) {
+ var source = new EventSource("{{ url_for('sse.stream') }}");
+
+ source.addEventListener('propageValide', function(event) {
var data = JSON.parse(event.data);
alert("The server says " + data.message);
var tree=$.ui.fancytree.getTree("#tree1");
// title: "Document using a custom icon",
// icon: "customdoc1.gif"
//});
- }, false);
+ }, false);
+
+ source.addEventListener('appendChildren', function(event) {
+ var data = JSON.parse(event.data);
+ var id = data.id;
+ var nodeList = data.nodeList;
+ var pos = data.pos;
+
+ alert("The server says " + data.message);
+ var tree=$.ui.fancytree.getTree("#tree1");
+ var activeNode = tree.getActiveNode();
+ //p1=tree.getNodeByKey('8304986a334211ec853cac220bca9aa6')
+ //activeNode.addChildren({
+ // title: "Document using a custom icon",
+ // icon: "customdoc1.gif"
+ //});
+ }, false);
+
+ source.addEventListener('deleteChildren', function(event) {
+ var data = JSON.parse(event.data);
+ var idList = data.idList;
+
+ alert("The server says " + data.message);
+ var tree=$.ui.fancytree.getTree("#tree1");
+ var activeNode = tree.getActiveNode();
+ //p1=tree.getNodeByKey('8304986a334211ec853cac220bca9aa6')
+ //activeNode.addChildren({
+ // title: "Document using a custom icon",
+ // icon: "customdoc1.gif"
+ //});
+ }, false);
+
+
source.addEventListener('error', function(event) {
alert("Failed to connect to event stream. Is Redis running?");
}, false);