websocket init

This commit is contained in:
afornerot 2024-03-15 15:44:29 +01:00
parent 11c6d4635f
commit 13c9c8bd3d
15 changed files with 332 additions and 25 deletions

4
.env
View File

@ -40,9 +40,9 @@ MAILER_NOREPLY=noreply@noreply.fr
# WEBSOCKET
WSS_USE=0
WSS_USE=1
WSS_PORT=5588
WSS_URL=ws://localhost:5588
# Proxy
PROXY_USE=0

View File

@ -69,7 +69,7 @@ app_sonde:
#== Wss ==================================================================================================================
app_wss_sample:
path: /user/wss/sampble
path: /user/wss/sample
defaults: { _controller: App\Controller\WebsocketController:sample }
#== Crop =================================================================================================================
@ -345,3 +345,8 @@ app_scrumissue_ctrlchange:
app_scrumissue_view:
path: /user/scrumissue/view/{id}
defaults: { _controller: App\Controller\ScrumissueController:view }
#== Poker =============================================================================================================
app_poker_get:
path: /user/poker/{userid}/{issueid}
defaults: { _controller: App\Controller\ScrumissueController:getpoker }

View File

@ -34,7 +34,7 @@ parameters:
wssuse: '%env(resolve:WSS_USE)%'
wssport: '%env(resolve:WSS_PORT)%'
wssurl: 'wss://%env(resolve:APP_WEBURL)%/wss%env(resolve:APP_ALIAS)%'
wssurl: '%env(resolve:WSS_URL)%'
proxyUse: '%env(resolve:PROXY_USE)%'
proxyHost: '%env(resolve:PROXY_HOST)%'
@ -104,4 +104,9 @@ services:
app.gieta.service:
public: true
class: App\Service\giteaService
arguments: ["@session","%giteaUrl%"]
arguments: ["@session","%giteaUrl%"]
App\Websocket\MessageHandler:
public: true
arguments:
- "@service_container"

View File

@ -22,14 +22,15 @@ services:
container_name: ninegitea-app
image: reg.cadoles.com/envole/ninegitea
ports:
- "8005:80"
- "8005:80"
- "5588:5588"
volumes:
- ./src:/app/src:delegated
- ./templates:/app/templates:delegated
- ./config:/app/config:delegated
- ./.env:/app/.env:delegated
- ./.env.local:/app/.env.local:delegated
- ./public/uploads:/app/public/uploads:delegated
- ./misc:/app/misc:delegated
adminer:
image: adminer

View File

@ -12,4 +12,6 @@ composer install --no-interaction
bin/console d:s:u --force --complete
bin/console app:Websocket &
exec $@

View File

@ -424,6 +424,7 @@ class ScrumController extends AbstractController
{
$em = $this->getDoctrine()->getManager();
$fgcsv = $request->get("fgcsv");
$fgpoker = $request->get("fgpoker");
// Récupérer les repos de gitea
$scrum=$em->getRepository("App:Scrum")->findOneBy(["id"=>$id]);
@ -594,6 +595,7 @@ class ScrumController extends AbstractController
"filterexcludes" => $filterexcludes,
"filterassignees" => $filterassignees,
"showfilters" => $showfilters,
"fgpoker" => $fgpoker,
]);
}

View File

@ -280,4 +280,13 @@ class ScrumissueController extends AbstractController
return new JsonResponse(false);
}
public function getpoker($userid,$issueid,Request $request) {
return new Response(0);
}
public function setpoker($userid,$issueid,Request $request) {
}
}

View File

@ -2,6 +2,8 @@
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@ -85,6 +87,16 @@ class Scrumissue
*/
private $scrumsprint;
/**
* @ORM\OneToMany(targetEntity="Userpoker", mappedBy="scrumissue", cascade={"persist"}, orphanRemoval=true)
*/
private $userpokers;
public function __construct()
{
$this->userpokers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@ -234,6 +246,37 @@ class Scrumissue
return $this;
}
/**
* @return Collection|Userpoker[]
*/
public function getUserpokers(): Collection
{
return $this->userpokers;
}
public function addUserpoker(Userpoker $userpoker): self
{
if (!$this->userpokers->contains($userpoker)) {
$this->userpokers[] = $userpoker;
$userpoker->setScrumissue($this);
}
return $this;
}
public function removeUserpoker(Userpoker $userpoker): self
{
if ($this->userpokers->contains($userpoker)) {
$this->userpokers->removeElement($userpoker);
// set the owning side to null (unless already changed)
if ($userpoker->getScrumissue() === $this) {
$userpoker->setScrumissue(null);
}
}
return $this;
}
}

View File

@ -85,6 +85,11 @@ class User implements UserInterface, \Serializable
*/
private $preference;
/**
* @ORM\OneToMany(targetEntity="Userpoker", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
*/
private $userpokers;
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users", cascade={"persist"})
* @ORM\JoinTable(name="usergroupe",
@ -107,6 +112,7 @@ class User implements UserInterface, \Serializable
{
$this->groups = new ArrayCollection();
$this->scrums = new ArrayCollection();
$this->userpokers = new ArrayCollection();
}
public function getUsername(): ?string
@ -172,7 +178,7 @@ class User implements UserInterface, \Serializable
public function getDisplayname()
{
return $this->firstname." ".$this->lastname;
return $this->username;
}
public function setId(int $id): self
@ -336,4 +342,35 @@ class User implements UserInterface, \Serializable
return $this;
}
/**
* @return Collection|Userpoker[]
*/
public function getUserpokers(): Collection
{
return $this->userpokers;
}
public function addUserpoker(Userpoker $userpoker): self
{
if (!$this->userpokers->contains($userpoker)) {
$this->userpokers[] = $userpoker;
$userpoker->setUser($this);
}
return $this;
}
public function removeUserpoker(Userpoker $userpoker): self
{
if ($this->userpokers->contains($userpoker)) {
$this->userpokers->removeElement($userpoker);
// set the owning side to null (unless already changed)
if ($userpoker->getUser() === $this) {
$userpoker->setUser(null);
}
}
return $this;
}
}

82
src/Entity/Userpoker.php Normal file
View File

@ -0,0 +1,82 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Userpoker
*
* @ORM\Entity()
* @ORM\Table(name="userpoker")
*/
class Userpoker
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="name", type="integer")
*
*/
private $nb;
/**
* @ORM\ManyToOne(targetEntity="Scrumissue", inversedBy="userpokers")
*/
private $scrumissue;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="userpokers")
*/
private $user;
public function getId(): ?int
{
return $this->id;
}
public function getNb(): ?int
{
return $this->nb;
}
public function setNb(int $nb): self
{
$this->nb = $nb;
return $this;
}
public function getScrumissue(): ?Scrumissue
{
return $this->scrumissue;
}
public function setScrumissue(?Scrumissue $scrumissue): self
{
$this->scrumissue = $scrumissue;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}

View File

@ -265,6 +265,14 @@ class ScrumRepository extends ServiceEntityRepository
}
$scrumissue->setGiteajson(json_decode(json_encode($giteaissue), true));
// Si le ticket est lié à un sprint on s'assure que ce sprint est bien lié au milestone du ticket
if($scrumissue->getScrumsprint()) {
if($scrumissue->getScrumsprint()->getGiteamilestone()!=$scrumissue->getGiteamilestone()) {
$scrumissue->setScrumsprint(null);
}
}
$this->_em->persist($scrumissue);
$this->_em->flush();

View File

@ -33,6 +33,8 @@ function ModalLoad(idmodal,title,path) {
}
{% if wssuse %}
console.log("pouet");
function subscribe(channeltype,channelkey,userkey) {
console.log("== SUBSCRIBE "+channeltype+"-"+channelkey+" with userkey "+userkey);
conn.send(JSON.stringify({

View File

@ -32,6 +32,10 @@
{% block body %}
<div class="d-flex">
<div id="filters" class="d-flex flex-column pl-2 pr-2 " style="width:350px; background-color:var(--colorbgbodydark);min-height:1500px;">
{% if fgpoker %}
<div id="online" class="mt-2"></div>
{% endif %}
<div style="width:100%" class="mt-3">
<label class="control-label" style="color:var(--colorftbodydark)">Filtre TICKET</label>
<input type="number" id="filterticket" class=" form-control">
@ -124,7 +128,7 @@
{% endif %}
{% endfor %}
</select>
</div>
</div>
</div>
<div class="pl-3" style="width:100%;">
@ -149,12 +153,17 @@
<th style="width:200px">Type</th>
<th style="width:70px"class="no-string">N°</th>
<th style="width:1000px">Titre</th>
{% if (not wssuse or not fgpoker) %}
<th style="width:200px">Equipe</th>
<th style="width:250px">Priorité</th>
<th style="width:70px">Poid</th>
<th style="width:135px">Affecté à</th>
<th style="width:135px">Statut</th>
<th style="width:300px">Etiquettes</th>
{% else %}
<th style="width:300px">Poker</th>
{% endif %}
<th style="width:135px">Statut</th>
<th style="width:70px">Poid</th>
</tr>
</thead>
@ -183,7 +192,7 @@
{% set types = "" %}
{% set datateams = "" %}
{% set datatypes = "" %}
{% set prioritys = '<span class="btn-link tag mr-1" style="background-color:#70c24a"><i class="fas fa-tag"></i>'~giteaprioritys|last~'</span>' %}
{% set prioritys = (not giteaprioritys?'':'<span class="btn-link tag mr-1" style="background-color:#70c24a"><i class="fas fa-tag"></i>'~giteaprioritys|last~'</span>') %}
{% set dataprioritys = ','~giteaprioritys|last %}
{% set labels = "" %}
{% set datalabels = "" %}
@ -210,7 +219,7 @@
{% set dataassignees=dataassignees~','~assignee.username %}
{% endfor %}
<tr data-milestone="{{datamilestone}}" data-sprint="{{datasprint}}" data-ticket="{{dataticket}}" data-column="{{statut}}" data-teams="{{datateams}}" data-prioritys="{{dataprioritys}}" data-types="{{datatypes}}" data-labels="{{datalabels}}" data-assignees="{{dataassignees}}">
<tr data-id="{{giteaissue.issueid}}" data-milestone="{{datamilestone}}" data-sprint="{{datasprint}}" data-ticket="{{dataticket}}" data-column="{{statut}}" data-teams="{{datateams}}" data-prioritys="{{dataprioritys}}" data-types="{{datatypes}}" data-labels="{{datalabels}}" data-assignees="{{dataassignees}}">
<td>
<a target="_blank" class="btn btn-link fa fa-file" href="{{giteaissue.html_url}}"></a>
</td>
@ -225,15 +234,11 @@
{{ giteaissue.title }}
</a>
</td>
{% if (not wssuse or not fgpoker) %}
<td>{{ teams|raw }}</td>
<td>{{ prioritys|raw }}</td>
<td>
<div id="modissu{{ giteaissue.issueid }}" data-issue="{{ giteaissue.issueid }}" data-giteaid="{{giteaissue.number}}" data-giteatitle="{{ giteaissue.title }}" type="button" class="modissu btn btn-link">
<i class="fas fa-weight-hanging"></i> = <span id="issue{{giteaissue.issueid}}-weight">{{ giteaissue.weight }}</span>
</div>
</td>
{% set dataorder="" %}
{% for assignee in giteaissue.assignees %}
{% set dataorder=dataorder~assignee.username %}
@ -244,8 +249,19 @@
<img src="{{assignee.avatar_url}}" class="assignee" title="{{assignee.username}}">
{% endfor %}
</td>
<td>{{ statut }}</td>
<td>{{ labels|raw }}</td>
{% else %}
<td>
<div class="pokertd d-flex"></div>
</td>
{% endif %}
<td>{{ statut }}</td>
<td>
<div id="modissu{{ giteaissue.issueid }}" data-issue="{{ giteaissue.issueid }}" data-giteaid="{{giteaissue.number}}" data-giteatitle="{{ giteaissue.title }}" type="button" class="modissu btn btn-link">
<i class="fas fa-weight-hanging"></i> = <span id="issue{{giteaissue.issueid}}-weight">{{ giteaissue.weight }}</span>
</div>
</td>
</tr>
{% endif %}
{% endfor %}
@ -846,4 +862,89 @@
$("#mycontent").show();
});
{% if wssuse and fgpoker %}
var conn;
function connect() {
conn = new WebSocket("{{wssurl}}");
conn.onopen = function(e) {
console.log("== CONNECT");
{% set userkey = "" %}
{% if app.user %}
{% set userkey = app.user.apikey %}
{%endif%}
subscribe("home",{{id}},"{{userkey}}");
sendMessage({command: "alive"});
};
conn.onmessage = function(e) {
ret=JSON.parse(e.data);
console.log("MESSAGE REU ="+ret.command);
switch(ret.command) {
case "alive" :
if(!$('#online'+ret.from.id).length) {
img='<img id="online'+ret.from.id+'" src="'+ret.from.avatar+'" class="avatar ml-2 mr-2" title="'+ret.from.displayname+'">';
$("#online").append(img);
$("tr").each(function(){
line=$(this);
issueid=$(this).data("id");
url="{{path("app_poker_get",{userid:"xxx",issueid:"yyy"})}}";
url=url.replace("xxx",ret.from.id);
url=url.replace("yyy",issueid);
$.ajax({
method: "POST",
url: url,
async: false,
success: function(data) {
html ='<div class="d-flex flex-column align-items-center" data-user="'+ret.from.id+'">';
html+='<img src="'+ret.from.avatar+'" class="avatar mb-1" style="zoom:80%;" title="'+ret.from.displayname+'">';
html+='<input class="pokervalue" id="poker-'+ret.from.id+'-'+issueid+'" data-user="'+ret.from.id+'" data-issue="'+issueid+'" type="number" style="width:60px" value="'+data+'"></input>';
html+='</div>';
line.find(".pokertd").append(html);
},
});
})
}
if(ret.from.id!={{app.user.id}}) {
console.log("meto");
sendMessage({command: "meto"});
}
break;
case "adead" :
$('#online'+ret.from.id).remove();
$('[data-user='+ret.from.id+']').remove();
break;
case "meto" :
if(!$('#online'+ret.from.id).length) {
html='<img id="online'+ret.from.id+'" src="'+ret.from.avatar+'" class="avatar ml-2 mr-2" title="'+ret.from.displayname+'">';
$("#online").append(html);
$(".pokertd").append(html);
}
break;
}
};
conn.onclose = function(e) {
console.log("== DISCONNECT");
$('#online img').remove();
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() { connect(); }, 1000);
};
}
connect();
$("body").on("input", ".pokervalue", function () {
console.log($(this).val());
});
{% endif %}
{% endblock %}

View File

@ -1,15 +1,20 @@
{% extends 'base.html.twig' %}
{% block body %}
{{wssurl}}
<div id="chat" class="text-center mt-5">
<div class="mb-2">online</div>
<div id="online" style="mt-2"></div>
</div>
{% endblock %}
{% block localjavascript %}
{% if wssuse %}
<script>
var conn;
function connect() {
conn = new WebSocket("{{wssurl}}");
conn.onopen = function(e) {
console.log("== CONNECT");
{% set userkey = "" %}
@ -20,13 +25,14 @@
subscribe("home",1,"{{userkey}}");
sendMessage({command: "alive"});
};
conn.onmessage = function(e) {
ret=JSON.parse(e.data);
console.log(ret.log);
switch(ret.command) {
case "alive" :
if(!$('#online'+ret.from.id).length) {
console.log(ret);
html='<img id="online'+ret.from.id+'" src="'+ret.from.avatar+'" class="avatar ml-2 mr-2" title="'+ret.from.displayname+'">';
$("#online").append(html);
}
@ -57,5 +63,5 @@
}
connect();
</script>
{% endif %}
{% endif %}
{% endblock %}

View File

@ -152,6 +152,10 @@
{% endblock %}
<script>
{{ include('Include/javascript.js.twig') }}
</script>
<script>
{% if app.session.get('viewclosed') %}