- second commit
This commit is contained in:
parent
4fc3bb0a01
commit
59a99ff3c8
61 changed files with 2625 additions and 1182 deletions
|
@ -117,7 +117,7 @@ export default class UsersController {
|
|||
const roles = await Role.query().pluck('name', 'id');
|
||||
// const userHasRoles = user.roles;
|
||||
const userHasRoles = await user.related('roles').query().orderBy('name').pluck('id');
|
||||
|
||||
// let test = Object.keys(userHasRoles).map((key) => userHasRoles[key]);
|
||||
return inertia.render('Admin/User/Edit', {
|
||||
roles: roles,
|
||||
user: user,
|
||||
|
|
|
@ -4,20 +4,34 @@ import Person from 'App/Models/Person';
|
|||
|
||||
// node ace make:controller Author
|
||||
export default class AuthorsController {
|
||||
public async index({}: HttpContextContract) {
|
||||
// select * from gba.persons
|
||||
// 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()
|
||||
.whereHas('datasets', (dQuery) => {
|
||||
dQuery.wherePivot('role', 'author');
|
||||
})
|
||||
.withCount('datasets', (query) => {
|
||||
query.as('datasets_count');
|
||||
});
|
||||
|
||||
public async index({}: HttpContextContract) {
|
||||
// select * from gba.persons
|
||||
// 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()
|
||||
.whereHas('datasets', (dQuery) => {
|
||||
dQuery.wherePivot('role', 'author')
|
||||
})
|
||||
.withCount('datasets', (query) => {
|
||||
query.as('datasets_count')
|
||||
});
|
||||
|
||||
return authors;
|
||||
}
|
||||
return authors;
|
||||
}
|
||||
|
||||
public async persons({ request }: HttpContextContract) {
|
||||
const authors = Person.query().where('status', true);
|
||||
|
||||
if (request.input('filter')) {
|
||||
// users = users.whereRaw('name like %?%', [request.input('search')])
|
||||
const searchTerm = request.input('filter');
|
||||
authors
|
||||
.where('first_name', 'ilike', `%${searchTerm}%`)
|
||||
.orWhere('last_name', 'like', `%${searchTerm}%`)
|
||||
.orWhere('email', 'like', `%${searchTerm}%`);
|
||||
}
|
||||
|
||||
let persons = await authors;
|
||||
return persons;
|
||||
}
|
||||
}
|
||||
|
|
162
app/Controllers/Http/Submitter/DatasetController.ts
Normal file
162
app/Controllers/Http/Submitter/DatasetController.ts
Normal file
|
@ -0,0 +1,162 @@
|
|||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
||||
// import User from 'App/Models/User';
|
||||
// import Role from 'App/Models/Role';
|
||||
// import Database from '@ioc:Adonis/Lucid/Database';
|
||||
import License from 'App/Models/License';
|
||||
// import type { ModelQueryBuilderContract } from '@ioc:Adonis/Lucid/Orm';
|
||||
// import CreateUserValidator from 'App/Validators/CreateUserValidator';
|
||||
// import UpdateUserValidator from 'App/Validators/UpdateUserValidator';
|
||||
// import { RenderResponse } from '@ioc:EidelLev/Inertia';
|
||||
import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator';
|
||||
|
||||
enum TitleTypes {
|
||||
Main = 'Main',
|
||||
Sub = 'Sub',
|
||||
Alternative = 'Alternative',
|
||||
Translated = 'Translated',
|
||||
Other = 'Other',
|
||||
}
|
||||
|
||||
enum DescriptionTypes {
|
||||
Abstract = 'Abstract',
|
||||
Methods = 'Methods',
|
||||
Series_information = 'Series_information',
|
||||
Technical_info = 'Technical_info',
|
||||
Translated = 'Translated',
|
||||
Other = 'Other',
|
||||
}
|
||||
|
||||
export default class DatasetController {
|
||||
public async create({ inertia }: HttpContextContract) {
|
||||
const licenses = await License.query().select('id', 'name_long').pluck('name_long', 'id');
|
||||
|
||||
const doctypes = {
|
||||
analysisdata: { label: 'Analysis', value: 'analysisdata' },
|
||||
measurementdata: { label: 'Measurements', value: 'measurementdata' },
|
||||
monitoring: 'Monitoring',
|
||||
remotesensing: 'Remote Sensing',
|
||||
gis: 'GIS',
|
||||
models: 'Models',
|
||||
mixedtype: 'Mixed Type',
|
||||
};
|
||||
|
||||
// const titletypes = {
|
||||
// Sub: 'Sub',
|
||||
// Alternative: 'Alternative',
|
||||
// Translated: 'Translated',
|
||||
// Other: 'Other',
|
||||
// };
|
||||
|
||||
// const languages = await Database.from('languages').select('*').where('active', true);
|
||||
return inertia.render('Submitter/Dataset/Create', {
|
||||
licenses: licenses,
|
||||
doctypes: doctypes,
|
||||
titletypes: Object.values(TitleTypes).filter((x) => x.valueOf() !== 'Main'),
|
||||
descriptiontypes: Object.values(DescriptionTypes).filter((x) => x.valueOf() !== 'Abstract'),
|
||||
// descriptiontypes: DescriptionTypes
|
||||
});
|
||||
}
|
||||
|
||||
public async firstStep({ request, response }: HttpContextContract) {
|
||||
const newDatasetSchema = schema.create({
|
||||
language: schema.string({ trim: true }, [
|
||||
rules.regex(/^[a-zA-Z0-9-_]+$/), //Must be alphanumeric with hyphens or underscores
|
||||
]),
|
||||
licenses: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one license for the new dataset
|
||||
rights: schema.string([rules.equalTo('true')]),
|
||||
});
|
||||
|
||||
try {
|
||||
// Step 2 - Validate request body against the schema
|
||||
|
||||
await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
||||
// console.log({ payload });
|
||||
} catch (error) {
|
||||
// Step 3 - Handle errors
|
||||
// return response.badRequest(error.messages);
|
||||
throw error;
|
||||
}
|
||||
return response.redirect().back();
|
||||
}
|
||||
|
||||
public async secondStep({ request, response }: HttpContextContract) {
|
||||
const newDatasetSchema = schema.create({
|
||||
language: schema.string({ trim: true }, [
|
||||
rules.regex(/^[a-zA-Z0-9-_]+$/), //Must be alphanumeric with hyphens or underscores
|
||||
]),
|
||||
licenses: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one license for the new dataset
|
||||
type: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
||||
creating_corporation: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
||||
titles: schema.array([rules.minLength(1)]).members(
|
||||
schema.object().members({
|
||||
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
||||
type: schema.enum(Object.values(TitleTypes)),
|
||||
language: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
||||
}),
|
||||
),
|
||||
descriptions: schema.array([rules.minLength(1)]).members(
|
||||
schema.object().members({
|
||||
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
||||
type: schema.enum(Object.values(DescriptionTypes)),
|
||||
language: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
try {
|
||||
// Step 2 - Validate request body against the schema
|
||||
await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
||||
// console.log({ payload });
|
||||
} catch (error) {
|
||||
// Step 3 - Handle errors
|
||||
// return response.badRequest(error.messages);
|
||||
throw error;
|
||||
}
|
||||
return response.redirect().back();
|
||||
}
|
||||
|
||||
// public async store({ request, response, session }: HttpContextContract) {
|
||||
// // node ace make:validator CreateUser
|
||||
// try {
|
||||
// // Step 2 - Validate request body against the schema
|
||||
// await request.validate(CreateUserValidator);
|
||||
// // console.log({ payload });
|
||||
// } catch (error) {
|
||||
// // Step 3 - Handle errors
|
||||
// // return response.badRequest(error.messages);
|
||||
// throw error;
|
||||
// }
|
||||
// const input = request.only(['login', 'email', 'password']);
|
||||
// const user = await User.create(input);
|
||||
// if (request.input('roles')) {
|
||||
// const roles: Array<number> = request.input('roles');
|
||||
// await user.related('roles').attach(roles);
|
||||
// }
|
||||
|
||||
// session.flash('message', 'User has been created successfully');
|
||||
// return response.redirect().toRoute('user.index');
|
||||
// }
|
||||
|
||||
public messages: CustomMessages = {
|
||||
'minLength': '{{ field }} must be at least {{ options.minLength }} characters long',
|
||||
'maxLength': '{{ field }} must be less then {{ options.maxLength }} characters long',
|
||||
'required': '{{ field }} is required',
|
||||
'unique': '{{ field }} must be unique, and this value is already taken',
|
||||
// 'confirmed': '{{ field }} is not correct',
|
||||
'licences.minLength': 'at least {{ options.minLength }} permission must be defined',
|
||||
'licences.*.number': 'Define roles as valid numbers',
|
||||
'rights.equalTo': 'you must agree to continue',
|
||||
|
||||
'titles.0.value.minLength': 'Main Title must be at least {{ options.minLength }} characters long',
|
||||
'titles.0.value.required': 'Main Title is required',
|
||||
'titles.*.value.required': 'Additional title is required, if defined',
|
||||
'titles.*.type.required': 'Additional title type is required',
|
||||
'titles.*.language.required': 'Additional title language is required',
|
||||
|
||||
'descriptions.0.value.minLength': 'Main Abstract must be at least {{ options.minLength }} characters long',
|
||||
'descriptions.0.value.required': 'Main Abstract is required',
|
||||
'descriptions.*.value.required': 'Additional description is required, if defined',
|
||||
'descriptions.*.type.required': 'Additional description type is required',
|
||||
'descriptions.*.language.required': 'Additional description language is required',
|
||||
};
|
||||
}
|
37
app/Models/License.ts
Normal file
37
app/Models/License.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { column, BaseModel, SnakeCaseNamingStrategy } from '@ioc:Adonis/Lucid/Orm';
|
||||
|
||||
export default class License extends BaseModel {
|
||||
public static namingStrategy = new SnakeCaseNamingStrategy();
|
||||
public static primaryKey = 'id';
|
||||
public static table = 'document_licences';
|
||||
public static selfAssignPrimaryKey = false;
|
||||
|
||||
@column({
|
||||
isPrimary: true,
|
||||
})
|
||||
public id: number;
|
||||
|
||||
@column({})
|
||||
public active: boolean;
|
||||
|
||||
@column({})
|
||||
public langauge: string;
|
||||
|
||||
@column({})
|
||||
public link_licence: string;
|
||||
|
||||
@column({})
|
||||
public link_logo: string;
|
||||
|
||||
@column({})
|
||||
public display_name: string;
|
||||
|
||||
@column({})
|
||||
public name_long: string;
|
||||
|
||||
@column({})
|
||||
public name: string;
|
||||
|
||||
@column({})
|
||||
public sortOrder: number;
|
||||
}
|
|
@ -54,7 +54,7 @@ export default class Person extends BaseModel {
|
|||
serializeAs: 'name'
|
||||
})
|
||||
public get fullName() {
|
||||
return this.firstName + ' ' + this.lastName;
|
||||
return `${this.firstName} ${this.lastName} (${this.email})`;
|
||||
}
|
||||
|
||||
@computed()
|
||||
|
|
|
@ -3,101 +3,101 @@ import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|||
// import { Request } from '@adonisjs/core/build/standalone';
|
||||
|
||||
export default class UpdateUserValidator {
|
||||
protected ctx: HttpContextContract;
|
||||
public schema;
|
||||
protected ctx: HttpContextContract;
|
||||
public schema;
|
||||
|
||||
constructor(ctx: HttpContextContract) {
|
||||
this.ctx = ctx;
|
||||
this.schema = this.createSchema();
|
||||
}
|
||||
constructor(ctx: HttpContextContract) {
|
||||
this.ctx = ctx;
|
||||
this.schema = this.createSchema();
|
||||
}
|
||||
|
||||
// public get schema() {
|
||||
// return this._schema;
|
||||
// }
|
||||
// public get schema() {
|
||||
// return this._schema;
|
||||
// }
|
||||
|
||||
private createSchema() {
|
||||
return schema.create({
|
||||
login: schema.string({ trim: true }, [
|
||||
rules.minLength(3),
|
||||
rules.maxLength(50),
|
||||
rules.unique({
|
||||
table: 'accounts',
|
||||
column: 'login',
|
||||
// whereNot: { id: this.refs.id }
|
||||
whereNot: { id: this.ctx?.params.id },
|
||||
}),
|
||||
// rules.regex(/^[a-zA-Z0-9-_]+$/),
|
||||
//Must be alphanumeric with hyphens or underscores
|
||||
]),
|
||||
email: schema.string({}, [
|
||||
rules.email(),
|
||||
rules.unique({ table: 'accounts', column: 'email', whereNot: { id: this.ctx?.params.id } }),
|
||||
]),
|
||||
password: schema.string.optional([rules.confirmed(), rules.minLength(6)]),
|
||||
roles: schema.array.optional([rules.minLength(1)]).members(schema.number()), // define at least one role for the new user
|
||||
});
|
||||
}
|
||||
private createSchema() {
|
||||
return schema.create({
|
||||
login: schema.string({ trim: true }, [
|
||||
rules.minLength(3),
|
||||
rules.maxLength(50),
|
||||
rules.unique({
|
||||
table: 'accounts',
|
||||
column: 'login',
|
||||
// whereNot: { id: this.refs.id }
|
||||
whereNot: { id: this.ctx?.params.id },
|
||||
}),
|
||||
// rules.regex(/^[a-zA-Z0-9-_]+$/),
|
||||
//Must be alphanumeric with hyphens or underscores
|
||||
]),
|
||||
email: schema.string({}, [
|
||||
rules.email(),
|
||||
rules.unique({ table: 'accounts', column: 'email', whereNot: { id: this.ctx?.params.id } }),
|
||||
]),
|
||||
password: schema.string.optional([rules.confirmed(), rules.minLength(6)]),
|
||||
roles: schema.array.optional([rules.minLength(1)]).members(schema.number()), // define at least one role for the new user
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Define schema to validate the "shape", "type", "formatting" and "integrity" of data.
|
||||
*
|
||||
* For example:
|
||||
* 1. The username must be of data type string. But then also, it should
|
||||
* not contain special characters or numbers.
|
||||
* ```
|
||||
* schema.string({}, [ rules.alpha() ])
|
||||
* ```
|
||||
*
|
||||
* 2. The email must be of data type string, formatted as a valid
|
||||
* email. But also, not used by any other user.
|
||||
* ```
|
||||
* schema.string({}, [
|
||||
* rules.email(),
|
||||
* rules.unique({ table: 'users', column: 'email' }),
|
||||
* ])
|
||||
* ```
|
||||
*/
|
||||
/*
|
||||
* Define schema to validate the "shape", "type", "formatting" and "integrity" of data.
|
||||
*
|
||||
* For example:
|
||||
* 1. The username must be of data type string. But then also, it should
|
||||
* not contain special characters or numbers.
|
||||
* ```
|
||||
* schema.string({}, [ rules.alpha() ])
|
||||
* ```
|
||||
*
|
||||
* 2. The email must be of data type string, formatted as a valid
|
||||
* email. But also, not used by any other user.
|
||||
* ```
|
||||
* schema.string({}, [
|
||||
* rules.email(),
|
||||
* rules.unique({ table: 'users', column: 'email' }),
|
||||
* ])
|
||||
* ```
|
||||
*/
|
||||
|
||||
// public refs = schema.refs({
|
||||
// id: this.ctx.params.id
|
||||
// })
|
||||
// public refs = schema.refs({
|
||||
// id: this.ctx.params.id
|
||||
// })
|
||||
|
||||
// public schema = schema.create({
|
||||
// login: schema.string({ trim: true }, [
|
||||
// rules.minLength(3),
|
||||
// rules.maxLength(50),
|
||||
// rules.unique({
|
||||
// table: 'accounts',
|
||||
// column: 'login',
|
||||
// // whereNot: { id: this.refs.id }
|
||||
// whereNot: { id: this.ctx?.params.id },
|
||||
// }),
|
||||
// // rules.regex(/^[a-zA-Z0-9-_]+$/),
|
||||
// //Must be alphanumeric with hyphens or underscores
|
||||
// ]),
|
||||
// email: schema.string({}, [rules.email(), rules.unique({ table: 'accounts', column: 'email' })]),
|
||||
// password: schema.string.optional([rules.confirmed(), rules.minLength(6)]),
|
||||
// roles: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one role for the new user
|
||||
// });
|
||||
// public schema = schema.create({
|
||||
// login: schema.string({ trim: true }, [
|
||||
// rules.minLength(3),
|
||||
// rules.maxLength(50),
|
||||
// rules.unique({
|
||||
// table: 'accounts',
|
||||
// column: 'login',
|
||||
// // whereNot: { id: this.refs.id }
|
||||
// whereNot: { id: this.ctx?.params.id },
|
||||
// }),
|
||||
// // rules.regex(/^[a-zA-Z0-9-_]+$/),
|
||||
// //Must be alphanumeric with hyphens or underscores
|
||||
// ]),
|
||||
// email: schema.string({}, [rules.email(), rules.unique({ table: 'accounts', column: 'email' })]),
|
||||
// password: schema.string.optional([rules.confirmed(), rules.minLength(6)]),
|
||||
// roles: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one role for the new user
|
||||
// });
|
||||
|
||||
/**
|
||||
* Custom messages for validation failures. You can make use of dot notation `(.)`
|
||||
* for targeting nested fields and array expressions `(*)` for targeting all
|
||||
* children of an array. For example:
|
||||
*
|
||||
* {
|
||||
* 'profile.username.required': 'Username is required',
|
||||
* 'scores.*.number': 'Define scores as valid numbers'
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public messages: CustomMessages = {
|
||||
'minLength': '{{ field }} must be at least {{ options.minLength }} characters long',
|
||||
'maxLength': '{{ field }} must be less then {{ options.maxLength }} characters long',
|
||||
'required': '{{ field }} is required',
|
||||
'unique': '{{ field }} must be unique, and this value is already taken',
|
||||
'confirmed': '{{ field }} is not correct',
|
||||
'roles.minLength': 'at least {{ options.minLength }} role must be defined',
|
||||
'roles.*.number': 'Define roles as valid numbers',
|
||||
};
|
||||
/**
|
||||
* Custom messages for validation failures. You can make use of dot notation `(.)`
|
||||
* for targeting nested fields and array expressions `(*)` for targeting all
|
||||
* children of an array. For example:
|
||||
*
|
||||
* {
|
||||
* 'profile.username.required': 'Username is required',
|
||||
* 'scores.*.number': 'Define scores as valid numbers'
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public messages: CustomMessages = {
|
||||
'minLength': '{{ field }} must be at least {{ options.minLength }} characters long',
|
||||
'maxLength': '{{ field }} must be less then {{ options.maxLength }} characters long',
|
||||
'required': '{{ field }} is required',
|
||||
'unique': '{{ field }} must be unique, and this value is already taken',
|
||||
'confirmed': '{{ field }} is not correct',
|
||||
'roles.minLength': 'at least {{ options.minLength }} role must be defined',
|
||||
'roles.*.number': 'Define roles as valid numbers',
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue