Skip to content

Commit

Permalink
Show row id in url for row widget
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Hempel <Philipp.Hempel1@web.de>
  • Loading branch information
Hephi2 committed Aug 9, 2023
1 parent 9b64210 commit 7c4f5b6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 49 deletions.
76 changes: 37 additions & 39 deletions lib/Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,37 +289,48 @@ private function enhanceView(View $view, string $userId): void {
// set if this is a shared table with you (somebody else shared it with you)
// (senseless if we have no user in context)
if ($userId !== '') {
try {
$permissions = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getId(), 'view', $userId);
$view->setIsShared(true);
$canManageTable = false;
if ($userId !== $view->getOwnership()) {
try {
$manageTableShare = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getTableId(), 'table', $userId);
$canManageTable = $manageTableShare['manage'] ?? false;
$permissions = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getId(), 'view', $userId);
$view->setIsShared(true);
$canManageTable = false;
try {
$manageTableShare = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getTableId(), 'table', $userId);
$canManageTable = $manageTableShare['manage'] ?? false;
} catch (NotFoundError $e) {
} catch (\Exception $e) {
throw new InternalError($e);
}
$view->setOnSharePermissions([
'read' => $permissions['read'] ?? false,
'create' => $permissions['create'] ?? false,
'update' => $permissions['update'] ?? false,
'delete' => $permissions['delete'] ?? false,
'manage' => $permissions['manage'] ?? false,
'manageTable' => $canManageTable
]);
} catch (NotFoundError $e) {
} catch (\Exception $e) {
throw new InternalError($e);
$this->logger->warning('Exception occurred while setting shared permissions: '.$e->getMessage().' No permissions granted.');
$view->setOnSharePermissions([
'read' => false,
'create' => false,
'update' => false,
'delete' => false,
'manage' => false,
'manageTable' => false
]);
}
} else {
// set hasShares if this table is shared by you (you share it with somebody else)
// (senseless if we have no user in context)
try {
$allShares = $this->shareService->findAll('view', $view->getId());
$view->setHasShares(count($allShares) !== 0);
} catch (InternalError $e) {
}
$view->setOnSharePermissions([
'read' => $permissions['read'] ?? false,
'create' => $permissions['create'] ?? false,
'update' => $permissions['update'] ?? false,
'delete' => $permissions['delete'] ?? false,
'manage' => $permissions['manage'] ?? false,
'manageTable' => $canManageTable
]);
} catch (NotFoundError $e) {
} catch (\Exception $e) {
$this->logger->warning('Exception occurred while setting shared permissions: '.$e->getMessage().' No permissions granted.');
$view->setOnSharePermissions([
'read' => false,
'create' => false,
'update' => false,
'delete' => false,
'manage' => false,
'manageTable' => false
]);
}

}

if (!$this->permissionsService->canReadRowsByElement($view, 'view', $userId)) {
Expand All @@ -331,19 +342,6 @@ private function enhanceView(View $view, string $userId): void {
} catch (InternalError|PermissionError $e) {
}

if (!$this->permissionsService->canManageTableById($view->getTableId(), $userId)) {
return;
}

// set hasShares if this table is shared by you (you share it with somebody else)
// (senseless if we have no user in context)
if ($userId !== '') {
try {
$allShares = $this->shareService->findAll('view', $view->getId());
$view->setHasShares(count($allShares) !== 0);
} catch (InternalError $e) {
}
}
if($view->getIsShared()) {
// Remove detailed view filtering and sorting information if necessary
if(!$view->getOnSharePermissions()['manageTable']) {
Expand Down
14 changes: 8 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script>
import { NcContent, NcAppContent } from '@nextcloud/vue'
import Navigation from './modules/navigation/sections/Navigation.vue'
import { mapState, mapGetters } from 'vuex'
import { mapState } from 'vuex'
import Sidebar from './modules/sidebar/sections/Sidebar.vue'
export default {
Expand Down Expand Up @@ -53,13 +53,15 @@ export default {
},
methods: {
routing(currentRoute) {
if (currentRoute.name === 'table') {
if (currentRoute.name === 'row') {
this.$store.commit('setActiveRowId', parseInt(currentRoute.params.rowId))
} else {
this.$store.commit('setActiveRowId', null)
}
if (currentRoute.path.startsWith('/table/')) {
this.$store.commit('setActiveTableId', parseInt(currentRoute.params.tableId))
} else if (currentRoute.name === 'view') {
} else if (currentRoute.path.startsWith('/view/')) {
this.$store.commit('setActiveViewId', parseInt(currentRoute.params.viewId))
} else if (currentRoute.name === 'row') {
this.$store.commit('setActiveViewId', parseInt(currentRoute.params.viewId))
this.$store.commit('setActiveRowId', parseInt(currentRoute.params.rowId))
}
},
},
Expand Down
5 changes: 4 additions & 1 deletion src/modules/main/sections/MainWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default {
},
computed: {
...mapState(['activeRowId']),
...mapState({
columns: state => state.data.columns,
rows: state => state.data.rows,
Expand All @@ -82,7 +83,6 @@ export default {
this.reload(true)
},
methods: {
createColumn() {
emit('tables:column:create')
Expand Down Expand Up @@ -128,6 +128,9 @@ export default {
id: this.element.id,
isView: this.isView,
}
if (this.activeRowId) {
emit('tables:row:edit', { row: this.rows.find(r => r.id === this.activeRowId), columns: this.columns })
}
this.localLoading = false
}
},
Expand Down
2 changes: 0 additions & 2 deletions src/modules/main/sections/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
</template>

<script>
import { mapState } from 'vuex'
import TableView from '../partials/TableView.vue'
import EmptyView from './EmptyView.vue'
Expand Down Expand Up @@ -127,7 +126,6 @@ export default {
}
},
computed: {
...mapState(['activeRowId']),
isViewSettingSet() {
return !(!this.viewSetting || ((!this.viewSetting.hiddenColumns || this.viewSetting.hiddenColumns.length === 0) && (!this.viewSetting.sorting) && (!this.viewSetting.filter || this.viewSetting.filter.length === 0)))
},
Expand Down
10 changes: 9 additions & 1 deletion src/modules/modals/EditRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ export default {
},
watch: {
row() {
this.loadValues()
if (this.row) {
if (this.$router.currentRoute.path.includes('/row/')) {
this.$router.replace(this.$router.currentRoute.path.split('/row/')[0])
}
this.$router.push(this.$router.currentRoute.path + '/row/' + this.row.id)
this.$store.commit('setActiveRowId', null)
this.loadValues()
}
},
},
methods: {
Expand All @@ -99,6 +106,7 @@ export default {
}
},
actionCancel() {
this.$router.back()
this.reset()
this.$emit('close')
},
Expand Down
5 changes: 5 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export default new Router({
component: MainDashboardWrapper,
name: 'table',
},
{
path: '/table/:tableId/row/:rowId',
component: MainDashboardWrapper,
name: 'row',
},
{
path: '/view/:viewId',
component: MainViewWrapper,
Expand Down

0 comments on commit 7c4f5b6

Please sign in to comment.