svg
This commit is contained in:
parent
6a31f22fb8
commit
5db15283f2
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Scrumpriority as Entity;
|
||||
use App\Form\ScrumpriorityType as Form;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ScrumpriorityController extends AbstractController
|
||||
{
|
||||
private $data = "scrumpriority";
|
||||
private $route = "app_scrumpriority";
|
||||
private $render = "Scrumpriority/";
|
||||
private $entity = "App:Scrumpriority";
|
||||
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function submit($scrumid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
$data = new Entity();
|
||||
$data->setScrum($scrum);
|
||||
|
||||
$last = $em->getRepository('App:Scrumpriority')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
|
||||
if(!$last) $data->setRowid(0);
|
||||
else $data->setRowid($last->getRowid()+1);
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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);
|
||||
$scrum=$data->getScrum();
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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->render($this->render.'close.html.twig');
|
||||
}
|
||||
}
|
||||
|
||||
public function select($scrumid, Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
|
||||
$scrumprioritys = $scrum->getScrumprioritys();
|
||||
$output=array();
|
||||
foreach($scrumprioritys as $scrumpriority) {
|
||||
array_push($output,array("id"=>$scrumpriority->getId(),"name"=>"<b>".$scrumpriority->getName()."</b><br><small>liè au label gitea ".$scrumpriority->getGiteajson()["name"]."</small>"));
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function order($scrumid, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrumpriorityids=explode(",",$request->get('lstordered'));
|
||||
$i=1;
|
||||
foreach($scrumpriorityids as $id) {
|
||||
$scrumpriority=$em->getRepository($this->entity)->find($id);
|
||||
if($scrumpriority) {
|
||||
$scrumpriority->setRowid($i);
|
||||
$em->persist($scrumpriority);
|
||||
$em->flush();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Scrumpriority
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="scrumpriority", uniqueConstraints={@ORM\UniqueConstraint(name="gitealabel", columns={"giteaid","scrum_id"})} )
|
||||
*/
|
||||
class Scrumpriority
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string")
|
||||
*
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $rowid;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $giteaid;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
private $giteajson;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Scrum", inversedBy="scrumprioritys")
|
||||
*/
|
||||
private $scrum;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRowid(): ?int
|
||||
{
|
||||
return $this->rowid;
|
||||
}
|
||||
|
||||
public function setRowid(int $rowid): self
|
||||
{
|
||||
$this->rowid = $rowid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGiteaid(): ?int
|
||||
{
|
||||
return $this->giteaid;
|
||||
}
|
||||
|
||||
public function setGiteaid(int $giteaid): self
|
||||
{
|
||||
$this->giteaid = $giteaid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGiteajson(): ?array
|
||||
{
|
||||
return $this->giteajson;
|
||||
}
|
||||
|
||||
public function setGiteajson(array $giteajson): self
|
||||
{
|
||||
$this->giteajson = $giteajson;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getScrum(): ?Scrum
|
||||
{
|
||||
return $this->scrum;
|
||||
}
|
||||
|
||||
public function setScrum(?Scrum $scrum): self
|
||||
{
|
||||
$this->scrum = $scrum;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class ScrumpriorityType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('name',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$choices=[];
|
||||
foreach($options["gitealabels"] as $label) {
|
||||
$choices[$label->name]=$label->id;
|
||||
}
|
||||
|
||||
$builder->add('giteaid',
|
||||
ChoiceType::class, [
|
||||
"label" => "Label Gitea",
|
||||
"choices" => $choices,
|
||||
"disabled" => ($options["mode"]=="submit"?false:true),
|
||||
"placeholder" => "Selectionnez un label gitea",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Scrumpriority',
|
||||
'mode' => 'string',
|
||||
'gitealabels' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block localjavascript %}
|
||||
$(document).ready(function() {
|
||||
window.parent.$("#mymodalpriority").modal('hide');
|
||||
});
|
||||
{% endblock %}
|
|
@ -0,0 +1,51 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form.submit) }}
|
||||
<button class="btn btn-secondary" onClick="closeModal();">Annuler</button>
|
||||
|
||||
{% if mode=="update" %}
|
||||
<a href="{{ path('app_scrumpriority_delete',{'id':scrumpriority.id}) }}"
|
||||
class="btn btn-danger float-right"
|
||||
data-method="delete"
|
||||
data-confirm="Êtes-vous sûr de vouloir supprimer cet entregistrement ?">
|
||||
Supprimer
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<br><br>
|
||||
|
||||
{% if app.session.flashbag.has('error') %}
|
||||
<div class='alert alert-danger' style='margin: 5px 0px'>
|
||||
<strong>Erreur</strong><br>
|
||||
{% for flashMessage in app.session.flashbag.get('error') %}
|
||||
{{ flashMessage }}<br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if app.session.flashbag.has('notice') %}
|
||||
<div class='alert alert-info' style='margin: 5px 0px'>
|
||||
<strong>Information</strong><br>
|
||||
{% for flashMessage in app.session.flashbag.get('notice') %}
|
||||
{{ flashMessage }}<br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{{ form_row(form.name) }}
|
||||
{{ form_row(form.giteaid) }}
|
||||
{{ form_end(form) }}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block localjavascript %}
|
||||
$(document).ready(function() {
|
||||
$("#scrumpriority_name").focus();
|
||||
});
|
||||
|
||||
function closeModal() {
|
||||
window.parent.$("#mymodalpriority").modal('hide');
|
||||
}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue