Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed May 20, 2022
2 parents d111be6 + b9df4df commit 55351d3
Show file tree
Hide file tree
Showing 751 changed files with 10,993 additions and 53,154 deletions.
134 changes: 83 additions & 51 deletions app/admin/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
use Admin\Classes\Navigation;
use Admin\Classes\OnboardingSteps;
use Admin\Classes\PermissionManager;
use Admin\Classes\UserState;
use Admin\Classes\Widgets;
use Admin\Facades\AdminLocation;
use Admin\Facades\AdminMenu;
use Admin\Middleware\LogUserLastSeen;
use Admin\Requests\Location;
use Igniter\Flame\ActivityLog\Models\Activity;
use Igniter\Flame\Foundation\Providers\AppServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use System\Classes\MailManager;
use System\Libraries\Assets;
Expand All @@ -35,8 +35,7 @@ public function boot()
if ($this->app->runningInAdmin()) {
$this->resolveFlashSessionKey();
$this->replaceNavMenuItem();

$this->app['router']->pushMiddlewareToGroup('web', LogUserLastSeen::class);
$this->extendLocationOptionsFields();
}
}

Expand All @@ -62,6 +61,8 @@ public function register()
$this->registerMainMenuItems();
$this->registerNavMenuItems();
$this->registerOnboardingSteps();

$this->app[Kernel::class]->appendMiddlewareToGroup('web', LogUserLastSeen::class);
}
}

Expand All @@ -88,13 +89,6 @@ protected function registerAssets()

// Admin asset bundles
$manager->registerBundle('scss', '~/app/admin/assets/scss/admin.scss', null, 'admin');
$manager->registerBundle('js', [
'~/app/system/assets/ui/flame.js',
'~/app/admin/assets/node_modules/js-cookie/src/js.cookie.js',
'~/app/admin/assets/node_modules/select2/dist/js/select2.min.js',
'~/app/admin/assets/node_modules/metismenu/dist/metisMenu.min.js',
'~/app/admin/assets/js/src/app.js',
], '~/app/admin/assets/js/admin.js', 'admin');
});
}

Expand Down Expand Up @@ -248,7 +242,7 @@ protected function registerFormWidgets()
protected function registerMainMenuItems()
{
AdminMenu::registerCallback(function (Navigation $manager) {
$manager->registerMainItems([
$menuItems = [
'preview' => [
'icon' => 'fa-store',
'attributes' => [
Expand All @@ -272,7 +266,8 @@ protected function registerMainMenuItems()
'attributes' => [
'class' => 'nav-link',
'href' => '',
'data-toggle' => 'dropdown',
'data-bs-toggle' => 'dropdown',
'data-bs-auto-close' => 'outside',
],
],
'settings' => [
Expand All @@ -282,25 +277,22 @@ protected function registerMainMenuItems()
'options' => ['System\Models\Settings_model', 'listMenuSettingItems'],
'permission' => 'Site.Settings',
],
'locations' => [
'type' => 'partial',
'path' => 'locations/picker',
'options' => ['Admin\Classes\UserPanel', 'listLocations'],
],
'user' => [
'type' => 'partial',
'path' => 'top_nav_user_menu',
'options' => ['Admin\Classes\UserPanel', 'listMenuLinks'],
],
]);
});
];

Event::listen('admin.menu.extendUserMenuLinks', function (Collection $items) {
$items->put('userState', [
'priority' => 10,
'label' => 'admin::lang.text_set_status',
'iconCssClass' => 'fa fa-circle fa-fw text-'.UserState::forUser()->getStatusColorName(),
'attributes' => [
'data-toggle' => 'modal',
'data-target' => '#editStaffStatusModal',
'role' => 'button',
],
]);
if (AdminLocation::listLocations()->isEmpty())
unset($menuItems['locations']);

$manager->registerMainItems($menuItems);
});
}

Expand All @@ -321,7 +313,7 @@ protected function registerNavMenuItems()
'restaurant' => [
'priority' => 10,
'class' => 'restaurant',
'icon' => 'fa-store',
'icon' => 'fa-gem',
'title' => lang('admin::lang.side_menu.restaurant'),
'child' => [
'locations' => [
Expand Down Expand Up @@ -364,7 +356,7 @@ protected function registerNavMenuItems()
'sales' => [
'priority' => 30,
'class' => 'sales',
'icon' => 'fa-chart-bar',
'icon' => 'fa-file-invoice',
'title' => lang('admin::lang.side_menu.sale'),
'child' => [
'orders' => [
Expand Down Expand Up @@ -400,7 +392,7 @@ protected function registerNavMenuItems()
'marketing' => [
'priority' => 40,
'class' => 'marketing',
'icon' => 'fa-chart-line',
'icon' => 'fa-bullseye',
'title' => lang('admin::lang.side_menu.marketing'),
'child' => [],
],
Expand All @@ -426,27 +418,13 @@ protected function registerNavMenuItems()
],
],
],
'users' => [
'customers' => [
'priority' => 100,
'class' => 'users',
'class' => 'customers',
'icon' => 'fa-user',
'title' => lang('admin::lang.side_menu.user'),
'child' => [
'customers' => [
'priority' => 10,
'class' => 'customers',
'href' => admin_url('customers'),
'title' => lang('admin::lang.side_menu.customer'),
'permission' => 'Admin.Customers',
],
'staffs' => [
'priority' => 20,
'class' => 'staffs',
'href' => admin_url('staffs'),
'title' => lang('admin::lang.side_menu.staff'),
'permission' => 'Admin.Staffs',
],
],
'href' => admin_url('customers'),
'title' => lang('admin::lang.side_menu.customer'),
'permission' => 'Admin.Customers',
],
'localisation' => [
'priority' => 300,
Expand Down Expand Up @@ -495,7 +473,7 @@ protected function registerNavMenuItems()
'system' => [
'priority' => 999,
'class' => 'system',
'icon' => 'fa-cogs',
'icon' => 'fa-cog',
'title' => lang('admin::lang.side_menu.system'),
'child' => [
'settings' => [
Expand All @@ -505,6 +483,13 @@ protected function registerNavMenuItems()
'title' => lang('admin::lang.side_menu.setting'),
'permission' => 'Site.Settings',
],
'staffs' => [
'priority' => 10,
'class' => 'staffs',
'title' => lang('admin::lang.side_menu.user'),
'href' => admin_url('staffs'),
'permission' => 'Admin.Staffs',
],
'extensions' => [
'priority' => 20,
'class' => 'extensions',
Expand Down Expand Up @@ -539,7 +524,7 @@ protected function replaceNavMenuItem()
if (AdminLocation::check()) {
$manager->mergeNavItem('locations', [
'href' => admin_url('locations/settings'),
'title' => lang('admin::lang.side_menu.setting'),
'title' => lang('admin::lang.locations.text_form_name'),
], 'restaurant');
}
});
Expand Down Expand Up @@ -738,6 +723,10 @@ protected function registerSchedule()
Classes\Allocator::allocate();
})->name('Assignables Allocator')->withoutOverlapping(5)->runInBackground()->everyMinute();
}

$schedule->call(function () {
Classes\UserState::clearExpiredStatus();
})->name('Clear user custom away status')->withoutOverlapping(5)->runInBackground()->everyMinute();
});
}

Expand All @@ -748,13 +737,23 @@ protected function registerSystemSettings()
'setup' => [
'label' => 'lang:admin::lang.settings.text_tab_setup',
'description' => 'lang:admin::lang.settings.text_tab_desc_setup',
'icon' => 'fa fa-toggle-on',
'icon' => 'fa fa-file-invoice',
'priority' => 1,
'permission' => ['Site.Settings'],
'url' => admin_url('settings/edit/setup'),
'form' => '~/app/admin/models/config/setup_settings',
'request' => 'Admin\Requests\SetupSettings',
],
'tax' => [
'label' => 'lang:admin::lang.settings.text_tab_tax',
'description' => 'lang:admin::lang.settings.text_tab_desc_tax',
'icon' => 'fa fa-file',
'priority' => 6,
'permission' => ['Site.Settings'],
'url' => admin_url('settings/edit/tax'),
'form' => '~/app/admin/models/config/tax_settings',
'request' => 'Admin\Requests\TaxSettings',
],
'user' => [
'label' => 'lang:admin::lang.settings.text_tab_user',
'description' => 'lang:admin::lang.settings.text_tab_desc_user',
Expand All @@ -768,4 +767,37 @@ protected function registerSystemSettings()
]);
});
}

protected function extendLocationOptionsFields()
{
Event::listen('admin.locations.defineOptionsFormFields', function () {
return [
'guest_order' => [
'label' => 'lang:system::lang.settings.label_guest_order',
'accordion' => 'lang:admin::lang.locations.text_tab_general_options',
'type' => 'radiotoggle',
'comment' => 'lang:admin::lang.locations.help_guest_order',
'default' => -1,
'options' => [
-1 => 'lang:admin::lang.text_use_default',
0 => 'lang:admin::lang.text_no',
1 => 'lang:admin::lang.text_yes',
],
],
];
});

Event::listen('system.formRequest.extendValidator', function ($formRequest, $dataHolder) {
if (!$formRequest instanceof Location)
return;

$dataHolder->attributes = array_merge($dataHolder->attributes, [
'guest_order' => lang('admin::lang.locations.label_guest_order'),
]);

$dataHolder->rules = array_merge($dataHolder->rules, [
'guest_order' => ['integer'],
]);
});
}
}
4 changes: 2 additions & 2 deletions app/admin/actions/AssigneeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function assigneeBindListsEvents()
{
if ($this->controller->isClassExtendedWith('Admin\Actions\ListController')) {
Event::listen('admin.list.extendQuery', function ($listWidget, $query) {
if (!(bool)$this->getConfig('applyScopeOnListQuery', TRUE))
if (!(bool)$this->getConfig('applyScopeOnListQuery', true))
return;

$this->assigneeApplyScope($query);
Expand All @@ -110,7 +110,7 @@ protected function assigneeBindFormEvents()
{
if ($this->controller->isClassExtendedWith('Admin\Actions\FormController')) {
$this->controller->bindEvent('admin.controller.extendFormQuery', function ($query) {
if (!(bool)$this->getConfig('applyScopeOnFormQuery', TRUE))
if (!(bool)$this->getConfig('applyScopeOnFormQuery', true))
return;

$this->assigneeApplyScope($query);
Expand Down
16 changes: 8 additions & 8 deletions app/admin/actions/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ public function create_onSave($context = null)

$this->validateFormRequest($model);

if ($this->controller->formValidate($model, $this->formWidget) === FALSE)
return Request::ajax() ? ['#notification' => $this->makePartial('flash')] : FALSE;
if ($this->controller->formValidate($model, $this->formWidget) === false)
return Request::ajax() ? ['#notification' => $this->makePartial('flash')] : false;

DB::transaction(function () use ($modelsToSave) {
foreach ($modelsToSave as $modelToSave) {
Expand Down Expand Up @@ -301,8 +301,8 @@ public function edit_onSave($context = null, $recordId = null)

$this->validateFormRequest($model);

if ($this->controller->formValidate($model, $this->formWidget) === FALSE)
return Request::ajax() ? ['#notification' => $this->makePartial('flash')] : FALSE;
if ($this->controller->formValidate($model, $this->formWidget) === false)
return Request::ajax() ? ['#notification' => $this->makePartial('flash')] : false;

DB::transaction(function () use ($modelsToSave) {
foreach ($modelsToSave as $modelToSave) {
Expand Down Expand Up @@ -411,7 +411,7 @@ protected function setFormTitle($default)
$title = lang($this->getConfig('name'));
$lang = lang($this->getConfig($this->context.'[title]', $default));

$pageTitle = (strpos($lang, ':name') !== FALSE)
$pageTitle = (strpos($lang, ':name') !== false)
? str_replace(':name', $title, $lang) : $lang;

Template::setTitle($pageTitle);
Expand Down Expand Up @@ -448,7 +448,7 @@ public function makeRedirect($context = null, $model = null)
$context .= '-close';
}

if (post('refresh', FALSE)) {
if (post('refresh', false)) {
return $this->controller->refresh();
}

Expand Down Expand Up @@ -527,9 +527,9 @@ protected function setModelAttributes($model, $saveData)

protected function validateFormRequest($model)
{
$requestClass = $this->getConfig('request', FALSE);
$requestClass = $this->getConfig('request', false);

if ($requestClass === FALSE)
if ($requestClass === false)
return;

if (!class_exists($requestClass))
Expand Down
10 changes: 5 additions & 5 deletions app/admin/actions/LocationAwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function locationApplyScope($query)
if (is_null($ids = AdminLocation::getIdOrAll()))
return;

(bool)$this->getConfig('addAbsenceConstraint', TRUE)
(bool)$this->getConfig('addAbsenceConstraint', true)
? $query->whereHasOrDoesntHaveLocation($ids)
: $query->whereHasLocation($ids);
}
Expand All @@ -68,20 +68,20 @@ protected function locationBindEvents()
{
if ($this->controller->isClassExtendedWith('Admin\Actions\ListController')) {
Event::listen('admin.list.extendQuery', function ($listWidget, $query) {
if ((bool)$this->getConfig('applyScopeOnListQuery', TRUE))
if ((bool)$this->getConfig('applyScopeOnListQuery', true))
$this->locationApplyScope($query);
});

Event::listen('admin.filter.extendQuery', function ($filterWidget, $query, $scope) {
if (array_get($scope->config, 'locationAware') === TRUE
&& (bool)$this->getConfig('applyScopeOnListQuery', TRUE)
if (array_get($scope->config, 'locationAware') === true
&& (bool)$this->getConfig('applyScopeOnListQuery', true)
) $this->locationApplyScope($query);
});
}

if ($this->controller->isClassExtendedWith('Admin\Actions\FormController')) {
$this->controller->bindEvent('admin.controller.extendFormQuery', function ($query) {
if ((bool)$this->getConfig('applyScopeOnFormQuery', TRUE))
if ((bool)$this->getConfig('applyScopeOnFormQuery', true))
$this->locationApplyScope($query);
});
}
Expand Down
Loading

0 comments on commit 55351d3

Please sign in to comment.