Skip to content

Commit

Permalink
Fix ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamek committed Sep 13, 2019
1 parent 9e77307 commit b9b43c3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 31 deletions.
30 changes: 20 additions & 10 deletions src/Dravencms/AdminModule/Components/Form/ItemGrid/ItemGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function createComponentGrid($name)
$grid = $this->baseGridFactory->create($this, $name);

$grid->setDataSource($this->itemRepository->getItemQueryBuilder($this->itemGroup));

$grid->setDefaultSort(['position' => 'ASC']);
$grid->addColumnText('name', 'Name')
->setSortable()
->setFilterText();
Expand All @@ -117,6 +117,7 @@ public function createComponentGrid($name)
})
->setFilterText();

$grid->addColumnPosition('position', 'Position', 'up!', 'down!');

$grid->addAction('itemOption', 'Options', 'ItemOption:', ['itemId' => 'id'])
->setIcon('bars')
Expand Down Expand Up @@ -144,7 +145,7 @@ public function createComponentGrid($name)
->setClass('btn btn-xs btn-danger ajax')
->setConfirm('Do you really want to delete row %s?', 'name');

$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'gridGroupActionDelete'];
$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete'];
}

$grid->addExportCsvFiltered('Csv export (filtered)', 'acl_resource_filtered.csv')
Expand All @@ -156,14 +157,6 @@ public function createComponentGrid($name)
return $grid;
}

/**
* @param array $ids
*/
public function gridGroupActionDelete(array $ids)
{
$this->handleDelete($ids);
}

/**
* @param $id
* @throws \Exception
Expand All @@ -186,6 +179,23 @@ public function handleDelete($id)
$this->onDelete();
}

public function handleUp($id)
{
$item = $this->itemRepository->getOneById($id);
$item->setPosition($item->getPosition() - 1);
$this->entityManager->persist($item);
$this->entityManager->flush();
}

public function handleDown($id)
{
$item = $this->itemRepository->getOneById($id);
$item->setPosition($item->getPosition() + 1);
$this->entityManager->persist($item);
$this->entityManager->flush();
}


public function render()
{
$template = $this->template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ public function createComponentGrid($name)
$grid = $this->baseGridFactory->create($this, $name);

$grid->setDataSource($this->itemGroupRepository->getItemGroupQueryBuilder($this->form));

$grid->setDefaultSort(['position' => 'ASC']);
$grid->addColumnText('identifier', 'Identifier')
->setSortable()
->setFilterText();

$grid->addColumnPosition('position', 'Position', 'up!', 'down!');

$grid->addColumnBoolean('isShowName', 'Show name');

if ($this->presenter->isAllowed('form', 'edit')) {
Expand All @@ -126,7 +128,7 @@ public function createComponentGrid($name)
->setClass('btn btn-xs btn-danger ajax')
->setConfirm('Do you really want to delete row %s?', 'identifier');

$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'gridGroupActionDelete'];
$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete'];
}

$grid->addExportCsvFiltered('Csv export (filtered)', 'acl_resource_filtered.csv')
Expand All @@ -138,14 +140,6 @@ public function createComponentGrid($name)
return $grid;
}

/**
* @param array $ids
*/
public function gridGroupActionDelete(array $ids)
{
$this->handleDelete($ids);
}

/**
* @param $id
* @throws \Exception
Expand All @@ -172,6 +166,23 @@ public function handleDelete($id)
$this->onDelete();
}

public function handleUp($id)
{
$item = $this->itemGroupRepository->getOneById($id);
$item->setPosition($item->getPosition() - 1);
$this->entityManager->persist($item);
$this->entityManager->flush();
}

public function handleDown($id)
{
$item = $this->itemGroupRepository->getOneById($id);
$item->setPosition($item->getPosition() + 1);
$this->entityManager->persist($item);
$this->entityManager->flush();
}


public function render()
{
$template = $this->template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ public function createComponentGrid($name)
$grid = $this->baseGridFactory->create($this, $name);

$grid->setDataSource($this->itemOptionRepository->getItemOptionQueryBuilder($this->item));

$grid->setDefaultSort(['position' => 'ASC']);
$grid->addColumnText('identifier', 'Identifier')
->setSortable()
->setFilterText();

$grid->addColumnPosition('position', 'Position', 'up!', 'down!');

if ($this->presenter->isAllowed('form', 'edit'))
{
Expand All @@ -100,9 +101,9 @@ public function createComponentGrid($name)
->setIcon('trash')
->setTitle('Smazat')
->setClass('btn btn-xs btn-danger ajax')
->setConfirm('Do you really want to delete row %s?', 'name');
->setConfirm('Do you really want to delete row %s?', 'identifier');

$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'gridGroupActionDelete'];
$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete'];
}

$grid->addExportCsvFiltered('Csv export (filtered)', 'acl_resource_filtered.csv')
Expand All @@ -114,13 +115,6 @@ public function createComponentGrid($name)
return $grid;
}

/**
* @param array $ids
*/
public function gridGroupActionDelete(array $ids)
{
$this->handleDelete($ids);
}

/**
* @param $id
Expand All @@ -140,6 +134,22 @@ public function handleDelete($id)
$this->onDelete();
}

public function handleUp($id)
{
$item = $this->itemOptionRepository->getOneById($id);
$item->setPosition($item->getPosition() - 1);
$this->entityManager->persist($item);
$this->entityManager->flush();
}

public function handleDown($id)
{
$item = $this->itemOptionRepository->getOneById($id);
$item->setPosition($item->getPosition() + 1);
$this->entityManager->persist($item);
$this->entityManager->flush();
}

public function render()
{
$template = $this->template;
Expand Down
12 changes: 11 additions & 1 deletion src/Dravencms/FrontModule/Components/Form/Form/Detail/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ public function createComponentForm()
$objInput->addRule(Form::MAX_LENGTH, 'Input must have maximaly %d characters', $formsItems->getMaxValue());
}

break;
case Item::TYPE_NUMBER:
$objInput->addRule(Form::NUMERIC, 'You must enter an number');
if ($formsItems->getMinValue()) {
$objInput->addRule(Form::MIN, 'Minimal number is %d', $formsItems->getMinValue());
}

if ($formsItems->getMaxValue()) {
$objInput->addRule(Form::MAX, 'Maximal number is %d', $formsItems->getMaxValue());
}
break;
}

Expand Down Expand Up @@ -252,7 +262,7 @@ public function createComponentForm()
$objInput->setAttribute('placeholder', $itemTranslation->getPlaceholder());
}

if ($itemTranslation->getDefaultValue() && !$form->isSubmitted()) {
if ($itemTranslation->getDefaultValue()) {
$objInput->setValue($itemTranslation->getDefaultValue());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Dravencms/Model/Form/Entities/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Form
/**
* @var ArrayCollection|ItemGroup[]
* @ORM\OneToMany(targetEntity="ItemGroup", mappedBy="form",cascade={"persist"})
* @ORM\OrderBy({"position" = "ASC"})
*/
private $itemGroups;

Expand Down
1 change: 1 addition & 0 deletions src/Dravencms/Model/Form/Entities/ItemGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ItemGroup
/**
* @var ArrayCollection|Item[]
* @ORM\OneToMany(targetEntity="Item", mappedBy="itemGroup",cascade={"persist"})
* @ORM\OrderBy({"position" = "ASC"})
*/
private $items;

Expand Down

0 comments on commit b9b43c3

Please sign in to comment.