Skip to content
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
2 changes: 1 addition & 1 deletion src/Forms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ import OcsResponse2Data from './utils/OcsResponse2Data.js'
import PermissionTypes from './mixins/PermissionTypes.js'
import Sidebar from './views/Sidebar.vue'
import logger from './utils/Logger.js'
import { FormState } from './models/FormStates.ts'
import { FormState } from './models/Constants.ts'

export default {
name: 'Forms',
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppNavigationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ import IconDeleteSvg from '@mdi/svg/svg/delete.svg?raw'

import FormsIcon from './Icons/FormsIcon.vue'

import { FormState } from '../models/FormStates.ts'
import { FormState } from '../models/Constants.ts'
import PermissionTypes from '../mixins/PermissionTypes.js'
import logger from '../utils/Logger.js'

Expand Down
3 changes: 2 additions & 1 deletion src/components/Questions/AnswerInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import NcActions from '@nextcloud/vue/components/NcActions'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcButton from '@nextcloud/vue/components/NcButton'

import { INPUT_DEBOUNCE_MS } from '../../models/Constants.ts'
import OcsResponse2Data from '../../utils/OcsResponse2Data.js'
import logger from '../../utils/Logger.js'

Expand Down Expand Up @@ -174,7 +175,7 @@ export default {
// As data instead of method, to have a separate debounce per AnswerInput
this.debounceOnInput = debounce((event) => {
return this.queue.add(() => this.onInput(event))
}, 500)
}, INPUT_DEBOUNCE_MS)
},

methods: {
Expand Down
10 changes: 10 additions & 0 deletions src/components/Questions/QuestionFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import { formatFileSize } from '@nextcloud/files'

/**
* A constant object representing file size units in bytes.
*
* @example
* ```typescript
* const kilobytes = FILE_SIZE_UNITS.kb; // 1024
* const megabytes = FILE_SIZE_UNITS.mb; // 1048576
* const gigabytes = FILE_SIZE_UNITS.gb; // 1073741824
* ```
*/
const FILE_SIZE_UNITS = {
kb: 1024,
mb: 1024 ** 2,
Expand Down
3 changes: 1 addition & 2 deletions src/components/Questions/QuestionMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,11 @@ import IconContentPaste from 'vue-material-design-icons/ContentPaste.vue'
import IconRadioboxBlank from 'vue-material-design-icons/RadioboxBlank.vue'

import AnswerInput from './AnswerInput.vue'
import { QUESTION_EXTRASETTINGS_OTHER_PREFIX } from '../../models/Constants.ts'
import QuestionMixin from '../../mixins/QuestionMixin.js'
import OptionInputDialog from '../OptionInputDialog.vue'
import QuestionMultipleMixin from '../../mixins/QuestionMultipleMixin.ts'

const QUESTION_EXTRASETTINGS_OTHER_PREFIX = 'system-other-answer:'

export default {
name: 'QuestionMultiple',

Expand Down
2 changes: 1 addition & 1 deletion src/components/SidebarTabs/SettingsSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ import TransferOwnership from './TransferOwnership.vue'

import { directive as ClickOutside } from 'v-click-outside'
import { loadState } from '@nextcloud/initial-state'
import { FormState } from '../../models/FormStates.ts'
import { FormState } from '../../models/Constants.ts'

export default {
components: {
Expand Down
11 changes: 6 additions & 5 deletions src/mixins/QuestionMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import debounce from 'debounce'

import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
import logger from '../utils/Logger.js'
import OcsResponse2Data from '../utils/OcsResponse2Data.js'
import Question from '../components/Questions/Question.vue'
Expand Down Expand Up @@ -214,7 +215,7 @@ export default {
onTitleChange: debounce(function (text) {
this.$emit('update:text', text)
this.saveQuestionProperty('text', text)
}, 200),
}, INPUT_DEBOUNCE_MS),

/**
* Forward the description change to the parent and store to db
Expand All @@ -224,7 +225,7 @@ export default {
onDescriptionChange: debounce(function (description) {
this.$emit('update:description', description)
this.saveQuestionProperty('description', description)
}, 200),
}, INPUT_DEBOUNCE_MS),

/**
* Forward the required change to the parent and store to db
Expand All @@ -234,7 +235,7 @@ export default {
onRequiredChange: debounce(function (isRequiredValue) {
this.$emit('update:isRequired', isRequiredValue)
this.saveQuestionProperty('isRequired', isRequiredValue)
}, 200),
}, INPUT_DEBOUNCE_MS),

/**
* Create mapper to forward the required change to the parent and store to db
Expand All @@ -247,7 +248,7 @@ export default {
const newExtraSettings = { ...this.extraSettings, ...newSettings }
this.$emit('update:extraSettings', newExtraSettings)
this.saveQuestionProperty('extraSettings', newExtraSettings)
}, 200),
}, INPUT_DEBOUNCE_MS),

/**
* Forward the technical-name change to the parent and store to db
Expand All @@ -257,7 +258,7 @@ export default {
onNameChange: debounce(function (name) {
this.$emit('update:name', name)
this.saveQuestionProperty('name', name)
}, 200),
}, INPUT_DEBOUNCE_MS),

/**
* Forward the required change to the parent and store to db
Expand Down
3 changes: 2 additions & 1 deletion src/mixins/QuestionMultipleMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { translate as t } from '@nextcloud/l10n'
import { generateOcsUrl } from '@nextcloud/router'
import { defineComponent } from 'vue'

import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
import axios from '@nextcloud/axios'
import debounce from 'debounce'
import logger from '../utils/Logger'
Expand Down Expand Up @@ -82,7 +83,7 @@ export default defineComponent({
* Debounced function to save options order
*/
onOptionsReordered() {
return debounce(this.saveOptionsOrder, 750)
return debounce(this.saveOptionsOrder, INPUT_DEBOUNCE_MS)
},
},

Expand Down
3 changes: 2 additions & 1 deletion src/mixins/UserSearchMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import debounce from 'debounce'

import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
import OcsResponse2Data from '../utils/OcsResponse2Data.js'
import logger from '../utils/Logger.js'
import ShareTypes from './ShareTypes.js'
Expand Down Expand Up @@ -76,7 +77,7 @@ export default {
*/
debounceGetSuggestions: debounce(function (...args) {
this.getSuggestions(...args)
}, 300),
}, INPUT_DEBOUNCE_MS),

/**
* Get suggestions
Expand Down
33 changes: 33 additions & 0 deletions src/models/Constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

/**
* Represents the state of a form.
*
* Possible values:
* - `FormActive` (0): The form is currently active and can be interacted with.
* - `FormClosed` (1): The form is closed and no longer accepting input.
* - `FormArchived` (2): The form is archived and stored for reference.
*
* Keep in sync with Constants.php
*/
export enum FormState {
FormActive = 0,
FormClosed = 1,
FormArchived = 2,
}

/**
* The debounce time in milliseconds for input events.
*
* This constant is used to limit the rate at which input-related
* operations are triggered, improving performance and user experience.
*/
export const INPUT_DEBOUNCE_MS = 400

/**
* A constant representing the prefix used for identifying "other" answers
*/
export const QUESTION_EXTRASETTINGS_OTHER_PREFIX = 'system-other-answer:'
15 changes: 0 additions & 15 deletions src/models/FormStates.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import IconLock from 'vue-material-design-icons/Lock.vue'
import IconPlus from 'vue-material-design-icons/Plus.vue'

import { FormState } from '../models/FormStates.ts'
import { FormState, INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
import answerTypes from '../models/AnswerTypes.js'
import Question from '../components/Questions/Question.vue'
import QuestionLong from '../components/Questions/QuestionLong.vue'
Expand Down Expand Up @@ -367,10 +367,10 @@ export default {
*/
saveTitle: debounce(async function () {
this.saveFormProperty('title')
}, 200),
}, INPUT_DEBOUNCE_MS),
saveDescription: debounce(async function () {
this.saveFormProperty('description')
}, 200),
}, INPUT_DEBOUNCE_MS),

/**
* Add a new question to the current form
Expand Down
2 changes: 1 addition & 1 deletion src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ import IconShareVariant from 'vue-material-design-icons/ShareVariant.vue'
import IconTable from 'vue-material-design-icons/Table.vue'
import IconTableSvg from '@mdi/svg/svg/table.svg?raw'

import { FormState } from '../models/FormStates.ts'
import { FormState } from '../models/Constants.ts'
import ResultsSummary from '../components/Results/ResultsSummary.vue'
import Submission from '../components/Results/Submission.vue'
import TopBar from '../components/TopBar.vue'
Expand Down
2 changes: 1 addition & 1 deletion src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ import IconCheckSvg from '@mdi/svg/svg/check.svg?raw'
import IconRefreshSvg from '@mdi/svg/svg/refresh.svg?raw'
import IconSendSvg from '@mdi/svg/svg/send.svg?raw'

import { FormState } from '../models/FormStates.ts'
import { FormState } from '../models/Constants.ts'
import answerTypes from '../models/AnswerTypes.js'
import logger from '../utils/Logger.js'

Expand Down
Loading