Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
82 changes: 82 additions & 0 deletions app/components/form/FilterTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
namespace App\Components\Form;

use App\Model\Entity\Task;
use App\Model\Entity\TaskGroup;
use App\Model\Repository\TaskRepository;
use App\Model\Repository\TaskGroupRepository;
use Nette\Application\UI\Control;
use Nette\Application\UI\Form;

class FilterTask extends Control
{
/** @var TaskRepository*/
public $taskRepository;
/** @var TaskGroupRepository*/
public $taskGroupRepository;
/** @var number */
public $idTaskGroup;

/**
* @param TaskRepository $taskRepository
* @param TaskGroupRepository $taskGroupRepository
*/
public function __construct(TaskRepository $taskRepository, TaskGroupRepository $taskGroupRepository)
{
parent::__construct();
$this->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');
}

}
}
21 changes: 20 additions & 1 deletion app/components/form/InsertTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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');
}

}
}
12 changes: 12 additions & 0 deletions app/components/form/templates/FilterTask.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{form filterTaskForm}
<div class="row">
<div class="col-md-10">
<div class="form-group">
{input search, class => 'form-control'}
</div>
</div>
<div class="col-md-2">
{input submit, class => 'btn btn-primary'}
</div>
</div>
{/form}
61 changes: 61 additions & 0 deletions app/components/modal/ChangeTaskGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace App\Components\Modal;

use App\Model\Entity\TaskGroup;
use App\Model\Repository\TaskGroupRepository;
use Nette\Application\UI\Control;
use Nette\Application\UI\Form;

class ChangeTaskGroup extends Control
{
/** @var TaskGroupRepository @inject*/
public $taskGroupRepository;

/**
* @param TaskGroupRepository $taskGroupRepository
*/
public function __construct(TaskGroupRepository $taskGroupRepository)
{
parent::__construct();
$this->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');

}
}
23 changes: 23 additions & 0 deletions app/components/modal/templates/ChangeTaskGroup.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="changeTaskGroupModal">
<div class="modal-dialog">
<div class="modal-content">
{form changeTaskGroupForm}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Change task group</h4>
</div>
<div class="modal-body">
<div class="form-group">
{label category /}
{input category, class => 'form-control'}
</div>
{input taskId, class => 'taskId'}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
{input submit, class => 'btn btn-primary'}
</div>
{/form}
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/config/config.local.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
doctrine:
user: root
user: quicktask
password: test
dbname: quicktask

Expand Down
2 changes: 2 additions & 0 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions app/factories/form/IFilterTaskFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace App\Factories\Form;

use App\Components\Form\FilterTask;

interface IFilterTaskFactory
{
/**
* @return FilterTask
*/
public function create();
}
12 changes: 12 additions & 0 deletions app/factories/modal/IChangeTaskGroupFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace App\Factories\Modal;

use App\Components\Modal\ChangeTaskGroup;

interface IChangeTaskGroupFactory
{
/**
* @return ChangeTaskGroup
*/
public function create();
}
15 changes: 15 additions & 0 deletions app/model/repository/TaskGroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ class TaskGroupRepository extends AbstractRepository
/** @var \Kdyby\Doctrine\EntityRepository */
private $taskGroup;

/** @var \Kdyby\Doctrine\EntityRepository */
private $task;

public function __construct(EntityManager $entityManager)
{
parent::__construct($entityManager);
$this->taskGroup = $this->entityManager->getRepository(Entity\TaskGroup::getClassName());
$this->task = $this->entityManager->getRepository(Entity\Task::getClassName());
}

/**
Expand Down Expand Up @@ -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();
}
}
34 changes: 32 additions & 2 deletions app/model/repository/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Loading