improved bulk actions detection
This commit is contained in:
parent
9d82b15651
commit
e0941e60fc
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\ViewComposers;
|
namespace App\Http\ViewComposers;
|
||||||
|
|
||||||
|
use Akaunting\Module\Module;
|
||||||
use Date;
|
use Date;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
@ -15,6 +16,13 @@ class Index
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function compose(View $view)
|
public function compose(View $view)
|
||||||
|
{
|
||||||
|
$this->addLimits($view);
|
||||||
|
|
||||||
|
$this->addBulkActions($view);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addLimits(&$view)
|
||||||
{
|
{
|
||||||
$limits = ['10' => '10', '25' => '25', '50' => '50', '100' => '100'];
|
$limits = ['10' => '10', '25' => '25', '50' => '50', '100' => '100'];
|
||||||
|
|
||||||
@ -30,38 +38,39 @@ class Index
|
|||||||
}
|
}
|
||||||
|
|
||||||
$view->with(['limits' => $limits, 'this_year' => $this_year, 'years' => $years]);
|
$view->with(['limits' => $limits, 'this_year' => $this_year, 'years' => $years]);
|
||||||
|
}
|
||||||
|
|
||||||
// Add Bulk Action
|
protected function addBulkActions(&$view)
|
||||||
$module = false;
|
{
|
||||||
$view_name = $view->getName();
|
$class_name = '';
|
||||||
|
$view_name = str_replace('.index', '', $view->getName());
|
||||||
|
|
||||||
if (Str::contains($view_name, '::')) {
|
if (Str::contains($view_name, '::')) {
|
||||||
|
// my-blog::posts
|
||||||
$names = explode('::', $view_name);
|
$names = explode('::', $view_name);
|
||||||
|
|
||||||
$params = explode('.', $names[1]);
|
|
||||||
|
|
||||||
$group = $params[0];
|
|
||||||
$type = $params[1];
|
|
||||||
|
|
||||||
// Check is module
|
|
||||||
$module = module($names[0]);
|
$module = module($names[0]);
|
||||||
|
|
||||||
|
if (!$module instanceof Module) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = explode('.', $names[1]);
|
||||||
|
$file_name = !empty($tmp[1]) ? Str::studly($tmp[0]) . '\\' . Str::studly($tmp[1]) : Str::studly($tmp[0]);
|
||||||
|
|
||||||
|
$class_name = 'Modules\\' . $module->getStudlyName() . '\BulkActions\\' . $file_name;
|
||||||
} else {
|
} else {
|
||||||
$params = explode('.', $view_name);
|
// common.items
|
||||||
|
$tmp = explode('.', $view_name);
|
||||||
|
$file_name = !empty($tmp[1]) ? Str::studly($tmp[0]) . '\\' . Str::studly($tmp[1]) : Str::studly($tmp[0]);
|
||||||
|
|
||||||
$group = $params[0];
|
$class_name = 'App\BulkActions\\' . $file_name;
|
||||||
$type = $params[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($module instanceof \Akaunting\Module\Module) {
|
if (!class_exists($class_name)) {
|
||||||
$class = 'Modules\\' . $module->getStudlyName() . '\BulkActions\\' . ucfirst($group) . '\\' . ucfirst($type);
|
return;
|
||||||
} else {
|
|
||||||
$class = 'App\BulkActions\\' . ucfirst($group) . '\\' . ucfirst($type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists($class)) {
|
$view->with(['bulk_actions' => app($class_name)->actions]);
|
||||||
$bulk_actions = app($class);
|
|
||||||
|
|
||||||
$view->with(['bulk_actions' => $bulk_actions->actions]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user