- add references, collections and identifiers to dataset model
All checks were successful
CI Pipeline / japa-tests (push) Successful in 52s
All checks were successful
CI Pipeline / japa-tests (push) Successful in 52s
- npm updates
This commit is contained in:
parent
f6d735d0fd
commit
5f8fe1c16d
|
@ -7,6 +7,7 @@ import Title from 'App/Models/Title';
|
|||
import Description from 'App/Models/Description';
|
||||
import Language from 'App/Models/Language';
|
||||
import Coverage from 'App/Models/Coverage';
|
||||
import Collection from 'App/Models/Collection';
|
||||
// import CreateUserValidator from 'App/Validators/CreateUserValidator';
|
||||
// import UpdateUserValidator from 'App/Validators/UpdateUserValidator';
|
||||
import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator';
|
||||
|
@ -48,6 +49,14 @@ export default class DatasetController {
|
|||
datasets.orderBy('id', 'asc');
|
||||
}
|
||||
|
||||
// const results = await Database
|
||||
// .query()
|
||||
// .select(Database.raw("CONCAT('https://doi.org/', b.value) AS concatenated_value"))
|
||||
// .from('documents as doc')
|
||||
// .innerJoin('dataset_identifiers as b', 'doc.id', 'b.dataset_id')
|
||||
// .groupBy('a.id').toQuery();
|
||||
|
||||
|
||||
// const users = await User.query().orderBy('login').paginate(page, limit);
|
||||
const myDatasets = await datasets
|
||||
.whereIn('server_state', [
|
||||
|
@ -117,10 +126,8 @@ export default class DatasetController {
|
|||
.map(([key, value]) => ({ value: key, label: value })),
|
||||
// descriptiontypes: DescriptionTypes
|
||||
projects: projects,
|
||||
referenceIdentifierTypes: Object.entries(ReferenceIdentifierTypes)
|
||||
.map(([key, value]) => ({ value: key, label: value })),
|
||||
relationTypes: Object.entries(RelationTypes)
|
||||
.map(([key, value]) => ({ value: key, label: value })),
|
||||
referenceIdentifierTypes: Object.entries(ReferenceIdentifierTypes).map(([key, value]) => ({ value: key, label: value })),
|
||||
relationTypes: Object.entries(RelationTypes).map(([key, value]) => ({ value: key, label: value })),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -245,15 +252,12 @@ export default class DatasetController {
|
|||
depth_min: schema.number.optional([rules.requiredIfExists('depth_max')]),
|
||||
depth_max: schema.number.optional([rules.requiredIfExists('depth_min')]),
|
||||
}),
|
||||
references: schema.array([rules.uniqueArray('value')]).members(
|
||||
references: schema.array.optional([rules.uniqueArray('value')]).members(
|
||||
schema.object().members({
|
||||
value: schema.string({ trim: true }, [
|
||||
rules.minLength(3),
|
||||
rules.maxLength(255),
|
||||
]),
|
||||
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
||||
type: schema.enum(Object.values(ReferenceIdentifierTypes)),
|
||||
relation: schema.enum(Object.values(RelationTypes)),
|
||||
// language: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
||||
label: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
||||
}),
|
||||
),
|
||||
subjects: schema.array([rules.minLength(3), rules.uniqueArray('value')]).members(
|
||||
|
@ -404,6 +408,10 @@ export default class DatasetController {
|
|||
}
|
||||
}
|
||||
|
||||
// save collection
|
||||
const collection: Collection | null = await Collection.query().where('id', 21).first();
|
||||
collection && (await dataset.useTransaction(trx).related('collections').attach([collection.id]));
|
||||
|
||||
// save coverage
|
||||
const coverageData = request.input('coverage');
|
||||
if (coverageData) {
|
||||
|
@ -481,6 +489,12 @@ export default class DatasetController {
|
|||
'subjects.*.type.required': 'keyword type is required',
|
||||
'subjects.*.language.required': 'language of keyword is required',
|
||||
|
||||
'references.*.value.required': 'Additional reference value is required, if defined',
|
||||
'references.*.type.required': 'Additional reference identifier type is required',
|
||||
'references.*.relation.required': 'Additional reference relation type is required',
|
||||
'references.*.label.required': 'Additional reference label is required',
|
||||
|
||||
'files.minLength': 'At least {{ options.minLength }} file upload is required.',
|
||||
'files.*.size': 'file size is to big',
|
||||
'files.extnames': 'file extension is not supported',
|
||||
};
|
||||
|
|
45
app/Models/Collection.ts
Normal file
45
app/Models/Collection.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { column, BaseModel, SnakeCaseNamingStrategy, manyToMany, ManyToMany } from '@ioc:Adonis/Lucid/Orm';
|
||||
import Dataset from './Dataset';
|
||||
|
||||
export default class Collection extends BaseModel {
|
||||
public static namingStrategy = new SnakeCaseNamingStrategy();
|
||||
public static primaryKey = 'id';
|
||||
public static table = 'collections';
|
||||
public static fillable: string[] = ['name', 'number', 'role_id'];
|
||||
|
||||
@column({
|
||||
isPrimary: true,
|
||||
})
|
||||
public id: number;
|
||||
|
||||
@column({})
|
||||
public document_id: number;
|
||||
|
||||
@column({})
|
||||
public role_id?: number;
|
||||
|
||||
@column({})
|
||||
public number?: string;
|
||||
|
||||
@column({})
|
||||
public name: string;
|
||||
|
||||
@column({})
|
||||
public oai_subset?: string;
|
||||
|
||||
@column({})
|
||||
public parent_id?: number;
|
||||
|
||||
@column({})
|
||||
public visible: boolean;
|
||||
|
||||
@column({})
|
||||
public visible_publish: boolean;
|
||||
|
||||
@manyToMany(() => Dataset, {
|
||||
pivotForeignKey: 'collection_id',
|
||||
pivotRelatedForeignKey: 'document_id',
|
||||
pivotTable: 'link_documents_collections',
|
||||
})
|
||||
public datasets: ManyToMany<typeof Dataset>;
|
||||
}
|
|
@ -23,6 +23,8 @@ import Subject from './Subject';
|
|||
import File from './File';
|
||||
import Coverage from './Coverage';
|
||||
import DatasetReference from './DatasetReference';
|
||||
import Collection from './Collection';
|
||||
import DatasetIdentifier from './DatasetIdentifier';
|
||||
|
||||
export default class Dataset extends BaseModel {
|
||||
public static namingStrategy = new SnakeCaseNamingStrategy();
|
||||
|
@ -144,6 +146,23 @@ export default class Dataset extends BaseModel {
|
|||
})
|
||||
public references: HasMany<typeof DatasetReference>;
|
||||
|
||||
// public function collections()
|
||||
// {
|
||||
// return $this
|
||||
// ->belongsToMany(Collection::class, 'link_documents_collections', 'document_id', 'collection_id');
|
||||
// }
|
||||
@manyToMany(() => Collection, {
|
||||
pivotForeignKey: 'document_id',
|
||||
pivotRelatedForeignKey: 'collection_id',
|
||||
pivotTable: 'link_documents_collections',
|
||||
})
|
||||
public collections: ManyToMany<typeof Collection>;
|
||||
|
||||
@hasOne(() => DatasetIdentifier, {
|
||||
foreignKey: 'document_id',
|
||||
})
|
||||
public identifier: HasOne<typeof DatasetIdentifier>;
|
||||
|
||||
|
||||
@computed({
|
||||
serializeAs: 'main_title',
|
||||
|
|
40
app/Models/DatasetIdentifier.ts
Normal file
40
app/Models/DatasetIdentifier.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { column, BaseModel, SnakeCaseNamingStrategy, belongsTo, BelongsTo } from '@ioc:Adonis/Lucid/Orm';
|
||||
import { DateTime } from 'luxon';
|
||||
import Dataset from './Dataset';
|
||||
|
||||
export default class DatasetIdentifier extends BaseModel {
|
||||
public static namingStrategy = new SnakeCaseNamingStrategy();
|
||||
public static primaryKey = 'id';
|
||||
public static table = 'dataset_identifiers';
|
||||
public static fillable: string[] = ['value', 'label', 'type', 'relation'];
|
||||
|
||||
@column({
|
||||
isPrimary: true,
|
||||
})
|
||||
public id: number;
|
||||
|
||||
@column({})
|
||||
public document_id: number;
|
||||
|
||||
@column({})
|
||||
public type: string;
|
||||
|
||||
@column({})
|
||||
public value: string;
|
||||
|
||||
@column.dateTime({
|
||||
autoCreate: true,
|
||||
})
|
||||
public created_at?: DateTime;
|
||||
|
||||
@column.dateTime({
|
||||
autoCreate: true,
|
||||
autoUpdate: true,
|
||||
})
|
||||
public updated_at?: DateTime;
|
||||
|
||||
@belongsTo(() => Dataset, {
|
||||
foreignKey: 'document_id',
|
||||
})
|
||||
public dataset: BelongsTo<typeof Dataset>;
|
||||
}
|
|
@ -73,15 +73,12 @@ export default class CreateDatasetValidator {
|
|||
depth_min: schema.number.optional([rules.requiredIfExists('depth_max')]),
|
||||
depth_max: schema.number.optional([rules.requiredIfExists('depth_min')]),
|
||||
}),
|
||||
references: schema.array([rules.uniqueArray('value')]).members(
|
||||
references: schema.array.optional([rules.uniqueArray('value')]).members(
|
||||
schema.object().members({
|
||||
value: schema.string({ trim: true }, [
|
||||
rules.minLength(3),
|
||||
rules.maxLength(255),
|
||||
]),
|
||||
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
||||
type: schema.enum(Object.values(ReferenceIdentifierTypes)),
|
||||
relation: schema.enum(Object.values(RelationTypes)),
|
||||
// language: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
||||
label: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
||||
}),
|
||||
),
|
||||
subjects: schema.array([rules.minLength(3), rules.uniqueArray('value')]).members(
|
||||
|
@ -102,7 +99,7 @@ export default class CreateDatasetValidator {
|
|||
files: schema.array([rules.minLength(1)]).members(
|
||||
schema.file({
|
||||
size: '100mb',
|
||||
extnames: ['jpg', 'gif', 'png'],
|
||||
extnames: ['jpg', 'gif', 'png', 'tif'],
|
||||
}),
|
||||
),
|
||||
// upload: schema.object().members({
|
||||
|
@ -162,6 +159,12 @@ export default class CreateDatasetValidator {
|
|||
'subjects.*.type.required': 'keyword type is required',
|
||||
'subjects.*.language.required': 'language of keyword is required',
|
||||
|
||||
'references.*.value.required': 'Additional reference value is required, if defined',
|
||||
'references.*.type.required': 'Additional reference identifier type is required',
|
||||
'references.*.relation.required': 'Additional reference relation type is required',
|
||||
'references.*.label.required': 'Additional reference label is required',
|
||||
|
||||
'files.minLength': 'At least {{ options.minLength }} file upload is required.',
|
||||
'files.*.size': 'file size is to big',
|
||||
'files.extnames': 'file extension is not supported',
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ export default class DocumentFiles extends BaseSchema {
|
|||
.foreign('document_id', 'document_files_document_id_foreign')
|
||||
.references('id')
|
||||
.inTable('documents')
|
||||
.onDelete('CASCADE') // delete this when document is deleted
|
||||
.onDelete('CASCADE') // delete this file when document is deleted
|
||||
.onUpdate('CASCADE');
|
||||
table.string('path_name').notNullable();
|
||||
table.string('label');
|
||||
|
|
607
package-lock.json
generated
607
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -41,7 +41,7 @@
|
|||
"babel-preset-typescript-vue3": "^2.0.17",
|
||||
"chart.js": "^4.2.0",
|
||||
"eslint": "^8.32.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-adonis": "^2.1.1",
|
||||
"eslint-plugin-prettier": "^5.0.0-alpha.2",
|
||||
"naive-ui": "^2.34.3",
|
||||
|
|
|
@ -907,26 +907,33 @@ Removes a selected keyword
|
|||
|
||||
<CardBox class="mb-6 shadow" has-table title="Dataset References" :header-icon="mdiPlusCircle"
|
||||
v-on:header-icon-click="addReference">
|
||||
<table class="table table-hover" v-if="form.references.length">
|
||||
<table class="table-fixed border-green-900" v-if="form.references.length">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Value of the identifier</th>
|
||||
<th>Type</th>
|
||||
<th>Relation</th>
|
||||
<th>Label</th>
|
||||
<th></th>
|
||||
<th class="w-4/12">Value</th>
|
||||
<th class="w-2/12">Type</th>
|
||||
<th class="w-3/12">Relation</th>
|
||||
<th class="w-2/12">Label</th>
|
||||
<th class="w-1/12"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in form.references">
|
||||
<td data-label="Reference Value">
|
||||
<input name="Reference Value" class="form-control"
|
||||
placeholder="[VALUE]" v-model="item.value" />
|
||||
<!-- <input name="Reference Value" class="form-control"
|
||||
placeholder="[VALUE]" v-model="item.value" /> -->
|
||||
<FormControl required v-model="item.value" :type="'text'" placeholder="[VALUE]"
|
||||
:errors="form.errors.embargo_date">
|
||||
<div class="text-red-400 text-sm"
|
||||
v-if="form.errors[`references.${index}.value`] && Array.isArray(form.errors[`references.${index}.value`])">
|
||||
{{ form.errors[`references.${index}.value`].join(', ') }}
|
||||
</div>
|
||||
</FormControl>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<FormControl required v-model="form.references[index].type" type="select"
|
||||
:options="referenceIdentifierTypes"
|
||||
placeholder="[identifier type]">
|
||||
:options="referenceIdentifierTypes" placeholder="[type]">
|
||||
<div class="text-red-400 text-sm"
|
||||
v-if="Array.isArray(form.errors[`references.${index}.type`])">
|
||||
{{ form.errors[`references.${index}.type`].join(', ') }}
|
||||
|
@ -940,8 +947,7 @@ Removes a selected keyword
|
|||
'data-vv-scope' => 'step-2'])
|
||||
!!} -->
|
||||
<FormControl required v-model="form.references[index].relation" type="select"
|
||||
:options="relationTypes"
|
||||
placeholder="[relation type]">
|
||||
:options="relationTypes" placeholder="[relation type]">
|
||||
<div class="text-red-400 text-sm"
|
||||
v-if="Array.isArray(form.errors[`references.${index}.relation`])">
|
||||
{{ form.errors[`references.${index}.relation`].join(', ') }}
|
||||
|
@ -949,7 +955,14 @@ Removes a selected keyword
|
|||
</FormControl>
|
||||
</td>
|
||||
<td data-label="Reference Label">
|
||||
<input name="Reference Label" class="form-control" v-model="item.label" />
|
||||
<!-- <input name="Reference Label" class="form-control" v-model="item.label" /> -->
|
||||
<FormControl required v-model="form.references[index].label" type="text"
|
||||
placeholder="[reference label]">
|
||||
<div class="text-red-400 text-sm"
|
||||
v-if="form.errors[`references.${index}.label`] && Array.isArray(form.errors[`references.${index}.label`])">
|
||||
{{ form.errors[`references.${index}.label`].join(', ') }}
|
||||
</div>
|
||||
</FormControl>
|
||||
</td>
|
||||
<td class="before:hidden lg:w-1 whitespace-nowrap">
|
||||
<!-- <BaseButton color="info" :icon="mdiEye" small @click="isModalActive = true" /> -->
|
||||
|
|
Loading…
Reference in New Issue
Block a user