Skip to content

Commit

Permalink
Merge pull request #355 from crf-devs/add-missions
Browse files Browse the repository at this point in the history
Add missions crud
  • Loading branch information
mRoca authored Apr 30, 2020
2 parents 0de64a2 + 826149e commit 627bc21
Show file tree
Hide file tree
Showing 51 changed files with 946 additions and 263 deletions.
4 changes: 4 additions & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
@import "~bootstrap-select/sass/bootstrap-select";
@import "~daterangepicker/daterangepicker.css";

body {
letter-spacing: 0.01em;
}

label.required:not(.form-check-label)::before {
color: $red;
content: "*";
Expand Down
6 changes: 0 additions & 6 deletions assets/css/planning.scss
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;

Expand Down
25 changes: 25 additions & 0 deletions assets/js/_delete-item-modal.js
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');
});
});
54 changes: 54 additions & 0 deletions assets/js/_helpers.js
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('');
});
}
2 changes: 2 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ $.fn.selectpicker.Constructor.DEFAULTS.doneButtonText = 'Fermer';
$.fn.selectpicker.Constructor.DEFAULTS.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);

browserUpdate({ required: { e: -2, f: -2, o: -2, s: -2, c: -4 }, insecure: true, unsupported: true, api: 2020.04 });

import './_delete-item-modal';
15 changes: 0 additions & 15 deletions assets/js/availabilitable-list.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
const $ = require('jquery');
require('bootstrap');

$(document).ready(function () {
$('.trigger-delete').on('click', function (e) {
e.preventDefault();

$('#to-delete-name').html($(this).data('display-name'));
$('#confirm-update').data('url', $(this).data('href'));

$($(this).attr('data-modal')).modal('show');
});

$('#confirm-update').on('click', function () {
window.location = $(this).data('url');
$(this).closest('.modal').modal('hide');
});

$('form[name="organization_selector"] select').on('change', function () {
let $selectedOption = $('option:selected', this);
window.location = $selectedOption.data('url');
Expand Down
7 changes: 7 additions & 0 deletions assets/js/forecast.js
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);
});
18 changes: 0 additions & 18 deletions assets/js/mission-type.js

This file was deleted.

7 changes: 7 additions & 0 deletions assets/js/missions.js
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);
});
56 changes: 2 additions & 54 deletions assets/js/planning.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,6 @@
const $ = require('jquery');

function initDatesRange($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,
},
});
import { initDatesRange } from './_helpers';

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('');
});
}
const $ = require('jquery');

function hideUselessFilters() {
$('.search [data-hide="users"]').css('visibility', $('#hideUsers').prop('checked') ? 'hidden' : 'visible');
Expand Down
119 changes: 119 additions & 0 deletions src/Controller/Organization/Mission/MissionController.php
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');
}
}
2 changes: 1 addition & 1 deletion src/Controller/Organization/User/UserEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke(Request $request, User $userToEdit): Response
return $this->redirectToRoute('app_organization_user_list', ['organization' => $userToEdit->getNotNullOrganization()->id]);
}

return $this->render('organization/user/user-edit.html.twig', [
return $this->render('organization/user/edit.html.twig', [
'user' => $userToEdit,
'form' => $form->createView(),
])->setStatusCode($form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Organization/User/UserListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(Request $request, Organization $organization): Response
$currentOrganization = $this->getUser();

return $this->render(
'organization/user/user-list.html.twig',
'organization/user/list.html.twig',
[
'organization' => $organization,
'users' => $this->userRepository->findByOrganization($organization),
Expand Down
Loading

0 comments on commit 627bc21

Please sign in to comment.