|
|
@ -13,11 +13,22 @@ use MightyPork\Exceptions\NotApplicableException; |
|
|
|
|
|
|
|
|
|
|
|
class TableController extends Controller |
|
|
|
class TableController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
public function view(User $user, string $table) |
|
|
|
public function view(Request $request, User $user, string $table) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$input = $this->validate($request, [ |
|
|
|
|
|
|
|
'rev' => 'nullable|int' |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
/** @var Table $tableModel */ |
|
|
|
/** @var Table $tableModel */ |
|
|
|
$tableModel = $user->tables()->where('name', $table)->first(); |
|
|
|
$tableModel = $user->tables()->where('name', $table)->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($input->has('rev')) { |
|
|
|
|
|
|
|
$rev = (int)$input->rev; |
|
|
|
|
|
|
|
$revision = $tableModel->revisions()->orderBy('created_at')->skip($rev)->first(); |
|
|
|
|
|
|
|
if ($revision === null) abort(404, "No such revision"); |
|
|
|
|
|
|
|
} else { |
|
|
|
$revision = $tableModel->revision; |
|
|
|
$revision = $tableModel->revision; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return view('table.view', [ |
|
|
|
return view('table.view', [ |
|
|
|
'table' => $tableModel, |
|
|
|
'table' => $tableModel, |
|
|
@ -113,6 +124,7 @@ class TableController extends Controller |
|
|
|
$rowsData = null; |
|
|
|
$rowsData = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
$rowsData = array_map(function ($row) use ($columns) { |
|
|
|
$rowsData = array_map(function ($row) use ($columns) { |
|
|
|
|
|
|
|
if (count($row) == 0 || count($row)==1&&$row[0]=='') return null; |
|
|
|
if (count($row) != count($columns)) { |
|
|
|
if (count($row) != count($columns)) { |
|
|
|
throw new NotApplicableException("All rows must have " . count($columns) . " fields."); |
|
|
|
throw new NotApplicableException("All rows must have " . count($columns) . " fields."); |
|
|
|
} |
|
|
|
} |
|
|
@ -129,8 +141,10 @@ class TableController extends Controller |
|
|
|
'data' => json_encode($parsed), |
|
|
|
'data' => json_encode($parsed), |
|
|
|
]; |
|
|
|
]; |
|
|
|
}, $rowTable); |
|
|
|
}, $rowTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rowsData = array_filter($rowsData); |
|
|
|
} catch (\Exception $e) { |
|
|
|
} catch (\Exception $e) { |
|
|
|
return $this->backWithErrors(['columns' => $e->getMessage()]); |
|
|
|
return $this->backWithErrors(['data' => $e->getMessage()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$revisionFields = [ |
|
|
|
$revisionFields = [ |
|
|
|