-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from crf-devs/add-missions
Add missions crud
- Loading branch information
Showing
51 changed files
with
946 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
$tableBoxSize: 40px; | ||
|
||
.search { | ||
.hidden { | ||
display: none; | ||
} | ||
} | ||
|
||
.planning-actions-container { | ||
margin-bottom: 20px; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const $ = require('jquery'); | ||
require('bootstrap'); | ||
|
||
$(document).ready(function () { | ||
const $modal = $('#delete-item-modal'); | ||
if (!$modal.length) { | ||
return; | ||
} | ||
|
||
$('.trigger-delete').on('click', function (e) { | ||
e.preventDefault(); | ||
const $button = $(this); | ||
|
||
$('[data-role="name"]', $modal).text($button.data('display-name')); | ||
$('[data-role="message"]', $modal).text($button.data('message')); | ||
$('button[data-role="submit"]', $modal).data('url', $button.data('href')); | ||
|
||
$modal.modal('show'); | ||
}); | ||
|
||
$('button[data-role="submit"]', $modal).on('click', function () { | ||
window.location = $(this).data('url'); | ||
$(this).closest('.modal').modal('hide'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
export function initDatesRange($picker, $from, $to, withTime) { | ||
console.log($picker, $from, $to, withTime); | ||
if (!$picker.length) { | ||
return; | ||
} | ||
|
||
function displayDate() { | ||
if (withTime) { | ||
$picker.val($picker.data('daterangepicker').startDate.format('DD/MM/YYYY HH:mm') + ' à ' + $picker.data('daterangepicker').endDate.format('DD/MM/YYYY HH:mm')); | ||
} else { | ||
$picker.val($picker.data('daterangepicker').startDate.format('DD/MM/YYYY') + ' au ' + $picker.data('daterangepicker').endDate.format('DD/MM/YYYY')); | ||
} | ||
} | ||
|
||
$picker.daterangepicker({ | ||
autoUpdateInput: false, | ||
showDropdowns: false, | ||
timePicker: !!withTime, | ||
timePicker24Hour: true, | ||
timePickerIncrement: 30, | ||
applyClass: 'btn-sm btn-primary', | ||
cancelClass: 'btn-sm btn-default', | ||
locale: { | ||
cancelLabel: 'Supprimer', | ||
format: 'DD/MM/YYYY HH:mm', | ||
separator: ' - ', | ||
applyLabel: 'Valider', | ||
fromLabel: 'De', | ||
toLabel: 'à', | ||
customRangeLabel: 'Custom', | ||
daysOfWeek: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'], | ||
monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'], | ||
firstDay: 1, | ||
}, | ||
}); | ||
|
||
if ($from.val() !== '' && $to.val() !== '') { | ||
$picker.data('daterangepicker').setStartDate(new Date($from.val())); | ||
$picker.data('daterangepicker').setEndDate(new Date($to.val())); | ||
displayDate(); | ||
} | ||
|
||
$picker.on('apply.daterangepicker', function (ev, picker) { | ||
displayDate(); | ||
$from.val(picker.startDate.format('YYYY-MM-DDTHH:mm')).trigger('change'); | ||
$to.val(picker.endDate.format('YYYY-MM-DDTHH:mm')); | ||
}); | ||
|
||
$picker.on('cancel.daterangepicker', function () { | ||
$picker.val(''); | ||
$from.val('').trigger('change'); | ||
$to.val(''); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { initDatesRange } from './_helpers'; | ||
|
||
const $ = require('jquery'); | ||
|
||
$(document).ready(function () { | ||
initDatesRange($('#availableRange'), $('#availableFrom'), $('#availableTo'), true); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { initDatesRange } from './_helpers'; | ||
|
||
const $ = require('jquery'); | ||
|
||
$(document).ready(function () { | ||
initDatesRange($('#fromToRange'), $('#mission_startTime'), $('#mission_endTime'), true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/Controller/Organization/Mission/MissionController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Organization\Mission; | ||
|
||
use App\Entity\Mission; | ||
use App\Entity\Organization; | ||
use App\Form\Type\MissionType; | ||
use App\Repository\MissionRepository; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* @Route("/mission") | ||
* @Security("is_granted('ROLE_PARENT_ORGANIZATION')") | ||
*/ | ||
class MissionController extends AbstractController | ||
{ | ||
private MissionRepository $missionRepository; | ||
|
||
public function __construct(MissionRepository $missionRepository) | ||
{ | ||
$this->missionRepository = $missionRepository; | ||
} | ||
|
||
/** | ||
* @Route("/", name="app_organization_mission_index", methods={"GET"}) | ||
*/ | ||
public function index(): Response | ||
{ | ||
/** @var Organization $organization */ | ||
$organization = $this->getUser(); | ||
$missions = $this->missionRepository->findByOrganization($organization); | ||
|
||
return $this->render('organization/mission/index.html.twig', [ | ||
'missions' => $missions, | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/new", name="app_organization_mission_new", methods={"GET","POST"}) | ||
*/ | ||
public function new(Request $request): Response | ||
{ | ||
/** @var Organization $organization */ | ||
$organization = $this->getUser(); | ||
|
||
$mission = new Mission(); | ||
$mission->organization = $organization; | ||
$form = $this->createForm(MissionType::class, $mission); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$entityManager = $this->getDoctrine()->getManager(); | ||
$entityManager->persist($mission); | ||
$entityManager->flush(); | ||
|
||
return $this->redirectToRoute('app_organization_mission_show', ['id' => $mission->id]); | ||
} | ||
|
||
return $this->render('organization/mission/new.html.twig', [ | ||
'mission' => $mission, | ||
'form' => $form->createView(), | ||
])->setStatusCode($form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* @Route("/{id}", name="app_organization_mission_show", methods={"GET"}) | ||
* @Security("mission.organization == user") | ||
*/ | ||
public function show(Mission $mission): Response | ||
{ | ||
return $this->render('organization/mission/show.html.twig', [ | ||
'mission' => $mission, | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/{id}/edit", name="app_organization_mission_edit", methods={"GET","POST"}) | ||
* @Security("mission.organization == user") | ||
*/ | ||
public function edit(Request $request, Mission $mission): Response | ||
{ | ||
$form = $this->createForm(MissionType::class, $mission); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$this->getDoctrine()->getManager()->flush(); | ||
|
||
return $this->redirectToRoute('app_organization_mission_show', ['id' => $mission->id]); | ||
} | ||
|
||
return $this->render('organization/mission/edit.html.twig', [ | ||
'mission' => $mission, | ||
'form' => $form->createView(), | ||
])->setStatusCode($form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* @Route("/{id}/delete", name="app_organization_mission_delete", methods={"GET"}) | ||
* @Security("mission.organization == user") | ||
*/ | ||
public function delete(Mission $mission): RedirectResponse | ||
{ | ||
$entityManager = $this->getDoctrine()->getManager(); | ||
|
||
$entityManager->remove($mission); | ||
$entityManager->flush(); | ||
|
||
$this->addFlash('success', 'organization.mission.deleteSuccessMessage'); | ||
|
||
return $this->redirectToRoute('app_organization_mission_index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.