Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add UI elements to modify navigation display #1295

Open
wants to merge 11 commits into
base: enh/1177/enable-nav-display-logic
Choose a base branch
from
35 changes: 35 additions & 0 deletions lib/Db/ContextNavigationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCA\Tables\Db;

use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -41,4 +42,38 @@ public function setDisplayModeByShareId(int $shareId, int $displayMode, string $

return $this->insertOrUpdate($entity);
}

// we have to overwrite QBMapper`s update() because we do not have
// an id column in this table. Sad.
public function update(Entity $entity): ContextNavigation {
if (!$entity instanceof ContextNavigation) {
throw new \LogicException('Can only update context navigation entities');
}

// if entity wasn't changed it makes no sense to run a db query
$properties = $entity->getUpdatedFields();
if (\count($properties) === 0) {
return $entity;
}

$qb = $this->db->getQueryBuilder();
$qb->update($this->tableName);

// build the fields
foreach ($properties as $property => $updated) {
$column = $entity->propertyToColumn($property);
$getter = 'get' . ucfirst($property);
$value = $entity->$getter();

$type = $this->getParameterTypeForProperty($entity, $property);
$qb->set($column, $qb->createNamedParameter($value, $type));
}

$qb->where($qb->expr()->eq('share_id', $qb->createNamedParameter($entity->getShareId(), IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($entity->getUserId(), IQueryBuilder::PARAM_STR)));

$qb->executeStatement();

return $entity;
}
}
3 changes: 2 additions & 1 deletion lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ public function updateDisplayMode(int $shareId, int $displayMode, string $userId
}
} else {
// setting user display mode override only requires access
if (!$this->permissionsService->canAccessContextById($item->getId())) {
// this does not seem to work
if (!$this->permissionsService->canAccessContextById($item->getNodeId(), $userId)) {
throw new PermissionError(sprintf('PermissionError: can not update share with id %d', $shareId));
}
}
Expand Down
38 changes: 36 additions & 2 deletions src/modules/modals/CreateContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
</div>
<NcContextResource :resources.sync="resources" :receivers.sync="receivers" />
</div>
<div class="row space-T">
<NcActionCheckbox :checked="showInNavigationDefault" @change="updateDisplayMode">
Show in app list
</NcActionCheckbox>
<p class="nav-display-subtext">
This can be overridden by a per-account preference
</p>
</div>
<div class="row space-R row space-T">
<div class="fix-col-4 end">
<NcButton type="primary" :aria-label="t('tables', 'Create application')" data-cy="createContextSubmitBtn" @click="submit">
Expand All @@ -54,13 +62,15 @@
</template>

<script>
import { NcDialog, NcButton, NcIconSvgWrapper } from '@nextcloud/vue'
import { NcDialog, NcButton, NcIconSvgWrapper, NcActionCheckbox } from '@nextcloud/vue'
import { showError } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/style.css'
import NcContextResource from '../../shared/components/ncContextResource/NcContextResource.vue'
import NcIconPicker from '../../shared/components/ncIconPicker/NcIconPicker.vue'
import svgHelper from '../../shared/components/ncIconPicker/mixins/svgHelper.js'
import permissionBitmask from '../../shared/components/ncContextResource/mixins/permissionBitmask.js'
import { getCurrentUser } from '@nextcloud/auth'
import { NAV_ENTRY_MODE } from '../../shared/constants.js'

export default {
name: 'CreateContext',
Expand All @@ -70,6 +80,7 @@ export default {
NcButton,
NcIconSvgWrapper,
NcContextResource,
NcActionCheckbox,
},
mixins: [svgHelper, permissionBitmask],
props: {
Expand All @@ -90,6 +101,7 @@ export default {
description: '',
resources: [],
receivers: [],
showInNavigationDefault: false,
}
},
watch: {
Expand Down Expand Up @@ -150,18 +162,32 @@ export default {
description: this.description,
nodes: dataResources,
}
const res = await this.$store.dispatch('insertNewContext', { data, previousReceivers: [], receivers: this.receivers })
// adding share to oneself to have navigation display control
this.receivers.push(
{
id: getCurrentUser().uid,
displayName: getCurrentUser().uid,
icon: 'icon-user',
isUser: true,
key: 'user-' + getCurrentUser().uid,
})
const displayMode = this.showInNavigation ? 'NAV_ENTRY_MODE_ALL' : 'NAV_ENTRY_MODE_HIDDEN'
const res = await this.$store.dispatch('insertNewContext', { data, previousReceivers: [], receivers: this.receivers, displayMode: NAV_ENTRY_MODE[displayMode] })
if (res) {
return res.id
} else {
showError(t('tables', 'Could not create new application'))
}
},
updateDisplayMode() {
this.showInNavigation = !this.showInNavigation
},
reset() {
this.title = ''
this.errorTitle = false
this.setIcon(this.randomIcon())
this.customTitleChosen = false
this.showInNavigationDefault = false
},
},
}
Expand All @@ -175,5 +201,13 @@ export default {
display: inline-flex;
align-items: center;
}

.nav-display-subtext {
color: var(--color-text-maxcontrast)
}

li {
list-style: none;
}
}
</style>
49 changes: 44 additions & 5 deletions src/modules/modals/EditContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
</div>
<NcContextResource :resources.sync="resources" :receivers.sync="receivers" />
</div>

<div class="row space-T">
<NcActionCheckbox :checked="showInNavigationDefault" @change="updateDisplayMode">
Show in app list
</NcActionCheckbox>
<p class="nav-display-subtext">
This can be overridden by a per-account preference
</p>
</div>
<div class="row space-T">
<div class="fix-col-4 space-T justify-between">
<NcButton v-if="!prepareDeleteContext" type="error" @click="prepareDeleteContext = true">
Expand All @@ -62,14 +69,14 @@
</template>

<script>
import { NcDialog, NcButton, NcIconSvgWrapper } from '@nextcloud/vue'
import { NcDialog, NcButton, NcIconSvgWrapper, NcActionCheckbox } from '@nextcloud/vue'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
import '@nextcloud/dialogs/style.css'
import { mapGetters, mapState } from 'vuex'
import NcContextResource from '../../shared/components/ncContextResource/NcContextResource.vue'
import NcIconPicker from '../../shared/components/ncIconPicker/NcIconPicker.vue'
import { NODE_TYPE_TABLE, NODE_TYPE_VIEW, PERMISSION_READ, PERMISSION_CREATE, PERMISSION_UPDATE, PERMISSION_DELETE } from '../../shared/constants.js'
import { NODE_TYPE_TABLE, NODE_TYPE_VIEW, PERMISSION_READ, PERMISSION_CREATE, PERMISSION_UPDATE, PERMISSION_DELETE, NAV_ENTRY_MODE } from '../../shared/constants.js'
import svgHelper from '../../shared/components/ncIconPicker/mixins/svgHelper.js'
import permissionBitmask from '../../shared/components/ncContextResource/mixins/permissionBitmask.js'
import { emit } from '@nextcloud/event-bus'
Expand All @@ -83,6 +90,7 @@ export default {
NcIconPicker,
NcIconSvgWrapper,
NcContextResource,
NcActionCheckbox,
},
mixins: [svgHelper, permissionBitmask, permissionsMixin],
props: {
Expand Down Expand Up @@ -111,6 +119,7 @@ export default {
PERMISSION_UPDATE,
PERMISSION_DELETE,
prepareDeleteContext: false,
showInNavigationDefault: false,
}
},
computed: {
Expand All @@ -135,6 +144,7 @@ export default {
this.description = context.description
this.resources = context ? this.getContextResources(context) : []
this.receivers = context ? this.getContextReceivers(context) : []
this.showInNavigationDefault = this.getNavDisplay(context)
}
},
},
Expand Down Expand Up @@ -166,8 +176,17 @@ export default {
nodes: dataResources,
}
const context = this.getContext(this.contextId)

const res = await this.$store.dispatch('updateContext', { id: this.contextId, data, previousReceivers: Object.values(context.sharing), receivers: this.receivers })
// adding share to oneself to have navigation display control
this.receivers.push(
{
id: getCurrentUser().uid,
displayName: getCurrentUser().uid,
icon: 'icon-user',
isUser: true,
key: 'user-' + getCurrentUser().uid,
})
const displayMode = this.showInNavigation ? 'NAV_ENTRY_MODE_ALL' : 'NAV_ENTRY_MODE_HIDDEN'
const res = await this.$store.dispatch('updateContext', { id: this.contextId, data, previousReceivers: Object.values(context.sharing), receivers: this.receivers, displayMode: NAV_ENTRY_MODE[displayMode] })
if (res) {
showSuccess(t('tables', 'Updated application "{contextTitle}".', { contextTitle: this.title }))
this.actionCancel()
Expand All @@ -183,6 +202,15 @@ export default {
this.resources = context ? this.getContextResources(context) : []
this.receivers = context ? this.getContextReceivers(context) : []
this.prepareDeleteContext = false
this.showInNavigationDefault = this.getNavDisplay(context)
},
getNavDisplay(context) {
const shares = Object.keys(context.sharing || {})
if (shares.length) {
const displayMode = context.sharing[shares[0]].display_mode_default
return displayMode !== 0
}
return false
},
getContextReceivers(context) {
let sharing = Object.values(context.sharing)
Expand Down Expand Up @@ -240,6 +268,9 @@ export default {
}

},
updateDisplayMode() {
this.showInNavigation = !this.showInNavigation
},
actionTransfer() {
emit('tables:context:edit', null)
emit('tables:context:transfer', this.localContext)
Expand All @@ -260,4 +291,12 @@ export default {
padding-inline: 0 !important;
max-width: 100%;
}

.nav-display-subtext {
color: var(--color-text-maxcontrast)
}

li {
list-style: none;
}
</style>
34 changes: 31 additions & 3 deletions src/modules/navigation/partials/NavigationContextItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
</template>
</template>
<template #actions>
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" data-cy="navigationContextEditBtn" @click="editContext">
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" data-cy="navigationContextEditBtn"
@click="editContext">
<template #icon>
<PlaylistEdit :size="20" />
</template>
Expand All @@ -27,17 +28,21 @@
</template>
{{ t('tables', 'Transfer application') }}
</NcActionButton>
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" data-cy="navigationContextDeleteBtn" @click="deleteContext">
<NcActionButton v-if="ownsContext(context)" :close-after-click="true" data-cy="navigationContextDeleteBtn"
@click="deleteContext">
<template #icon>
<Delete :size="20" />
</template>
{{ t('tables', 'Delete application') }}
</NcActionButton>
<NcActionCheckbox :checked="showInNavigation" @change="updateDisplayMode">
Show in app list
</NcActionCheckbox>
</template>
</NcAppNavigationItem>
</template>
<script>
import { NcAppNavigationItem, NcActionButton, NcIconSvgWrapper } from '@nextcloud/vue'
import { NcAppNavigationItem, NcActionButton, NcIconSvgWrapper, NcActionCheckbox } from '@nextcloud/vue'
import '@nextcloud/dialogs/style.css'
import { mapGetters } from 'vuex'
import TableIcon from 'vue-material-design-icons/Table.vue'
Expand All @@ -47,6 +52,8 @@ import FileSwap from 'vue-material-design-icons/FileSwap.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
import permissionsMixin from '../../../shared/components/ncTable/mixins/permissionsMixin.js'
import svgHelper from '../../../shared/components/ncIconPicker/mixins/svgHelper.js'
import { getCurrentUser } from '@nextcloud/auth'
import { NAV_ENTRY_MODE } from '../../../shared/constants.js'

export default {
name: 'NavigationContextItem',
Expand All @@ -59,6 +66,7 @@ export default {
NcIconSvgWrapper,
NcAppNavigationItem,
NcActionButton,
NcActionCheckbox,
},

mixins: [permissionsMixin, svgHelper],
Expand All @@ -73,6 +81,7 @@ export default {
data() {
return {
icon: null,
showInNavigation: this.getNavDisplay(),
}
},
computed: {
Expand All @@ -99,6 +108,25 @@ export default {
deleteContext() {
emit('tables:context:delete', this.context)
},
getNavDisplay() {
const share = Object.values(this.context.sharing || {}).find(share => share.receiver === getCurrentUser().uid)
if (share) {
return share?.display_mode !== NAV_ENTRY_MODE.NAV_ENTRY_MODE_HIDDEN
enjeck marked this conversation as resolved.
Show resolved Hide resolved
}
return false
},
updateDisplayMode() {
const value = !this.showInNavigation
let displayMode = value ? NAV_ENTRY_MODE.NAV_ENTRY_MODE_RECIPIENTS : NAV_ENTRY_MODE.NAV_ENTRY_MODE_HIDDEN
if (this.ownsContext(this.context)) {
displayMode = value ? NAV_ENTRY_MODE.NAV_ENTRY_MODE_ALL : NAV_ENTRY_MODE.NAV_ENTRY_MODE_HIDDEN
}
const share = Object.values(this.context.sharing || {}).find(share => share.receiver === getCurrentUser().uid)
if (share) {
this.$store.dispatch('updateDisplayMode', { shareId: share.share_id, displayMode, target: 'self' })
this.showInNavigation = value
enjeck marked this conversation as resolved.
Show resolved Hide resolved
}
},
},

}
Expand Down
6 changes: 6 additions & 0 deletions src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ export const TYPE_TEXT = 'text'
export const TYPE_NUMBER = 'number'
export const TYPE_DATETIME = 'datetime'
export const TYPE_USERGROUP = 'usergroup'

export const NAV_ENTRY_MODE = {
NAV_ENTRY_MODE_HIDDEN: 0, // no nav bar entry
NAV_ENTRY_MODE_RECIPIENTS: 1, // nav bar entry for share recipients, but not the owner
NAV_ENTRY_MODE_ALL: 2, // nav bar entry for everybody
}
Loading
Loading