9797 </NcListItem >
9898</template >
9999
100- <script >
100+ <script lang="ts">
101+ import type { PropType } from ' vue'
102+ import type { FormsForm } from ' ../models/Entities.d.ts'
103+
101104import IconArchive from ' @material-symbols/svg-400/outlined/archive.svg?raw'
102105import IconPoll from ' @material-symbols/svg-400/outlined/bar_chart.svg?raw'
103106import IconCheck from ' @material-symbols/svg-400/outlined/check.svg?raw'
@@ -109,8 +112,10 @@ import IconArchiveOff from '@material-symbols/svg-400/outlined/unarchive.svg?raw
109112import { getCurrentUser } from ' @nextcloud/auth'
110113import axios from ' @nextcloud/axios'
111114import { showConfirmation , showError } from ' @nextcloud/dialogs'
115+ import { translate as t } from ' @nextcloud/l10n'
112116import moment from ' @nextcloud/moment'
113117import { generateOcsUrl } from ' @nextcloud/router'
118+ import { defineComponent } from ' vue'
114119import NcActionButton from ' @nextcloud/vue/components/NcActionButton'
115120import NcActionRouter from ' @nextcloud/vue/components/NcActionRouter'
116121import NcActionSeparator from ' @nextcloud/vue/components/NcActionSeparator'
@@ -122,7 +127,13 @@ import PermissionTypes from '../mixins/PermissionTypes.ts'
122127import { FormState } from ' ../models/Constants.ts'
123128import logger from ' ../utils/Logger.ts'
124129
125- export default {
130+ type NavigationTarget = ' submit' | ' formRoot'
131+
132+ interface AppNavigationFormData {
133+ loading: boolean
134+ }
135+
136+ export default defineComponent ({
126137 name: ' AppNavigationForm' ,
127138
128139 components: {
@@ -138,7 +149,7 @@ export default {
138149
139150 props: {
140151 form: {
141- type: Object ,
152+ type: Object as PropType < FormsForm > ,
142153 required: true ,
143154 },
144155
@@ -158,6 +169,7 @@ export default {
158169
159170 setup() {
160171 return {
172+ t ,
161173 FormsIcon ,
162174 IconArchive ,
163175 IconArchiveOff ,
@@ -170,65 +182,67 @@ export default {
170182 }
171183 },
172184
173- data () {
185+ data(): AppNavigationFormData {
174186 return {
175187 loading: false ,
176188 }
177189 },
178190
179191 computed: {
180- canEdit () {
192+ canEdit(): boolean {
181193 return this .form .permissions .includes (
182194 this .PERMISSION_TYPES .PERMISSION_EDIT ,
183195 )
184196 },
185197
186- canSeeResults () {
198+ canSeeResults(): boolean {
187199 return (
188200 this .form .permissions .includes (
189201 this .PERMISSION_TYPES .PERMISSION_RESULTS ,
190- ) || this .form .submissionCount > 0
202+ ) || ( this .form .submissionCount ?? 0 ) > 0
191203 )
192204 },
193205
194206 /**
195207 * Check if form is current form and set active
196208 */
197- isActive () {
198- return this .form .hash === this .$route .params .hash
209+ isActive(): boolean {
210+ return this .form .hash === String ( this .$route .params .hash )
199211 },
200212
201213 /**
202214 * Check if the form is archived
203215 */
204- isArchived () {
216+ isArchived(): boolean {
205217 return this .form .state === FormState .FormArchived
206218 },
207219
208220 /**
209221 * Check if form is expired
210222 */
211- isExpired () {
212- return this .form .expires && moment ().unix () > this .form .expires
223+ isExpired(): boolean {
224+ return Boolean ( this .form .expires && moment ().unix () > this .form .expires )
213225 },
214226
215227 /**
216228 * Check if form is locked
217229 */
218- isFormLocked () {
230+ isFormLocked(): boolean {
231+ const currentUserUid = getCurrentUser ()?.uid ?? ' '
232+ const lockedUntil = this .form .lockedUntil ?? - 1
219233 return (
220- this . form . lockedUntil === 0
221- || (this . form . lockedUntil > moment ().unix ()
222- && this .form .lockedBy !== getCurrentUser (). uid )
234+ lockedUntil === 0
235+ || (lockedUntil > moment ().unix ()
236+ && this .form .lockedBy !== currentUserUid )
223237 )
224238 },
225239
226240 /**
227241 * Return form title, or placeholder if not set
228242 *
229- * @return {string}
243+ * @return
230244 */
231- formTitle () {
245+ formTitle(): string {
232246 if (this .form .title ) {
233247 return this .form .title
234248 }
@@ -238,7 +252,7 @@ export default {
238252 /**
239253 * Return expiration details for subtitle
240254 */
241- formSubtitle () {
255+ formSubtitle(): string {
242256 if (this .form .state === FormState .FormClosed ) {
243257 // TRANSLATORS: The form was closed manually so it does not take new submissions
244258 return t (' forms' , ' Form closed' )
@@ -260,16 +274,16 @@ export default {
260274 /**
261275 * Return, if form has Subtitle
262276 */
263- hasSubtitle () {
277+ hasSubtitle(): boolean {
264278 return this .formSubtitle !== ' '
265279 },
266280
267281 /**
268282 * Route to use, depending on readOnly
269283 *
270- * @return {string} Route to 'submit' or 'formRoot'
284+ * @return Route to 'submit' or 'formRoot'
271285 */
272- routerTarget () {
286+ routerTarget(): NavigationTarget {
273287 if (this .readOnly ) {
274288 return ' submit'
275289 }
@@ -282,19 +296,19 @@ export default {
282296 /**
283297 * Closes the App-Navigation on mobile-devices
284298 */
285- mobileCloseNavigation () {
299+ mobileCloseNavigation(): void {
286300 this .$emit (' mobileCloseNavigation' )
287301 },
288302
289- onShareForm () {
303+ onShareForm(): void {
290304 this .$emit (' openSharing' , this .form .hash )
291305 },
292306
293- onCloneForm () {
307+ onCloneForm(): void {
294308 this .$emit (' clone' , this .form .id )
295309 },
296310
297- async onConfirmDelete () {
311+ async onConfirmDelete(): Promise < void > {
298312 const shouldDelete = await showConfirmation ({
299313 name: t (' forms' , ' Delete form' ),
300314 text: t (' forms' , ' Are you sure you want to delete {title}?' , {
@@ -309,7 +323,7 @@ export default {
309323 }
310324 },
311325
312- async onToggleArchive () {
326+ async onToggleArchive(): Promise < void > {
313327 try {
314328 // TODO: add loading status feedback ?
315329 await axios .patch (
@@ -324,8 +338,8 @@ export default {
324338 },
325339 },
326340 )
327- // eslint-disable-next-line vue/no-mutating-props
328- this .form .state = this .isArchived
341+
342+ ;( this .form as FormsForm ) .state = this .isArchived
329343 ? FormState .FormClosed
330344 : FormState .FormArchived
331345 } catch (error ) {
@@ -336,7 +350,7 @@ export default {
336350 }
337351 },
338352
339- async onDeleteForm () {
353+ async onDeleteForm(): Promise < void > {
340354 this .loading = true
341355 try {
342356 await axios .delete (
@@ -346,8 +360,9 @@ export default {
346360 )
347361 this .$emit (' delete' , this .form .id )
348362 } catch (error ) {
363+ const response = (error as { response? : unknown }).response
349364 logger .error (` Error while deleting ${this .formTitle } ` , {
350- error: error . response ,
365+ error: response ,
351366 })
352367 showError (
353368 t (' forms' , ' Error while deleting {title}' , {
@@ -359,5 +374,5 @@ export default {
359374 }
360375 },
361376 },
362- }
377+ })
363378 </script >
0 commit comments