From d820eb2a2ebe7c08d00e1bd05bd423cf17f7d7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pe=C5=A1ka?= Date: Tue, 10 Nov 2015 13:52:36 +0100 Subject: [PATCH] Kurzor ukoly --- app/bootstrap.php | 2 +- app/components/form/FilterTask.php | 82 +++++++++++++++++++ app/components/form/InsertTask.php | 21 ++++- .../form/templates/FilterTask.latte | 12 +++ app/components/modal/ChangeTaskGroup.php | 61 ++++++++++++++ .../modal/templates/ChangeTaskGroup.latte | 23 ++++++ app/config/config.local.neon | 2 +- app/config/config.neon | 2 + app/factories/form/IFilterTaskFactory.php | 12 +++ .../modal/IChangeTaskGroupFactory.php | 12 +++ app/model/repository/TaskGroupRepository.php | 15 ++++ app/model/repository/TaskRepository.php | 34 +++++++- app/presenter/TaskPresenter.php | 38 ++++++++- app/templates/@layout.latte | 4 + app/templates/Task/taskGroup.latte | 16 +++- www/css/style.css | 8 ++ www/js/main.js | 46 ++++++++++- 17 files changed, 381 insertions(+), 9 deletions(-) create mode 100644 app/components/form/FilterTask.php create mode 100644 app/components/form/templates/FilterTask.latte create mode 100644 app/components/modal/ChangeTaskGroup.php create mode 100644 app/components/modal/templates/ChangeTaskGroup.latte create mode 100644 app/factories/form/IFilterTaskFactory.php create mode 100644 app/factories/modal/IChangeTaskGroupFactory.php diff --git a/app/bootstrap.php b/app/bootstrap.php index 39d8bed..9edadac 100755 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -8,7 +8,7 @@ $configurator = new Nette\Configurator; /* Setup to allow ladenka in production mode */ -//$configurator->setDebugMode(TRUE); // debug mode MUST NOT be enabled on production server +$configurator->setDebugMode(TRUE); // debug mode MUST NOT be enabled on production server $configurator->enableDebugger(__DIR__ . '/../log'); $configurator->setTempDirectory(__DIR__ . '/../temp'); diff --git a/app/components/form/FilterTask.php b/app/components/form/FilterTask.php new file mode 100644 index 0000000..ccf0c13 --- /dev/null +++ b/app/components/form/FilterTask.php @@ -0,0 +1,82 @@ +taskRepository = $taskRepository; + $this->taskGroupRepository = $taskGroupRepository; + } + + public function render() + { + $template = $this->template; + $template->setFile(__DIR__ . '/templates/FilterTask.latte'); + $template->render(); + } + + /** + * @param int $idTaskGroup + */ + public function setTaskGroupId($idTaskGroup) + { + $this->idTaskGroup = $idTaskGroup; + } + + /** + * @return Form + */ + protected function createComponentFilterTaskForm() + { + + $searchSession = $this->presenter->getSession('serach'); + $word = $searchSession->searchString; + + $form = new Form(); + $form->getElementPrototype()->class('newTaskForm ajax'); + $form->addText('search', 'Search') + ->setDefaultValue($word); + $form->addHidden('idTaskGroup', $this->idTaskGroup); + $form->addSubmit('submit', 'Filtruj'); + $form->onSuccess[] = array($this, 'filterTaskFromSuccess'); + return $form; + } + + /** + * @param Form $form + * @param $values + */ + public function filterTaskFromSuccess(Form $form, $values) + { + + $searchSession = $this->presenter->getSession('serach'); + $searchSession->searchString = $values->search; + + if ($this->presenter->isAjax()) { + $this->presenter->redrawControl('tasks'); + } else { + $this->redirect('this'); + } + + } +} diff --git a/app/components/form/InsertTask.php b/app/components/form/InsertTask.php index 9997c70..b9913bd 100644 --- a/app/components/form/InsertTask.php +++ b/app/components/form/InsertTask.php @@ -43,12 +43,26 @@ public function setTaskGroupId($idTaskGroup) $this->idTaskGroup = $idTaskGroup; } + /** + * @param int $id + */ + public function handleDeleteTaskGroup($id) + { + $this->taskGroupRepository->delete($id); + if ($this->isAjax()) { + $this->redrawControl('taskGroups'); + } else { + $this->redirect('this'); + } + } + /** * @return Form */ protected function createComponentInsertTaskForm() { $form = new Form(); + $form->getElementPrototype()->class('newTaskForm'); $form->addText('name', 'Name') ->setRequired('Please fill task name'); $form->addText('date', 'Date') @@ -73,6 +87,11 @@ public function insertTaskFromSuccess(Form $form, $values) $taskEntity->setTaskGroup($taskGroup); $this->taskRepository->insert($taskEntity); $this->presenter->flashMessage('Task was created', 'success'); - $this->redirect('this'); + if ($this->presenter->isAjax()) { + $this->presenter->redrawControl('tasks'); + } else { + $this->redirect('this'); + } + } } diff --git a/app/components/form/templates/FilterTask.latte b/app/components/form/templates/FilterTask.latte new file mode 100644 index 0000000..f92692f --- /dev/null +++ b/app/components/form/templates/FilterTask.latte @@ -0,0 +1,12 @@ +{form filterTaskForm} +
+
+
+ {input search, class => 'form-control'} +
+
+
+ {input submit, class => 'btn btn-primary'} +
+
+{/form} \ No newline at end of file diff --git a/app/components/modal/ChangeTaskGroup.php b/app/components/modal/ChangeTaskGroup.php new file mode 100644 index 0000000..5f4faae --- /dev/null +++ b/app/components/modal/ChangeTaskGroup.php @@ -0,0 +1,61 @@ +taskGroupRepository = $taskGroupRepository; + } + + public function render() + { + $template = $this->template; + $template->setFile(__DIR__ . '/templates/ChangeTaskGroup.latte'); + $template->render(); + } + + /** + * @return Form + */ + protected function createComponentChangeTaskGroupForm() + { + $taskGroups = $this->taskGroupRepository->getAll(); + $result = array(); + foreach ($taskGroups as $taskGroup) { + $result[$taskGroup->getId()] = $taskGroup->getName(); + } + + $form = new Form(); + $form->addSelect('category', 'Category', $result); + $form->addHidden('taskId'); + $form->addSubmit('submit', 'Save'); + $form->onSuccess[] = array($this, 'changeTaskGroupFromSuccess'); + return $form; + } + + /** + * @param Form $form + * @param $values + */ + public function changeTaskGroupFromSuccess(Form $form, $values) + { + + $this->taskGroupRepository->setCategory($values->category, $values->taskId); + $this->presenter->flashMessage('Task group was changed', 'success'); + $this->redirect('this'); + + } +} diff --git a/app/components/modal/templates/ChangeTaskGroup.latte b/app/components/modal/templates/ChangeTaskGroup.latte new file mode 100644 index 0000000..aba5e2d --- /dev/null +++ b/app/components/modal/templates/ChangeTaskGroup.latte @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/app/config/config.local.neon b/app/config/config.local.neon index f6ed2ef..2b86d64 100644 --- a/app/config/config.local.neon +++ b/app/config/config.local.neon @@ -1,5 +1,5 @@ doctrine: - user: root + user: quicktask password: test dbname: quicktask diff --git a/app/config/config.neon b/app/config/config.neon index 8251824..0543680 100644 --- a/app/config/config.neon +++ b/app/config/config.neon @@ -20,7 +20,9 @@ services: - App\Model\Repository\TaskGroupRepository - App\Model\Repository\TaskRepository - App\Factories\Modal\IInsertTaskGroupFactory + - App\Factories\Modal\IChangeTaskGroupFactory - App\Factories\Form\IInsertTaskFactory + - App\Factories\Form\IFilterTaskFactory extensions: console: Kdyby\Console\DI\ConsoleExtension diff --git a/app/factories/form/IFilterTaskFactory.php b/app/factories/form/IFilterTaskFactory.php new file mode 100644 index 0000000..a22a8f1 --- /dev/null +++ b/app/factories/form/IFilterTaskFactory.php @@ -0,0 +1,12 @@ +taskGroup = $this->entityManager->getRepository(Entity\TaskGroup::getClassName()); + $this->task = $this->entityManager->getRepository(Entity\Task::getClassName()); } /** @@ -40,4 +44,15 @@ public function insert(Entity\TaskGroup $taskGroup) $this->entityManager->persist($taskGroup); $this->entityManager->flush(); } + + /** + * @param number $id + * @param number $category + */ + public function setCategory($category, $id) + { + $task = $this->task->find($id); + $task->setTaskGroup($this->getById($category)); + $this->entityManager->flush(); + } } diff --git a/app/model/repository/TaskRepository.php b/app/model/repository/TaskRepository.php index 7980e47..578b0c2 100644 --- a/app/model/repository/TaskRepository.php +++ b/app/model/repository/TaskRepository.php @@ -24,13 +24,43 @@ public function getById($id) return $this->task->find($id); } + /** + * @param number $id + * @return Entity\Task|null + */ + public function getStateById($id) + { + return $this->task->find($id); + } + /** * @param number $idTaskGroup * @return Entity\Task[] */ - public function getByTaskGroup($idTaskGroup) + public function getByTaskGroup($idTaskGroup, $word = "") { - return $this->task->findBy(array('taskGroup' => $idTaskGroup)); + + $q = $this->task->createQueryBuilder('t') + ->where('t.taskGroup = '.$idTaskGroup) + ->andWhere('t.name LIKE :name') + ->setParameter('name', '%'.$word.'%') + ->orderBy('t.date', 'DESC') + ->getQuery(); + $tasks = $q->getResult(); + return $tasks; + + } + + /** + * @param number $id + * @param number $state + */ + public function setState($id, $state) + { + $task = $this->task->find($id); + $task->setCompleted($state); + + $this->entityManager->flush(); } /** diff --git a/app/presenter/TaskPresenter.php b/app/presenter/TaskPresenter.php index 5e2bbf9..006af1e 100644 --- a/app/presenter/TaskPresenter.php +++ b/app/presenter/TaskPresenter.php @@ -13,8 +13,12 @@ class TaskPresenter extends BasePresenter public $taskRepository; /** @var \App\Factories\Modal\IInsertTaskGroupFactory @inject */ public $insertTaskGroupFactory; + /** @var \App\Factories\Modal\IChangeTaskGroupFactory @inject */ + public $changeTaskGroupFactory; /** @var \App\Factories\Form\IInsertTaskFactory @inject */ public $insertTaskFactory; + /** @var \App\Factories\Form\IFilterTaskFactory @inject */ + public $filterTaskFactory; /** @var number */ protected $idTaskGroup; @@ -36,12 +40,22 @@ public function handleDeleteTaskGroup($id) } } + /** + * @param int $id + */ + public function handleChangeTaskState($id, $stav) + { + + $task = $this->taskRepository->setState($id, $stav); + } + /** * @param number $idTaskGroup */ public function renderTaskGroup($idTaskGroup) { $this->idTaskGroup = $idTaskGroup; + $this->template->idTaskGroup = $idTaskGroup; $this->template->tasks = $this->getTasks($idTaskGroup); } @@ -54,6 +68,15 @@ protected function createComponentInsertTaskGroupModal() return $control; } + /** + * @return \App\Components\Modal\ChangeTaskGroup + */ + protected function createComponentChangeTaskGroupModal() + { + $control = $this->changeTaskGroupFactory->create(); + return $control; + } + /** * @return \App\Components\Form\InsertTask */ @@ -64,6 +87,16 @@ protected function createComponentInsertTaskForm() return $control; } + /** + * @return \App\Components\Form\FilterTask + */ + protected function createComponentFilterTaskForm() + { + $control = $this->filterTaskFactory->create(); + $control->setTaskGroupId($this->idTaskGroup); + return $control; + } + /** * @return array */ @@ -86,8 +119,11 @@ protected function getTaskGroups() */ protected function getTasks($idTaskGroup) { + $searchSession = $this->getSession('serach'); + $word = $searchSession->searchString; + $result = array(); - $tasks = $this->taskRepository->getByTaskGroup($idTaskGroup); + $tasks = $this->taskRepository->getByTaskGroup($idTaskGroup, $word); foreach ($tasks as $task) { $item = array(); $item['id'] = $task->getId(); diff --git a/app/templates/@layout.latte b/app/templates/@layout.latte index 17d3257..6b80e9b 100644 --- a/app/templates/@layout.latte +++ b/app/templates/@layout.latte @@ -10,7 +10,10 @@ + + {block head}{/block} + @@ -51,6 +54,7 @@ {block scripts} + diff --git a/app/templates/Task/taskGroup.latte b/app/templates/Task/taskGroup.latte index 7e265b7..1e41d99 100644 --- a/app/templates/Task/taskGroup.latte +++ b/app/templates/Task/taskGroup.latte @@ -1,20 +1,32 @@ {block content} - {control insertTaskForm}
+
+ {control filterTaskForm} +
+
+
{snippet tasks}
    {foreach $tasks as $task}
  • - + {$task['name']} {$task['date']|date:'d.m.Y'} +
  • {/foreach}
{/snippet}
+
+
+ {control insertTaskForm} +
+
+ + {control changeTaskGroupModal} {/block} {block scripts} diff --git a/www/css/style.css b/www/css/style.css index 4a73ec0..8b396a3 100644 --- a/www/css/style.css +++ b/www/css/style.css @@ -1,4 +1,12 @@ span.error-message { color: #a94442; font-weight: bold; +} +.row { + margin-bottom: 10px; +} +.katRight { + float: right; + height: 22px; + padding: 0 12px !important; } \ No newline at end of file diff --git a/www/js/main.js b/www/js/main.js index 55ccd4c..a686c08 100755 --- a/www/js/main.js +++ b/www/js/main.js @@ -1,7 +1,51 @@ $(document).ready(function(){ - $.nette.init(); + $.nette.ext('reload', { + complete: function () { + $('input').iCheck({ + checkboxClass: 'icheckbox_square-grey' + }); + } + }); + $.nette.init(); + + $('#frm-insertTaskForm-insertTaskForm').on('submit', function (e) { + e.preventDefault(); + + $(this).netteAjax(e); + }); + + $('input').iCheck({ + checkboxClass: 'icheckbox_square-grey' + }); + $('.datepicker').datepicker({ orientation: 'left top' }); + + $('.iCheck-helper').on('click', function(){ + var stav = 0; + var id = $(this).parent().children( ".taskCheck" ).attr('id'); + if($(this).parent().children( ".taskCheck" ).is(':checked')) { + stav = 1; + } + else { + stav = 0; + } + + $.ajax({ + url: "/task/task-group/"+id+"?stav="+stav+"&idTaskGroup=1&do=changeTaskState" + }); + }); + +}); + +$(document).on("click", ".katRight", function () { + var myId = $(this).data('id'); + var ids = myId.split('-'); + + $('.modal-body #frm-changeTaskGroupModal-changeTaskGroupForm-category').val(ids[0]); + $('.modal-body .taskId').val(ids[1]); + // $(".modal-body #bookId").val( myBookId ); + }); \ No newline at end of file