/** * @param Resource $resource * @param array $pages */ public function onCreatedResourcePages(array $pages) { $index = $pages['index']; $create = $pages['create']; $edit = $pages['edit']; $destroy = $pages['destroy']; foreach ($pages as $action => $page) { // Left menu root node $left = Node::create(array('title' => $page->title, 'page_id' => $page->id, 'container_id' => \NavigationContainersTableSeeder::LEFT)); // Right menu root node $right = Node::create(array('title' => $page->title, 'page_id' => $page->id, 'container_id' => \NavigationContainersTableSeeder::RIGHT)); $base = substr($page->alias, 0, strrpos($page->alias, '.')); switch ($action) { case 'index': $left->children()->create(array('title' => 'Dashboard', 'page_id' => Page::whereAlias('admin.index')->first()->id, 'link_class' => 'btn btn-default')); $right->children()->create(array('title' => $create->title, 'page_id' => $create->id, 'link_class' => 'btn btn-primary')); break; case 'create': $left->children()->create(array('title' => $index->title, 'page_id' => $index->id, 'link_class' => 'btn btn-default')); break; case 'edit': $left->children()->create(array('title' => $index->title, 'page_id' => $index->id, 'link_class' => 'btn btn-default')); // Delete $right->children()->create(array('title' => $destroy->title, 'page_id' => $destroy->id, 'link_class' => 'btn btn-danger')); break; } } }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Installing...' . PHP_EOL; foreach (array('resources', 'layouts', 'sections', 'blocks', 'pages', 'content', 'navigation_container', 'navigation_node') as $table) { if (Schema::hasTable($table)) { Schema::drop($table); } } echo 'Creating resources...' . PHP_EOL; $controller = App::make('Boyhagemann\\Admin\\Controller\\ResourceController'); $controller->getModelBuilder()->export(); $layout = App::make('Boyhagemann\\Pages\\Controller\\LayoutController'); $layout->getModelBuilder()->export(); $section = App::make('Boyhagemann\\Pages\\Controller\\SectionController'); $section->getModelBuilder()->export(); $block = App::make('Boyhagemann\\Pages\\Controller\\BlockController'); $block->getModelBuilder()->export(); $page = App::make('Boyhagemann\\Pages\\Controller\\PageController'); $page->getModelBuilder()->export(); $content = App::make('Boyhagemann\\Pages\\Controller\\ContentController'); $content->getModelBuilder()->export(); $container = App::make('Boyhagemann\\Navigation\\Controller\\ContainerController'); $container->getModelBuilder()->export(); $node = App::make('Boyhagemann\\Navigation\\Controller\\NodeController'); $node->getModelBuilder()->export(); echo 'Seeding resources...' . PHP_EOL; Layout::create(array('title' => 'Admin Layout', 'name' => 'admin::layouts.admin')); Layout::create(array('title' => 'Default Layout', 'name' => 'layouts.default')); Section::create(array('id' => 1, 'title' => 'Main content', 'name' => 'content', 'layout_id' => 1)); Section::create(array('id' => 2, 'title' => 'Sidebar', 'name' => 'sidebar', 'layout_id' => 1)); Section::create(array('id' => 3, 'title' => 'Main Menu', 'name' => 'menu', 'layout_id' => 1)); Section::create(array('id' => 4, 'title' => 'Content', 'name' => 'content', 'layout_id' => 2)); Container::create(array('id' => 1, 'title' => 'Admin menu', 'name' => 'admin')); $contentNode = Node::create(array('id' => 1, 'title' => 'Content', 'container_id' => 1)); Block::create(array('id' => 1, 'title' => 'Admin menu', 'controller' => 'Boyhagemann\\Navigation\\Controller\\MenuController@admin')); Block::create(array('id' => 2, 'title' => 'Copy resource', 'controller' => 'Boyhagemann\\Admin\\Controller\\ResourceController@copy')); Block::create(array('id' => 3, 'title' => 'Text', 'controller' => 'Boyhagemann\\Text\\Controller\\TextController@text')); Content::create(array('global' => 1, 'page_id' => 1, 'section_id' => 3, 'block_id' => 1)); Page::createWithContent('Admin home', '/admin', 'Boyhagemann\\Admin\\Controller\\IndexController@index', 'get', 'admin::layouts.admin'); Page::createWithContent('Page content', '/admin/pages/{page}/content', 'Boyhagemann\\Pages\\Controller\\PageController@content', 'get', 'admin::layouts.admin'); Page::createWithContent('Add content', '/admin/pages/{page}/content/create/{block}', 'Boyhagemann\\Pages\\Controller\\PageController@addContent', 'get', 'admin::layouts.admin'); $tree = Page::createWithContent('Tree', '/admin/nodes/tree', 'Boyhagemann\\Navigation\\Controller\\NodeController@tree', 'get', 'admin::layouts.admin'); Node::create(array('id' => 2, 'title' => 'Tree', 'container_id' => 1, 'page_id' => $tree->id)); echo 'Registering resources...' . PHP_EOL; $controller->save('Layout', 'admin/layouts', get_class($layout)); $controller->save('Section', 'admin/sections', get_class($section)); $controller->save('Block', 'admin/blocks', get_class($block)); $controller->save('Pages', 'admin/pages', get_class($page)); $controller->save('Content', 'admin/content', get_class($content)); $controller->save('Container', 'admin/containers', get_class($container)); $controller->save('Node', 'admin/nodes', get_class($node)); echo 'Creating pages and navigation...' . PHP_EOL; foreach (App::make('Boyhagemann\\Admin\\Model\\Resource')->get() as $resource) { $controller->savePages($resource); $controller->saveNavigation($resource, $contentNode); } echo 'Done.' . PHP_EOL; }
public function admin() { $menu = App::make('Menu\\Menu'); $this->menu = $menu->handler('admin', array('class' => 'nav navbar-nav')); $nodes = Node::whereDepth(0)->whereContainerId(1)->with('page')->get(); foreach ($nodes as $node) { $this->buildMenu($node); } return $this->menu->render(); }
public function container($container, $class = 'nav navbar-nav') { $this->menu = App::make('Menu\\Menu')->handler($container, compact('class')); $nodes = Node::getChildrenByRouteAndContainer(Route::currentRouteName(), $container); if (!$nodes->count()) { return; } foreach ($nodes as $node) { $this->buildMenu($node); } return $this->menu->render(); }
/** * @param Model $model * @param CrudController $controller */ public function onSaved(Model $model, CrudController $controller) { // We are only interested in a resource controller if (!$controller instanceof ResourceController) { return; } // When the form is posted, we need this field. // If it is not checked, then we don't have to do anything. if (!Input::get('create_dashboard_navigation')) { return; } // Add a dashboard app pointing to the 'create' route of this resource Node::create(array('title' => sprintf('Create %s', Str::lower($model->title)), 'description' => Input::get('description'), 'page_id' => Page::whereAlias(sprintf('admin.%s.create', Str::slug($model->title)))->first()->id, 'icon_class' => 'icon-file', 'container_id' => NavigationContainersTableSeeder::DASHBOARD)); }
public function saveNavigation(Resource $resource, Node $baseNode = null) { $container = Container::whereName('admin')->first(); $pages = $resource->pages; foreach ($pages as $page) { $node = new Node(); $node->title = $page->title; $node->page()->associate($page); $node->container()->associate($container); $node->save(); if (trim($page->route, '/') == $resource->url) { $root = $node; if ($baseNode) { $root->makeChildOf($baseNode); } } else { $node->makeChildOf($root); } } }