stub of the row editor
This commit is contained in:
@@ -26,7 +26,9 @@ class BaseModel extends Model
|
||||
public function getRelationValue($key)
|
||||
{
|
||||
if ($this->exists && !method_exists($this, $key)) {
|
||||
throw new \LogicException("No attribute or relation ".var_export($key, true));
|
||||
if (!isset($this->original[$key])) {
|
||||
throw new \LogicException("No attribute or relation " . var_export($key, true));
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getRelationValue($key);
|
||||
|
||||
@@ -40,12 +40,12 @@ class Revision extends BaseModel
|
||||
* @param Column[] $columns
|
||||
* @return \Illuminate\Database\Query\Builder|static
|
||||
*/
|
||||
public function rowsData($columns, $withId=true)
|
||||
public function rowsData($columns, $withId=true, $named=true)
|
||||
{
|
||||
$selects = $withId ? ["data->>'_id' as _id"] : [];
|
||||
|
||||
foreach ($columns as $col) {
|
||||
$selects[] = "data->>'$col->id' as $col->name";
|
||||
$selects[] = "data->>'$col->id' as " . ($named ? $col->name : $col->id);
|
||||
}
|
||||
|
||||
return $this->rows()->select([])->selectRaw(implode(', ', $selects));
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ namespace App\Models;
|
||||
* Row in a data table
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $data - JSONB, always containing _id
|
||||
* @property object|\RowData $data - JSONB, always containing _id
|
||||
*/
|
||||
class Row extends BaseModel
|
||||
{
|
||||
|
||||
+22
-9
@@ -22,7 +22,9 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
* @property string $origin
|
||||
* @property int $visits
|
||||
* @property-read string $viewRoute
|
||||
* @property-read string $draftRoute
|
||||
* @property-read string $settingsRoute
|
||||
* @property-read string $deleteRoute
|
||||
* @property-read User $owner
|
||||
* @property-read Table $parentTable
|
||||
* @property-read Table[]|Collection $forks
|
||||
@@ -123,21 +125,32 @@ class Table extends BaseModel
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name == 'viewRoute') {
|
||||
return route('table.view', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
|
||||
}
|
||||
if (ends_with($name, 'Route')) {
|
||||
$arg = [
|
||||
'user' => $this->cachedOwner()->name,
|
||||
'table' => $this->name
|
||||
];
|
||||
|
||||
if ($name == 'settingsRoute') {
|
||||
return route('table.conf', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
|
||||
}
|
||||
|
||||
if ($name == 'deleteRoute') {
|
||||
return route('table.delete', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
|
||||
switch ($name) {
|
||||
case 'viewRoute': return route('table.view', $arg);
|
||||
case 'settingsRoute': return route('table.conf', $arg);
|
||||
case 'draftRoute': return route('table.draft', $arg);
|
||||
case 'deleteRoute': return route('table.delete', $arg);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
public function getDraftRoute($tab=null)
|
||||
{
|
||||
return route('table.draft', [
|
||||
'user' => $this->cachedOwner()->name,
|
||||
'table' => $this->name,
|
||||
'tab' => $tab,
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopeForList(Builder $query)
|
||||
{
|
||||
return $query->with('revision:id,row_count')->with('owner:id,name,title')
|
||||
|
||||
Reference in New Issue
Block a user