diff --git a/src/ninegitea-1.0/composer.lock b/src/ninegitea-1.0/composer.lock index 3a143b2..f3dcecf 100644 --- a/src/ninegitea-1.0/composer.lock +++ b/src/ninegitea-1.0/composer.lock @@ -3613,6 +3613,7 @@ "mail", "mailer" ], + "abandoned": "symfony/mailer", "time": "2019-11-12T09:31:26+00:00" }, { @@ -5226,6 +5227,7 @@ "symfony", "words" ], + "abandoned": "EnglishInflector from the String component", "time": "2020-05-20T17:43:50+00:00" }, { @@ -7293,6 +7295,7 @@ ], "description": "Symfony SwiftmailerBundle", "homepage": "http://symfony.com", + "abandoned": "symfony/mailer", "time": "2019-11-14T16:18:31+00:00" }, { @@ -8362,12 +8365,12 @@ "version": "1.9.0", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "9dc4f203e36f2b486149058bade43c851dd97451" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/9dc4f203e36f2b486149058bade43c851dd97451", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/9dc4f203e36f2b486149058bade43c851dd97451", "reference": "9dc4f203e36f2b486149058bade43c851dd97451", "shasum": "" }, diff --git a/src/ninegitea-1.0/config/routes.yaml b/src/ninegitea-1.0/config/routes.yaml index af50651..74984bd 100644 --- a/src/ninegitea-1.0/config/routes.yaml +++ b/src/ninegitea-1.0/config/routes.yaml @@ -164,6 +164,11 @@ app_group_select: path: /user/group/select defaults: { _controller: App\Controller\GroupController:select } +#== Report ======================================================================================================= +app_report: + path: /user/report/{id} + defaults: { _controller: App\Controller\ReportController:list } + #== Scrum ======================================================================================================== app_scrum: path: /user/scrum @@ -181,6 +186,10 @@ app_scrum_stat: path: /user/scrum/stat/{id} defaults: { _controller: App\Controller\ScrumController:stat } +app_scrum_info: + path: /user/scrum/info/{id} + defaults: { _controller: App\Controller\ScrumController:info } + app_scrum_update: path: /master/scrum/update/{id} defaults: { _controller: App\Controller\ScrumController:update } @@ -265,6 +274,14 @@ app_scrumissue_order: path: /user/scrumissue/order defaults: { _controller: App\Controller\ScrumissueController:order } +app_scrumissue_info: + path: /user/scrumissue/info + defaults: { _controller: App\Controller\ScrumissueController:info } + +app_scrumissue_update: + path: /user/scrumissue/update + defaults: { _controller: App\Controller\ScrumissueController:update } + app_scrumissue_ctrlchange: path: /user/scrumissue/ctrlchange defaults: { _controller: App\Controller\ScrumissueController:ctrlchange } diff --git a/src/ninegitea-1.0/src/Controller/IssueController.php b/src/ninegitea-1.0/src/Controller/IssueController.php index bc9b01f..61275af 100755 --- a/src/ninegitea-1.0/src/Controller/IssueController.php +++ b/src/ninegitea-1.0/src/Controller/IssueController.php @@ -64,6 +64,19 @@ class IssueController extends AbstractController $json=$scrum->getGiteajson(); $json["issues"]=$giteaissues; $json["category"]=$scrum->getCategory(); + foreach($json["issues"] as $key => $giteaissue) { + $issue=$em->getRepository("App:Scrumissue")->findOneBy(["giteaid"=>$giteaissue->id]); + if($issue) { + $json["issues"][$key]->weight=$issue->getWeight(); + $json["issues"][$key]->issueid=$issue->getId(); + $json["issues"][$key]->scrumid=$issue->getScrum()->getId(); + } + else { + $json["issues"][$key]->weight=0; + $json["issues"][$key]->issueid=0; + $json["issues"][$key]->scrumid=0; + } + } $tmp=[]; foreach($scrum->getScrumcolumns() as $column) { diff --git a/src/ninegitea-1.0/src/Controller/ReportController.php b/src/ninegitea-1.0/src/Controller/ReportController.php new file mode 100755 index 0000000..99fdbd1 --- /dev/null +++ b/src/ninegitea-1.0/src/Controller/ReportController.php @@ -0,0 +1,310 @@ +giteaservice = $giteaservice; } + + public function list($id,Request $request) + { + set_time_limit(0); + + $em = $this->getDoctrine()->getManager(); + $scrum = $em->getRepository("App:Scrum")->find($id); + $repoid = $scrum->getGiteaid(); + $repoowner = $scrum->getGiteajson()["owner"]["login"]; + $reponame = $scrum->getGiteajson()["name"]; + + $repo=$this->giteaservice->getRepo($repoid); + $issues=$this->giteaservice->getIssues($repoowner,$reponame,"?state=all"); + + foreach($issues as $keyissue => $issue) { + $issues[$keyissue]->body = $this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$issues[$keyissue]->body); + $issues[$keyissue]->comments=$this->giteaservice->getIssueComments($repoowner,$reponame,$issue->number); + foreach($issues[$keyissue]->comments as $keycomment => $comment) { + $issues[$keyissue]->comments[$keycomment]->body=$this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$issues[$keyissue]->comments[$keycomment]->body); + } + + $issues[$keyissue]->timelines=$this->giteaservice->getIssueTimelines($repoowner,$reponame,$issue->number); + } + + // Affichage du formulaire + return $this->render('Report/list.html.twig', [ + 'useheader' => false, + 'usesidebar' => false, + 'maxwidth' => true, + 'repo' => $repo, + 'issues' => $issues, + ]); + + } + + public function submit(Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data = new Entity(); + + // Récupérer les repos de gitea + $gitearepos=$this->giteaservice->getRepos(); + + // Création du formulaire + $form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitearepos"=>$gitearepos)); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm(null,$form,$request,$data,"submit"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + $gitearepo=$this->giteaservice->getRepo($data->getGiteaid()); + $data->setGiteaname($gitearepo->full_name); + $data->setGiteajson(json_decode(json_encode($gitearepo), true)); + + $em->persist($data); + $em->flush(); + + // Retour à la liste + return $this->redirectToRoute($this->route); + } + + // Affichage du formulaire + return $this->render($this->render.'edit.html.twig', [ + 'useheader' => true, + 'usesidebar' => false, + 'maxwidth' => true, + $this->data => $data, + 'mode' => 'submit', + 'form' => $form->createView() + ]); + } + + public function update($id,Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data=$em->getRepository($this->entity)->find($id); + + // Récupérer les repos de gitea + $gitearepos=$this->giteaservice->getRepos(); + + // Création du formulaire + $form = $this->createForm(Form::class,$data,array("mode"=>"update","gitearepos"=>$gitearepos)); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm(null,$form,$request,$data,"update"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + $gitearepo=$this->giteaservice->getRepo($data->getGiteaid()); + $data->setGiteaname($gitearepo->full_name); + $data->setGiteajson(json_decode(json_encode($gitearepo), true)); + + $em->persist($data); + $em->flush(); + + // Retour à la liste + return $this->redirectToRoute($this->route); + } + + // Affichage du formulaire + return $this->render($this->render.'edit.html.twig', [ + 'useheader' => true, + 'usesidebar' => false, + 'maxwidth' => true, + $this->data => $data, + 'mode' => 'update', + 'form' => $form->createView() + ]); + } + + public function delete($id,Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data=$em->getRepository($this->entity)->find($id); + + // Controle avant suppression + $error=false; + if($id<0) $error=true; + + if($error) + return $this->redirectToRoute($this->route."_update",["id"=>$id]); + else { + $em->remove($data); + $em->flush(); + + // Retour à la liste + return $this->redirectToRoute($this->route); + } + } + + public function view($id,Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data=$em->getRepository($this->entity)->find($id); + if(!$data) return $this->redirectToRoute($this->route); + + $em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$gitealabels); + + // Préférences utilisateur + $filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id); + $filterteams = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterteams",$id); + $filterprioritys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterprioritys",$id); + $filterlabels = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterlabels",$id); + $filterassignees = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterassignees",$id); + $filterexcludes = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterexcludes",$id); + $showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id); + + return $this->render($this->render.'view.html.twig', [ + 'useheader' => true, + 'usesidebar' => false, + 'usetitle' => $data->getName(), + 'giteaassignees' => $giteaassignees, + 'giteacolumns' => $giteacolumns, + 'giteamilestones' => $giteamilestones, + 'giteateams' => $giteateams, + 'giteaprioritys' => $giteaprioritys, + 'gitealabels' => $gitealabels, + 'filtermilestones' => $filtermilestones, + 'filterteams' => $filterteams, + 'filterprioritys' => $filterprioritys, + 'filterlabels' => $filterlabels, + 'filterassignees' => $filterassignees, + 'filterexcludes' => $filterexcludes, + 'showfilters' => $showfilters, + $this->data => $data, + ]); + } + + public function stat($id,Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data=$em->getRepository($this->entity)->find($id); + if(!$data) return $this->redirectToRoute($this->route); + + $em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$gitealabels); + + // Préférences utilisateur + $filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id); + $filterteams = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterteams",$id); + $showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id); + + $tbstat=[]; + foreach($data->getScrumIssues() as $issue) { + + $labels=$issue->getGiteajson()["labels"]; + $haveteams=true; + if($filterteams) { + $haveteams=false; + foreach($filterteams as $filterteam) { + foreach($labels as $label) { + if($label["id"]==$filterteam) { + $haveteams=true; + } + } + } + } + + if($haveteams) { + $idmilestone=($issue->getGiteamilestone()?$issue->getGiteamilestone():-100); + $lbmilestone=($issue->getGiteamilestone()?$issue->getGiteamilestonename():"Aucun"); + if(!array_key_exists($idmilestone,$tbstat)) { + $tbstat[$idmilestone]=["id"=>$idmilestone,"name"=>$lbmilestone,"stat"=>[]]; + } + + if(!array_key_exists($issue->getScrumcolumn()->getId(),$tbstat[$idmilestone]["stat"])) { + $tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]=[ + "id"=>$issue->getScrumcolumn()->getId(), + "label"=>$issue->getScrumcolumn()->getName(), + "total"=>0, + "color"=>"#".$issue->getScrumcolumn()->getGiteajson()["color"], + "labels"=>[], + ]; + } + + foreach($labels as $label) { + if($issue->getScrumcolumn()->getGiteaid()!=$label["id"]) { + if(!array_key_exists($label["id"],$tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["labels"])) { + $tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["labels"][$label["id"]] = [ + "id"=>$label["id"], + "label"=>$label["name"], + "total"=>0, + "color"=>"#".$label["color"], + ]; + } + $tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["labels"][$label["id"]]["total"]++; + } + } + + $tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["total"]++; + } + } + + foreach($tbstat as $k1=>$milestone) { + foreach($milestone["stat"] as $k2=>$statut) { + $keysort = array_column($tbstat[$k1]["stat"][$k2]["labels"], 'label'); + array_multisort($keysort, SORT_ASC, $tbstat[$k1]["stat"][$k2]["labels"]); + } + + } + + return $this->render($this->render.'stat.html.twig', [ + 'useheader' => true, + 'usesidebar' => false, + 'usetitle' => $data->getName(), + 'giteaassignees' => $giteaassignees, + 'giteacolumns' => $giteacolumns, + 'giteamilestones' => $giteamilestones, + 'giteateams' => $giteateams, + 'giteaprioritys' => $giteaprioritys, + 'gitealabels' => $gitealabels, + 'filtermilestones' => $filtermilestones, + 'filterteams' => $filterteams, + 'showfilters' => $showfilters, + $this->data => $data, + 'tbstat' => $tbstat, + ]); + } + + protected function getErrorForm($id,$form,$request,$data,$mode) { + if ($form->get('submit')->isClicked()&&$mode=="delete") { + } + + if ($form->get('submit')->isClicked() && $mode=="submit") { + } + + if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) { + } + + if ($form->get('submit')->isClicked() && !$form->isValid()) { + $this->get('session')->getFlashBag()->clear(); + + $errors = $form->getErrors(); + foreach( $errors as $error ) { + $request->getSession()->getFlashBag()->add("error", $error->getMessage()); + } + } + } +} diff --git a/src/ninegitea-1.0/src/Controller/ScrumController.php b/src/ninegitea-1.0/src/Controller/ScrumController.php index 1e9272f..dc5b373 100755 --- a/src/ninegitea-1.0/src/Controller/ScrumController.php +++ b/src/ninegitea-1.0/src/Controller/ScrumController.php @@ -5,6 +5,7 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Form\FormError; use App\Entity\Scrum as Entity; @@ -298,6 +299,34 @@ class ScrumController extends AbstractController ]); } + public function info($id,Request $request) + { + $em = $this->getDoctrine()->getManager(); + + // Rechercher du scrum en cours + $scrum=$em->getRepository("App:Scrum")->find($id); + if(!$scrum) return new JsonResponse(['message' => 'No Issue'], 403); + + $giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); + + $weights=[]; + foreach($giteaissues as $giteaissue) { + $scrumissue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrum,"giteaid"=>$giteaissue->id]); + if($scrumissue) { + if($giteaissue->milestone) $milestoneid=$giteaissue->milestone->id; + else $milestoneid=-100; + + if(!array_key_exists($milestoneid,$weights)) $weights[$milestoneid]=0; + $weights[$milestoneid]=$weights[$milestoneid]+$scrumissue->getWeight(); + } + } + + $output=[]; + $output["weights"]=$weights; + + return new JsonResponse($output); + } + protected function getErrorForm($id,$form,$request,$data,$mode) { if ($form->get('submit')->isClicked()&&$mode=="delete") { } diff --git a/src/ninegitea-1.0/src/Controller/ScrumissueController.php b/src/ninegitea-1.0/src/Controller/ScrumissueController.php index 3c30ed1..54c97fe 100755 --- a/src/ninegitea-1.0/src/Controller/ScrumissueController.php +++ b/src/ninegitea-1.0/src/Controller/ScrumissueController.php @@ -105,10 +105,55 @@ class ScrumissueController extends AbstractController $em->flush(); - return new JsonResponse(); } + public function info(Request $request) + { + $em = $this->getDoctrine()->getManager(); + + $id=$request->get('id'); + + // Rechercher l'issue en cours + $scrumissue=$em->getRepository("App:Scrumissue")->find($id); + if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); + + $output=[]; + $output["weight"]=$scrumissue->getWeight(); + + return new JsonResponse($output); + } + + public function update(Request $request) + { + $em = $this->getDoctrine()->getManager(); + + $id=$request->get('id'); + $weight=$request->get('weight'); + + // Rechercher l'issue en cours + $scrumissue=$em->getRepository("App:Scrumissue")->find($id); + if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); + + $scrumissue->setWeight($weight); + $em->flush(); + + $giteaissues=$this->giteaservice->getIssues($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"]); + + $weights=[]; + foreach($giteaissues as $giteaissue) { + $issue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrumissue->getScrum(),"giteaid"=>$giteaissue->id]); + if($issue) { + if($giteaissue->milestone) $milestoneid=$giteaissue->milestone->id; + else $milestoneid=-100; + + if(!array_key_exists($milestoneid,$weights)) $weights[$milestoneid]=0; + $weights[$milestoneid]=$weights[$milestoneid]+$issue->getWeight(); + } + } + return new JsonResponse($weights); + } + public function ctrlchange(Request $request) { $em = $this->getDoctrine()->getManager(); diff --git a/src/ninegitea-1.0/src/Entity/Scrumissue.php b/src/ninegitea-1.0/src/Entity/Scrumissue.php index 7f10e6a..8da46c6 100644 --- a/src/ninegitea-1.0/src/Entity/Scrumissue.php +++ b/src/ninegitea-1.0/src/Entity/Scrumissue.php @@ -26,6 +26,11 @@ class Scrumissue */ private $rowid; + /** + * @ORM\Column(type="integer") + */ + private $weight=0; + /** * @ORM\Column(type="integer") */ @@ -198,5 +203,17 @@ class Scrumissue return $this; } + public function getWeight(): ?int + { + return $this->weight; + } + + public function setWeight(int $weight): self + { + $this->weight = $weight; + + return $this; + } + } \ No newline at end of file diff --git a/src/ninegitea-1.0/src/Service/giteaService.php b/src/ninegitea-1.0/src/Service/giteaService.php index 7acd6f3..b4775ba 100644 --- a/src/ninegitea-1.0/src/Service/giteaService.php +++ b/src/ninegitea-1.0/src/Service/giteaService.php @@ -10,10 +10,12 @@ class giteaService private $params; private $session; private $url; - + private $giteaUrl; + public function __construct(SessionInterface $session,ParameterBagInterface $params,$giteaUrl) { $this->params = $params; + $this->giteaUrl = $giteaUrl; $this->url = $giteaUrl."/api/v1"; $this->session = $session; } @@ -29,6 +31,7 @@ class giteaService ]; $body = \Unirest\Request\Body::json($query); + $response=$this->api("POST",$apiurl,$body); if(!$response||$response->code!="200") return false; @@ -38,6 +41,31 @@ class giteaService } } + public function deletetoken($username) { + $apiurl=$this->url."/users/".$username."/tokens/".$this->session->get("giteatoken"); + $response=$this->api("DELETE",$apiurl,null,$this->session->get("giteatoken")); + } + + public function markdown($context,$mode,$body) { + $apiurl = $this->url."/markdown"; + $query= [ + "Context" => $context, + "Mode" => $mode, + "Text" => $body, + "Wiki" => false, + ]; + + $body = \Unirest\Request\Body::json($query); + + + $response=$this->api("POST",$apiurl,$body,$this->session->get("giteatoken")); + if(!$response||$response->code!="200") return false; + else { + $response->body= str_replace($this->giteaUrl,$this->giteaUrl.$context,$response->body); + return $response->body; + } + } + public function getuser() { $apiurl = $this->url."/user"; $response=$this->api("GET",$apiurl,null,$this->session->get("giteatoken")); @@ -48,7 +76,6 @@ class giteaService public function getuserprofil($id) { $apiurl = $this->url."/users/$id"; $response=$this->api("GET",$apiurl,null,$this->session->get("giteatoken")); - dump($response); if(!$response||$response->code!="200") return false; else return $response->body; } @@ -156,8 +183,9 @@ class giteaService else return $response->body; } - public function getissues($owner,$name) { - $apiurl = $this->url."/repos/$owner/$name/issues?state=open"; + public function getissues($owner,$name,$state="?state=open") { + $apiurl = $this->url."/repos/$owner/$name/issues".$state; + $page=1; $limit=20; $issues=[]; @@ -210,11 +238,25 @@ class giteaService $apiurl = $this->url."/repos/$owner/$name/issues/$index"; $body = \Unirest\Request\Body::json($patchs); $response=$this->api("PATCH",$apiurl,$body,$this->session->get("giteatoken")); - dump($response); if(!$response||$response->code!="201") return false; else return $response->body; } + public function getissuecomments($owner,$name,$index) { + $apiurl = $this->url."/repos/$owner/$name/issues/$index/comments"; + $response=$this->api("GET",$apiurl,null,$this->session->get("giteatoken")); + if(!$response||$response->code!="200") return false; + else return $response->body; + } + + + public function getissuetimelines($owner,$name,$index) { + $apiurl = $this->url."/repos/$owner/$name/issues/$index/timeline"; + $response=$this->api("GET",$apiurl,null,$this->session->get("giteatoken")); + if(!$response||$response->code!="200") return false; + else return $response->body; + } + private function api($method,$url,$query,$token=null) { // Entete $headers = [ diff --git a/src/ninegitea-1.0/templates/Issue/list.html.twig b/src/ninegitea-1.0/templates/Issue/list.html.twig index 103e2bf..8dbd1d3 100644 --- a/src/ninegitea-1.0/templates/Issue/list.html.twig +++ b/src/ninegitea-1.0/templates/Issue/list.html.twig @@ -146,6 +146,7 @@