From 69c8d91bf1bb8d57a472582614cf949faea954b6 Mon Sep 17 00:00:00 2001 From: DeluzeDEV Date: Tue, 14 Jul 2020 16:21:48 +0200 Subject: [PATCH 01/33] Refactor --- .../src/api/endpoints/authorisation/login.js | 2 +- .../src/api/endpoints/authorisation/logout.js | 2 +- .../api/endpoints/authorisation/password.js | 2 +- .../api/endpoints/authorisation/register.js | 2 +- .../src/api/endpoints/password/forgotten.js | 2 +- .../src/api/endpoints/password/reset.js | 4 +- .../components/Authorisation/LoginCard.vue | 4 +- .../Authorisation/PasswordForgottenCard.vue | 7 +- .../Authorisation/PasswordResetCard.vue | 50 +++-- .../components/Authorisation/RegisterCard.vue | 2 + .../src/guards/AuthorisationGuard | 9 - .../src/guards/AuthorisationGuard.js | 11 + .../src/templates/Authorisation.vue | 19 +- .../src/views/AuthorisationCallback.vue | 13 +- .../src/views/InvitationAccept.vue | 180 ++++++++------- .../Authorisation/src/views/Login.vue | 11 +- .../Authorisation/src/views/PasswordReset.vue | 14 +- .../Crud/src/components/Resource.vue | 11 +- .../components/VuetifyResourceBaseForm.vue | 6 - .../forms/{User.vue => UserForm.vue} | 20 +- .../Crud/src/mixins/formDataValues.js | 6 +- .../templates/Crud/src/views/UserResource.vue | 57 +++-- generator/templates/Default/src/App.vue | 14 +- .../Default/src/Views/PageForbidden.vue | 28 --- .../Default/src/Views/PageNotFound.vue | 28 --- .../src/api/implementation/app/index.js | 13 +- .../src/api/implementation/app/interceptor.js | 23 +- .../src/api/implementation/app/wrapper.js | 56 +---- .../Default/src/api/util/response.js | 11 + .../api/utils/handleTooManyRequestsError.js | 10 - .../Default/src/application/util/url.js | 15 ++ .../Default/src/components/AppBarMenu.vue | 17 +- .../Default/src/components/BaseForm.vue | 12 +- .../src/components/PaginatedAutocomplete.vue | 212 +++++++++--------- .../Default/src/components/menu/MainMenu.vue | 17 ++ .../{MainMenu.vue => menu/Menu.vue} | 55 ++--- .../templates/Default/src/router/index.js | 2 - .../templates/Default/src/store/index.js | 9 +- .../src/store/modules/Authorisation.js | 5 + .../Default/src/store/modules/Error.js | 1 - .../Default/src/templates/Default.vue | 28 ++- .../templates/Default/src/views/Home.vue | 23 +- .../Default/src/views/PageForbidden.vue | 13 ++ .../Default/src/views/PageNotFound.vue | 13 ++ .../Plugins/sentry/src/plugins/sentry.js | 8 +- prompts.js | 6 +- 46 files changed, 507 insertions(+), 546 deletions(-) delete mode 100644 generator/templates/Authorisation/src/guards/AuthorisationGuard create mode 100644 generator/templates/Authorisation/src/guards/AuthorisationGuard.js rename generator/templates/Crud/src/components/forms/{User.vue => UserForm.vue} (83%) delete mode 100644 generator/templates/Default/src/Views/PageForbidden.vue delete mode 100644 generator/templates/Default/src/Views/PageNotFound.vue create mode 100644 generator/templates/Default/src/api/util/response.js delete mode 100644 generator/templates/Default/src/api/utils/handleTooManyRequestsError.js create mode 100644 generator/templates/Default/src/application/util/url.js create mode 100644 generator/templates/Default/src/components/menu/MainMenu.vue rename generator/templates/Default/src/components/{MainMenu.vue => menu/Menu.vue} (57%) create mode 100644 generator/templates/Default/src/views/PageForbidden.vue create mode 100644 generator/templates/Default/src/views/PageNotFound.vue diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js index 42e28bb..d7919fa 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js @@ -1,4 +1,4 @@ -import {post} from '../../implementation/app/wrapper'; +import {post} from '../../implementation/app'; export default function (email, password) { return post('auth/login', { diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/logout.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/logout.js index 8f4931a..fbc1259 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/logout.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/logout.js @@ -1,4 +1,4 @@ -import {post} from '../../implementation/app/wrapper.js'; +import {post} from '../../implementation/app'; export default function () { return post('auth/logout'); diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js index 19db457..98bbf24 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js @@ -1,4 +1,4 @@ -import {post} from '../../implementation/app/wrapper.js'; +import {post} from '../../implementation/app'; function passwordForgotten(email) { return post('password/forgotten', { diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js index d5b155e..800b5e9 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js @@ -1,4 +1,4 @@ -import {post} from '../../implementation/app/wrapper.js'; +import {post} from '../../implementation/app'; export default function (email, name) { return post('registration', { diff --git a/generator/templates/Authorisation/src/api/endpoints/password/forgotten.js b/generator/templates/Authorisation/src/api/endpoints/password/forgotten.js index 3644853..f76f541 100644 --- a/generator/templates/Authorisation/src/api/endpoints/password/forgotten.js +++ b/generator/templates/Authorisation/src/api/endpoints/password/forgotten.js @@ -1,4 +1,4 @@ -import {post} from '../../implementation/app/wrapper.js'; +import {post} from '../../implementation/app'; export default function (email) { return post('password/forgotten', { diff --git a/generator/templates/Authorisation/src/api/endpoints/password/reset.js b/generator/templates/Authorisation/src/api/endpoints/password/reset.js index b32be24..83caf14 100644 --- a/generator/templates/Authorisation/src/api/endpoints/password/reset.js +++ b/generator/templates/Authorisation/src/api/endpoints/password/reset.js @@ -1,10 +1,10 @@ -import {post} from '../../implementation/app/wrapper.js'; +import {post} from '../../implementation/app'; export default async function (email, token, password, passwordConfirmation) { return post('registration', { email: email, token: token, password: password, - password_confirmation: passwordConfirmation + password_confirmation: passwordConfirmation, }); } diff --git a/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue b/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue index 9d66b95..89a4ba8 100644 --- a/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue +++ b/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue @@ -61,7 +61,7 @@ export default { }, computed: { ...mapGetters({ - findError: 'Error/find', + findError: 'error/find', }), }, methods: { @@ -70,7 +70,7 @@ export default { LoginRequest(this.form.email, this.form.password) .then(res => { this.isRedirecting = true; - this.redirectToAuthDispense(res.data.token); + this.redirectToAuthDispense(res.data.data.token); }) .catch(() => this.errorMessage = this.findError('email')) .finally(() => this.isLoading = false); diff --git a/generator/templates/Authorisation/src/components/Authorisation/PasswordForgottenCard.vue b/generator/templates/Authorisation/src/components/Authorisation/PasswordForgottenCard.vue index 8b7ddb1..6172785 100644 --- a/generator/templates/Authorisation/src/components/Authorisation/PasswordForgottenCard.vue +++ b/generator/templates/Authorisation/src/components/Authorisation/PasswordForgottenCard.vue @@ -49,16 +49,15 @@ export default { if (!this.isValid) return; this.isLoading = true; + this.alertMessage = ''; + this.alertType = 'error'; ForgottenRequest(this.form.email) .then(() => { this.alertMessage = 'Er is een wachtwoord vergeten mail verstuurd mits er een account bestaat met het gegeven email adres.'; this.alertType = 'success'; }) - .catch(() => { - this.alertMessage = 'De ingevulde gegevens kloppen niet.'; - this.alertType = 'error'; - }) + .catch(() => this.alertMessage = 'De ingevulde gegevens kloppen niet.') .finally(() => this.isLoading = false); }, }, diff --git a/generator/templates/Authorisation/src/components/Authorisation/PasswordResetCard.vue b/generator/templates/Authorisation/src/components/Authorisation/PasswordResetCard.vue index ee7574d..8457ed3 100644 --- a/generator/templates/Authorisation/src/components/Authorisation/PasswordResetCard.vue +++ b/generator/templates/Authorisation/src/components/Authorisation/PasswordResetCard.vue @@ -1,10 +1,10 @@ - - - diff --git a/generator/templates/Authorisation/src/views/AuthorisationCallback.vue b/generator/templates/Authorisation/src/views/AuthorisationCallback.vue index 7bec31d..9ffb628 100644 --- a/generator/templates/Authorisation/src/views/AuthorisationCallback.vue +++ b/generator/templates/Authorisation/src/views/AuthorisationCallback.vue @@ -1,23 +1,26 @@ - diff --git a/generator/templates/Authorisation/src/views/Login.vue b/generator/templates/Authorisation/src/views/Login.vue index ca603e4..c0a541b 100644 --- a/generator/templates/Authorisation/src/views/Login.vue +++ b/generator/templates/Authorisation/src/views/Login.vue @@ -9,16 +9,15 @@ - - - diff --git a/generator/templates/Authorisation/src/views/PasswordReset.vue b/generator/templates/Authorisation/src/views/PasswordReset.vue index 75f4ceb..add04e6 100644 --- a/generator/templates/Authorisation/src/views/PasswordReset.vue +++ b/generator/templates/Authorisation/src/views/PasswordReset.vue @@ -6,11 +6,13 @@ - diff --git a/generator/templates/Crud/src/components/Resource.vue b/generator/templates/Crud/src/components/Resource.vue index ea9c700..f290d96 100644 --- a/generator/templates/Crud/src/components/Resource.vue +++ b/generator/templates/Crud/src/components/Resource.vue @@ -174,7 +174,6 @@ export default { this.appendFormData(formData, this.mapCreateFormValuesHandler(cloneDeep(this.createForm.values))); return formData; - }, createEvent() { this.errors = {}; @@ -192,16 +191,14 @@ export default { } else { resolve(); } - }).catch((error) => { - this.errors = error.data.errors; + }).catch(error => { + this.errors = error.response.data.errors; reject(); }); - } else { reject(); } }); - }); }, getUpdateFormValues() { @@ -225,8 +222,8 @@ export default { } else { resolve(); } - }).catch((error) => { - this.errors = error.data.errors; + }).catch(error => { + this.errors = error.response.data.errors; reject(); }); diff --git a/generator/templates/Crud/src/components/VuetifyResourceBaseForm.vue b/generator/templates/Crud/src/components/VuetifyResourceBaseForm.vue index bb5a277..38c7c80 100644 --- a/generator/templates/Crud/src/components/VuetifyResourceBaseForm.vue +++ b/generator/templates/Crud/src/components/VuetifyResourceBaseForm.vue @@ -11,12 +11,6 @@ export default { }, type: Object, }, - errors: { - default() { - return {}; - }, - type: Object, - }, isUpdateForm: { type: Boolean, default: false, diff --git a/generator/templates/Crud/src/components/forms/User.vue b/generator/templates/Crud/src/components/forms/UserForm.vue similarity index 83% rename from generator/templates/Crud/src/components/forms/User.vue rename to generator/templates/Crud/src/components/forms/UserForm.vue index 265958d..00a93df 100644 --- a/generator/templates/Crud/src/components/forms/User.vue +++ b/generator/templates/Crud/src/components/forms/UserForm.vue @@ -3,7 +3,7 @@ Gebruiker - + - diff --git a/generator/templates/Crud/src/mixins/formDataValues.js b/generator/templates/Crud/src/mixins/formDataValues.js index 54a6a5c..e5e1e25 100644 --- a/generator/templates/Crud/src/mixins/formDataValues.js +++ b/generator/templates/Crud/src/mixins/formDataValues.js @@ -2,8 +2,8 @@ export default { methods: { appendFormData(form_data, values, startKey = '') { if (typeof values === 'object') { - for (let key in values) { - let currentKey = startKey.length ? startKey + '[' + key + ']' : key; + for (const key in values) { + const currentKey = startKey.length ? startKey + '[' + key + ']' : key; if (typeof values[key] === 'object' && !(values[key] instanceof File)) { this.appendFormData(form_data, values[key], currentKey); @@ -14,4 +14,4 @@ export default { } }, }, -}; \ No newline at end of file +}; diff --git a/generator/templates/Crud/src/views/UserResource.vue b/generator/templates/Crud/src/views/UserResource.vue index 7030391..d69c4d5 100644 --- a/generator/templates/Crud/src/views/UserResource.vue +++ b/generator/templates/Crud/src/views/UserResource.vue @@ -1,42 +1,39 @@ - - - +export default { + components: {Resource}, + name: 'UserResource', + data() { + return { + tableContent: [ + { + text: 'Naam', + align: 'left', + sortable: true, + value: 'name', + }, + { + text: 'E-mail', + align: 'left', + sortable: true, + value: 'email', + }, + ], + }; + }, +}; + diff --git a/generator/templates/Default/src/App.vue b/generator/templates/Default/src/App.vue index 48ed9ce..c0b1ce4 100644 --- a/generator/templates/Default/src/App.vue +++ b/generator/templates/Default/src/App.vue @@ -4,14 +4,8 @@ - diff --git a/generator/templates/Default/src/Views/PageForbidden.vue b/generator/templates/Default/src/Views/PageForbidden.vue deleted file mode 100644 index 321fbe0..0000000 --- a/generator/templates/Default/src/Views/PageForbidden.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/generator/templates/Default/src/Views/PageNotFound.vue b/generator/templates/Default/src/Views/PageNotFound.vue deleted file mode 100644 index 13062fd..0000000 --- a/generator/templates/Default/src/Views/PageNotFound.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/generator/templates/Default/src/api/implementation/app/index.js b/generator/templates/Default/src/api/implementation/app/index.js index 9f0a86f..587b58b 100644 --- a/generator/templates/Default/src/api/implementation/app/index.js +++ b/generator/templates/Default/src/api/implementation/app/index.js @@ -1,7 +1,7 @@ import axios from 'axios'; import {onRequestFulFilled, onRequestRejected, onResponseFulFilled, onResponseRejected} from './interceptor'; -import {destroy, get, getPaginated, post, put} from './wrapper' +import {getPaginated} from './wrapper'; /** * Returns an axios instance @@ -23,12 +23,17 @@ const instance = axios.create(config); instance.interceptors.request.use(onRequestFulFilled, onRequestRejected); instance.interceptors.response.use(onResponseFulFilled, onResponseRejected); +const get = axios.get; +const post = axios.post; +const destroy = axios.delete; +const put = axios.put; + export { - get, getPaginated, + get, post, - put, destroy, -} + put, +}; export default instance; diff --git a/generator/templates/Default/src/api/implementation/app/interceptor.js b/generator/templates/Default/src/api/implementation/app/interceptor.js index 06a8ffb..40621e5 100644 --- a/generator/templates/Default/src/api/implementation/app/interceptor.js +++ b/generator/templates/Default/src/api/implementation/app/interceptor.js @@ -26,8 +26,8 @@ function onRequestFulFilled(request) { function computeHeaders() { return { - Authorization: store.getters['Authorisation/isLoggedIn'] - ? `Bearer ${store.state.Authorisation.token}` + Authorization: store.getters['authorisation/isLoggedIn'] + ? `Bearer ${store.state.authorisation.token}` : undefined, }; } @@ -50,23 +50,18 @@ function onResponseFulFilled(response) { * @param error {AxiosError} */ function onResponseRejected(error) { + const response = error.response; + const status = response.status; + const errors = response.data.errors; - if (typeof error === 'string' || !error.response) return Promise.reject(error); - - const status = error.response.status; - - const data = error.response.data; - /* Now we know there was an error during submitting */ - if (data.errors && status === 422) { - /* For now, all errors will be removed on route change - * We might need to add global errors later on */ - Object.keys(data.errors).forEach(key => store.commit('Error/add', { + if (errors && status === 422) { + Object.keys(errors).forEach(key => store.commit('error/add', { key: key, - message: data.errors[key][0], + message: error[key][0], })); } - return Promise.reject(error.response); + return Promise.reject(error); } export { diff --git a/generator/templates/Default/src/api/implementation/app/wrapper.js b/generator/templates/Default/src/api/implementation/app/wrapper.js index f6b8a7e..c26eb7f 100644 --- a/generator/templates/Default/src/api/implementation/app/wrapper.js +++ b/generator/templates/Default/src/api/implementation/app/wrapper.js @@ -1,15 +1,17 @@ import handle from './index'; -async function get(url, params = {}) { - const result = await handle.get(url, { - params: params, - }); - - return result.data; -} - -async function getPaginated(url, page = 1, perPage = 10, search, sortBy, descending, params) { - const result = await handle.get(url, { +/** + * @param url + * @param page + * @param perPage + * @param search + * @param sortBy + * @param descending + * @param params + * @return {Promise} + */ +function getPaginated(url, page = 1, perPage = 10, search, sortBy, descending, params) { + return handle.get(url, { params: { page: page, perPage: perPage, @@ -20,42 +22,8 @@ async function getPaginated(url, page = 1, perPage = 10, search, sortBy, descend ...params, }, }); - - return result.data; -} - -async function post(url, data = {}, params = {}) { - const result = await handle.post(url, data, { - params: params, - }); - - /* Not all of our post requests will get a body back */ - if (result.data.data) return result.data; - - return result; -} - -async function put(url, data = {}, params = {}) { - const result = await handle.put(url, data, { - params: params, - }); - - /* Not all of our post requests will get a body back */ - if (result.data.data) return result.data; - - return result; -} - -function destroy(url, params = {}) { - return handle.delete(url, { - params: params, - }); } export { - get, getPaginated, - post, - put, - destroy, }; diff --git a/generator/templates/Default/src/api/util/response.js b/generator/templates/Default/src/api/util/response.js new file mode 100644 index 0000000..d086308 --- /dev/null +++ b/generator/templates/Default/src/api/util/response.js @@ -0,0 +1,11 @@ +import dayjs from 'generator/templates/Default/src/plugins/dayJs.js'; + +function getRateLimitMinutes(response, defaultMinutes = 15) { + const timestamp = response.headers['x-ratelimit-reset'] * 1000; + + return dayjs(timestamp).diff(dayjs(), 'minute') || defaultMinutes; +} + +export { + getRateLimitMinutes, +}; diff --git a/generator/templates/Default/src/api/utils/handleTooManyRequestsError.js b/generator/templates/Default/src/api/utils/handleTooManyRequestsError.js deleted file mode 100644 index d17eaff..0000000 --- a/generator/templates/Default/src/api/utils/handleTooManyRequestsError.js +++ /dev/null @@ -1,10 +0,0 @@ -import dayjs from '../../plugins/dayJs.js'; - -export default function handleTooManyRequestsError(result) { - const timestamp = result.headers['x-ratelimit-reset'] * 1000; - const minutes = dayjs(timestamp).diff(dayjs(), 'minute') || 15; - return { - message: `Je hebt te vaak een foutieve login poging gehad. Probeer het over ${minutes} minuten opnieuw.`, - success: false, - }; -} diff --git a/generator/templates/Default/src/application/util/url.js b/generator/templates/Default/src/application/util/url.js new file mode 100644 index 0000000..1f23e8f --- /dev/null +++ b/generator/templates/Default/src/application/util/url.js @@ -0,0 +1,15 @@ +const fragmentRegExp = new RegExp(`[\\#&]${key}=([^&#]*)`); + +function getFragment(key, defaultValue = '') { + const result = fragmentRegExp.exec(location.hash); + + if (result && result.length >= 2) { + return decodeURIComponent(result)[1]; + } + + return defaultValue; +} + +export { + getFragment, +}; diff --git a/generator/templates/Default/src/components/AppBarMenu.vue b/generator/templates/Default/src/components/AppBarMenu.vue index 3eb97d6..5b2dd44 100644 --- a/generator/templates/Default/src/components/AppBarMenu.vue +++ b/generator/templates/Default/src/components/AppBarMenu.vue @@ -21,13 +21,14 @@ diff --git a/generator/templates/Default/src/components/BaseForm.vue b/generator/templates/Default/src/components/BaseForm.vue index dfec9b3..5c7580e 100644 --- a/generator/templates/Default/src/components/BaseForm.vue +++ b/generator/templates/Default/src/components/BaseForm.vue @@ -1,11 +1,13 @@ + diff --git a/generator/templates/Default/src/views/PageForbidden.vue b/generator/templates/Default/src/views/PageForbidden.vue new file mode 100644 index 0000000..f03d014 --- /dev/null +++ b/generator/templates/Default/src/views/PageForbidden.vue @@ -0,0 +1,13 @@ + + + diff --git a/generator/templates/Default/src/views/PageNotFound.vue b/generator/templates/Default/src/views/PageNotFound.vue new file mode 100644 index 0000000..f82d218 --- /dev/null +++ b/generator/templates/Default/src/views/PageNotFound.vue @@ -0,0 +1,13 @@ + + + diff --git a/generator/templates/Plugins/sentry/src/plugins/sentry.js b/generator/templates/Plugins/sentry/src/plugins/sentry.js index 07f31a9..863e0c4 100644 --- a/generator/templates/Plugins/sentry/src/plugins/sentry.js +++ b/generator/templates/Plugins/sentry/src/plugins/sentry.js @@ -1,12 +1,12 @@ -import * as Sentry from '@sentry/browser'; -import * as Integrations from '@sentry/integrations'; +import {init} from '@sentry/browser'; +import {Vue as SentryVue} from '@sentry/integrations'; import Vue from 'vue'; if (process.env.VUE_APP_SENTRY) { - Sentry.init({ + init({ environment: process.env.VUE_APP_ENV, release: process.env.VUE_APP_RELEASE, dsn: process.env.VUE_APP_SENTRY, - integrations: [new Integrations.Vue({Vue, attachProps: true})], + integrations: [new SentryVue({Vue, attachProps: true})], }); } diff --git a/prompts.js b/prompts.js index 4d4917e..3b757a0 100644 --- a/prompts.js +++ b/prompts.js @@ -29,8 +29,8 @@ module.exports = [ message: 'Which plugins should we install for you?', choices: [ { - value: 'sentry', - name: 'error logging with sentry', + value: 'Sentry', + name: 'error logging with Sentry', checked: true, }, { @@ -40,7 +40,7 @@ module.exports = [ }, { value: 'fontawesomepro', - name: 'Font awesome pro', + name: 'FontAwesome Pro', checked: false, }, ], From 3943a7859cf83cd064d0c59fa7bebfdf8e617199 Mon Sep 17 00:00:00 2001 From: DeluzeDEV Date: Tue, 14 Jul 2020 16:50:00 +0200 Subject: [PATCH 02/33] Form data send empty string on null --- .../templates/Default/src/api/util/objectToFormDataConverter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generator/templates/Default/src/api/util/objectToFormDataConverter.js b/generator/templates/Default/src/api/util/objectToFormDataConverter.js index 43b0539..342d421 100644 --- a/generator/templates/Default/src/api/util/objectToFormDataConverter.js +++ b/generator/templates/Default/src/api/util/objectToFormDataConverter.js @@ -33,6 +33,8 @@ function convert(obj, data, parent) { convert(val, data, finalName); else if (typeof val === 'boolean') data.append(finalName, val ? '1' : '0'); + else if (val === null || val === '') + data.append(finalName, ''); else if (val !== undefined) data.append(finalName, val); }); From c41029828a025ec0fbf104326755ca0f1d074f37 Mon Sep 17 00:00:00 2001 From: DeluzeDEV Date: Tue, 14 Jul 2020 17:00:29 +0200 Subject: [PATCH 03/33] Form data send empty string on null --- .../Default/src/api/util/objectToFormDataConverter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/templates/Default/src/api/util/objectToFormDataConverter.js b/generator/templates/Default/src/api/util/objectToFormDataConverter.js index 342d421..f5f467d 100644 --- a/generator/templates/Default/src/api/util/objectToFormDataConverter.js +++ b/generator/templates/Default/src/api/util/objectToFormDataConverter.js @@ -33,9 +33,9 @@ function convert(obj, data, parent) { convert(val, data, finalName); else if (typeof val === 'boolean') data.append(finalName, val ? '1' : '0'); - else if (val === null || val === '') + else if (val === '') data.append(finalName, ''); - else if (val !== undefined) + else if (val) data.append(finalName, val); }); From 886dde40d3167871484cd46188314d8b3a5554f8 Mon Sep 17 00:00:00 2001 From: DeluzeDEV Date: Thu, 16 Jul 2020 11:31:57 +0200 Subject: [PATCH 04/33] Add Verify.vue --- .../src/templates/Authorisation.vue | 2 +- .../Authorisation/src/views/Verify.vue | 115 ++++++++++++++++++ .../src/api/implementation/app/wrapper.js | 1 - .../src/api/util/objectToFormDataConverter.js | 10 +- .../Default/src/application/util/url.js | 2 +- .../templates/Default/src/router/index.js | 5 + .../templates/Default/src/store/index.js | 4 +- .../{Authorisation.js => authorisation.js} | 0 .../src/store/modules/{Error.js => error.js} | 0 9 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 generator/templates/Authorisation/src/views/Verify.vue rename generator/templates/Default/src/store/modules/{Authorisation.js => authorisation.js} (100%) rename generator/templates/Default/src/store/modules/{Error.js => error.js} (100%) diff --git a/generator/templates/Authorisation/src/templates/Authorisation.vue b/generator/templates/Authorisation/src/templates/Authorisation.vue index 2c4e046..c612ed8 100644 --- a/generator/templates/Authorisation/src/templates/Authorisation.vue +++ b/generator/templates/Authorisation/src/templates/Authorisation.vue @@ -1,6 +1,6 @@ diff --git a/generator/templates/Default/src/api/implementation/app/index.js b/generator/templates/Default/src/api/implementation/app/index.js index 587b58b..2b1a305 100644 --- a/generator/templates/Default/src/api/implementation/app/index.js +++ b/generator/templates/Default/src/api/implementation/app/index.js @@ -2,6 +2,7 @@ import axios from 'axios'; import {onRequestFulFilled, onRequestRejected, onResponseFulFilled, onResponseRejected} from './interceptor'; import {getPaginated} from './wrapper'; +import {transformParams, transformRequest, transformResponse} from './transformer'; /** * Returns an axios instance @@ -16,6 +17,9 @@ const config = { headers: { Accept: 'application/json', }, + transformRequest: [transformRequest], + transformResponse: [transformResponse], + paramsSerializer: transformParams, }; const instance = axios.create(config); diff --git a/generator/templates/Default/src/api/implementation/app/transformer.js b/generator/templates/Default/src/api/implementation/app/transformer.js index d0c78b0..2711048 100644 --- a/generator/templates/Default/src/api/implementation/app/transformer.js +++ b/generator/templates/Default/src/api/implementation/app/transformer.js @@ -1,8 +1,10 @@ -import {snakeToCamel} from '../../../util/keyConverter'; +import {camelToSnake, snakeToCamel} from '../../util/keyConverter'; +import objectToFormData from '../../util/objectToFormDataConverter.js'; +import Qs from 'qs'; /** - * @param response {} - * @returns {{}, string} + * @param response + * @returns {{}} */ function transformResponse(response) { if (typeof response === 'string' && response.length > 0) { @@ -17,6 +19,24 @@ function transformResponse(response) { return response; } +/** + * @param data + * @return {FormData} + */ +function transformRequest(data) { + if (data) { + data = camelToSnake(data); + } + + return objectToFormData(data); +} + +function transformParams(params) { + return Qs.stringify(camelToSnake(params)); +} + export { transformResponse, + transformRequest, + transformParams, }; diff --git a/generator/templates/Default/src/api/util/response.js b/generator/templates/Default/src/api/util/response.js index d086308..41e9240 100644 --- a/generator/templates/Default/src/api/util/response.js +++ b/generator/templates/Default/src/api/util/response.js @@ -1,4 +1,4 @@ -import dayjs from 'generator/templates/Default/src/plugins/dayJs.js'; +import dayjs from '../../plugins/dayJs.js'; function getRateLimitMinutes(response, defaultMinutes = 15) { const timestamp = response.headers['x-ratelimit-reset'] * 1000; diff --git a/generator/templates/Default/src/application/util/url.js b/generator/templates/Default/src/application/util/url.js index b6add0c..2448455 100644 --- a/generator/templates/Default/src/application/util/url.js +++ b/generator/templates/Default/src/application/util/url.js @@ -1,6 +1,5 @@ -const fragmentRegExp = new RegExp(`[\\#&]${key}=([^&#]*)`); - function getFragment(key, defaultValue = '') { + const fragmentRegExp = new RegExp(`[\\#&]${key}=([^&#]*)`); const result = fragmentRegExp.exec(location.hash); if (result && result.length >= 2) { diff --git a/generator/templates/Default/src/components/BaseForm.vue b/generator/templates/Default/src/components/BaseForm.vue index 5c7580e..50ca43b 100644 --- a/generator/templates/Default/src/components/BaseForm.vue +++ b/generator/templates/Default/src/components/BaseForm.vue @@ -1,5 +1,5 @@ diff --git a/generator/templates/Crud/src/views/UserResource.vue b/generator/templates/Crud/src/views/UserResource.vue index d69c4d5..7527df0 100644 --- a/generator/templates/Crud/src/views/UserResource.vue +++ b/generator/templates/Crud/src/views/UserResource.vue @@ -1,12 +1,10 @@ @@ -15,25 +13,25 @@ import Resource from '@/components/Resource.vue'; export default { - components: {Resource}, name: 'UserResource', - data() { - return { - tableContent: [ - { - text: 'Naam', - align: 'left', - sortable: true, - value: 'name', - }, - { - text: 'E-mail', - align: 'left', - sortable: true, - value: 'email', - }, - ], - }; + components: { + Resource, + }, + computed: { + tableContent: () => [ + { + text: 'Naam', + align: 'left', + sortable: true, + value: 'name', + }, + { + text: 'E-mail', + align: 'left', + sortable: true, + value: 'email', + }, + ], }, }; From 918c44f4b61de7f076182e17aff84a0eac2ec791 Mon Sep 17 00:00:00 2001 From: DeluzeDEV Date: Thu, 16 Jul 2020 16:42:07 +0200 Subject: [PATCH 14/33] Fix Menu.vue exception on undefined item array --- generator/templates/Default/src/components/menu/Menu.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/templates/Default/src/components/menu/Menu.vue b/generator/templates/Default/src/components/menu/Menu.vue index 4c8b22b..d9c757b 100644 --- a/generator/templates/Default/src/components/menu/Menu.vue +++ b/generator/templates/Default/src/components/menu/Menu.vue @@ -5,7 +5,7 @@ :disabled="item.disabled" :prepend-icon="item.icon" no-action - v-if="!!item.items.length" + v-if="!!item.items && item.items.length" v-model="item.active">