From 12c04c41745f2de7fb8cfb3ec9b339f900d257e6 Mon Sep 17 00:00:00 2001 From: ricardovanlaarhoven Date: Wed, 21 Oct 2020 10:24:27 +0200 Subject: [PATCH 01/21] New models --- .../Default/src/application/models/model.js | 43 ++++++------------- .../Default/src/application/util/url.js | 2 +- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/generator/templates/Default/src/application/models/model.js b/generator/templates/Default/src/application/models/model.js index ed45054..262d4e6 100644 --- a/generator/templates/Default/src/application/models/model.js +++ b/generator/templates/Default/src/application/models/model.js @@ -29,48 +29,29 @@ class Model { const value = assignable[key]; const type = typeof value; - if (typeof data[key] === type) { - assignable[key] = data[key]; + if (typeof data === 'undefined') { + assignable[key] = value; return; } - const defaultValue = this.getDefaultValueFromType(type, value); - - assignable[key] = data[key] || defaultValue; - }); - - Object.keys(data) - .forEach(key => { - if (typeof assignable[key] === 'undefined') { - assignable[key] = data[key]; - } + const apiValue = data[key]; + assignable[key] = this.convertByType(type, value, apiValue); }); return assignable; } - /** - * @private - * @param type - * @param defaultModelValue - * @return {*} - */ - getDefaultValueFromType(type, defaultModelValue) { - let defaultValue; - - if (type === 'string') { - defaultValue = defaultModelValue || ''; + convertByType(type, currentValue, apiValue) { + if (type === 'object' && currentValue && typeof currentValue.mapResponse === 'function') { + return currentValue.mapResponse(apiValue); + } else if (type === 'string') { + return apiValue ? String(apiValue) : ''; } else if (type === 'boolean') { - defaultValue = defaultModelValue || false; + return Boolean(apiValue); } else if (type === 'number') { - defaultValue = defaultModelValue || 0; - } else if (Array.isArray(defaultModelValue)) { - defaultValue = defaultModelValue || []; - } else { - defaultValue = defaultModelValue || null; + return parseFloat(apiValue); } - - return defaultValue; + return apiValue || currentValue; } } diff --git a/generator/templates/Default/src/application/util/url.js b/generator/templates/Default/src/application/util/url.js index 4c606b9..59801b5 100644 --- a/generator/templates/Default/src/application/util/url.js +++ b/generator/templates/Default/src/application/util/url.js @@ -1,6 +1,6 @@ function getFragment(key, defaultValue = '') { const fragmentRegExp = new RegExp(`[\\#&]${key}=([^&#]*)`); - const result = fragmentRegExp.exec(location.hash); + const result = fragmentRegExp.exec(window.location.hash); if (result && result.length >= 2) { return decodeURIComponent(result[1]); From b1aa9c9cb89adb61a9caab44a204678a630ffb8d Mon Sep 17 00:00:00 2001 From: ricardovanlaarhoven Date: Wed, 21 Oct 2020 10:24:46 +0200 Subject: [PATCH 02/21] update API implementation and keyConverter --- .../src/api/implementation/app/index.js | 8 +++--- .../src/api/implementation/app/interceptor.js | 27 +++++++++++++------ .../src/api/implementation/app/transformer.js | 12 ++++++--- .../src/api/implementation/app/wrapper.js | 12 +++++---- .../Default/src/api/util/keyConverter.js | 22 ++++++++------- .../Default/src/api/util/response.js | 2 +- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/generator/templates/Default/src/api/implementation/app/index.js b/generator/templates/Default/src/api/implementation/app/index.js index 57da027..e6f32e6 100644 --- a/generator/templates/Default/src/api/implementation/app/index.js +++ b/generator/templates/Default/src/api/implementation/app/index.js @@ -7,7 +7,6 @@ import { onResponseRejected, } from './interceptor'; import { transformParams, transformRequest, transformResponse } from './transformer'; -import { getPaginated } from './wrapper'; /** * Returns an axios instance @@ -32,13 +31,12 @@ const instance = axios.create(config); instance.interceptors.request.use(onRequestFulFilled, onRequestRejected); instance.interceptors.response.use(onResponseFulFilled, onResponseRejected); -const get = instance.get; -const post = instance.post; +const { get } = instance; +const { post } = instance; const destroy = instance.delete; -const put = instance.put; +const { put } = instance; export { - getPaginated, get, post, destroy, diff --git a/generator/templates/Default/src/api/implementation/app/interceptor.js b/generator/templates/Default/src/api/implementation/app/interceptor.js index 696c42c..26a843e 100644 --- a/generator/templates/Default/src/api/implementation/app/interceptor.js +++ b/generator/templates/Default/src/api/implementation/app/interceptor.js @@ -1,4 +1,5 @@ -import store from '../../../store'; +import router from '@/router'; +import store from '@/store'; /** * @param request {AxiosRequestConfig} @@ -9,14 +10,14 @@ function onRequestFulFilled(request) { if (request.data instanceof FormData) { request.data.append('_method', 'put'); } else { - request.data['_method'] = 'put'; + request.data._method = 'put'; } } const computedHeaders = computeHeaders(); Object.keys(computedHeaders) - .forEach(header => { + .forEach((header) => { Object.assign(request.headers.common, { [header]: computedHeaders[header], }); @@ -51,17 +52,27 @@ function onResponseFulFilled(response) { * @param error {AxiosError} */ function onResponseRejected(error) { - const response = error.response; + const { response } = error; if (!response) return Promise.reject(error); // network error, not axios related - const status = response.status; - const errors = response.data.errors; + const { status } = response; + const { errors } = response.data; + + if (status === 401) { + store.dispatch('authorisation/logout'); + router.push({ name: 'login' }); + return; + } else if (status === 403) { + router.push({ name: '403' }); + } else if (status === 404) { + router.push({ name: '404' }); + } if (errors && status === 422) { Object.keys(errors) - .forEach(key => store.commit('error/add', { - key: key, + .forEach((key) => store.commit('error/add', { + key, message: errors[key][0], })); } diff --git a/generator/templates/Default/src/api/implementation/app/transformer.js b/generator/templates/Default/src/api/implementation/app/transformer.js index d7d647c..b71cbcc 100644 --- a/generator/templates/Default/src/api/implementation/app/transformer.js +++ b/generator/templates/Default/src/api/implementation/app/transformer.js @@ -1,7 +1,7 @@ import Qs from 'qs'; -import Model from '../../../application/models/model.js'; +import Model from '../../../application/models/model'; import { camelToSnake, snakeToCamel } from '../../util/keyConverter'; -import objectToFormData from '../../util/objectToFormDataConverter.js'; +import objectToFormData from '../../util/objectToFormDataConverter'; /** * @param response @@ -9,8 +9,12 @@ import objectToFormData from '../../util/objectToFormDataConverter.js'; */ function transformResponse(response) { if (typeof response === 'string' && response.length > 0) { - const result = JSON.parse(response); - return snakeToCamel(result); + try { + const result = JSON.parse(response); + return snakeToCamel(result); + } catch (e) { + return response; + } } if (!response) { diff --git a/generator/templates/Default/src/api/implementation/app/wrapper.js b/generator/templates/Default/src/api/implementation/app/wrapper.js index 9456dbf..c067a9d 100644 --- a/generator/templates/Default/src/api/implementation/app/wrapper.js +++ b/generator/templates/Default/src/api/implementation/app/wrapper.js @@ -1,4 +1,5 @@ -import handle from './index'; +import { get } from '@/api/implementation/app'; +import { convertCamelToSnake } from '@/api/util/keyConverter.js'; /** * @param url @@ -14,17 +15,18 @@ function getPaginated(url, page = 1, perPage = 10, search, sortBy, descending, p if (search) { params.search = search; } + if (sortBy) { - params.sortBy = sortBy; + params.sortBy = convertCamelToSnake(sortBy); } if (typeof descending !== 'undefined') { params.desc = descending ? '1' : '0'; } - return handle.get(url, { + return get(url, { params: { - page: page, - perPage: perPage, + page, + perPage, ...params, }, }); diff --git a/generator/templates/Default/src/api/util/keyConverter.js b/generator/templates/Default/src/api/util/keyConverter.js index 54338a0..775b9c4 100644 --- a/generator/templates/Default/src/api/util/keyConverter.js +++ b/generator/templates/Default/src/api/util/keyConverter.js @@ -6,9 +6,11 @@ function camelToSnake(data) { const target = Array.isArray(data) ? [] : {}; Object.keys(data) - .forEach(key => { + .forEach((key) => { Object.assign(target, { - [convertCamelToSnake(key)]: isIterableObject(data[key]) ? camelToSnake(data[key]) : data[key], + [convertCamelToSnake(key)]: isIterableObject(data[key]) + ? camelToSnake(data[key]) + : data[key], }); }); @@ -16,9 +18,7 @@ function camelToSnake(data) { } function convertCamelToSnake(key) { - return key.replace(/[A-Z]/g, value => { - return '_' + value[0].toLowerCase(); - }); + return key.replace(/[A-Z]/g, (value) => `_${value[0].toLowerCase()}`); } function snakeToCamel(data) { @@ -29,9 +29,11 @@ function snakeToCamel(data) { const target = Array.isArray(data) ? [] : {}; Object.keys(data) - .forEach(key => { + .forEach((key) => { Object.assign(target, { - [convertSnakeToCamel(key)]: isIterableObject(data[key]) ? snakeToCamel(data[key]) : data[key], + [convertSnakeToCamel(key)]: isIterableObject(data[key]) + ? snakeToCamel(data[key]) + : data[key], }); }); @@ -39,9 +41,7 @@ function snakeToCamel(data) { } function convertSnakeToCamel(key) { - return key.replace(/_\w/g, value => { - return value[1].toUpperCase(); - }); + return key.replace(/_\w/g, (value) => value[1].toUpperCase()); } function isIterableObject(target) { @@ -51,4 +51,6 @@ function isIterableObject(target) { export { snakeToCamel, camelToSnake, + convertCamelToSnake, + convertSnakeToCamel, }; diff --git a/generator/templates/Default/src/api/util/response.js b/generator/templates/Default/src/api/util/response.js index 3b3c370..b3f8a8e 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 '../../plugins/dayJs.js'; +import dayjs from '../../plugins/dayJs'; function getRateLimitMinutes(response, defaultMinutes = 15) { const remainingMilliseconds = (+response.headers['retry-after']) * 1000; From e51e5305b49f543b350de84505016a5f8a5482a2 Mon Sep 17 00:00:00 2001 From: ricardovanlaarhoven Date: Wed, 21 Oct 2020 10:24:55 +0200 Subject: [PATCH 03/21] rename mainMenu --- .../src/components/menu/{MainMenu.vue => TheMainMenu.vue} | 2 +- generator/templates/Default/src/templates/Default.vue | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename generator/templates/Default/src/components/menu/{MainMenu.vue => TheMainMenu.vue} (91%) diff --git a/generator/templates/Default/src/components/menu/MainMenu.vue b/generator/templates/Default/src/components/menu/TheMainMenu.vue similarity index 91% rename from generator/templates/Default/src/components/menu/MainMenu.vue rename to generator/templates/Default/src/components/menu/TheMainMenu.vue index fbddc96..c2073a2 100644 --- a/generator/templates/Default/src/components/menu/MainMenu.vue +++ b/generator/templates/Default/src/components/menu/TheMainMenu.vue @@ -2,7 +2,7 @@ import Menu from './Menu.vue'; export default { - name: 'MainMenu', + name: 'TheMainMenu', extends: Menu, computed: { items: () => [ diff --git a/generator/templates/Default/src/templates/Default.vue b/generator/templates/Default/src/templates/Default.vue index cf83c88..5fbda4b 100644 --- a/generator/templates/Default/src/templates/Default.vue +++ b/generator/templates/Default/src/templates/Default.vue @@ -9,7 +9,7 @@ - + @@ -29,13 +29,13 @@ diff --git a/generator/templates/Authorisation/src/views/Verify.vue b/generator/templates/Authorisation/src/views/Verify.vue deleted file mode 100644 index f3fcb48..0000000 --- a/generator/templates/Authorisation/src/views/Verify.vue +++ /dev/null @@ -1,116 +0,0 @@ - - - -= diff --git a/generator/templates/Crud/src/router/routes/authorised.js b/generator/templates/Crud/src/router/routes/authorised.js new file mode 100644 index 0000000..cfa1439 --- /dev/null +++ b/generator/templates/Crud/src/router/routes/authorised.js @@ -0,0 +1,18 @@ +import AuthorisationGuard from '@/router/guards/AuthorisationGuard.js'; + +export default { + path: '', + beforeEnter: AuthorisationGuard, + component: () => import('@/templates/Default'), + children: [ + { + path: '', + name: 'home', + component: () => import('@/views/Home'), + },{ + path: '/users', + name: 'users', + component: () => import('@/views/UserResource.vue') + }, + ] +} diff --git a/generator/templates/Default/src/router/guards/AuthorisationGuard.js b/generator/templates/Default/src/router/guards/AuthorisationGuard.js new file mode 100644 index 0000000..e4a8746 --- /dev/null +++ b/generator/templates/Default/src/router/guards/AuthorisationGuard.js @@ -0,0 +1,4 @@ +export default function (to, from, next) { + // @TODO place your guard here + next(); +} diff --git a/generator/templates/Default/src/router/index.js b/generator/templates/Default/src/router/index.js index 5ec4d1d..36cf412 100644 --- a/generator/templates/Default/src/router/index.js +++ b/generator/templates/Default/src/router/index.js @@ -1,91 +1,29 @@ import Vue from 'vue'; import Router from 'vue-router'; <%_ if (options.useAuthorisation) { _%> -import AuthorisationGuard from '../guards/AuthorisationGuard'; +import authorisation from './routes/authorisation.js'; <%_ } _%> +import authorised from './routes/authorised.js'; Vue.use(Router); +const routes = [ +<%_ if (options.useAuthorisation) { _%> + authorisation, +<%_ } _%> + authorised, +]; + + +routes.push( + { + path: '*', + redirect: '404', + }, +); + export default new Router({ - mode: 'history', - base: process.env.BASE_URL, - routes: [ - { - path: '', - redirect: {name: 'home'}, - }, - <%_ if (options.useAuthorisation) { _%> - { - path: '', - component: () => import('@/templates/Authorisation'), - children: [ - { - path: '/login', - name: 'login', - component: () => import('@/views/Login'), - }, - { - path: '/auth/callback', - name: 'auth.callback', - component: () => import('@/views/AuthorisationCallback'), - }, - { - path: '/password/forgotten', - name: 'password.forgotten', - component: () => import('@/views/PasswordForgotten.vue'), - }, - { - path: '/password/reset/:token', - name: 'password.reset', - component: () => import('@/views/PasswordReset.vue'), - }, - { - path: '/invitation/accept/:token', - name: 'invitation.accept', - component: () => import('@/views/InvitationAccept.vue'), - }, - { - path: '/registration/verify', - name: 'registration.verify', - component: () => import('@/views/Verify.vue'), - }, - ] - }, - <%_ } _%> - { - path: '', - <%_ if (options.useAuthorisation) { _%> - beforeEnter: AuthorisationGuard, - <%_ } _%> - component: () => import('@/templates/Default'), - children: [ - { - path: '/', - name: 'home', - component: () => import('@/views/Home'), - }, - <%_ if (options.useCrud) { _%> - { - path: '/users', - name: 'users', - component: () => import('@/views/UserResource.vue') - }, - <%_ } _%> - { - path: '/404', - name: '404', - component: () => import('@/views/PageNotFound.vue'), - }, - { - path: '/403', - name: '403', - component: () => import('@/views/PageForbidden.vue'), - }, - { - path: '*', - redirect: '/404' - }, - ], - }, - ], + mode: 'history', + base: process.env.BASE_URL, + routes: routes, }); diff --git a/generator/templates/Default/src/router/routes/authorised.js b/generator/templates/Default/src/router/routes/authorised.js new file mode 100644 index 0000000..a83f8ac --- /dev/null +++ b/generator/templates/Default/src/router/routes/authorised.js @@ -0,0 +1,14 @@ +import AuthorisationGuard from '@/router/guards/AuthorisationGuard.js'; + +export default { + path: '', + beforeEnter: AuthorisationGuard, + component: () => import('@/templates/Default'), + children: [ + { + path: '', + name: 'home', + component: () => import('@/views/Home'), + }, + ] +} From e36078f3cdef9a8879e64719da53d996b4f0e29b Mon Sep 17 00:00:00 2001 From: ricardovanlaarhoven Date: Wed, 21 Oct 2020 12:08:19 +0200 Subject: [PATCH 08/21] add new authorisatrion routes --- README.md | 9 +++-- .../src/api/endpoints/authorisation/login.js | 4 +-- .../api/endpoints/authorisation/password.js | 8 ++--- .../authorisation/password/forgotten.js | 7 ++++ .../endpoints/authorisation/password/reset.js | 10 ++++++ .../api/endpoints/authorisation/register.js | 16 +++++---- .../components/Authorisation/LoginCard.vue | 6 ---- .../Authorisation/PasswordForgottenCard.vue | 3 +- .../Authorisation/PasswordResetCard.vue | 3 +- .../src/routes/routes/authorisation.js | 36 +++++++++++++++++++ .../AuthorisationCallback.vue | 0 .../{ => authorisation}/InvitationAccept.vue | 1 - .../src/views/{ => authorisation}/Login.vue | 0 .../{ => authorisation}/PasswordForgotten.vue | 0 .../{ => authorisation}/PasswordReset.vue | 0 .../RegistrationVerify.vue | 0 .../Default/src/templates/Default.vue | 4 +-- 17 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 generator/templates/Authorisation/src/api/endpoints/authorisation/password/forgotten.js create mode 100644 generator/templates/Authorisation/src/api/endpoints/authorisation/password/reset.js create mode 100644 generator/templates/Authorisation/src/routes/routes/authorisation.js rename generator/templates/Authorisation/src/views/{ => authorisation}/AuthorisationCallback.vue (100%) rename generator/templates/Authorisation/src/views/{ => authorisation}/InvitationAccept.vue (98%) rename generator/templates/Authorisation/src/views/{ => authorisation}/Login.vue (100%) rename generator/templates/Authorisation/src/views/{ => authorisation}/PasswordForgotten.vue (100%) rename generator/templates/Authorisation/src/views/{ => authorisation}/PasswordReset.vue (100%) rename generator/templates/Authorisation/src/views/{ => authorisation}/RegistrationVerify.vue (100%) diff --git a/README.md b/README.md index 3bd7e5a..3b55e54 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,14 @@ vue add kingscode-scaffold npm run serve ``` -Mind that some of the choices you make in the `vue create my-app` and -later in the `vue add vuetify` will be overwritten by vuetify or the kings code scaffold. +Mind that some choices you make in the `vue create my-app` and +later in the `vue add vuetify` will be overwritten by vuetify, or the kings code scaffold. ## Configuration -``` -Notice: it does not matter which choice you make with options that are not documented. - ``` +> Notice: it does not matter which choice you make with options that are not documented. + ### Vue: We'd recommend you to choose diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js index 90bdfed..628d706 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/login.js @@ -2,7 +2,7 @@ import { post } from '../../implementation/app'; export default function (email, password) { return post('auth/login', { - email: email, - password: password, + email, + password, }); } diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js index c64d13c..4c4a188 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/password.js @@ -2,15 +2,15 @@ import { post } from '../../implementation/app'; function passwordForgotten(email) { return post('password/forgotten', { - email: email, + email, }); } function passwordReset(token, email, password, passwordConfirmation) { return post('password/reset', { - token: token, - email: email, - password: password, + token, + email, + password, password_confirmation: passwordConfirmation, }); } diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/password/forgotten.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/password/forgotten.js new file mode 100644 index 0000000..f3c75c5 --- /dev/null +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/password/forgotten.js @@ -0,0 +1,7 @@ +import { post } from '@/api/implementation/app'; + +export default function (email) { + return post('password/forgotten', { + email, + }); +} diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/password/reset.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/password/reset.js new file mode 100644 index 0000000..803ce62 --- /dev/null +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/password/reset.js @@ -0,0 +1,10 @@ +import { post } from '@/api/implementation/app'; + +export default async function (email, token, password, passwordConfirmation) { + return post('password/reset', { + email, + token, + password, + password_confirmation: passwordConfirmation, + }); +} diff --git a/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js b/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js index 65259aa..3ba48ef 100644 --- a/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js +++ b/generator/templates/Authorisation/src/api/endpoints/authorisation/register.js @@ -1,22 +1,24 @@ import { post } from '../../implementation/app'; -function register(email, name) { - return post('registration', { +function verify(token, email, password, passwordConfirmation) { + return post('registration/verify', { + token, email, - name, + password, + password_confirmation: passwordConfirmation, }); } -function verify(token, email, password, passwordConfirmation) { - return post('registration/verify', { - token: token, +function acceptInvitation(email, token, password, passwordConfirmation) { + return post('invitation/accept', { email: email, password: password, password_confirmation: passwordConfirmation, + token: token, }); } export { - register, verify, + acceptInvitation, }; diff --git a/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue b/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue index 3210ca0..8e22197 100644 --- a/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue +++ b/generator/templates/Authorisation/src/components/Authorisation/LoginCard.vue @@ -51,7 +51,6 @@ + diff --git a/generator/templates/Default/src/components/crud/fields/KAutocomplete.vue b/generator/templates/Default/src/components/crud/fields/KAutocomplete.vue new file mode 100644 index 0000000..c5c959a --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KAutocomplete.vue @@ -0,0 +1,21 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KDateField.vue b/generator/templates/Default/src/components/crud/fields/KDateField.vue new file mode 100644 index 0000000..d37a94d --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KDateField.vue @@ -0,0 +1,96 @@ + + + + diff --git a/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue b/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue new file mode 100644 index 0000000..6a57fc6 --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue @@ -0,0 +1,38 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KFileField.vue b/generator/templates/Default/src/components/crud/fields/KFileField.vue new file mode 100644 index 0000000..5420be1 --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KFileField.vue @@ -0,0 +1,97 @@ + + + + + diff --git a/generator/templates/Default/src/components/crud/fields/KPaginatedAutocomplete.vue b/generator/templates/Default/src/components/crud/fields/KPaginatedAutocomplete.vue new file mode 100644 index 0000000..34a8fe9 --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KPaginatedAutocomplete.vue @@ -0,0 +1,129 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KRadioGroup.vue b/generator/templates/Default/src/components/crud/fields/KRadioGroup.vue new file mode 100644 index 0000000..d1cf11a --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KRadioGroup.vue @@ -0,0 +1,34 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KSelect.vue b/generator/templates/Default/src/components/crud/fields/KSelect.vue new file mode 100644 index 0000000..15d3f9b --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KSelect.vue @@ -0,0 +1,21 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KTextField.vue b/generator/templates/Default/src/components/crud/fields/KTextField.vue new file mode 100644 index 0000000..0302bb8 --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KTextField.vue @@ -0,0 +1,21 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KTextarea.vue b/generator/templates/Default/src/components/crud/fields/KTextarea.vue new file mode 100644 index 0000000..4893ef4 --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KTextarea.vue @@ -0,0 +1,17 @@ + + + diff --git a/generator/templates/Default/src/components/crud/fields/KTimeField.vue b/generator/templates/Default/src/components/crud/fields/KTimeField.vue new file mode 100644 index 0000000..6f06f11 --- /dev/null +++ b/generator/templates/Default/src/components/crud/fields/KTimeField.vue @@ -0,0 +1,87 @@ + + + diff --git a/generator/templates/Default/src/newmain.js b/generator/templates/Default/src/newmain.js index 93eb674..24bdd62 100644 --- a/generator/templates/Default/src/newmain.js +++ b/generator/templates/Default/src/newmain.js @@ -1,6 +1,6 @@ import '@babel/polyfill' import Vue from 'vue' -import {vuetify} from './plugins'; +import { i18n, vuetify } from './plugins'; <%_ if (options.useCrud) { _%> import VuetifyResource from '@kingscode/vuetify-resource'; <%_ } _%> @@ -22,6 +22,7 @@ Vue.config.productionTip = false; new Vue({ router, vuetify, + i18n, <%_ if (options.useAuthorisation) { _%> store, <%_ } _%> diff --git a/generator/templates/Default/src/plugins/index.js b/generator/templates/Default/src/plugins/index.js index 0932732..4d6d2d3 100644 --- a/generator/templates/Default/src/plugins/index.js +++ b/generator/templates/Default/src/plugins/index.js @@ -5,8 +5,12 @@ import './analytics'; <%_ if (options.plugins.includes('sentry')) { _%> import './sentry'; <%_ } _%> +import i18n from './i18n'; import vuetify from './vuetify'; cssVars(); -export {vuetify}; +export { + i18n, vuetify, +}; + diff --git a/generator/templates/Default/src/router/index.js b/generator/templates/Default/src/router/index.js index 36cf412..64a1553 100644 --- a/generator/templates/Default/src/router/index.js +++ b/generator/templates/Default/src/router/index.js @@ -8,6 +8,10 @@ import authorised from './routes/authorised.js'; Vue.use(Router); const routes = [ + { + path: '', + redirect: { name: 'home' }, + }, <%_ if (options.useAuthorisation) { _%> authorisation, <%_ } _%> diff --git a/generator/templates/Default/src/store/modules/error.js b/generator/templates/Default/src/store/modules/error.js index d7e8a96..2dec0f9 100644 --- a/generator/templates/Default/src/store/modules/error.js +++ b/generator/templates/Default/src/store/modules/error.js @@ -4,28 +4,31 @@ export default { errors: [], }, mutations: { - remove: (state, key) => state.errors.splice(state.errors.findIndex(x => x.key === key), 1), - clear: state => state.errors = [], + remove: (state, key) => state.errors.splice(state.errors.findIndex((x) => x.key === key), 1), + clear: (state) => { + state.errors = []; + }, add: (state, { message, key }) => { - const target = state.errors.find(x => x.key === key); + const target = state.errors.find((x) => x.key === key); if (!target) { return state.errors.push({ - key: key, - message: message, + key, + message, }); } target.message = message; + return state.errors; }, }, getters: { - find: state => key => { - const error = state.errors.find(x => x.key === key); + find: (state) => (key) => { + const error = state.errors.find((x) => x.key === key); return error ? error.message : ''; }, - first: state => { + first: (state) => { if (!state.errors.length) { return ''; } From f596149327768e810e41ccc226d1f82c3a0dfd74 Mon Sep 17 00:00:00 2001 From: ricardovanlaarhoven Date: Wed, 21 Oct 2020 17:21:23 +0200 Subject: [PATCH 10/21] wip --- .../Crud/src/components/forms/UserForm.vue | 50 +++++++++---------- .../templates/Crud/src/locales/nl/user.json | 7 +++ .../templates/Crud/src/views/UserResource.vue | 34 +++++++------ .../components/crud/fields/KFieldGroup.vue | 1 - .../Default/src/components/menu/Menu.vue | 2 +- 5 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 generator/templates/Crud/src/locales/nl/user.json diff --git a/generator/templates/Crud/src/components/forms/UserForm.vue b/generator/templates/Crud/src/components/forms/UserForm.vue index c0dcbef..63bb285 100644 --- a/generator/templates/Crud/src/components/forms/UserForm.vue +++ b/generator/templates/Crud/src/components/forms/UserForm.vue @@ -1,37 +1,33 @@ diff --git a/generator/templates/Crud/src/locales/nl/user.json b/generator/templates/Crud/src/locales/nl/user.json new file mode 100644 index 0000000..14108fe --- /dev/null +++ b/generator/templates/Crud/src/locales/nl/user.json @@ -0,0 +1,7 @@ +{ + "title": "Gebruiker|Gebruikers", + "fields": { + "name": "Naam", + "email": "E-mail" + } +} diff --git a/generator/templates/Crud/src/views/UserResource.vue b/generator/templates/Crud/src/views/UserResource.vue index 50e46eb..0cadacc 100644 --- a/generator/templates/Crud/src/views/UserResource.vue +++ b/generator/templates/Crud/src/views/UserResource.vue @@ -5,7 +5,7 @@ :delete-request="deleteHandler" :form-component="() => import('../components/forms/UserForm.vue')" :index-request="indexHandler" - :meta="{name: 'gebruiker', namePlural: 'gebruikers'}" + :meta="{name: $tc('user.title', 1), namePlural: $tc('user.title', 2)}" :model-type="modelType" :show-request="showHandler" :table-content="tableContent" @@ -16,7 +16,7 @@ diff --git a/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue b/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue index 6a57fc6..ef4f203 100644 --- a/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue +++ b/generator/templates/Default/src/components/crud/fields/KFieldGroup.vue @@ -28,7 +28,6 @@ export default { computed: { computedFieldProps() { return { - filled: true, validateOnBlur: true, ...this.fieldProps, }; diff --git a/generator/templates/Default/src/components/menu/Menu.vue b/generator/templates/Default/src/components/menu/Menu.vue index 74fd5c0..d8ede5a 100644 --- a/generator/templates/Default/src/components/menu/Menu.vue +++ b/generator/templates/Default/src/components/menu/Menu.vue @@ -1,5 +1,5 @@