/** @test */ public function it_saves_and_loads_query_state() { $request = Mockery::mock('Illuminate\\Http\\Request'); $request->shouldReceive('query')->once()->andReturn(['name' => 'value']); $session = Mockery::mock('Illuminate\\Session\\Store'); $session->shouldReceive('set')->with('model_name.index.query', ['name' => 'value'])->once(); $session->shouldReceive('get')->with('model_name.index.query')->once()->andReturn(['name' => 'value']); $queryState = new QueryState($session, $request); $queryState->setPrefix('model_name'); $queryState->save(); $state = $queryState->load(); $this->assertEquals(['name' => 'value'], $state); }
/** * @return View */ public function table() { if ($result = $this->checkCustomActionCall()) { return $result; } if (Input::get('datatable_request')) { return $this->asyncTable(); } $this->queryState->save(); $columns = $this->modelItem->getColumns(); $unsortableColumns = []; $nameToSequanceNumber = []; foreach ($columns as $i => $column) { $nameToSequanceNumber[$column->getName()] = $i; if ($column->isSortable() == false) { $unsortableColumns[] = $i; } } $viewFilters = $this->modelItem->getViewFilters(); $jsFilters = []; foreach ($viewFilters as $i => $filter) { $filterData = ['type' => $filter->getFilterType(), 'sequanceNumber' => isset($nameToSequanceNumber[$filter->getName()]) ? $nameToSequanceNumber[$filter->getName()] : null]; if ($filter->getFilterType() == \SleepingOwl\Admin\ViewFilters\ViewFilter\Date::TYPE) { $filterData['rule'] = $filter->getRule(); } $jsFilters[] = $filterData; } $data = ['title' => $this->modelItem->getTitle(), 'columns' => $columns, 'viewFilters' => $viewFilters, 'newEntryRoute' => $this->admin_router->routeToCreate($this->modelName, Input::query()), 'modelItem' => $this->modelItem, 'unsortableColumns' => $unsortableColumns, 'jsFilters' => $jsFilters, 'rows' => []]; if (!$this->modelItem->isAsync()) { $tableData = []; try { $tableData = $this->modelRepository->tableData(); } catch (ModelNotFoundException $e) { return $this->pageNotFound(); } $data = array_merge($data, $tableData); } $data['subtitle'] = $this->modelRepository->getSubtitle(); return $this->makeView('model.table', $data); }
/** * @return View */ public function table() { if ($result = $this->checkCustomActionCall()) { return $result; } if (Input::get('datatable_request')) { return $this->asyncTable(); } $this->queryState->save(); $data = ['title' => $this->modelItem->getTitle(), 'columns' => $this->modelItem->getColumns(), 'newEntryRoute' => $this->admin_router->routeToCreate($this->modelName, Input::query()), 'modelItem' => $this->modelItem, 'rows' => []]; if (!$this->modelItem->isAsync()) { $tableData = []; try { $tableData = $this->modelRepository->tableData(); } catch (ModelNotFoundException $e) { App::abort(404); } $data = array_merge($data, $tableData); } $data['subtitle'] = $this->modelRepository->getSubtitle(); return $this->makeView('model.table', $data); }