Browse Source

Extract validation rules from each components

pull/341/head
Hironsan 5 years ago
parent
commit
c45d54cc0e
6 changed files with 59 additions and 30 deletions
  1. 13
      frontend/components/organisms/LabelCreationForm.vue
  2. 8
      frontend/components/organisms/LabelList.vue
  3. 11
      frontend/components/organisms/MemberAdditionForm.vue
  4. 6
      frontend/components/organisms/MemberList.vue
  5. 18
      frontend/components/organisms/ProjectCreationForm.vue
  6. 33
      frontend/rules/index.js

13
frontend/components/organisms/LabelCreationForm.vue

@ -14,7 +14,7 @@
> >
<v-text-field <v-text-field
v-model="labelName" v-model="labelName"
:rules="nameRules"
:rules="labelNameRules"
label="Label name" label="Label name"
prepend-icon="label" prepend-icon="label"
/> />
@ -40,6 +40,7 @@
<script> <script>
import BaseCard from '@/components/molecules/BaseCard' import BaseCard from '@/components/molecules/BaseCard'
import { colorRules, labelNameRules } from '@/rules/index'
export default { export default {
components: { components: {
@ -62,14 +63,8 @@ export default {
labelName: '', labelName: '',
suffixKey: '', suffixKey: '',
color: '', color: '',
nameRules: [
v => !!v || 'Label name is required',
v =>
(v && v.length <= 30) || 'Label name must be less than 30 characters'
],
colorRules: [
v => !!v || 'Color is required'
]
labelNameRules,
colorRules
} }
}, },

8
frontend/components/organisms/LabelList.vue

@ -26,6 +26,7 @@
<template v-slot:input> <template v-slot:input>
<v-text-field <v-text-field
:value="item.text" :value="item.text"
:rules="labelNameRules"
label="Edit" label="Edit"
single-line single-line
@change="updateLabel({ id: item.id, text: $event })" @change="updateLabel({ id: item.id, text: $event })"
@ -54,6 +55,7 @@
<template v-slot:input> <template v-slot:input>
<v-color-picker <v-color-picker
:value="item.backgroundColor" :value="item.backgroundColor"
:rules="colorRules"
show-swatches show-swatches
hide-mode-switch hide-mode-switch
width="800" width="800"
@ -68,6 +70,8 @@
</template> </template>
<script> <script>
import { colorRules, labelNameRules } from '@/rules/index'
export default { export default {
props: { props: {
headers: { headers: {
@ -97,7 +101,9 @@ export default {
}, },
data() { data() {
return { return {
search: ''
search: '',
colorRules,
labelNameRules
} }
}, },
methods: { methods: {

11
frontend/components/organisms/MemberAdditionForm.vue

@ -17,7 +17,7 @@
:items="items" :items="items"
:loading="isLoading" :loading="isLoading"
:search-input.sync="username" :search-input.sync="username"
:rules="userRules"
:rules="userNameRules"
color="white" color="white"
hide-no-data hide-no-data
hide-selected hide-selected
@ -41,6 +41,7 @@
<script> <script>
import BaseCard from '@/components/molecules/BaseCard' import BaseCard from '@/components/molecules/BaseCard'
import { userNameRules, roleRules } from '@/rules/index'
export default { export default {
components: { components: {
@ -66,12 +67,8 @@ export default {
isLoading: false, isLoading: false,
selectedUser: null, selectedUser: null,
roles: ['Admin', 'Member'], roles: ['Admin', 'Member'],
userRules: [
v => !!v || 'User is required'
],
roleRules: [
v => !!v || 'Role is required'
]
userNameRules,
roleRules
} }
}, },

6
frontend/components/organisms/MemberList.vue

@ -37,6 +37,7 @@
<v-select <v-select
:value="item.role" :value="item.role"
:items="roles" :items="roles"
:rules="roleRules"
label="Role" label="Role"
@input="setNewRole" @input="setNewRole"
/> />
@ -47,6 +48,8 @@
</template> </template>
<script> <script>
import { roleRules } from '@/rules/index'
export default { export default {
props: { props: {
headers: { headers: {
@ -80,7 +83,8 @@ export default {
data() { data() {
return { return {
search: '', search: '',
newRole: null
newRole: null,
roleRules
} }
}, },
methods: { methods: {

18
frontend/components/organisms/ProjectCreationForm.vue

@ -14,7 +14,7 @@
> >
<v-text-field <v-text-field
v-model="name" v-model="name"
:rules="nameRules"
:rules="projectNameRules"
label="Project name" label="Project name"
prepend-icon="mdi-account-multiple" prepend-icon="mdi-account-multiple"
data-test="project-name" data-test="project-name"
@ -32,7 +32,7 @@
<v-select <v-select
v-model="projectType" v-model="projectType"
:items="projectTypes" :items="projectTypes"
:rules="[v => !!v || 'Type is required']"
:rules="projectTypeRules"
label="projectType" label="projectType"
prepend-icon="mdi-keyboard" prepend-icon="mdi-keyboard"
data-test="project-type" data-test="project-type"
@ -45,6 +45,7 @@
<script> <script>
import BaseCard from '@/components/molecules/BaseCard' import BaseCard from '@/components/molecules/BaseCard'
import { projectNameRules, descriptionRules, projectTypeRules } from '@/rules/index'
export default { export default {
components: { components: {
@ -71,16 +72,9 @@ export default {
name: '', name: '',
description: '', description: '',
projectType: null, projectType: null,
nameRules: [
v => !!v || 'Project name is required',
v =>
(v && v.length <= 30) || 'Project name must be less than 30 characters'
],
descriptionRules: [
v => !!v || 'Description is required',
v =>
(v && v.length <= 100) || 'Description must be less than 100 characters'
]
projectNameRules,
projectTypeRules,
descriptionRules
} }
}, },

33
frontend/rules/index.js

@ -0,0 +1,33 @@
// Rules for project label.
export const colorRules = [
v => !!v || 'Color is required'
]
export const labelNameRules = [
v => !!v || 'Label name is required',
v => (v && v.length <= 30) || 'Label name must be less than 30 characters'
]
// Rules for project member.
export const userNameRules = [
v => !!v || 'User is required'
]
export const roleRules = [
v => !!v || 'Role is required'
]
// Rules for a project.
export const projectNameRules = [
v => !!v || 'Project name is required',
v => (v && v.length <= 30) || 'Project name must be less than 30 characters'
]
export const descriptionRules = [
v => !!v || 'Description is required',
v => (v && v.length <= 100) || 'Description must be less than 100 characters'
]
export const projectTypeRules = [
v => !!v || 'Project type is required'
]
Loading…
Cancel
Save