add export csv

This commit is contained in:
afornerot 2023-05-10 10:18:40 +02:00
parent 2c123e7089
commit 1b7ac66fe8
3 changed files with 118 additions and 255 deletions

View File

@ -165,10 +165,14 @@ app_group_select:
defaults: { _controller: App\Controller\GroupController:select } defaults: { _controller: App\Controller\GroupController:select }
#== Report ======================================================================================================= #== Report =======================================================================================================
app_report: app_report_list:
path: /user/report/{id} path: /user/report/list/{id}
defaults: { _controller: App\Controller\ReportController:list } defaults: { _controller: App\Controller\ReportController:list }
app_report_csv:
path: /user/report/csv/{id}
defaults: { _controller: App\Controller\ReportController:csv }
#== Scrum ======================================================================================================== #== Scrum ========================================================================================================
app_scrum: app_scrum:
path: /user/scrum path: /user/scrum

View File

@ -5,17 +5,18 @@ namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\FormError; use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use App\Entity\Scrum as Entity; use Symfony\Component\Filesystem\Filesystem;
use App\Entity\Scrumissue as Scrumissue; use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use App\Form\ScrumType as Form;
use App\Service\giteaService; use App\Service\giteaService;
class ReportController extends AbstractController class ReportController extends AbstractController
{ {
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; } public function __construct(KernelInterface $appKernel, giteaService $giteaservice) {
$this->appKernel = $appKernel;
$this->giteaservice = $giteaservice;
}
public function list($id,Request $request) public function list($id,Request $request)
{ {
@ -51,260 +52,52 @@ class ReportController extends AbstractController
} }
public function submit(Request $request) public function csv($id,Request $request)
{ {
// Initialisation de l'enregistrement set_time_limit(0);
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$data = new Entity(); $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");
$fs = new Filesystem();
$rootdir = $this->appKernel->getProjectDir();
$destdir = $rootdir."/var/log/export.csv";
// Récupérer les repos de gitea $csvh = fopen($destdir, 'w');
$gitearepos=$this->giteaservice->getRepos(); $d = ';'; // this is the default but i like to be explicit
$e = '"'; // this is the default but i like to be explicit
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitearepos"=>$gitearepos));
// Récupération des data du formulaire $tbcumul=[];
$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); foreach($issues as $issue) {
$em->flush(); $monthsubmit=new \DateTime($issue->created_at);
$monthsubmit=$monthsubmit->format("Ym");
if(!array_key_exists($monthsubmit,$tbcumul))
$tbcumul[$monthsubmit]=["month"=>$monthsubmit,"nbsubmit"=>0,"nbclose"=>0];
$tbcumul[$monthsubmit]["nbsubmit"]=$tbcumul[$monthsubmit]["nbsubmit"]+1;
// Retour à la liste $monthclose=new \DateTime($issue->closed_at);
return $this->redirectToRoute($this->route); $monthclose=$monthclose->format("Ym");
} if(!array_key_exists($monthclose,$tbcumul))
$tbcumul[$monthclose]=["month"=>$monthclose,"nbsubmit"=>0,"nbclose"=>0];
// Affichage du formulaire $tbcumul[$monthclose]["nbclose"]=$tbcumul[$monthclose]["nbclose"]+1;
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($tbcumul as $cumul) {
foreach($milestone["stat"] as $k2=>$statut) { fputcsv($csvh, $cumul, $d, $e);
$keysort = array_column($tbstat[$k1]["stat"][$k2]["labels"], 'label');
array_multisort($keysort, SORT_ASC, $tbstat[$k1]["stat"][$k2]["labels"]);
}
} }
fclose($csvh);
$response = new BinaryFileResponse($destdir);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
return $response;
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());
}
}
}
} }

View File

@ -0,0 +1,66 @@
{% extends "base.html.twig" %}
{% block localstyle %}
body {
background-color: #efefef;
}
.issuetitle {
margin-top:100px;
page-break-before: always;
}
.issuediv {
zoom:60%;
}
.issuecontent {
width:80%;
}
.issuedetail {
width:20%;
}
@media print {
body {
background-color: transparent;
}
}
{% endblock %}
{% block body %}
<h1>{{repo.full_name}}</h1>
<table class="mt-4 table table-striped table-bordered table-hover" id="dataTables" style="width:100%; zoom:80%;">
<thead>
<tr>
<th>id</th>
<th>titre</th>
<th>submit</th>
<th>clos</th>
</tr>
</thead>
<tbody>
{% for issue in issues %}
<tr>
<td>{{issue.number}}</td>
<td>{{issue.title}}</td>
<td>{{issue.created_at|date("d/m/Y H:i")}}</td>
<td>{{ (issue.closed_at ? issue.closed_at|date("d/m/Y H:i") : "") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block localjavascript %}
$(document).ready(function() {
$('#dataTables').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
{% endblock %}