Skip to content

Commit

Permalink
fix: update context navigation display elements
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Aug 22, 2024
1 parent 774736f commit e0b033f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public function updateDisplayMode(int $shareId, int $displayMode, string $userId
}
} else {
// setting user display mode override only requires access
// this does not seem to work
if (!$this->permissionsService->canAccessContextById($item->getId())) {
throw new PermissionError(sprintf('PermissionError: can not update share with id %d', $shareId));
}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/modals/CreateContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@
</div>
<div class="row space-T">
<div>
{{ t('tables', 'Navigation bar entry') }}
{{ t('tables', 'Navigation bar display') }}
</div>
<NcCheckboxRadioSwitch :checked.sync="displayMode" value="NAV_ENTRY_MODE_HIDDEN"
name="NAV_ENTRY_MODE_HIDDEN" type="radio">
No navigation bar entry
Hide navigation entry for everybody
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :checked.sync="displayMode" value="NAV_ENTRY_MODE_RECIPIENTS"
name="NAV_ENTRY_MODE_RECIPIENTS" type="radio">
Navigation bar entry for share recipients, but not the owner
Show navigation entry for everybody, except me
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :checked.sync="displayMode" value="NAV_ENTRY_MODE_ALL" name="NAV_ENTRY_MODE_ALL"
type="radio">
Navigation bar entry for everybody
Show navigation entry for everybody
</NcCheckboxRadioSwitch>
<br>
</div>
Expand Down
24 changes: 22 additions & 2 deletions src/modules/modals/EditContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@
</div>
<NcContextResource :resources.sync="resources" :receivers.sync="receivers" />
</div>

<div class="row space-T">
<div>
{{ t('tables', 'Navigation bar display') }}
</div>
<NcCheckboxRadioSwitch :checked.sync="displayMode" value="NAV_ENTRY_MODE_HIDDEN"
name="NAV_ENTRY_MODE_HIDDEN" type="radio">
Hide navigation entry for everybody
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :checked.sync="displayMode" value="NAV_ENTRY_MODE_RECIPIENTS"
name="NAV_ENTRY_MODE_RECIPIENTS" type="radio">
Show navigation entry for everybody, except me
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :checked.sync="displayMode" value="NAV_ENTRY_MODE_ALL" name="NAV_ENTRY_MODE_ALL"
type="radio">
Show navigation entry for everybody
</NcCheckboxRadioSwitch>
<br>
</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 @@ -59,7 +76,7 @@
</template>

<script>
import { NcModal, NcButton, NcIconSvgWrapper } from '@nextcloud/vue'
import { NcModal, NcButton, NcIconSvgWrapper, NcCheckboxRadioSwitch } from '@nextcloud/vue'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
import '@nextcloud/dialogs/dist/index.css'
Expand All @@ -71,6 +88,7 @@ import svgHelper from '../../shared/components/ncIconPicker/mixins/svgHelper.js'
import permissionBitmask from '../../shared/components/ncContextResource/mixins/permissionBitmask.js'
import { emit } from '@nextcloud/event-bus'
import permissionsMixin from '../../shared/components/ncTable/mixins/permissionsMixin.js'
import { NAV_ENTRY_MODE } from '../../shared/constants.js'

Check failure on line 91 in src/modules/modals/EditContext.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'NAV_ENTRY_MODE' is defined but never used

Check failure on line 91 in src/modules/modals/EditContext.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'/home/runner/work/tables/tables/src/shared/constants.js' imported multiple times
export default {
name: 'EditContext',
Expand All @@ -80,6 +98,7 @@ export default {
NcIconPicker,
NcIconSvgWrapper,
NcContextResource,
NcCheckboxRadioSwitch,
},
mixins: [svgHelper, permissionBitmask, permissionsMixin],
props: {
Expand Down Expand Up @@ -108,6 +127,7 @@ export default {
PERMISSION_UPDATE,
PERMISSION_DELETE,
prepareDeleteContext: false,
displayMode: 'NAV_ENTRY_MODE_HIDDEN', // TODO: get the actual saved display mode
}
},
computed: {
Expand Down
28 changes: 18 additions & 10 deletions src/modules/navigation/partials/NavigationContextItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -23,13 +24,14 @@
</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 :value="showInNavigation" @change="updateDisplayMode">
<NcActionCheckbox v-if="!ownsContext(context)" :value="showInNavigation" @change="updateDisplayMode">
Show in Navigation
</NcActionCheckbox>
</template>
Expand All @@ -47,6 +49,7 @@ 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 Down Expand Up @@ -74,7 +77,7 @@ export default {
data() {
return {
icon: null,
showInNavigation: false,
showInNavigation: this.getDisplayMode(),
}
},
computed: {
Expand All @@ -101,13 +104,18 @@ export default {
deleteContext() {
emit('tables:context:delete', this.context)
},
getDisplayMode() {
const share = Object.values(this.context.sharing || {}).find(share => share.receiver === getCurrentUser().uid)
if (share) {
return share.display_mode
}
return 0
},
updateDisplayMode() {
this.showInNavigation = !this.showInNavigation
if (this.context) {
const share = Object.values(this.context.sharing || {}).find(share => share.receiver === getCurrentUser().uid)
if (share) {
this.$store.dispatch('updateDisplayMode', { shareId: share.share_id, displayMode: this.showInNavigation ? 1 : 0, userId: getCurrentUser().uid })
}
this.showInNavigation = this.showInNavigation ? 0 : 1
const share = Object.values(this.context.sharing || {}).find(share => share.receiver === getCurrentUser().uid)
if (share) {
this.$store.dispatch('updateDisplayMode', { shareId: share.share_id, displayMode: this.showInNavigation ? NAV_ENTRY_MODE['NAV_ENTRY_MODE_RECIPIENTS'] : NAV_ENTRY_MODE['NAV_ENTRY_MODE_HIDDEN'], target: 'self' })

Check failure on line 118 in src/modules/navigation/partials/NavigationContextItem.vue

View workflow job for this annotation

GitHub Actions / NPM lint

["NAV_ENTRY_MODE_RECIPIENTS"] is better written in dot notation

Check failure on line 118 in src/modules/navigation/partials/NavigationContextItem.vue

View workflow job for this annotation

GitHub Actions / NPM lint

["NAV_ENTRY_MODE_HIDDEN"] is better written in dot notation
}
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const TYPE_DATETIME = 'datetime'
export const TYPE_USERGROUP = 'usergroup'

export const NAV_ENTRY_MODE = {
NAV_ENTRY_MODE_HIDDEN: 0,
NAV_ENTRY_MODE_RECIPIENTS: 1,
NAV_ENTRY_MODE_ALL: 2,
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
}
4 changes: 2 additions & 2 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ export default new Vuex.Store({
}
},

async updateDisplayMode({ dispatch }, { shareId, displayMode, userId }) {
async updateDisplayMode({ dispatch }, { shareId, displayMode, target }) {
try {
await axios.put(generateUrl('/apps/tables/share/' + shareId + '/display-mode'), { displayMode, userId })
await axios.put(generateUrl('/apps/tables/share/' + shareId + '/display-mode'), { displayMode, target })
} catch (e) {
displayError(e, t('tables', 'Could not update display mode.'))
}
Expand Down

0 comments on commit e0b033f

Please sign in to comment.