Skip to content

Commit

Permalink
List categories based on the current location
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jul 10, 2018
1 parent 300e874 commit f3a02be
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 100 deletions.
1 change: 0 additions & 1 deletion assets/js/local.timeslot.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
$('[data-timepicker-option]').removeClass('active')
$('[data-timepicker-option="'+value+'"]').addClass('active')

console.log(this.selectedType, value)
if (value === 'asap') {
$container.addClass('hide')
} else {
Expand Down
12 changes: 6 additions & 6 deletions components/Categories.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace SamPoyigi\Local\Components;

use Admin\Models\Categories_model;
use Location;
use Main\Template\Page;

class Categories extends \System\Classes\BaseComponent
Expand All @@ -24,26 +25,25 @@ public static function getMenusPageOptions()
public function onRun()
{
$this->page['menusPage'] = $this->property('menusPage');
$this->page['selectedCategory'] = $this->getSelectedCategory();
$this->page['categories'] = $this->loadCategories();
$this->page['categories'] = $categories = $this->loadCategories();
$this->page['selectedCategory'] = $this->findSelectedCategory($categories);
}

protected function loadCategories()
{
$query = Categories_model::orderBy('name');

// category must have at least one menu
// $query->whereHasMenus();
$query->whereHasOrDoesntHaveLocation(Location::getId());

return $query->get()->toTree();
}

protected function getSelectedCategory()
protected function findSelectedCategory($categories)
{
$slug = $this->param('category');
if (!strlen($slug))
return null;

return Categories_model::whereSlug($slug)->first();
return $categories->where('permalink_slug', $slug)->first();
}
}
35 changes: 3 additions & 32 deletions components/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace SamPoyigi\Local\Components;

use Admin\Models\Categories_model;
use Admin\Models\Menus_model;
use Location;

class Menu extends \System\Classes\BaseComponent
{
Expand All @@ -12,10 +12,6 @@ class Menu extends \System\Classes\BaseComponent
public function defineProperties()
{
return [
'isGrouped' => [
'label' => 'Group Menu Items',
'type' => 'switch',
],
'menusPerPage' => [
'label' => 'Menus Per Page',
'type' => 'number',
Expand All @@ -42,13 +38,11 @@ public function defineProperties()

public function onRun()
{
$this->page['menuIsGrouped'] = $isGrouped = $this->property('isGrouped');
$this->page['showMenuImages'] = $this->property('showMenuImages');
$this->page['menuImageWidth'] = $this->property('menuImageWidth');
$this->page['menuImageHeight'] = $this->property('menuImageHeight');

$this->page['menuList'] = $isGrouped ?
$this->loadGroupedList() : $this->loadList();
$this->page['menuList'] = $this->loadList();
}

protected function loadList()
Expand All @@ -57,33 +51,10 @@ protected function loadList()
'page' => $this->param('page'),
'pageLimit' => $this->property('menusPerPage'),
'sort' => $this->property('sort', 'menu_priority asc'),
'location' => Location::getId(),
'category' => $this->param('category'),
]);

return $list;
}

protected function loadGroupedList()
{
$query = Categories_model::with([
'menus' => function ($menusQuery) {
$menusQuery->listFrontEnd([
'pageLimit' => null,
'sort' => $this->property('sort', 'menu_priority asc'),
]);
},
'menus.special',
'menus.mealtime',
'menus.menu_options',
]);

$query->whereHasMenus();

if ($this->param('category'))
$query->whereSlug($this->param('category'));

$list = $query->get();

return $list;
}
}
12 changes: 4 additions & 8 deletions components/menu/default.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<div class="menu-list">
<?php if ($menuIsGrouped) { ?>
<?= partial('@grouped'); ?>
<?php } else { ?>
<?= partial('@items', ['menuItems' => $menuList]); ?>
<?= partial('@items', ['menuItems' => $menuList]); ?>

<div class="pagination-bar text-right">
<div class="links"><?= $menuList->links(); ?></div>
</div>
<?php } ?>
<div class="pagination-bar text-right">
<div class="links"><?= $menuList->links(); ?></div>
</div>
</div>
53 changes: 0 additions & 53 deletions components/menu/grouped.php

This file was deleted.

0 comments on commit f3a02be

Please sign in to comment.