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' )
@@ -258,16 +272,16 @@ export default {
258272 /**
259273 * Return, if form has Subtitle
260274 */
261- hasSubtitle () {
275+ hasSubtitle(): boolean {
262276 return this .formSubtitle !== ' '
263277 },
264278
265279 /**
266280 * Route to use, depending on readOnly
267281 *
268- * @return {string} Route to 'submit' or 'formRoot'
282+ * @return Route to 'submit' or 'formRoot'
269283 */
270- routerTarget () {
284+ routerTarget(): NavigationTarget {
271285 if (this .readOnly ) {
272286 return ' submit'
273287 }
@@ -280,19 +294,19 @@ export default {
280294 /**
281295 * Closes the App-Navigation on mobile-devices
282296 */
283- mobileCloseNavigation () {
297+ mobileCloseNavigation(): void {
284298 this .$emit (' mobileCloseNavigation' )
285299 },
286300
287- onShareForm () {
301+ onShareForm(): void {
288302 this .$emit (' openSharing' , this .form .hash )
289303 },
290304
291- onCloneForm () {
305+ onCloneForm(): void {
292306 this .$emit (' clone' , this .form .id )
293307 },
294308
295- async onConfirmDelete () {
309+ async onConfirmDelete(): Promise < void > {
296310 const shouldDelete = await showConfirmation ({
297311 name: t (' forms' , ' Delete form' ),
298312 text: t (' forms' , ' Are you sure you want to delete {title}?' , {
@@ -307,7 +321,7 @@ export default {
307321 }
308322 },
309323
310- async onToggleArchive () {
324+ async onToggleArchive(): Promise < void > {
311325 try {
312326 // TODO: add loading status feedback ?
313327 await axios .patch (
@@ -322,8 +336,8 @@ export default {
322336 },
323337 },
324338 )
325- // eslint-disable-next-line vue/no-mutating-props
326- this .form .state = this .isArchived
339+
340+ ;( this .form as FormsForm ) .state = this .isArchived
327341 ? FormState .FormClosed
328342 : FormState .FormArchived
329343 } catch (error ) {
@@ -334,7 +348,7 @@ export default {
334348 }
335349 },
336350
337- async onDeleteForm () {
351+ async onDeleteForm(): Promise < void > {
338352 this .loading = true
339353 try {
340354 await axios .delete (
@@ -344,8 +358,9 @@ export default {
344358 )
345359 this .$emit (' delete' , this .form .id )
346360 } catch (error ) {
361+ const response = (error as { response? : unknown }).response
347362 logger .error (` Error while deleting ${this .formTitle } ` , {
348- error: error . response ,
363+ error: response ,
349364 })
350365 showError (
351366 t (' forms' , ' Error while deleting {title}' , {
@@ -357,5 +372,5 @@ export default {
357372 }
358373 },
359374 },
360- }
375+ })
361376 </script >
0 commit comments