From ebf66d7e829ce216b97e69c707b292e634e16b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 21 Apr 2020 18:03:43 +0200 Subject: [PATCH] Fix forms change saving & add question scroll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- appinfo/routes.php | 24 ++++++------- src/Forms.vue | 8 +---- src/mixins/QuestionMixin.js | 14 ++++++++ src/mixins/ViewsMixin.js | 4 +++ src/router.js | 8 ++--- src/utils/FormsUtils.js | 37 -------------------- src/views/Create.vue | 69 +++++++++++++++++++------------------ 7 files changed, 70 insertions(+), 94 deletions(-) delete mode 100644 src/utils/FormsUtils.js diff --git a/appinfo/routes.php b/appinfo/routes.php index 1000169..1f04c27 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -34,18 +34,18 @@ return [ ['name' => 'page#goto_form', 'url' => '/{hash}', 'verb' => 'GET'], ['name' => 'page#insert_submission', 'url' => '/insert/submission', 'verb' => 'POST'], - ['name' => 'api#getForms', 'url' => 'api/v1/forms', 'verb' => 'GET'], - ['name' => 'api#newForm', 'url' => 'api/v1/form', 'verb' => 'POST'], - ['name' => 'api#getForm', 'url' => 'api/v1/form/{id}', 'verb' => 'GET'], - ['name' => 'api#updateForm', 'url' => 'api/v1/form/update/', 'verb' => 'POST'], - ['name' => 'api#deleteForm', 'url' => 'api/v1/form/{id}', 'verb' => 'DELETE'], - ['name' => 'api#updateQuestion', 'url' => 'api/v1/question/update', 'verb' => 'POST'], - ['name' => 'api#reorderQuestions', 'url' => 'api/v1/question/reorder', 'verb' => 'POST'], - ['name' => 'api#newQuestion', 'url' => 'api/v1/question', 'verb' => 'POST'], - ['name' => 'api#deleteQuestion', 'url' => 'api/v1/question/{id}', 'verb' => 'DELETE'], - ['name' => 'api#newOption', 'url' => 'api/v1/option', 'verb' => 'POST'], - ['name' => 'api#deleteOption', 'url' => 'api/v1/option/{id}', 'verb' => 'DELETE'], - ['name' => 'api#getSubmissions', 'url' => 'api/v1/submissions/{hash}', 'verb' => 'GET'], + ['name' => 'api#getForms', 'url' => '/api/v1/forms', 'verb' => 'GET'], + ['name' => 'api#newForm', 'url' => '/api/v1/form', 'verb' => 'POST'], + ['name' => 'api#getForm', 'url' => '/api/v1/form/{id}', 'verb' => 'GET'], + ['name' => 'api#updateForm', 'url' => '/api/v1/form/update/', 'verb' => 'POST'], + ['name' => 'api#deleteForm', 'url' => '/api/v1/form/{id}', 'verb' => 'DELETE'], + ['name' => 'api#updateQuestion', 'url' => '/api/v1/question/update', 'verb' => 'POST'], + ['name' => 'api#reorderQuestions', 'url' => '/api/v1/question/reorder', 'verb' => 'POST'], + ['name' => 'api#newQuestion', 'url' => '/api/v1/question', 'verb' => 'POST'], + ['name' => 'api#deleteQuestion', 'url' => '/api/v1/question/{id}', 'verb' => 'DELETE'], + ['name' => 'api#newOption', 'url' => '/api/v1/option', 'verb' => 'POST'], + ['name' => 'api#deleteOption', 'url' => '/api/v1/option/{id}', 'verb' => 'DELETE'], + ['name' => 'api#getSubmissions', 'url' => '/api/v1/submissions/{hash}', 'verb' => 'GET'], ['name' => 'system#get_site_users_and_groups', 'url' => '/get/siteusers', 'verb' => 'POST'], ] diff --git a/src/Forms.vue b/src/Forms.vue index ceb5b6e..d02ac3d 100644 --- a/src/Forms.vue +++ b/src/Forms.vue @@ -25,7 +25,7 @@ - @@ -71,8 +71,6 @@ import Content from '@nextcloud/vue/dist/Components/Content' import AppNavigationForm from './components/AppNavigationForm' import EmptyContent from './components/EmptyContent' -import { formatForm } from './utils/FormsUtils' - export default { name: 'Forms', @@ -97,10 +95,6 @@ export default { return this.forms && this.forms.length === 0 }, - formattedForms() { - return this.forms.map(formatForm) - }, - hash() { return this.$route.params.hash }, diff --git a/src/mixins/QuestionMixin.js b/src/mixins/QuestionMixin.js index 504200e..4056d30 100644 --- a/src/mixins/QuestionMixin.js +++ b/src/mixins/QuestionMixin.js @@ -94,5 +94,19 @@ export default { onDelete() { this.$emit('delete') }, + + /** + * Focus the first focusable element + */ + focus() { + this.edit = true + this.$el.scrollIntoView({ behavior: 'smooth' }) + this.$nextTick(() => { + const title = this.$el.querySelector('.question__header-title') + if (title) { + title.select() + } + }) + }, }, } diff --git a/src/mixins/ViewsMixin.js b/src/mixins/ViewsMixin.js index b112269..0354c2e 100644 --- a/src/mixins/ViewsMixin.js +++ b/src/mixins/ViewsMixin.js @@ -21,6 +21,10 @@ export default { props: { + hash: { + type: String, + default: '', + }, form: { type: Object, required: true, diff --git a/src/router.js b/src/router.js index de954d1..39b6af0 100644 --- a/src/router.js +++ b/src/router.js @@ -56,7 +56,7 @@ export default new Router({ { path: '/:hash', name: 'fill', - props: true, + props: { default: true }, }, { path: '/:hash/edit', @@ -65,13 +65,13 @@ export default new Router({ sidebar: Sidebar, }, name: 'edit', - props: true, + props: { default: true }, }, { path: '/:hash/results', component: Results, name: 'results', - props: true, + props: { default: true }, }, { path: '/:hash/clone', @@ -80,7 +80,7 @@ export default new Router({ sidebar: Sidebar, }, name: 'clone', - props: true, + props: { default: true }, }, ], }) diff --git a/src/utils/FormsUtils.js b/src/utils/FormsUtils.js deleted file mode 100644 index d8ccc7c..0000000 --- a/src/utils/FormsUtils.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @copyright Copyright (c) 2020 John Molakvoæ - * - * @author John Molakvoæ - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -/** - * Format a form object prior to forms v2.0 - * - * @param {Object} form the form raw object - * @returns {Object} properly formatted form object - */ -const formatForm = function(form) { - // clone form - const newForm = Object.assign({}, form) - - // cleanup - delete newForm.event - return newForm -} - -export { formatForm } diff --git a/src/views/Create.vue b/src/views/Create.vue index f5de89e..a254696 100644 --- a/src/views/Create.vue +++ b/src/views/Create.vue @@ -27,7 +27,7 @@ -->