Skip to content

Commit f3df198

Browse files
committed
Add lastUpdated sorting to frontend
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 46a016e commit f3df198

7 files changed

Lines changed: 46 additions & 2 deletions

File tree

src/Forms.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@
103103
</template>
104104

105105
<script>
106-
import { emit } from '@nextcloud/event-bus'
106+
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
107107
import { generateOcsUrl } from '@nextcloud/router'
108108
import { loadState } from '@nextcloud/initial-state'
109109
import { showError } from '@nextcloud/dialogs'
110110
import axios from '@nextcloud/axios'
111+
import moment from '@nextcloud/moment'
111112
112113
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent.js'
113114
import NcAppNavigation from '@nextcloud/vue/dist/Components/NcAppNavigation.js'
@@ -224,6 +225,14 @@ export default {
224225
this.loadForms()
225226
},
226227
228+
mounted() {
229+
subscribe('change-last-updated', (id) => this.onLastUpdatedByEventBus(id))
230+
},
231+
232+
unmounted() {
233+
unsubscribe('change-last-updated', (id) => this.onLastUpdatedByEventBus(id))
234+
},
235+
227236
methods: {
228237
/**
229238
* Closes the App-Navigation on mobile-devices
@@ -349,6 +358,23 @@ export default {
349358
this.$router.push({ name: 'root' })
350359
}
351360
},
361+
362+
/**
363+
* Update last updated timestamp in given form
364+
*
365+
* @param {number} id the form id
366+
*/
367+
onLastUpdatedByEventBus(id) {
368+
const formIndex = this.forms.findIndex(form => form.id === id)
369+
if (formIndex !== -1) {
370+
this.forms[formIndex].lastUpdated = moment().unix()
371+
this.forms.sort((b, a) => a.lastUpdated - b.lastUpdated)
372+
} else {
373+
const sharedFormIndex = this.sharedForms.findIndex(form => form.id === id)
374+
this.sharedForms[sharedFormIndex].lastUpdated = moment().unix()
375+
this.sharedForms.sort((a, b) => a.lastUpdated - b.lastUpdated)
376+
}
377+
},
352378
},
353379
}
354380
</script>

src/mixins/QuestionMixin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
*
2121
*/
2222
import { debounce } from 'debounce'
23-
import { generateOcsUrl } from '@nextcloud/router'
2423
import { showError } from '@nextcloud/dialogs'
24+
import { emit } from '@nextcloud/event-bus'
25+
import { generateOcsUrl } from '@nextcloud/router'
2526
import axios from '@nextcloud/axios'
2627

2728
import logger from '../utils/Logger.js'
@@ -256,6 +257,7 @@ export default {
256257
[key]: value,
257258
},
258259
})
260+
emit('change-last-updated', this.$attrs.formId)
259261
} catch (error) {
260262
logger.error('Error while saving question', { error })
261263
showError(t('forms', 'Error while saving question'))

src/mixins/ViewsMixin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { generateOcsUrl } from '@nextcloud/router'
2424
import { showError } from '@nextcloud/dialogs'
25+
import { emit } from '@nextcloud/event-bus'
2526
import axios from '@nextcloud/axios'
2627
import MarkdownIt from 'markdown-it'
2728

@@ -152,6 +153,7 @@ export default {
152153
[key]: this.form[key],
153154
},
154155
})
156+
emit('change-last-updated', this.form.id)
155157
} catch (error) {
156158
logger.error('Error saving form property', { error })
157159
showError(t('forms', 'Error while saving form'))

src/views/Create.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ import { directive as ClickOutside } from 'v-click-outside'
129129
import { generateOcsUrl } from '@nextcloud/router'
130130
import { loadState } from '@nextcloud/initial-state'
131131
import { showError } from '@nextcloud/dialogs'
132+
import { emit } from '@nextcloud/event-bus'
132133
import axios from '@nextcloud/axios'
133134
import moment from '@nextcloud/moment'
134135
import debounce from 'debounce'
@@ -333,6 +334,8 @@ export default {
333334
lastQuestion.focus()
334335
})
335336
337+
emit('change-last-updated', this.form.id)
338+
336339
} catch (error) {
337340
logger.error('Error while adding new question', { error })
338341
showError(t('forms', 'There was an error while adding the new question'))
@@ -354,6 +357,7 @@ export default {
354357
await axios.delete(generateOcsUrl('apps/forms/api/v2/question/{id}', { id }))
355358
const index = this.form.questions.findIndex(search => search.id === id)
356359
this.form.questions.splice(index, 1)
360+
emit('change-last-updated', this.form.id)
357361
} catch (error) {
358362
logger.error(`Error while removing question ${id}`, { error })
359363
showError(t('forms', 'There was an error while removing the question'))
@@ -374,6 +378,7 @@ export default {
374378
formId: this.form.id,
375379
newOrder,
376380
})
381+
emit('change-last-updated', this.form.id)
377382
} catch (error) {
378383
logger.error('Error while saving form', { error })
379384
showError(t('forms', 'Error while saving form'))

src/views/Results.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
import { generateOcsUrl } from '@nextcloud/router'
134134
import { getRequestToken } from '@nextcloud/auth'
135135
import { getFilePickerBuilder, showError, showSuccess } from '@nextcloud/dialogs'
136+
import { emit } from '@nextcloud/event-bus'
136137
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
137138
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
138139
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent.js'
@@ -270,6 +271,7 @@ export default {
270271
await axios.delete(generateOcsUrl('apps/forms/api/v2/submission/{id}', { id }))
271272
const index = this.form.submissions.findIndex(search => search.id === id)
272273
this.form.submissions.splice(index, 1)
274+
emit('change-last-updated', this.form.id)
273275
} catch (error) {
274276
logger.error(`Error while removing response ${id}`, { error })
275277
showError(t('forms', 'There was an error while removing this response'))
@@ -287,6 +289,7 @@ export default {
287289
try {
288290
await axios.delete(generateOcsUrl('apps/forms/api/v2/submissions/{formId}', { formId: this.form.id }))
289291
this.form.submissions = []
292+
emit('change-last-updated', this.form.id)
290293
} catch (error) {
291294
logger.error('Error while removing responses', { error })
292295
showError(t('forms', 'There was an error while removing responses'))

src/views/Sidebar.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
</template>
5353

5454
<script>
55+
import { emit } from '@nextcloud/event-bus'
5556
import NcAppSidebar from '@nextcloud/vue/dist/Components/NcAppSidebar.js'
5657
import NcAppSidebarTab from '@nextcloud/vue/dist/Components/NcAppSidebarTab.js'
5758
import IconSettings from 'vue-material-design-icons/Cog.vue'
@@ -114,14 +115,17 @@ export default {
114115
*/
115116
onAddShare(share) {
116117
this.form.shares.push(share)
118+
emit('change-last-updated', this.form.id)
117119
},
118120
onRemoveShare(share) {
119121
const index = this.form.shares.findIndex(search => search.id === share.id)
120122
this.form.shares.splice(index, 1)
123+
emit('change-last-updated', this.form.id)
121124
},
122125
onUpdateShare(share) {
123126
const index = this.form.shares.findIndex(search => search.id === share.id)
124127
this.form.shares.splice(index, 1, share)
128+
emit('change-last-updated', this.form.id)
125129
},
126130
},
127131
}

src/views/Submit.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import { loadState } from '@nextcloud/initial-state'
106106
import { generateOcsUrl } from '@nextcloud/router'
107107
import { showError } from '@nextcloud/dialogs'
108+
import { emit } from '@nextcloud/event-bus'
108109
import axios from '@nextcloud/axios'
109110
import moment from '@nextcloud/moment'
110111
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent.js'
@@ -274,6 +275,7 @@ export default {
274275
shareHash: this.shareHash,
275276
})
276277
this.success = true
278+
emit('change-last-updated', this.form.id)
277279
} catch (error) {
278280
logger.error('Error while submitting the form', { error })
279281
showError(t('forms', 'There was an error submitting the form'))

0 commit comments

Comments
 (0)