hotfix (dashboard): display allow email contact in card box client
- Added the `allowEmailContact` property to the `CardBoxClient` component to display the email contact status. - Added the `allowEmailContact` computed property to the `Person` model to determine if email contact is allowed based on the related datasets. - Preloaded the datasets relation in the `AuthorsController` to access the pivot attributes. - Updated the `Dashboard.vue` to pass the `allowEmailContact` prop to the `CardBoxClient` component. - Updated the `array_contains_types` validation rule to correct the error message for descriptions. - Updated the `FormCheckRadio.vue` to correctly handle the radio button and checkbox components.
This commit is contained in:
parent
09f65359f9
commit
f89b119b18
6 changed files with 31 additions and 49 deletions
|
@ -9,6 +9,7 @@ export default class AuthorsController {
|
|||
// where exists (select * from gba.documents inner join gba.link_documents_persons on "documents"."id" = "link_documents_persons"."document_id"
|
||||
// where ("link_documents_persons"."role" = 'author') and ("persons"."id" = "link_documents_persons"."person_id"));
|
||||
const authors = await Person.query()
|
||||
.preload('datasets')
|
||||
.where('name_type', 'Personal')
|
||||
.whereHas('datasets', (dQuery) => {
|
||||
dQuery.wherePivot('role', 'author');
|
||||
|
|
|
@ -3,7 +3,7 @@ import { DateTime } from 'luxon';
|
|||
import dayjs from 'dayjs';
|
||||
import Dataset from './dataset.js';
|
||||
import BaseModel from './base_model.js';
|
||||
import type { ManyToMany } from "@adonisjs/lucid/types/relations";
|
||||
import type { ManyToMany } from '@adonisjs/lucid/types/relations';
|
||||
|
||||
export default class Person extends BaseModel {
|
||||
public static namingStrategy = new SnakeCaseNamingStrategy();
|
||||
|
@ -64,7 +64,6 @@ export default class Person extends BaseModel {
|
|||
// return '2023-03-21 08:45:00';
|
||||
// }
|
||||
|
||||
|
||||
@computed({
|
||||
serializeAs: 'dataset_count',
|
||||
})
|
||||
|
@ -79,6 +78,16 @@ export default class Person extends BaseModel {
|
|||
return contributor_type;
|
||||
}
|
||||
|
||||
@computed({ serializeAs: 'allow_email_contact' })
|
||||
public get allowEmailContact() {
|
||||
// If the datasets relation is missing or empty, return false instead of null.
|
||||
if (!this.datasets || this.datasets.length === 0) {
|
||||
return false;
|
||||
}
|
||||
// Otherwise return the pivot attribute from the first related dataset.
|
||||
return this.datasets[0].$extras?.pivot_allow_email_contact;
|
||||
}
|
||||
|
||||
@manyToMany(() => Dataset, {
|
||||
pivotForeignKey: 'person_id',
|
||||
pivotRelatedForeignKey: 'document_id',
|
||||
|
|
|
@ -39,6 +39,10 @@ const props = defineProps({
|
|||
type: String,
|
||||
default: null,
|
||||
},
|
||||
allowEmailContact: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
}
|
||||
});
|
||||
|
||||
const pillType = computed(() => {
|
||||
|
@ -82,8 +86,7 @@ const pillType = computed(() => {
|
|||
{{ name }}
|
||||
</h4>
|
||||
<p class="text-gray-500 dark:text-slate-400">
|
||||
<!-- {{ date }} @ {{ login }} -->
|
||||
{{ email }}
|
||||
<div v-if="props.allowEmailContact"> {{ email }}</div>
|
||||
</p>
|
||||
</div>
|
||||
</BaseLevel>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
|
||||
interface Props {
|
||||
name: string;
|
||||
type?: 'checkbox' | 'radio' | 'switch';
|
||||
|
@ -10,58 +9,27 @@ interface Props {
|
|||
inputValue: string | number | boolean;
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'checkbox',
|
||||
validator: (value: string) => ['checkbox', 'radio', 'switch'].includes(value),
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
modelValue: {
|
||||
type: [Array, String, Number, Boolean],
|
||||
default: null,
|
||||
},
|
||||
inputValue: {
|
||||
type: [String, Number, Boolean],
|
||||
required: true,
|
||||
},
|
||||
});// const props = defineProps<Props>();
|
||||
const props = defineProps<Props>();
|
||||
|
||||
// const emit = defineEmits(['update:modelValue']);
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', value: Props['modelValue']): void }>();
|
||||
|
||||
const computedValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => {
|
||||
// If type is radio, wrap the new value inside an array.
|
||||
if (props.type === 'radio') {
|
||||
emit('update:modelValue', [value]);
|
||||
} else {
|
||||
emit('update:modelValue', value);
|
||||
}
|
||||
emit('update:modelValue', props.type === 'radio' ? [value] : value);
|
||||
},
|
||||
});
|
||||
|
||||
const inputType = computed(() => (props.type === 'radio' ? 'radio' : 'checkbox'));
|
||||
|
||||
// Define isChecked for radio inputs: it's true when the current modelValue equals the inputValue
|
||||
const isChecked = computed(() => {
|
||||
if (props.type === 'radio') {
|
||||
return Array.isArray(computedValue.value) &&
|
||||
computedValue.value.length > 0 &&
|
||||
computedValue.value[0] === props.inputValue;
|
||||
} else if (props.type === 'checkbox') {
|
||||
return Array.isArray(computedValue.value) &&
|
||||
computedValue.value.length > 0 &&
|
||||
computedValue.value.includes(props.inputValue);
|
||||
}
|
||||
return computedValue.value === props.inputValue;
|
||||
if (Array.isArray(computedValue.value) && computedValue.value.length > 0) {
|
||||
return props.type === 'radio'
|
||||
? computedValue.value[0] === props.inputValue
|
||||
: computedValue.value.includes(props.inputValue);
|
||||
}
|
||||
return computedValue.value === props.inputValue;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ const userHasRoles = (roleNames: Array<string>): boolean => {
|
|||
:date="client.created_at"
|
||||
:text="client.identifier_orcid"
|
||||
:count="client.dataset_count"
|
||||
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col justify-between">
|
||||
|
|
|
@ -53,9 +53,9 @@ async function arrayContainsTypes(value: unknown, options: Options, field: Field
|
|||
} else if (field.getFieldPath() === 'descriptions') {
|
||||
// For descriptions we expect one abstracts description and minimum one translated description.
|
||||
if (!hasTypeA && !hasTypeB) {
|
||||
errorMessage = 'For descriptions, define one abstracts description and minimum one translated description.';
|
||||
errorMessage = 'For descriptions, define one abstract description and minimum one translated description.';
|
||||
} else if (!hasTypeA) {
|
||||
errorMessage = 'For descriptions, define one abstracts description.';
|
||||
errorMessage = 'For descriptions, define one abstract description.';
|
||||
} else if (!hasTypeB) {
|
||||
errorMessage = 'For descriptions, define minimum one translated description.';
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue