Skip to content

Commit a1ee322

Browse files
committed
add frontend handling of locked form
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent e456bd3 commit a1ee322

9 files changed

Lines changed: 72 additions & 3 deletions

File tree

src/components/PillMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:key="option.id"
1111
:aria-label="isMobile ? option.ariaLabel : null"
1212
:checked="active.id"
13-
:disabled="disabled"
13+
:disabled="disabled || option.disabled"
1414
class="pill-menu__toggle"
1515
:class="{ 'pill-menu__toggle--icon-only': isMobile && option.icon }"
1616
button-variant

src/components/SidebarTabs/SettingsSidebarTab.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ export default {
166166
type: Object,
167167
required: true,
168168
},
169+
170+
locked: {
171+
type: Boolean,
172+
required: true,
173+
},
169174
},
170175
171176
data() {

src/components/SidebarTabs/SharingSidebarTab.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ export default {
232232
type: Object,
233233
required: true,
234234
},
235+
236+
locked: {
237+
type: Boolean,
238+
required: true,
239+
},
235240
},
236241
237242
data() {

src/components/TopBar.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const editView = {
5353
icon: mdiPencil,
5454
title: t('forms', 'Edit'),
5555
id: 'edit',
56+
disabled: false,
5657
}
5758
const resultsView = {
5859
ariaLabel: t('forms', 'Show results'),
@@ -78,6 +79,11 @@ export default {
7879
default: false,
7980
},
8081
82+
locked: {
83+
type: Boolean,
84+
required: true,
85+
},
86+
8187
sidebarOpened: {
8288
type: Boolean,
8389
default: false,
@@ -112,7 +118,10 @@ export default {
112118
views.push(submitView)
113119
}
114120
if (this.canEdit) {
115-
views.push(editView)
121+
views.push({
122+
...editView,
123+
disabled: this.locked,
124+
})
116125
}
117126
if (this.canSeeResults) {
118127
views.push(resultsView)

src/mixins/ViewsMixin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import { getCurrentUser } from '@nextcloud/auth'
67
import { generateOcsUrl } from '@nextcloud/router'
78
import { showError } from '@nextcloud/dialogs'
89
import { emit } from '@nextcloud/event-bus'
@@ -12,6 +13,7 @@ import MarkdownIt from 'markdown-it'
1213
import CancelableRequest from '../utils/CancelableRequest.js'
1314
import OcsResponse2Data from '../utils/OcsResponse2Data.js'
1415
import logger from '../utils/Logger.js'
16+
import moment from '@nextcloud/moment'
1517

1618
export default {
1719
provide() {
@@ -92,6 +94,20 @@ export default {
9294
|| this.form.description
9395
)
9496
},
97+
98+
isFormLocked() {
99+
logger.debug('Checking if form is locked', {
100+
lockedUntil: this.form.lockedUntil,
101+
currentTime: moment().unix(),
102+
formLockedBy: this.form.lockedBy,
103+
currentUser: getCurrentUser().uid,
104+
})
105+
return (
106+
this.form.lockedUntil === 0
107+
|| (this.form.lockedUntil > moment().unix()
108+
&& this.form.lockedBy !== getCurrentUser().uid)
109+
)
110+
},
95111
},
96112

97113
methods: {

src/views/Create.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<!-- Show results & sidebar button -->
1212
<TopBar
1313
:archived="isFormArchived"
14+
:locked="isFormLocked"
1415
:permissions="form?.permissions"
1516
:sidebar-opened="sidebarOpened"
1617
:submission-count="form?.submissionCount"
@@ -39,6 +40,29 @@
3940
</template>
4041
</NcEmptyContent>
4142

43+
<NcEmptyContent
44+
v-else-if="isFormLocked"
45+
class="emtpycontent"
46+
:name="t('forms', 'Form is locked')"
47+
:description="
48+
t(
49+
'forms',
50+
'Form \'{title}\' is locked by \'{lockedBy}\' and cannot be modified. The lock will expire {lockedUntil}',
51+
{
52+
title: form.title,
53+
lockedBy: form.lockedBy,
54+
lockedUntil:
55+
form.lockedUntil === 0
56+
? t('forms', 'never')
57+
: t('forms', lockedUntilFormatted),
58+
},
59+
)
60+
">
61+
<template #icon>
62+
<IconLock :size="64" />
63+
</template>
64+
</NcEmptyContent>
65+
4266
<template v-else>
4367
<!-- Forms title & description-->
4468
<header>
@@ -279,6 +303,10 @@ export default {
279303
const { datetime, ...filteredAnswerTypes } = answerTypes
280304
return filteredAnswerTypes
281305
},
306+
307+
lockedUntilFormatted() {
308+
return moment(this.form.lockedUntil, 'X').fromNow()
309+
}
282310
},
283311
284312
watch: {

src/views/Results.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
<TopBar
2222
:archived="isFormArchived"
23+
:locked="isFormLocked"
2324
:permissions="form?.permissions"
2425
:sidebar-opened="sidebarOpened"
2526
:submission-count="form?.submissionCount"

src/views/Sidebar.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</template>
1717
<SharingSidebarTab
1818
:form="form"
19+
:locked="isFormLocked"
1920
@update:formProp="onPropertyChange"
2021
@add-share="onAddShare"
2122
@remove-share="onRemoveShare"
@@ -29,7 +30,10 @@
2930
<template #icon>
3031
<IconSettings :size="20" />
3132
</template>
32-
<SettingsSidebarTab :form="form" @update:formProp="onPropertyChange" />
33+
<SettingsSidebarTab
34+
:form="form"
35+
:locked="isFormLocked"
36+
@update:formProp="onPropertyChange" />
3337
</NcAppSidebarTab>
3438
</NcAppSidebar>
3539
</template>

src/views/Submit.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<TopBar
1111
v-if="!publicView"
1212
:archived="isArchived"
13+
:locked="isFormLocked"
1314
:permissions="form?.permissions"
1415
:sidebar-opened="sidebarOpened"
1516
:submission-count="form?.submissionCount"

0 commit comments

Comments
 (0)