Implement the GUI for the repeating events.

referencing #4
This commit is contained in:
Tim Schumacher 2014-07-28 22:15:06 +02:00
parent 7719e760ec
commit 90b6f52446
7 changed files with 572 additions and 0 deletions

View file

@ -0,0 +1,262 @@
<?php
namespace Hackspace\Bundle\CalciferBundle\Controller;
use Hackspace\Bundle\CalciferBundle\Entity\RepeatingEvent;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Hackspace\Bundle\CalciferBundle\Entity\Location;
use Hackspace\Bundle\CalciferBundle\Entity\Tag;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Hackspace\Bundle\CalciferBundle\Entity\Event;
use Hackspace\Bundle\CalciferBundle\Form\EventType;
use Symfony\Component\HttpFoundation\Response;
/**
* Location controller.
*
* @Route("/termine/wiederholend")
*/
class RepeatingEventController extends Controller
{
/**
* Displays all repeating events
*
* @Route("/", name="repeating_event_show")
* @Method("GET")
* @Template()
*/
public function indexAction()
{
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
/** @var EntityRepository $repo */
$repo = $em->getRepository('CalciferBundle:RepeatingEvent');
$entities = $repo->findAll();
return [
'entities' => $entities,
];
}
/**
* Displays a form to create a repeating event
*
* @Route("/neu", name="repeating_event_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$entity = new RepeatingEvent();
return [
'entity' => $entity,
];
}
/**
* Creates a repeating event
*
* @Route("/neu", name="repeating_event_create")
* @Method("POST")
* @Template("CalciferBundle:RepeatingEvent:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new RepeatingEvent();
$this->fillEntity($request, $entity);
if ($this->validateRepeatingEvent($entity)) {
$ret = $this->saveRepeatingEvent($request, $entity);
if ($entity->id > 0) {
return $this->redirect($this->generateUrl('repeating_event_show'));
} else {
throw new \Exception('Could not save repeating event?!?');
}
}
return [
'entity' => $entity,
];
}
/**
* Displays a form to edit a repeating event
*
* @Route("/{slug}/bearbeiten",name="repeating_event_edit")
* @Method("GET")
* @Template()
*/
public function editAction($slug)
{
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
/** @var EntityRepository $repo */
$repo = $em->getRepository('CalciferBundle:RepeatingEvent');
/** @var Event $entity */
$entity = $repo->findOneBy(['slug' => $slug]);
if (!$entity) {
throw $this->createNotFoundException('Unable to find RepeatingEvent entity.');
}
return array(
'entity' => $entity,
);
}
/**
* Updates a repeating event
*
* @Route("/{slug}/bearbeiten",name="repeating_event_update")
* @Method("POST")
* @Template("CalciferBundle:RepeatingEvent:edit.html.twig")
*/
public function updateAction(Request $request, $slug)
{
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
/** @var EntityRepository $repo */
$repo = $em->getRepository('CalciferBundle:RepeatingEvent');
/** @var Event $entity */
$entity = $repo->findOneBy(['slug' => $slug]);
if (!$entity) {
throw $this->createNotFoundException('Unable to find RepeatingEvent entity.');
}
$this->fillEntity($request, $entity);
if ($this->validateRepeatingEvent($entity)) {
$ret = $this->saveRepeatingEvent($request, $entity);
if ($entity->id > 0) {
return $this->redirect($this->generateUrl('repeating_event_show'));
} else {
throw new \Exception('Could not save repeating event?!?');
}
}
return [
'entity' => $entity,
];
}
private function fillEntity(Request $request, RepeatingEvent $entity)
{
$fields = [
'duration',
'repeating_pattern',
'summary',
'description',
'url',
];
foreach ($fields as $field) {
$entity->$field = $request->get($field);
}
if (strlen($entity->duration) == 0)
$entity->duration = null;
$nextdate = $request->get('nextdate');
$nextdate = new \DateTime($nextdate);
$entity->nextdate = $nextdate;
}
private function validateRepeatingEvent(RepeatingEvent $entity)
{
$fields = [
'nextdate',
'repeating_pattern',
'summary',
];
foreach ($fields as $field) {
if ((is_null($entity->$field)) && (strlen($entity->$field) > 0))
return false;
}
return true;
}
private function saveRepeatingEvent(Request $request, RepeatingEvent $entity)
{
$location = $request->get('location');
$location_lat = $request->get('location_lat');
$location_lon = $request->get('location_lon');
if (strlen($location) > 0) {
// check if the location already exists
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('CalciferBundle:Location');
$results = $repo->findBy(['name' => $location]);
if (count($results) > 0) {
$location_obj = $results[0];
if (strlen($location_lat) > 0) {
$location_obj->lat = $location_lat;
}
if (strlen($location_lon) > 0) {
$location_obj->lon = $location_lon;
}
$em->persist($location_obj);
$em->flush();
$entity->location = $results[0];
} else {
$location_obj = new Location();
$location_obj->name = $location;
if (strlen($location_lat) > 0) {
$location_obj->lat = $location_lat;
}
if (strlen($location_lon) > 0) {
$location_obj->lon = $location_lon;
}
$location_obj->slug = \URLify::filter($location_obj->name, 255, 'de');
$em->persist($location_obj);
$em->flush();
$entity->location = $location_obj;
}
} else {
$entity->location = null;
}
$tags = $request->get('tags');
if (strlen($tags) > 0) {
$tags = explode(',', $tags);
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('CalciferBundle:Tag');
$entity->clearTags();
foreach ($tags as $tag) {
$tag = trim($tag);
$results = $repo->findBy(['name' => $tag]);
if (count($results) > 0) {
$entity->addTag($results[0]);
} else {
$tag_obj = new Tag();
$tag_obj->name = $tag;
$tag_obj->slug = \URLify::filter($tag_obj->name, 255, 'de');
$em->persist($tag_obj);
$em->flush();
$entity->addTag($tag_obj);
}
}
} else {
$entity->clearTags();
}
$entity->slug = \URLify::filter($entity->summary,255,'de');
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $entity;
}
}

View file

@ -0,0 +1,6 @@
$(document).ready(function(){
$('.ui.dropdown.selection')
.dropdown()
.dropdown('set value',$('.ui.dropdown.selection input[type=hidden]').val())
;
});

View file

@ -0,0 +1,37 @@
{% extends 'CalciferBundle::layout.html.twig' %}
{% block css %}
{% stylesheets filter="compass"
"@CalciferBundle/Resources/assets/css/jquery.datetimepicker.scss"
"@CalciferBundle/Resources/assets/css/events.scss"
"@CalciferBundle/Resources/assets/css/leaflet.scss"
%}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/jquery.datetimepicker.js"
"@CalciferBundle/Resources/assets/js/repeating_events.js"
"@CalciferBundle/Resources/assets/js/events.js"
"@CalciferBundle/Resources/assets/js/leaflet.js"
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% block body -%}
<div class="ui one column page grid">
<div class="ui column">
<h1>Wiederholenden Termin bearbeiten</h1>
</div>
</div>
<div class="ui one column page grid">
<div class="ui column">
{{ include('CalciferBundle:RepeatingEvent:repeating_event_form.html.twig',{'entity':entity}) }}
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,65 @@
{% extends 'CalciferBundle::layout.html.twig' %}
{% block css %}
{% stylesheets filter="compass"
"@CalciferBundle/Resources/assets/css/events.scss" %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/events.js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% block body -%}
<div class="ui one column page grid title">
<div class="ui column">
<h1 class="ui header">
Wiederholende Termine
</h1>
</div>
</div>
<div class="ui one column page grid stackable">
<div class="column">
<table class="ui table">
<thead>
<tr>
<th>Zusammenfassung</th>
<th>Nächstes Datum</th>
<th>Wiederholungsmuster</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>
{{ entity.summary }}
</td>
<td>
{{ entity.nextdate.format('Y-m-d H:i') }}
</td>
<td>
{{ entity.getFormatedRepeatPattern() }}
</td>
<td>
<a href="{{ path('repeating_event_edit', {'slug':entity.slug}) }}">Bearbeiten</a>
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="4"><a href="{{ path('repeating_event_new') }}">Neuen wiederholenden Termin anlegen</a></td>
</tr>
</tfoot>
</table>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,35 @@
{% extends 'CalciferBundle::layout.html.twig' %}
{% block css %}
{% stylesheets filter="compass"
"@CalciferBundle/Resources/assets/css/jquery.datetimepicker.scss"
"@CalciferBundle/Resources/assets/css/events.scss"
"@CalciferBundle/Resources/assets/css/leaflet.scss" %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/jquery.datetimepicker.js"
"@CalciferBundle/Resources/assets/js/repeating_events.js"
"@CalciferBundle/Resources/assets/js/events.js"
"@CalciferBundle/Resources/assets/js/leaflet.js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% block body -%}
<div class="ui one column page grid">
<div class="ui column">
<h1>Wiederholenden Termin erstellen</h1>
</div>
</div>
<div class="ui one column page grid">
<div class="ui column">
{{ include('CalciferBundle:RepeatingEvent:repeating_event_form.html.twig') }}
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,166 @@
<form method="post"
action="{% if entity.id|default(0) > 0 %}{{ path('repeating_event_update',{'slug':entity.slug}) }}{% else %}{{ path('repeating_event_create') }}{% endif %}">
<div class="ui form segment">
<div class="field">
<label class="control-label required" for="event_startdate">Nächster Termin</label>
<div class="ui left labeled icon input">
<input type="datetime"
id="event_nextdate"
name="nextdate"
required="required"
value="{{ entity.nextdate.format('Y-m-d H:i')|default('') }}"
placeholder="{{ "now"|date('d.m.Y H:00') }}"
class="form-control">
<i class="icon calendar"></i>
<div class="ui corner label">
<i class="icon asterisk"></i>
</div>
</div>
</div>
<div class="field">
<label class="control-label required" for="event_duration">Dauer</label>
<div class="ui left labeled input attached-label">
<input type="text"
id="event_duration"
name="duration"
pattern="\d*"
value="{{ entity.duration }}"
class="form-control">
<div class="ui bottom attached label">
Hier gibst du bitte die Dauer der Veranstaltung in Minuten an.
</div>
</div>
</div>
<div class="field">
<label class="control-label required" for="event_duration">Wiederholungsmuster</label>
<div class="ui left labeled input">
<div class="ui dropdown selection fluid">
<input name="repeating_pattern" type="hidden" value="{{ entity.repeating_pattern|default('') }}">
<div class="default text">Bitte wähle einen Wert aus</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="PD7">Wöchentlich</div>
<div class="item" data-value="PD14">Jede 2. Woche</div>
<div class="item" data-value="PM1">Monatlich</div>
</div>
<div class="ui corner label">
<i class="icon asterisk"></i>
</div>
</div>
</div>
</div>
<div class="field">
<label class="" for="event_summary">Zusammenfassung</label>
<div class="ui left labeled input">
<input type="text"
id="event_summary"
name="summary"
value="{{ entity.summary|default('') }}"
required="required"
maxlength="255"
class="form-control">
<div class="ui corner label">
<i class="icon asterisk"></i>
</div>
</div>
</div>
<div class="field">
<label class="control-label required" for="event_summary">Beschreibung</label>
<div class="ui left labeled icon input attached-label">
<textarea name="description">{{ entity.description|default('') }}</textarea>
<div class="ui bottom attached label">Du kannst hier <a href="https://en.wikipedia.org/wiki/Markdown">Markdown</a>
benutzen.
</div>
</div>
</div>
<div class="field">
<label class="control-label required" for="event_url">URL</label>
<div class="ui left labeled icon input">
<input type="text"
id="event_url"
name="url"
maxlength="255"
value="{{ entity.url|default('') }}"
class="form-control">
<i class="icon globe"></i>
</div>
</div>
<div class="field">
<label class="control-label required" for="event_location">Ort</label>
<div class="ui left labeled icon input attached-{% if entity.location.lat|default(0) > 0 %}geo-{% endif %}label">
<input type="text"
id="event_location"
name="location"
maxlength="255"
value="{{ entity.location.name|default('') }}"
class="form-control">
<input type="hidden" name="location_lat" value="{{ entity.location.lat|default('') }}">
<input type="hidden" name="location_lon" value="{{ entity.location.lon|default('') }}">
<i class="icon map marker"></i>
<div class="ui bottom attached label">
Du kannst zu diesem Ort auch Geokoordinaten <a href="#" class="add_geo">hinterlegen</a>.<br/>
<span class="coords">{% if entity.location.lat|default(0) > 0 %}Folgende Koordinaten sind angegeben: lat:{{ entity.location.lat }}, lon:{{ entity.location.lon }}{% endif %}</span>
</div>
<div class="ui modal geo chooser">
<i class="close icon"></i>
<div class="header">
Wähle einen Punkt auf der Karte
</div>
<div class="content">
<div id="map"></div>
</div>
<div class="actions">
<div class="ui button cancel">
Cancel
</div>
<div class="ui button ok">
Okay
</div>
</div>
</div>
</div>
</div>
<div class="field">
<label class="" for="event_tags">Tags</label>
<div class="ui left icon input attached-label">
<input type="text"
id="event_tags"
name="tags"
value="{{ entity.getTagsAsText() }}"
class="form-control">
<i class="icon tag"></i>
<div class="ui bottom attached label">Du kannst hier kommasepariert <a
href="https://en.wikipedia.org/wiki/Tag_%28metadata%29">Tags</a> angeben.
</div>
</div>
</div>
<input type="submit" class="ui button blue" value="Speichern"/>
</div>
</form>

View file

@ -3,6 +3,7 @@
<div class="ui column">
<div class="title item"><a href="{{ path('') }}">Calcifer</a></div>
<div class="item"><a href="{{ path('_new') }}">Neuer Termin</a> </div>
<div class="item"><a href="{{ path('repeating_event_show') }}">Wiederholende Termine</a></div>
</div>
</div>
</header>