From 5db15283f26d9c10b5ae37a1c70323fdbb9289f6 Mon Sep 17 00:00:00 2001 From: afornerot Date: Wed, 9 Feb 2022 18:08:27 +0100 Subject: [PATCH] svg --- .../Controller/ScrumpriorityController.php | 194 ++++++++++++++++++ .../src/Entity/Scrumpriority.php | 116 +++++++++++ .../src/Form/ScrumpriorityType.php | 58 ++++++ .../templates/Scrumpriority/close.html.twig | 11 + .../templates/Scrumpriority/edit.html.twig | 51 +++++ 5 files changed, 430 insertions(+) create mode 100755 src/ninegitea-1.0/src/Controller/ScrumpriorityController.php create mode 100644 src/ninegitea-1.0/src/Entity/Scrumpriority.php create mode 100644 src/ninegitea-1.0/src/Form/ScrumpriorityType.php create mode 100755 src/ninegitea-1.0/templates/Scrumpriority/close.html.twig create mode 100755 src/ninegitea-1.0/templates/Scrumpriority/edit.html.twig diff --git a/src/ninegitea-1.0/src/Controller/ScrumpriorityController.php b/src/ninegitea-1.0/src/Controller/ScrumpriorityController.php new file mode 100755 index 0000000..1ab2cf3 --- /dev/null +++ b/src/ninegitea-1.0/src/Controller/ScrumpriorityController.php @@ -0,0 +1,194 @@ +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 reconnecter"); + + // 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"=>"".$scrumpriority->getName()."
liè au label gitea ".$scrumpriority->getGiteajson()["name"]."")); + } + + $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()); + } + } + } +} diff --git a/src/ninegitea-1.0/src/Entity/Scrumpriority.php b/src/ninegitea-1.0/src/Entity/Scrumpriority.php new file mode 100644 index 0000000..91a9744 --- /dev/null +++ b/src/ninegitea-1.0/src/Entity/Scrumpriority.php @@ -0,0 +1,116 @@ +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; + } + +} \ No newline at end of file diff --git a/src/ninegitea-1.0/src/Form/ScrumpriorityType.php b/src/ninegitea-1.0/src/Form/ScrumpriorityType.php new file mode 100644 index 0000000..06dd300 --- /dev/null +++ b/src/ninegitea-1.0/src/Form/ScrumpriorityType.php @@ -0,0 +1,58 @@ +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', + )); + } +} diff --git a/src/ninegitea-1.0/templates/Scrumpriority/close.html.twig b/src/ninegitea-1.0/templates/Scrumpriority/close.html.twig new file mode 100755 index 0000000..6ad0c10 --- /dev/null +++ b/src/ninegitea-1.0/templates/Scrumpriority/close.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +{% endblock %} + +{% block localjavascript %} + $(document).ready(function() { + window.parent.$("#mymodalpriority").modal('hide'); + }); +{% endblock %} diff --git a/src/ninegitea-1.0/templates/Scrumpriority/edit.html.twig b/src/ninegitea-1.0/templates/Scrumpriority/edit.html.twig new file mode 100755 index 0000000..d600a54 --- /dev/null +++ b/src/ninegitea-1.0/templates/Scrumpriority/edit.html.twig @@ -0,0 +1,51 @@ +{% extends 'base.html.twig' %} + +{% block body %} +{{ form_start(form) }} + {{ form_widget(form.submit) }} + + + {% if mode=="update" %} + + Supprimer + + {% endif %} + +

+ + {% if app.session.flashbag.has('error') %} +
+ Erreur
+ {% for flashMessage in app.session.flashbag.get('error') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + {% if app.session.flashbag.has('notice') %} +
+ Information
+ {% for flashMessage in app.session.flashbag.get('notice') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% 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 %}