first commit symfony 6
This commit is contained in:
@ -2,81 +2,16 @@
|
||||
|
||||
{% block body %}
|
||||
{% if app.user %}
|
||||
<button class="btn btn-primary" onClick="send()">Send</button>
|
||||
<div id="chat"></div>
|
||||
<div class="row">
|
||||
<div class="col col-md6">
|
||||
<h3>Chat #1</h3>
|
||||
{{ render(path("app_publish_sample",{id:1})) }}
|
||||
</div>
|
||||
|
||||
<div class="col col-md6">
|
||||
<h3>Chat #2</h3>
|
||||
{{ render(path("app_publish_sample",{id:2})) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block localscript %}
|
||||
{% if app.user %}
|
||||
<script>
|
||||
|
||||
function connect() {
|
||||
channel="chat";
|
||||
id=1;
|
||||
const eventSource = new EventSource("{{ mercure('chat-1')|escape('js') }}");
|
||||
|
||||
eventSource.onopen = function(e) {
|
||||
console.log("== ONOPEN");
|
||||
sendMessage(channel,id,{command: "alive"});
|
||||
};
|
||||
|
||||
eventSource.onclose = function(e) {
|
||||
console.log("== ONCLOSE");
|
||||
sendMessage(channel,id,{command: "dead"});
|
||||
setTimeout(function() { connect(); }, 1000);
|
||||
};
|
||||
|
||||
eventSource.onmessage = event => {
|
||||
data=JSON.parse(event.data);
|
||||
ret=data.ret;
|
||||
console.log("== ONMESSAGE = "+ret.command);
|
||||
console.log(ret);
|
||||
|
||||
switch (ret.command) {
|
||||
case "alive":
|
||||
sendMessage(channel,id,{command: "meto"});
|
||||
break;
|
||||
|
||||
case "meto":
|
||||
break;
|
||||
|
||||
case "dead":
|
||||
break;
|
||||
|
||||
case "push":
|
||||
$("#chat").prepend('<div class="card mt-3"><div class="card-body">'+ret.message+'</div></div>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on("beforeunload", function() {
|
||||
sendMessage(channel,id,{command: "dead"});
|
||||
})
|
||||
}
|
||||
connect();
|
||||
|
||||
|
||||
function sendMessage(channel,id,msg) {
|
||||
url="{{path("app_publish",{channel:'xxx',id:'yyy'})}}";
|
||||
url=url.replace('xxx',channel);
|
||||
url=url.replace('yyy',id);
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: url,
|
||||
data: {
|
||||
msg: msg
|
||||
},
|
||||
success: function(data, dataType)
|
||||
{
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function send() {
|
||||
sendMessage('chat',1,{command: "push", message:"pouet"});
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -1,17 +1,9 @@
|
||||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block localstyle %}
|
||||
<style>
|
||||
label {
|
||||
color: var(--colorftbodylight);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div style="text-align:center">
|
||||
<img src="{{ appAlias }}uploads/logo/{{ app.session.get('logolight') }}" style="height:120px;margin-top:10px;margin-bottom:20px;">
|
||||
<h1 style="border:none">{{appName}}</h1>
|
||||
<h1 style="border:none">{{app.session.get('appname')}}</h1>
|
||||
{{ form_start(form, {'action': path('app_loginldapcheck'), 'method': 'POST'}) }}
|
||||
<div class="card homecard mb-3" style="width:400px; margin:auto; text-align: left;">
|
||||
<div class="card-body">
|
||||
|
@ -1,17 +1,11 @@
|
||||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block localstyle %}
|
||||
<style>
|
||||
label {
|
||||
color: var(--colorftbodylight);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block body %}
|
||||
<div style="text-align:center">
|
||||
<img src="{{ appAlias }}uploads/logo/{{ app.session.get('logolight') }}" style="height:120px;margin-top:10px;margin-bottom:20px;">
|
||||
<h1 style="border:none">{{appName}}</h1>
|
||||
<h1 style="border:none">{{app.session.get('appname')}}</h1>
|
||||
<form action="{{ path('app_login') }}" method="post">
|
||||
<div class="card homecard mb-3" style="width:400px; margin:auto">
|
||||
<div class="card-body">
|
||||
|
20
templates/Home/noperm.html.twig
Normal file
20
templates/Home/noperm.html.twig
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block body %}
|
||||
Vous avez pu vous connecter à {{ app.session.get('appname') }} mais vous n'avez aucun compte sur l'application.<br>
|
||||
Contacter votre administrateur si vous souhaitez y accéder.<br><br>
|
||||
Vous allez être déconnectés d'ici quelques secondes.
|
||||
{% endblock %}
|
||||
|
||||
{% block localscript %}
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Redirection vers la mire d'authentification
|
||||
setTimeout(function(){
|
||||
window.location.href="{{ path("app_logout") }}";
|
||||
}, 6000);
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
95
templates/Home/publishsample.html.twig
Normal file
95
templates/Home/publishsample.html.twig
Normal file
@ -0,0 +1,95 @@
|
||||
{% if app.user %}
|
||||
{% set idwidget=uniqueId() %}
|
||||
<div id="chat{{idwidget}}">
|
||||
<textarea class="form-control mb-2" id="pushmessage" rows="3"></textarea>
|
||||
<button class="btn btn-primary" onClick="send{{idwidget}}()" class="mt-2">Send</button>
|
||||
<div id="aliveusers" class="mt-3 mb-3"></div>
|
||||
<div id="chat"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
function connect{{idwidget}}() {
|
||||
channel="chat";
|
||||
id{{idwidget}}={{id}};
|
||||
const eventSource = new EventSource("{{ mercure('chat-'~id)|escape('js') }}");
|
||||
|
||||
eventSource.onopen = function(e) {
|
||||
console.log("== ONOPEN");
|
||||
sendMessage{{idwidget}}(channel,id{{idwidget}},{command: "alive"});
|
||||
};
|
||||
|
||||
eventSource.onclose = function(e) {
|
||||
console.log("== ONCLOSE");
|
||||
sendMessage{{idwidget}}(channel,id,{command: "dead"});
|
||||
setTimeout(function() { connect{{idwidget}}(); }, 5000);
|
||||
};
|
||||
|
||||
eventSource.onmessage = event => {
|
||||
data=JSON.parse(event.data);
|
||||
ret=data.ret;
|
||||
console.log("== ONMESSAGE = "+ret.command);
|
||||
console.log(ret);
|
||||
|
||||
switch (ret.command) {
|
||||
case "alive":
|
||||
sendMessage{{idwidget}}(channel,id{{idwidget}},{command: "meto"});
|
||||
break;
|
||||
|
||||
case "meto":
|
||||
if(!$("#chat{{idwidget}} #aliveuser"+ret.from.id).length) {
|
||||
html='<img id="aliveuser'+ret.from.id+'" src="'+ret.from.avatar+'" title="'+ret.from.displayname+'"class="avatar me-1">';
|
||||
$("#chat{{idwidget}} #aliveusers").append(html);
|
||||
}
|
||||
break;
|
||||
|
||||
case "dead":
|
||||
sendMessage{{idwidget}}(channel,id{{idwidget}},{command: "alive"});
|
||||
if($("#aliveuser"+ret.from.id).length) {
|
||||
$("#aliveuser"+ret.from.id).remove();
|
||||
}
|
||||
break;
|
||||
|
||||
case "push":
|
||||
html ='<div class="card mt-1"><div class="card-body d-flex">';
|
||||
html+='<img id="msguser'+ret.from.id+'" src="'+ret.from.avatar+'" title="'+ret.from.displayname+'"class="avatar me-1">';
|
||||
html+='<div class="ps-2"><small>'+ret.message.replace(/\n/g,"<br>")+'</small></div>';
|
||||
html+='</div></div>';
|
||||
|
||||
$("#chat{{idwidget}} #chat").prepend(html);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on("beforeunload", function() {
|
||||
sendMessage{{idwidget}}(channel,id{{idwidget}},{command: "dead"});
|
||||
})
|
||||
}
|
||||
connect{{idwidget}}();
|
||||
|
||||
|
||||
function sendMessage{{idwidget}}(channel,id,msg) {
|
||||
url="{{path("app_publish",{channel:'xxx',id:'yyy'})}}";
|
||||
url=url.replace('xxx',channel);
|
||||
url=url.replace('yyy',id{{idwidget}});
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: url,
|
||||
data: {
|
||||
msg: msg
|
||||
},
|
||||
success: function(data, dataType)
|
||||
{
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function send{{idwidget}}() {
|
||||
if($("#chat{{idwidget}} #pushmessage").val()) {
|
||||
sendMessage{{idwidget}}('chat',1,{command: "push", message:$("#chat{{idwidget}} #pushmessage").val()});
|
||||
$("#chat{{idwidget}} #pushmessage").val("");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
Reference in New Issue
Block a user