Skip to content

Commit

Permalink
Merge pull request #442 from nextcloud/replace-base-view-with-dashboard
Browse files Browse the repository at this point in the history
Replace base view with dashboard
  • Loading branch information
Hephi2 committed Aug 3, 2023
2 parents fc54bd9 + b6fbb83 commit 0abc927
Show file tree
Hide file tree
Showing 56 changed files with 1,398 additions and 745 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Share your tables with users and groups within your cloud.
Have a good time and manage whatever you want.
]]></description>
<version>0.6.0-dev0</version>
<version>0.6.0-dev1</version>
<licence>agpl</licence>
<author mail="florian.steffens@nextcloud.com" >Florian Steffens</author>
<namespace>Tables</namespace>
Expand Down
9 changes: 6 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
['name' => 'api1#createColumn', 'url' => '/api/1/views/{viewId}/columns', 'verb' => 'POST'],
['name' => 'api1#updateColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'PUT'],
['name' => 'api1#getColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'GET'],
['name' => 'api1#deleteColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'DELETE'],
['name' => 'api1#deleteColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'DELETE'],
// -> rows
['name' => 'api1#indexTableRowsSimple', 'url' => '/api/1/tables/{tableId}/rows/simple', 'verb' => 'GET'],
['name' => 'api1#indexViewRows', 'url' => '/api/1/views/{viewId}/rows', 'verb' => 'GET'],
Expand All @@ -63,20 +63,23 @@
['name' => 'view#destroy', 'url' => '/view/{id}', 'verb' => 'DELETE'],

// columns
['name' => 'column#index', 'url' => '/view/{viewId}/column/{tableId}', 'verb' => 'GET'],
['name' => 'column#indexTableByView', 'url' => '/column/table/{tableId}/view/{viewId}', 'verb' => 'GET'],
['name' => 'column#index', 'url' => '/column/table/{tableId}', 'verb' => 'GET'],
['name' => 'column#show', 'url' => '/column/{id}', 'verb' => 'GET'],
['name' => 'column#indexView', 'url' => '/column/view/{viewId}', 'verb' => 'GET'],
['name' => 'column#create', 'url' => '/column', 'verb' => 'POST'],
['name' => 'column#update', 'url' => '/column/{id}', 'verb' => 'PUT'],
['name' => 'column#destroy', 'url' => '/column/{id}', 'verb' => 'DELETE'],

// rows
['name' => 'row#index', 'url' => '/row/table/{tableId}', 'verb' => 'GET'],
['name' => 'row#show', 'url' => '/row/{id}', 'verb' => 'GET'],
['name' => 'row#indexView', 'url' => '/row/view/{viewId}', 'verb' => 'GET'],
['name' => 'row#create', 'url' => '/row', 'verb' => 'POST'],
['name' => 'row#update', 'url' => '/row/{id}/column/{columnId}', 'verb' => 'PUT'],
['name' => 'row#updateSet', 'url' => '/row/{id}', 'verb' => 'PUT'],
['name' => 'row#destroy', 'url' => '/view/{viewId}/row/{id}', 'verb' => 'DELETE'],
['name' => 'row#destroyByView', 'url' => '/view/{viewId}/row/{id}', 'verb' => 'DELETE'],
['name' => 'row#destroy', 'url' => '/table/{tableId}/row/{id}', 'verb' => 'DELETE'],

// shares
['name' => 'share#index', 'url' => '/share/table/{tableId}', 'verb' => 'GET'],
Expand Down
16 changes: 14 additions & 2 deletions lib/Controller/ColumnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ public function __construct(
/**
* @NoAdminRequired
*/
public function index(int $tableId, int $viewId): DataResponse {
public function index(int $tableId, ?int $viewId): DataResponse {
return $this->handleError(function () use ($tableId, $viewId) {
return $this->service->findAllByTable($tableId, $viewId);
});
}

/**
* @NoAdminRequired
*/
public function indexTableByView(int $tableId, ?int $viewId): DataResponse {
return $this->handleError(function () use ($tableId, $viewId) {
return $this->service->findAllByTable($tableId, $viewId);
});
Expand Down Expand Up @@ -60,7 +69,8 @@ public function show(int $id): DataResponse {
* @NoAdminRequired
*/
public function create(
int $viewId,
?int $tableId,
?int $viewId,
string $type,
?string $subtype,
string $title,
Expand All @@ -85,6 +95,7 @@ public function create(
?array $selectedViewIds
): DataResponse {
return $this->handleError(function () use (
$tableId,
$viewId,
$type,
$subtype,
Expand All @@ -110,6 +121,7 @@ public function create(
$selectedViewIds) {
return $this->service->create(
$this->userId,
$tableId,
$viewId,
$type,
$subtype,
Expand Down
37 changes: 31 additions & 6 deletions lib/Controller/RowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public function __construct(
$this->userId = $userId;
}

/**
* @NoAdminRequired
*/
public function index(int $tableId): DataResponse {
return $this->handleError(function () use ($tableId) {
return $this->service->findAllByTable($tableId);
});
}

/**
* @NoAdminRequired
*/
Expand All @@ -53,11 +62,13 @@ public function show(int $id): DataResponse {
* @NoAdminRequired
*/
public function create(
int $viewId,
?int $tableId,
?int $viewId,
array $data
): DataResponse {
return $this->handleError(function () use ($viewId, $data) {
return $this->handleError(function () use ($tableId, $viewId, $data) {
return $this->service->create(
$tableId,
$viewId,
$data);
});
Expand All @@ -69,17 +80,20 @@ public function create(
public function update(
int $id,
int $columnId,
int $viewId,
?int $tableId,
?int $viewId,
string $data
): DataResponse {
return $this->handleError(function () use (
$id,
$tableId,
$viewId,
$columnId,
$data
) {
return $this->service->update(
$id,
$tableId,
$viewId,
$columnId,
$data,
Expand All @@ -92,17 +106,20 @@ public function update(
*/
public function updateSet(
int $id,
int $viewId,
?int $tableId,
?int $viewId,
array $data

): DataResponse {
return $this->handleError(function () use (
$id,
$tableId,
$viewId,
$data
) {
return $this->service->updateSet(
$id,
$tableId,
$viewId,
$data,
$this->userId);
Expand All @@ -112,9 +129,17 @@ public function updateSet(
/**
* @NoAdminRequired
*/
public function destroy(int $id, int $viewId): DataResponse {
public function destroy(int $id, int $tableId): DataResponse {
return $this->handleError(function () use ($id, $tableId) {
return $this->service->delete($id, $tableId, null, $this->userId);
});
}
/**
* @NoAdminRequired
*/
public function destroyByView(int $id, int $viewId): DataResponse {
return $this->handleError(function () use ($id, $viewId) {
return $this->service->delete($id, $viewId, $this->userId);
return $this->service->delete($id, null, $viewId, $this->userId);
});
}
}
40 changes: 40 additions & 0 deletions lib/Db/ColumnMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ public function findAllByTable(int $tableID): array {
return $this->findEntities($qb);
}

/**
* @param integer $tableID
* @return array
* @throws Exception
*/
public function findAllIdsByTable(int $tableID): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id')
->from($this->table)
->where($qb->expr()->eq('table_id', $qb->createNamedParameter($tableID)));
$result = $qb->executeQuery();
$ids = [];
while ($row = $result->fetch()) {
$ids[] = $row['id'];
}
return $ids;
}

/**
* @param array $neededColumnIds
* @return array<string> Array with key = columnId and value = [column-type]-[column-subtype]
Expand Down Expand Up @@ -77,4 +95,26 @@ public function getColumnTypes(array $neededColumnIds): array {
}
return $out;
}


/**
* @param int $tableId
* @return int
*/
public function countColumns(int $tableId): int {
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('*', 'counter'));
$qb->from($this->table);
$qb->where(
$qb->expr()->eq('table_id', $qb->createNamedParameter($tableId))
);

try {
$result = $this->findOneQuery($qb);
return (int)$result['counter'];
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
$this->logger->warning('Exception occurred: '.$e->getMessage().' Returning 0.');
return 0;
}
}
}
45 changes: 24 additions & 21 deletions lib/Db/RowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,13 @@ private function addOrderByRules(IQueryBuilder $qb, $sortArray) {
}
}

/**
*
*/
public function countRowsForBaseView(View $view): int {
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('*', 'counter'));
$qb->from($this->table);
$qb->where(
$qb->expr()->eq('table_id', $qb->createNamedParameter($view->getTableId()))
);

try {
$result = $this->findOneQuery($qb);
return (int)$result['counter'];
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
$this->logger->warning('Exception occurred: '.$e->getMessage().' Returning 0.');
return 0;
}
}

/**
* @param View $view
* @param $userId
* @return int
* @throws InternalError
*/
public function countRowsForNotBaseView(View $view, $userId): int {
public function countRowsForView(View $view, $userId): int {
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('*', 'counter'))
->from($this->table)
Expand Down Expand Up @@ -252,6 +232,29 @@ private function addFilterToQuery(IQueryBuilder $qb, View $view, array $neededCo
}
}

/**
* @param int $tableId
* @param int|null $limit
* @param int|null $offset
* @return array
* @throws Exception
*/
public function findAllByTable(int $tableId, ?int $limit = null, ?int $offset = null): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->table)
->where($qb->expr()->eq('table_id', $qb->createNamedParameter($tableId)));

if ($limit !== null) {
$qb->setMaxResults($limit);
}
if ($offset !== null) {
$qb->setFirstResult($offset);
}

return $this->findEntities($qb);
}

/**
* @param View $view
* @param string $userId
Expand Down
1 change: 0 additions & 1 deletion lib/Db/ShareMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function findAllSharesForNode(string $nodeType, int $nodeId, string $send
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->table)
->where($qb->expr()->eq('sender', $qb->createNamedParameter($sender, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter($nodeType, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT)));
return $this->findEntities($qb);
Expand Down
20 changes: 14 additions & 6 deletions lib/Db/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
/**
* @psalm-suppress PropertyNotSetInConstructor
*
* @method getTitle(): string
* @method setTitle(string $title)
* @method getEmoji(): string
* @method setEmoji(string $emoji)
* @method getOwnership(): string
* @method setOwnership(string $ownership)
* @method getOwnerDisplayName(): string
Expand All @@ -20,10 +24,12 @@
* @method setHasShares(bool $hasShares)
* @method getRowsCount(): int
* @method setRowsCount(int $rowsCount)
* @method getBaseView(): View
* @method setBaseView(View $setBaseView)
* @method getColumnsCount(): int
* @method setColumnsCount(int $rowsCount)
* @method getViews(): array
* @method setViews(array $setViews)
* @method setViews(array $views)
* @method getColumns(): array
* @method setColumns(array $columns)
* @method getCreatedBy(): string
* @method setCreatedBy(string $createdBy)
* @method getCreatedAt(): string
Expand All @@ -35,7 +41,6 @@
*/
class Table extends Entity implements JsonSerializable {
protected ?string $title = null;

protected ?string $emoji = null;
protected ?string $ownership = null;
protected ?string $ownerDisplayName = null;
Expand All @@ -48,8 +53,9 @@ class Table extends Entity implements JsonSerializable {

protected ?bool $hasShares = false;
protected ?int $rowsCount = 0;
protected ?View $baseView = null;
protected ?int $columnsCount = 0;
protected ?array $views = null;
protected ?array $columns = null;

public function __construct() {
$this->addType('id', 'integer');
Expand All @@ -58,6 +64,8 @@ public function __construct() {
public function jsonSerialize(): array {
return [
'id' => $this->id,
'title' => $this->title,
'emoji' => $this->emoji,
'ownership' => $this->ownership,
'ownerDisplayName' => $this->ownerDisplayName,
'createdBy' => $this->createdBy,
Expand All @@ -68,7 +76,7 @@ public function jsonSerialize(): array {
'onSharePermissions' => $this->onSharePermissions,
'hasShares' => $this->hasShares,
'rowsCount' => $this->rowsCount,
'baseView' => $this->baseView,
'columnsCount' => $this->columnsCount,
'views' => $this->views,
];
}
Expand Down
Loading

0 comments on commit 0abc927

Please sign in to comment.