/** * Renders grid. * * @return View|string */ public function render() { $key = $this->getInputProcessor()->getUniqueRequestId(); $caching_time = $this->config->getCachingTime(); if ($caching_time && ($output = Cache::get($key))) { return $output; } else { $this->prepare(); $provider = $this->config->getDataProvider(); $provider->reset(); $output = View::make($this->getMainTemplate(), $this->getViewData())->render(); if ($caching_time) { Cache::put($key, $output, $caching_time); } return $output; } }
/** * @return View */ public function render() { $key = $this->getInputProcessor()->getUniqueRequestId(); $caching_time = $this->config->getCachingTime(); if ($caching_time and $output = Cache::get($key)) { return $output; } else { $this->prepare(); // if ($dp = Cache::get($key)) { // $this->config->setDataProvider($dp); // } else { // $dp = $this->config->getDataProvider(); // $dp->reset(); # performs query // Cache::put($key, $dp, 5); // } $provider = $this->config->getDataProvider(); $provider->reset(); $output = View::make($this->getMainTemplate(), $this->getViewData())->render(); if ($caching_time) { Cache::put($key, $output, $caching_time); } return $output; } }
public function getShow($id) { /** @var Operation $operation $op */ $operation = Operation::findOrFail($id); Model::$current_table = $operation->getDiffTableAttribute(); $model = new Model(); $query = $model->newQuery(); $diff = $operation->getDiffProcessor(); foreach ($diff->getPkColumns() as $name) { $query->addSelect($name); } foreach ($diff->getDiffColumns() as $name) { $query->addSelect("{$name}_1"); $query->addSelect("{$name}_2"); $query->addSelect(DB::raw("{$name}_1 - {$name}_2 as {$name}_diff")); } $dp = new EloquentDataProvider($query); $config = new GridConfig(); $config->setDataProvider($dp); foreach ($diff->getPkColumns() as $name) { $config->addColumn((new FieldConfig())->setName($name)->setSortable(true)->addFilter(new FilterConfig())); } foreach ($diff->getDiffColumns() as $name) { $config->addColumn((new FieldConfig())->setName("{$name}_1")->setSortable(true)); $config->addColumn((new FieldConfig())->setName("{$name}_2")->setSortable(true)); $config->addColumn((new FieldConfig())->setName("{$name}_diff")->setSortable(true)); } $config->getComponentByName(THead::NAME)->addComponent((new OneCellRow())->setComponents([new RecordsPerPage(), new ColumnsHider(), new RenderFunc(function () { return ' <button class="btn btn-primary"> <span class="glyphicon glyphicon-filter"></span> Filter </button>'; })])->setRenderSection(THead::SECTION_END)); $grid = new Grid($config); return \View::make('db-diff::show', compact('grid', 'operation')); }