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

More usable and accessible navigation between View/Edit/Results #1381

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Forms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
:key="form.id"
:form="form"
:read-only="true"
@open-sharing="openSharing"
jancborchardt marked this conversation as resolved.
Show resolved Hide resolved
@mobile-close-navigation="mobileCloseNavigation" />
</template>
</NcAppNavigation>
Expand Down Expand Up @@ -92,9 +93,9 @@
<router-view :form.sync="selectedForm"
:sidebar-opened.sync="sidebarOpened"
@open-sharing="openSharing" />
<router-view v-if="!selectedForm.partial"
<router-view v-if="!selectedForm.partial && canEdit"
:form="selectedForm"
:opened.sync="sidebarOpened"
:sidebar-opened.sync="sidebarOpened"
:active.sync="sidebarActive"
name="sidebar" />
</template>
Expand Down Expand Up @@ -158,6 +159,9 @@ export default {
},

computed: {
canEdit() {
return this.selectedForm.permissions.includes(this.PERMISSION_TYPES.PERMISSION_EDIT)
},
hasForms() {
return !this.noOwnedForms || !this.noSharedForms
},
Expand Down Expand Up @@ -236,7 +240,7 @@ export default {
* @param {string} hash the hash of the form to load
*/
openSharing(hash) {
if (hash !== this.routeHash || this.$route.name !== 'edit') {
if (hash !== this.routeHash) {
this.$router.push({ name: 'edit', params: { hash } })
}
this.sidebarActive = 'forms-sharing'
Expand Down
130 changes: 80 additions & 50 deletions src/components/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,51 @@
-->
<template>
<div class="top-bar" role="toolbar">
<slot />
<NcButton v-if="canSubmit && $route.name !== 'submit'"
v-tooltip="t('forms', 'View form')"
:aria-label="t('forms', 'View form')"
type="tertiary"
@click="showSubmit">
<template #icon>
<IconEye :size="20" />
</template>
</NcButton>
<NcButton v-if="canEdit && $route.name !== 'edit'"
v-tooltip="t('forms', 'Edit form')"
:aria-label="t('forms', 'Edit form')"
type="tertiary"
@click="showEdit">
<template #icon>
<IconPencil :size="20" />
</template>
</NcButton>
<NcButton v-if="canSeeResults && $route.name !== 'results'"
v-tooltip="t('forms', 'Results')"
:aria-label="t('forms', 'Results')"
type="tertiary"
@click="showResults">
<template #icon>
<IconPoll :size="20" />
</template>
</NcButton>
<div v-if="!canOnlySubmit" class="top-bar__view-select">
<NcButton v-if="canSubmit"
:aria-label="isMobile ? t('forms', 'View form') : null"
:type="$route.name === 'submit' ? 'secondary' : 'tertiary'"
@click="showSubmit">
<template #icon>
<IconEye :size="20" />
</template>
<template v-if="!isMobile">
{{ t('forms', 'View') }}
</template>
jancborchardt marked this conversation as resolved.
Show resolved Hide resolved
</NcButton>
<NcButton v-if="canEdit"
:aria-label="isMobile ? t('forms', 'Edit form') : null"
:type="$route.name === 'edit' ? 'secondary' : 'tertiary'"
@click="showEdit">
<template #icon>
<IconPencil :size="20" />
</template>
<template v-if="!isMobile">
{{ t('forms', 'Edit') }}
</template>
jancborchardt marked this conversation as resolved.
Show resolved Hide resolved
</NcButton>
<NcButton v-if="canSeeResults"
:aria-label="isMobile ? t('forms', 'Show results') : null"
:type="$route.name === 'results' ? 'secondary' : 'tertiary'"
@click="showResults">
<template #icon>
<IconPoll :size="20" />
</template>
<template v-if="!isMobile">
{{ t('forms', 'Results') }}
</template>
jancborchardt marked this conversation as resolved.
Show resolved Hide resolved
</NcButton>
</div>
<NcButton v-if="canShare && !sidebarOpened"
v-tooltip="t('forms', 'Share form')"
:aria-label="t('forms', 'Share form')"
:aria-label="isMobile ? t('forms', 'Share form') : null"
type="tertiary"
@click="onShareForm">
<template #icon>
<IconShareVariant :size="20" />
</template>
<template v-if="!isMobile">
{{ t('forms', 'Share') }}
</template>
</NcButton>
<NcButton v-if="showSidebarToggle"
v-tooltip="t('forms', 'Toggle settings')"
Expand All @@ -77,6 +86,7 @@

<script>
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
import IconEye from 'vue-material-design-icons/Eye.vue'
import IconMenuOpen from 'vue-material-design-icons/MenuOpen.vue'
import IconPencil from 'vue-material-design-icons/Pencil.vue'
Expand All @@ -96,7 +106,7 @@ export default {
NcButton,
},

mixins: [PermissionTypes],
mixins: [isMobile, PermissionTypes],

props: {
sidebarOpened: {
Expand All @@ -123,8 +133,11 @@ export default {
// This probably can get a permission of itself
return this.canEdit || this.canSeeResults
},
canOnlySubmit() {
return this.permissions.length === 1 && this.permissions.includes(this.PERMISSION_TYPES.PERMISSION_SUBMIT)
},
showSidebarToggle() {
return this.sidebarOpened !== null
return this.canEdit && this.sidebarOpened !== null
},
},

Expand All @@ -137,30 +150,36 @@ export default {
* Router methods
*/
showEdit() {
this.$router.push({
name: 'edit',
params: {
hash: this.$route.params.hash,
},
})
if (this.$route.name !== 'edit') {
this.$router.push({
name: 'edit',
params: {
hash: this.$route.params.hash,
},
})
}
},

showResults() {
this.$router.push({
name: 'results',
params: {
hash: this.$route.params.hash,
},
})
if (this.$route.name !== 'results') {
this.$router.push({
name: 'results',
params: {
hash: this.$route.params.hash,
},
})
}
},

showSubmit() {
this.$router.push({
name: 'submit',
params: {
hash: this.$route.params.hash,
},
})
if (this.$route.name !== 'submit') {
this.$router.push({
name: 'submit',
params: {
hash: this.$route.params.hash,
},
})
}
},

onShareForm() {
Expand All @@ -180,6 +199,17 @@ export default {
align-self: flex-end;
justify-content: flex-end;
padding: calc(var(--default-grid-baseline, 4px) * 2);

&__view-select {
display: flex;
height: 44px;
align-items: center;
align-self: flex-end;
justify-content: flex-end;
background: var(--color-main-background);
border: 2px solid var(--color-border);
border-radius: var(--border-radius-pill);
}
}

.icon--flipped {
Expand Down
8 changes: 8 additions & 0 deletions src/mixins/ViewsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default {
type: Boolean,
default: false,
},
sidebarOpened: {
type: Boolean,
required: true,
},
},

data() {
Expand All @@ -63,6 +67,10 @@ export default {
this.$emit('open-sharing', this.form.hash)
},

onSidebarChange(newState) {
this.$emit('update:sidebarOpened', newState)
},

/**
* Focus title after form load
*/
Expand Down
14 changes: 10 additions & 4 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ export default new Router({
},
{
path: '/:hash/results',
component: Results,
components: {
default: Results,
sidebar: Sidebar,
},
name: 'results',
props: true,
props: { default: true },
},
{
path: '/:hash/submit',
component: Submit,
components: {
default: Submit,
sidebar: Sidebar,
},
name: 'submit',
props: true,
props: { default: true },
},
],
})
10 changes: 0 additions & 10 deletions src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ export default {

mixins: [ViewsMixin],

props: {
sidebarOpened: {
type: Boolean,
required: true,
},
},

data() {
return {
maxStringLengths: loadState('forms', 'maxStringLengths'),
Expand Down Expand Up @@ -259,9 +252,6 @@ export default {
this.autoSizeDescription()
this.saveDescription()
},
onSidebarChange(newState) {
this.$emit('update:sidebarOpened', newState)
},

/**
* Title & description save methods
Expand Down
5 changes: 4 additions & 1 deletion src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
</NcAppContent>

<NcAppContent v-else>
<TopBar :permissions="form?.permissions" @share-form="onShareForm" />
<TopBar :permissions="form?.permissions"
:sidebar-opened="sidebarOpened"
@update:sidebarOpened="onSidebarChange"
@share-form="onShareForm" />
<header v-if="!noSubmissions">
<h2>{{ formTitle }}</h2>
<p>{{ t('forms', '{amount} responses', { amount: form.submissions.length }) }}</p>
Expand Down
11 changes: 4 additions & 7 deletions src/views/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->

<template>
<NcAppSidebar v-show="opened"
<NcAppSidebar v-show="sidebarOpened"
:active="active"
:title="t('forms', 'Form settings')"
@close="onClose"
Expand Down Expand Up @@ -71,28 +71,25 @@ export default {
SharingSidebarTab,
SettingsSidebarTab,
},

mixins: [ViewsMixin],

props: {
active: {
type: String,
default: 'forms-sharing',
},
opened: {
type: Boolean,
required: true,
},
},

methods: {
/**
* Sidebar state methods
*/
onClose() {
this.$emit('update:opened', false)
this.$emit('update:sidebarOpened', false)
},
onToggle() {
this.$emit('update:opened', !this.opened)
this.$emit('update:sidebarOpened', !this.sidebarOpened)
},
onUpdateActive(active) {
this.$emit('update:active', active)
Expand Down
2 changes: 2 additions & 0 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<NcAppContent v-else :class="{'app-content--public': publicView}">
<TopBar v-if="!publicView"
:permissions="form?.permissions"
:sidebar-opened="sidebarOpened"
@update:sidebarOpened="onSidebarChange"
@share-form="onShareForm" />

<!-- Forms title & description-->
Expand Down