-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathTopBar.vue
211 lines (190 loc) Β· 4.1 KB
/
TopBar.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!--
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div
:aria-label="t('forms', 'View mode')"
class="top-bar"
:class="{
'top-bar--has-sidebar': sidebarOpened,
}"
role="toolbar">
<PillMenu
v-if="!canOnlySubmit"
:active="currentView"
:options="availableViews"
@update:active="onChangeView" />
<NcButton
v-if="canShare && !sidebarOpened"
:aria-label="isMobile ? t('forms', 'Share form') : null"
type="tertiary"
@click="onShareForm">
<template #icon>
<IconShareVariant :size="20" />
</template>
<template v-if="!isMobile" #default>
{{ t('forms', 'Share') }}
</template>
</NcButton>
<NcButton
v-if="showSidebarToggle"
:aria-label="t('forms', 'Toggle settings')"
:title="t('forms', 'Toggle settings')"
type="tertiary"
@click="toggleSidebar">
<template #icon>
<IconMenuOpen
:size="24"
:class="{ 'icon--flipped': sidebarOpened }" />
</template>
</NcButton>
</div>
</template>
<script>
import { mdiEye, mdiPencil, mdiPoll } from '@mdi/js'
import { t } from '@nextcloud/l10n'
import { useIsMobile } from '@nextcloud/vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import IconShareVariant from 'vue-material-design-icons/ShareVariant.vue'
import logger from '../utils/Logger.js'
import PermissionTypes from '../mixins/PermissionTypes.js'
import PillMenu from './PillMenu.vue'
const submitView = {
ariaLabel: t('forms', 'View form'),
icon: mdiEye,
title: t('forms', 'View'),
id: 'submit',
}
const editView = {
ariaLabel: t('forms', 'Edit form'),
icon: mdiPencil,
title: t('forms', 'Edit'),
id: 'edit',
}
const resultsView = {
ariaLabel: t('forms', 'Show results'),
icon: mdiPoll,
title: t('forms', 'Results'),
id: 'results',
}
export default {
name: 'TopBar',
components: {
IconShareVariant,
NcButton,
PillMenu,
},
mixins: [PermissionTypes],
props: {
archived: {
type: Boolean,
default: false,
},
sidebarOpened: {
type: Boolean,
default: false,
},
permissions: {
type: Array,
default: () => [],
},
},
setup() {
return {
t,
isMobile: useIsMobile(),
}
},
computed: {
currentView() {
return this.availableViews.filter((v) => v.id === this.$route.name)[0]
},
availableViews() {
const views = []
if (this.canSubmit) {
views.push(submitView)
}
if (this.canEdit) {
views.push(editView)
}
if (this.canSeeResults) {
views.push(resultsView)
}
return views
},
canSubmit() {
return this.permissions.includes(this.PERMISSION_TYPES.PERMISSION_SUBMIT)
},
canEdit() {
return (
this.permissions.includes(this.PERMISSION_TYPES.PERMISSION_EDIT) &&
!this.archived
)
},
canSeeResults() {
return this.permissions.includes(
this.PERMISSION_TYPES.PERMISSION_RESULTS,
)
},
canShare() {
// This probably can get a permission of itself
return this.canEdit
},
canOnlySubmit() {
return (
this.permissions.length === 1 &&
this.permissions.includes(this.PERMISSION_TYPES.PERMISSION_SUBMIT)
)
},
},
methods: {
/**
* Router methods
*
* @param {object} option The selected pill menu option
*/
async onChangeView(option) {
if (this.$route.name === option.id) {
return
}
try {
await this.$router.push({
name: option.id,
params: {
hash: this.$route.params.hash,
},
})
} catch (error) {
logger.debug('Navigation cancelled', { error })
}
},
onShareForm() {
this.$emit('share-form')
},
},
}
</script>
<style lang="scss" scoped>
.top-bar {
display: flex;
align-items: center;
align-self: flex-end;
// allow to wrap on small screens
flex-wrap: wrap;
justify-content: flex-end;
// align with navigation and sidebar toggle, but ensure it is not overlayed
padding: var(--app-navigation-padding);
margin-inline: var(--default-clickable-area);
position: sticky;
top: 0;
z-index: 100;
&--has-sidebar {
// Remove margin as the toggle button does not exist when open
margin-inline-end: 0;
}
}
.icon--flipped {
transform: scaleX(-1);
}
</style>