Skip to content

Commit

Permalink
Merge pull request #37 from pilot/task-33
Browse files Browse the repository at this point in the history
Update event schedule manage, #34
  • Loading branch information
pilot authored Jul 6, 2016
2 parents 5c2e90c + 44afaae commit 9fba7a5
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 93 deletions.
61 changes: 29 additions & 32 deletions features/backend/schedule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Background:
| program5 | de_DE |
| program6 | de_DE |
| program7 | de_DE |
| program8 | de_DE |
| program8 | ru_RU |
| program9 | de_DE |
| program10 | de_DE |
| program11 | de_DE |
Expand Down Expand Up @@ -94,21 +94,15 @@ Scenario: Admin should have access to the schedule manage
When I click "Schedule"
Then I wait for a form
Then I should see "Add an entry"
And I should see the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
And I should see the row containing "2;My event;alex_symfony;March 1, 2016 10:30 - 11:30"
And I should see the row containing "3;My event;phil_php;March 1, 2016 11:30 - 12:30"
And I should see the row containing "4;My event;coffee1;March 1, 2016 12:30 - 13:00"
And I should see the row containing "5;My event;phil_doctrine;March 1, 2016 13:00 - 14:30"
And I should see the row containing "6;My event;end_keynote;March 1, 2016 14:30 - 15:00"
And I should see the row containing "7;My event;after_party;March 1, 2016 15:00 - 18:00"
And I should see the row containing "8;His event;keynote;April 1, 2016 10:00 - 10:30"
And I should see the row containing "9;His event;alex_symfony;April 1, 2016 10:30 - 11:30"
And I should see the row containing "10;His event;phil_php;April 1, 2016 11:30 - 12:30"
And I should see the row containing "11;His event;coffee1;April 1, 2016 12:30 - 13:00"
And I should see the row containing "12;His event;phil_doctrine;April 1, 2016 13:00 - 14:30"
And I should see the row containing "13;His event;end_keynote;April 1, 2016 14:30 - 15:00"
And I should see the row containing "14;His event;after_party;April 1, 2016 15:00 - 18:00"
When I click "Edit" on the row containing "14;His event;after_party;April 1, 2016 15:00 - 18:00"
Then I wait "1" seconds
And I should see the row containing "8;keynote;April 1, 2016 10:00 - 10:30"
And I should see the row containing "9;alex_symfony;April 1, 2016 10:30 - 11:30"
And I should see the row containing "10;phil_php;April 1, 2016 11:30 - 12:30"
And I should see the row containing "11;coffee1;April 1, 2016 12:30 - 13:00"
And I should see the row containing "12;phil_doctrine;April 1, 2016 13:00 - 14:30"
And I should see the row containing "13;end_keynote;April 1, 2016 14:30 - 15:00"
And I should see the row containing "14;after_party;April 1, 2016 15:00 - 18:00"
When I click "Edit" on the row containing "14;after_party;April 01, 2016 15:00 - 18:00"
Then I wait for a form
Then I should see "Edit program entry"

Expand All @@ -121,59 +115,62 @@ Scenario: Admin should have able to add schedule
And I click "Add an entry"
Then I wait for a form
Then I should see "Add program entry"
And I fill in "Start Time" with "2016-03-01 09:30"
And I fill in "End Time" with "2016-03-01 10:00"
And I fill in "Start Time" with "2016-04-01 09:30"
And I fill in "End Time" with "2016-04-01 10:00"
And I check "Topic?"
And I fill in "Title" with "Registration"
And I check "My event"
And I check "His event"
And I press "Add"
Then I wait for a form
Then I should see "Program added."
Then I should see the row containing "15;My event;Registration;March 1, 2016 09:30 - 10:00"
Then I should see the row containing "15;Registration;April 01, 2016 09:30 - 10:00"

@javascript
Scenario: Admin should have able to update schedule settings
Given I am sign in as admin
When I click "Schedule"
Then I wait for a form
Then I should see "Add an entry"
And I should see the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
When I click "Edit" on the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
And I should see the row containing "8;keynote;April 01, 2016 10:00 - 10:30"
When I click "Edit" on the row containing "8;keynote;April 01, 2016 10:00 - 10:30"
Then I wait for a form
Then I should see "Edit program entry"
And I fill in "Start Time" with "2016-03-01 09:30"
And I press "Update"
Then I wait for a form
Then I should see "Program updated."
Then I should see the row containing "1;My event;keynote;March 1, 2016 09:30 - 10:30"
Then I should see the row containing "8;keynote;keynote;April 01, 2016 09:30 - 10:30"

@javascript
Scenario: Admin should have delete to the schedule
Given I am sign in as admin
When I click "Schedule"
Then I wait for a form
Then I should see "Add an entry"
And I should see the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
And I should see the row containing "2;My event;alex_symfony;March 1, 2016 10:30 - 11:30"
Then I delete the record with id "2"
Then I wait for a form
And I should see the row containing "8;keynote;April 01, 2016 10:00 - 10:30"
And I should see the row containing "9;alex_symfony;April 01, 2016 10:30 - 11:30"
Then I click on the element with css selector "a.actions-9"
Then I click on the element with css selector "a#modal-confirm-9"
Then I wait "3" seconds
Then I click to confirm action
Then I wait "3" seconds
Then I should see "Program deleted."
Then I should not see the row containing "2;My event;alex_symfony;March 1, 2016 10:30 - 11:30"
Then I should not see the row containing "9;alex_symfony;March 1, 2016 10:30 - 11:30"

@javascript
Scenario: Admin should have able to update Russian schedule settings
Given I am sign in as admin
When I click "Schedule"
Then I wait for a form
Then I should see "Add an entry"
And I should see the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
When I click "Edit" on the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
Then I wait for a form
And I should see the row containing "8;keynote;April 01, 2016 10:00 - 10:30"
When I click "Edit" on the row containing "8;keynote;April 01, 2016 10:00 - 10:30"
Then I wait "2" seconds
Then I should see "Edit program entry"
And I click "ru"
Then I wait for a form
And I fills in "Title" with "test" inside "ru" tab
And I press "Update"
Then I wait for a form
Then I should see "Program updated."
Then I should see the row containing "1;My event;keynote;March 1, 2016 10:00 - 10:30"
Then I should see the row containing "8;keynote;April 01, 2016 10:00 - 10:30"
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function ajaxCallsListAction(Request $request)

return new JsonResponse([
'draw' => $request->get('draw') ? intval($request->get('draw')) : 0,
"recordsTotal" => $callsCount,
"recordsFiltered" => $callsCount,
"data" => $data,
'recordsTotal' => $callsCount,
'recordsFiltered' => $callsCount,
'data' => $data,
]);
}

Expand Down
44 changes: 43 additions & 1 deletion src/Event/EventBundle/Controller/Backend/ProgramController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Event\EventBundle\Controller\Backend;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Event\EventBundle\Controller\Controller;
use Event\EventBundle\Entity\Program;
use Event\EventBundle\Entity\Translation\ProgramTranslation;
Expand All @@ -13,10 +14,51 @@ class ProgramController extends Controller
public function indexAction()
{
return $this->render('EventEventBundle:Backend/Program:index.html.twig', array(
'program' => $this->getRepository('EventEventBundle:Program')->findBy([], ['startDate' => 'ASC'])
'events' => $this->getRepository('EventEventBundle:Event')->findBy([], ['id' => 'DESC']),
));
}

/**
* @param Request $request
*
* @return JsonResponse
*/
public function ajaxProgramListAction(Request $request)
{
$start = $request->get('start');
$length = $request->get('length');
$searchQuery = $request->get('search')['value'];
$order = $request->get('order');
$eventId = $request->get('event', $this->getEvent()->getId());

$program = $this->getRepository('EventEventBundle:Program')->getProgramByParameters($eventId, $searchQuery, $order, $start, $length);
$programCount = $this->getRepository('EventEventBundle:Program')->getProgramCountByParameters($eventId, $searchQuery);

$data = array_map(function (Program $entity) {
$actions = [
'editUrl' => $this->generateUrl('backend_program_edit', ['id' => $entity->getId()]),
'deleteUrl' => $this->generateUrl('backend_program_delete', ['id' => $entity->getId()]),
];

return [
$entity->getId(),
'<a href="'.$this->generateUrl('backend_program_edit', ['id' => $entity->getId()]).'">'.
($entity->getTitle() ? $entity->getTitle() : $entity->getSpeech()->getTitle()).
'</a>',
$entity->getStartDate()->format('F d, Y H:i').' - '.$entity->getEndDate()->format('H:i'),
$actions,

];
}, $program);

return new JsonResponse([
'draw' => $request->get('draw') ? intval($request->get('draw')) : 0,
'recordsTotal' => $programCount,
'recordsFiltered' => $programCount,
'data' => $data,
]);
}

public function manageAction(Request $request, $id = null)
{
if ($id === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Event/EventBundle/Entity/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Program
*
* @ORM\Table(name="ev_program")
* @ORM\Entity
* @ORM\Entity(repositoryClass="Event\EventBundle\Entity\Repository\ProgramRepository")
*/
class Program
{
Expand Down
90 changes: 90 additions & 0 deletions src/Event/EventBundle/Entity/Repository/ProgramRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Event\EventBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

/**
* ProgramRepository
*/
class ProgramRepository extends EntityRepository
{
/**
* @param integer $eventId
* @param string $searchQuery
* @param array $order
* @param integer $start
* @param integer $length
*
* @return array
*/
public function getProgramByParameters($eventId, $searchQuery, $order, $start, $length)
{
$qb = $this->createQueryBuilder('p')
->innerJoin('p.events', 'e');

if (count($order)) {
for ($i = 0, $ien = count($order); $i < $ien; $i++) {
switch ($order[$i]['column']) {
case '0':
$qb->addOrderBy('p.id', $order[$i]['dir']);
break;
case '1':
$qb->addOrderBy('p.title', $order[$i]['dir']);
break;
case '2':
$qb->addOrderBy('p.startDate', $order[$i]['dir']);
break;
}
}
}

$qb = $this->programQueryAddParams($qb, $eventId, $searchQuery);

$qb->setFirstResult($start)
->setMaxResults($length);

return $qb->getQuery()->getResult();
}

/**
* @param integer $eventId
* @param string $searchQuery
*
* @return array
*/
public function getProgramCountByParameters($eventId, $searchQuery)
{
$qb = $this->createQueryBuilder('p')
->innerJoin('p.events', 'e')
->select('COUNT(DISTINCT p.id)');

$qb = $this->programQueryAddParams($qb, $eventId, $searchQuery);

return $qb->getQuery()->getSingleScalarResult();
}

/**
* @param QueryBuilder $qb
* @param integer $eventId
* @param string $searchQuery
*
* @return \Doctrine\ORM\QueryBuilder
*/
protected function programQueryAddParams(QueryBuilder $qb, $eventId, $searchQuery)
{
if ($searchQuery != '') {
$qb->where($qb->expr()->like('LOWER(p.title)', ':query'));

$qb->setParameter('query', '%'.mb_strtolower(trim($searchQuery), mb_detect_encoding($searchQuery)).'%');
}

if ($eventId) {
$qb->andWhere($qb->expr()->eq('e.id', ':eventId'))
->setParameter('eventId', $eventId);
}

return $qb;
}
}
7 changes: 7 additions & 0 deletions src/Event/EventBundle/Resources/config/routing/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ backend_program:
path: /schedule
defaults: { _controller: EventEventBundle:Backend/Program:index }

backend_program_ajax_program_list:
path: /schedule/ajax-schedule-list
defaults: { _controller: EventEventBundle:Backend/Program:ajaxProgramList }
methods: ['GET']
options:
expose: true

backend_program_add:
path: /schedule/add
defaults: { _controller: EventEventBundle:Backend/Program:manage }
Expand Down
16 changes: 16 additions & 0 deletions src/Event/EventBundle/Resources/public/css/program/program.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.events-list {
text-align: right;
}

#program_length select, #select-event {
width: auto;
}

#program_wrapper table.dataTable thead th,
#program_wrapper table.dataTable thead td {
border-bottom: none;
}

#program_wrapper table.dataTable.no-footer {
border-bottom: 1px solid #ddd;
}
5 changes: 5 additions & 0 deletions src/Event/EventBundle/Resources/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
text-align: center;
}

/* js alerts */
.js-alert-success {
display: none;
}

/* form */
form input {
width: 300px;
Expand Down
49 changes: 49 additions & 0 deletions src/Event/EventBundle/Resources/public/js/program/program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$(function() {
var $body = $('body');

/* calls list table */
var dataTable = $('#program').DataTable({
processing: false,
serverSide: true,
lengthMenu: [50, 100, 200, 300],
order: [[2, 'asc']],
pagingType: 'full_numbers',
dom: "<'row'<'span3'l><'span6'f>r>t<'row'<'span3'i><'span6'p>>",
ajax: {
url: Routing.generate('backend_program_ajax_program_list'),
data: function (d) {
d.event = $('#select-event').val();
}
},
language: {
lengthMenu: "_MENU_ records per page",
infoEmpty: '0 of 0 entries'
},
createdRow: function(row, data, index) {
$(row).attr('id', 'item-' + data[0]);
},
columnDefs: [
{searchable: false, orderable: true, targets: 0, width: '5%'},
{searchable: true, orderable: true, targets: 1},
{searchable: false, orderable: true, targets: 2, width: '30%'},
{searchable: false, orderable: false, targets: 3, width: '10%',
render: function(data, type, row) {
return '\
<div class="btn-group">\
<a class="btn btn-small" href="' + data['editUrl'] + '"><i class="icon-edit"></i> Edit</a>\
<a class="btn btn-small dropdown-toggle actions-' + row[0] + '" data-toggle="dropdown" href="#"><span class="caret"></span></a>\
<ul class="dropdown-menu">\
<li><a href="' + data['deleteUrl'] + '" class="delete-call" id="modal-confirm-' + row[0] + '"><i class="icon-trash"></i> Delete</a></li>\
</ul>\
</div>\
';
}
}
]
});
/* end calls list table */

$body.on('change', '#select-event', function() {
dataTable.ajax.reload();
});
});
Loading

0 comments on commit 9fba7a5

Please sign in to comment.