Skip to content

Commit c413011

Browse files
authored
Merge pull request #307 from citation-file-format/165-new-validation-filter
simplified validation with filter
2 parents da54404 + 503f754 commit c413011

28 files changed

Lines changed: 437 additions & 330 deletions

docs/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/cffinit /

src/author-errors.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getMyErrors } from 'src/store/validator'
2+
3+
export const authorErrors = (index:number) => {
4+
const myErrors = [
5+
getMyErrors(`/authors/${index}`)
6+
]
7+
const myChildrenErrors = [
8+
getMyErrors(`/authors/${index}/given-names`),
9+
getMyErrors(`/authors/${index}/name-particle`),
10+
getMyErrors(`/authors/${index}/family-names`),
11+
getMyErrors(`/authors/${index}/name-suffix`),
12+
getMyErrors(`/authors/${index}/email`),
13+
getMyErrors(`/authors/${index}/affiliation`),
14+
getMyErrors(`/authors/${index}/orcid`)
15+
]
16+
const errors = [...myErrors, ...myChildrenErrors]
17+
return {
18+
hasError: errors.some(result => result.hasError),
19+
messages: errors[0].hasError ? errors[0].messages : []
20+
}
21+
}

src/authors-errors.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AuthorsType } from 'src/types'
2+
import { getMyErrors } from 'src/store/validator'
3+
import { authorErrors } from 'src/author-errors'
4+
5+
export const authorsErrors = (authors:AuthorsType) => {
6+
const myErrors = [
7+
getMyErrors('', ['authors']),
8+
getMyErrors('/authors')
9+
]
10+
const myChildrenErrors = authors?.map((_, index) => authorErrors(index))
11+
const errors = myChildrenErrors === undefined ? myErrors : [...myErrors, ...myChildrenErrors]
12+
return {
13+
hasError: errors.some(result => result.hasError),
14+
messages: errors.map(result => result.messages.join(', '))
15+
}
16+
}

src/components/AuthorCardEditing.vue

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<q-card
33
flat
44
bordered
5-
class="bg-formcard q-pa-md"
5+
v-bind:class="['bg-formcard', 'q-pa-md', authorErrors.hasError ? 'red-border' : '']"
66
>
77
<div class="row">
88
<q-input
@@ -14,7 +14,8 @@
1414
standout
1515
title="The person's given names."
1616
v-bind:model-value="givenNames"
17-
v-bind:rules="[validateGivenNames]"
17+
v-bind:error="givenNamesError.hasError"
18+
v-bind:error-message="givenNamesError.messages.join(', ')"
1819
v-on:update:modelValue="$emit('update', 'givenNames', $event)"
1920
/>
2021
</div>
@@ -28,7 +29,8 @@
2829
standout
2930
title="The person's name particle, e.g., a nobiliary particle or a [preposition] meaning 'of' or 'from' (for example 'von' in 'Alexander von Humboldt')."
3031
v-bind:model-value="nameParticle"
31-
v-bind:rules="[validateNameParticle]"
32+
v-bind:error="nameParticleError.hasError"
33+
v-bind:error-message="nameParticleError.messages.join(', ')"
3234
v-on:update:modelValue="$emit('update', 'nameParticle', $event)"
3335
/>
3436
<q-input
@@ -40,7 +42,8 @@
4042
standout
4143
title="The person's family names."
4244
v-bind:model-value="familyNames"
43-
v-bind:rules="[validateFamilyNames]"
45+
v-bind:error="familyNamesError.hasError"
46+
v-bind:error-message="familyNamesError.messages.join(', ')"
4447
v-on:update:modelValue="$emit('update', 'familyNames', $event)"
4548
/>
4649
<q-input
@@ -52,7 +55,8 @@
5255
standout
5356
title="The person's name suffix, e.g. 'Jr.' for Sammy Davis Jr. or 'III' for Frank Edwin Wright III."
5457
v-bind:model-value="nameSuffix"
55-
v-bind:rules="[validateNameSuffix]"
58+
v-bind:error="nameSuffixError.hasError"
59+
v-bind:error-message="nameSuffixError.messages.join(', ')"
5660
v-on:update:modelValue="$emit('update', 'nameSuffix', $event)"
5761
/>
5862
</div>
@@ -67,7 +71,8 @@
6771
title="The person's email address."
6872
type="email"
6973
v-bind:model-value="email"
70-
v-bind:rules="[validateEmail]"
74+
v-bind:error="emailError.hasError"
75+
v-bind:error-message="emailError.messages.join(', ')"
7176
v-on:update:modelValue="$emit('update', 'email', $event)"
7277
/>
7378
</div>
@@ -81,7 +86,8 @@
8186
standout
8287
title="The person's affiliation."
8388
v-bind:model-value="affiliation"
84-
v-bind:rules="[validateAffiliation]"
89+
v-bind:error="affiliationError.hasError"
90+
v-bind:error-message="affiliationError.messages.join(', ')"
8591
v-on:update:modelValue="$emit('update', 'affiliation', $event)"
8692
/>
8793
<q-input
@@ -93,10 +99,24 @@
9399
standout
94100
title="The person's ORCID identifier."
95101
v-bind:model-value="orcid"
96-
v-bind:rules="[ validateOrcid ]"
102+
v-bind:error="orcidError.hasError"
103+
v-bind:error-message="orcidError.messages.join(', ')"
97104
v-on:update:modelValue="$emit('update', 'orcid', $event)"
98105
/>
99106
</div>
107+
108+
<q-banner
109+
v-if="authorErrors.hasError && authorErrors.messages.length > 0"
110+
class="bg-warning text-negative"
111+
>
112+
<div
113+
v-bind:key="authindex"
114+
v-for="(screenMessage, authindex) in authorErrors.messages"
115+
>
116+
{{ screenMessage }}
117+
</div>
118+
</q-banner>
119+
100120
<q-card-actions align="right">
101121
<q-btn
102122
color="blue"
@@ -132,8 +152,10 @@
132152
</template>
133153

134154
<script lang="ts">
135-
import { defineComponent } from 'vue'
136-
import { makeOptionalFieldValidator } from '../validator'
155+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
156+
import { computed, defineComponent } from 'vue'
157+
import { getMyErrors } from 'src/store/validator'
158+
import { authorErrors } from 'src/author-errors'
137159
138160
export default defineComponent({
139161
name: 'AuthorCardEditing',
@@ -150,23 +172,23 @@ export default defineComponent({
150172
type: String,
151173
default: ''
152174
},
153-
nameSuffix: {
175+
familyNames: {
154176
type: String,
155177
default: ''
156178
},
157-
orcid: {
179+
nameSuffix: {
158180
type: String,
159181
default: ''
160182
},
161-
familyNames: {
183+
email: {
162184
type: String,
163185
default: ''
164186
},
165187
affiliation: {
166188
type: String,
167189
default: ''
168190
},
169-
email: {
191+
orcid: {
170192
type: String,
171193
default: ''
172194
},
@@ -175,15 +197,16 @@ export default defineComponent({
175197
default: 0
176198
}
177199
},
178-
setup () {
200+
setup (props) {
179201
return {
180-
validateGivenNames: makeOptionalFieldValidator('/definitions/person/properties/given-names'),
181-
validateNameParticle: makeOptionalFieldValidator('/definitions/person/properties/name-particle'),
182-
validateNameSuffix: makeOptionalFieldValidator('/definitions/person/properties/name-suffix'),
183-
validateFamilyNames: makeOptionalFieldValidator('/definitions/person/properties/family-names'),
184-
validateAffiliation: makeOptionalFieldValidator('/definitions/person/properties/affiliation'),
185-
validateEmail: makeOptionalFieldValidator('/definitions/person/properties/email'),
186-
validateOrcid: makeOptionalFieldValidator('/definitions/person/properties/orcid') // or /definitions/orcid ?
202+
givenNamesError: computed(() => getMyErrors(`/authors/${props.index}/given-names`)),
203+
nameParticleError: computed(() => getMyErrors(`/authors/${props.index}/name-particle`)),
204+
familyNamesError: computed(() => getMyErrors(`/authors/${props.index}/family-names`)),
205+
nameSuffixError: computed(() => getMyErrors(`/authors/${props.index}/name-suffix`)),
206+
emailError: computed(() => getMyErrors(`/authors/${props.index}/email`)),
207+
affiliationError: computed(() => getMyErrors(`/authors/${props.index}/affiliation`)),
208+
orcidError: computed(() => getMyErrors(`/authors/${props.index}/orcid`)),
209+
authorErrors: computed(() => authorErrors(props.index))
187210
}
188211
},
189212
emits: ['closePressed', 'removePressed', 'update', 'moveUp', 'moveDown']

src/components/AuthorCardViewing.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<q-card
33
bordered
4-
class="bg-formcard"
4+
v-bind:class="['bg-formcard', authorErrors.hasError ? 'red-border' : '']"
55
flat
66
style="display: flex; flex-direction: row"
77
>
@@ -43,8 +43,9 @@
4343
</template>
4444

4545
<script lang="ts">
46-
import { defineComponent, PropType } from 'vue'
46+
import { computed, defineComponent, PropType } from 'vue'
4747
import { AuthorType } from 'src/types'
48+
import { authorErrors } from 'src/author-errors'
4849
4950
export default defineComponent({
5051
name: 'AuthorCardViewing',
@@ -62,6 +63,11 @@ export default defineComponent({
6263
default: 0
6364
}
6465
},
66+
setup (props) {
67+
return {
68+
authorErrors: computed(() => authorErrors(props.index))
69+
}
70+
},
6571
emits: ['editPressed', 'moveDown', 'moveUp']
6672
})
6773
</script>

src/components/IdentifierCardEditing.vue

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
v-on:update:modelValue="
2828
$emit('updateValue', 'value', $event)
2929
"
30-
v-bind:rules="[ validateValue ]"
3130
/>
3231
</div>
3332
<div class="q-gutter-md items-center no-wrap">
@@ -41,7 +40,6 @@
4140
v-on:update:modelValue="
4241
$emit('updateDescription', 'description', $event)
4342
"
44-
v-bind:rules="[ validateDescription ]"
4543
/>
4644
</div>
4745
</q-card-section>
@@ -81,7 +79,6 @@
8179

8280
<script lang="ts">
8381
import { IdentifierTypeType } from '../types'
84-
import { makeFieldValidator, makeOptionalFieldValidator } from '../validator'
8582
import { defineComponent, PropType } from 'vue'
8683
8784
export default defineComponent({
@@ -108,17 +105,17 @@ export default defineComponent({
108105
default: 0
109106
}
110107
},
111-
setup (props) {
108+
setup () {
112109
// validating of value depends on type
113-
const valueValidators: Record<IdentifierTypeType, (val: unknown) => true | string > = {
114-
doi: makeFieldValidator('/definitions/identifier/anyOf/0/properties/value'),
115-
url: makeFieldValidator('/definitions/identifier/anyOf/1/properties/value'),
116-
swh: makeFieldValidator('/definitions/identifier/anyOf/2/properties/value'),
117-
other: makeFieldValidator('/definitions/identifier/anyOf/3/properties/value')
118-
}
110+
// const valueValidators: Record<IdentifierTypeType, (val: unknown) => true | string > = {
111+
// doi: makeFieldValidator('/definitions/identifier/anyOf/0/properties/value'),
112+
// url: makeFieldValidator('/definitions/identifier/anyOf/1/properties/value'),
113+
// swh: makeFieldValidator('/definitions/identifier/anyOf/2/properties/value'),
114+
// other: makeFieldValidator('/definitions/identifier/anyOf/3/properties/value')
115+
// }
119116
return {
120-
validateValue: (val: string) => valueValidators[props.type as IdentifierTypeType](val),
121-
validateDescription: makeOptionalFieldValidator('/definitions/identifier-description'),
117+
// validateValue: (val: string) => valueValidators[props.type as IdentifierTypeType](val),
118+
// validateDescription: makeOptionalFieldValidator('/definitions/identifier-description'),
122119
typeOptions: [
123120
{ label: 'DOI', value: 'doi' },
124121
{ label: 'URL', value: 'url' },

src/components/Keyword.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
outlined
88
placeholder="Type a keyword"
99
v-bind:model-value="keyword"
10-
v-bind:rules="[ validateKeyword ]"
10+
v-bind:error="FIXME.hasError"
11+
v-bind:error-message="FIXME.messages.join(', ')"
1112
v-on:update:modelValue="$emit('update', $event)"
1213
/>
1314
</div>
@@ -40,7 +41,6 @@
4041
</template>
4142

4243
<script lang="ts">
43-
import { makeFieldValidator } from 'src/validator'
4444
import { defineComponent } from 'vue'
4545
4646
export default defineComponent({
@@ -61,7 +61,7 @@ export default defineComponent({
6161
},
6262
setup () {
6363
return {
64-
validateKeyword: makeFieldValidator('/properties/keywords/items')
64+
FIXME: { hasError: false, messages: [] }
6565
}
6666
},
6767
emits: ['moveDown', 'moveUp', 'removePressed', 'update']

src/components/Preview.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@
3737
/>
3838
<div class="validation-msg">
3939
<p>
40-
Your CITATION.cff is {{ isValid ? "valid" : "not valid" }}
40+
Your CITATION.cff is {{ isValidCFF ? "valid" : "not valid" }}
4141
</p>
4242
</div>
4343
</template>
4444

4545
<script lang="ts">
4646
import { defineComponent, ref, computed } from 'vue'
4747
import { useCffstr } from 'src/store/cffstr'
48-
import { isValidCffFile } from 'src/validator'
48+
import { useErrors } from 'src/store/errors'
4949
5050
export default defineComponent({
5151
name: 'Preview',
5252
components: {
5353
},
5454
setup () {
5555
const { cffstr } = useCffstr()
56+
const { errors } = useErrors()
5657
const showTooltip = ref(false)
5758
5859
const copyToClipboard = async () => {
@@ -62,12 +63,12 @@ export default defineComponent({
6263
showTooltip.value = false
6364
}
6465
65-
const isValid = computed(isValidCffFile)
66+
const isValidCFF = computed(() => errors.value.length === 0)
6667
6768
return {
6869
cffstr,
6970
copyToClipboard,
70-
isValid,
71+
isValidCFF,
7172
showTooltip
7273
}
7374
}

src/components/ScreenAbstract.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
standout
2222
type="textarea"
2323
v-bind:model-value="abstract"
24-
v-bind:rules="[validateAbstract]"
24+
v-bind:error="false"
25+
v-bind:error-message="''"
2526
v-on:update:modelValue="setAbstract"
2627
/>
2728
</div>
@@ -35,10 +36,8 @@
3536
<script lang="ts">
3637
import Stepper from 'components/Stepper.vue'
3738
import StepperActions from 'components/StepperActions.vue'
38-
import { makeOptionalFieldValidator } from '../validator'
3939
import { defineComponent } from 'vue'
4040
import { useCff } from '../store/cff'
41-
4241
export default defineComponent({
4342
name: 'ScreenAbstract',
4443
components: {
@@ -49,8 +48,7 @@ export default defineComponent({
4948
const { abstract, setAbstract } = useCff()
5049
return {
5150
abstract,
52-
setAbstract,
53-
validateAbstract: makeOptionalFieldValidator('/properties/abstract')
51+
setAbstract
5452
}
5553
}
5654
})

0 commit comments

Comments
 (0)