- added views and controller coder for reviewer role - added program logic for publishing a dataset by editor - added reviewer menu - adapted routes.ts for additional routes
This commit is contained in:
parent
c70fa4a0d8
commit
18635f77b3
17 changed files with 1224 additions and 393 deletions
|
@ -9,6 +9,7 @@ import { readFileSync } from 'fs';
|
|||
import { transform } from 'saxon-js';
|
||||
import type { ModelQueryBuilderContract } from '@ioc:Adonis/Lucid/Orm';
|
||||
import { schema, CustomMessages } from '@ioc:Adonis/Core/Validator';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
// Create a new instance of the client
|
||||
const client = new Client({ node: 'http://localhost:9200' }); // replace with your OpenSearch endpoint
|
||||
|
@ -19,6 +20,7 @@ export default class DatasetsController {
|
|||
// 'required': '{{ field }} is required',
|
||||
// 'licenses.minLength': 'at least {{ options.minLength }} permission must be defined',
|
||||
'reviewer_id.required': 'reviewer_id must be defined',
|
||||
'publisher_name.required': 'publisher name must be defined',
|
||||
};
|
||||
|
||||
constructor() {
|
||||
|
@ -73,11 +75,11 @@ export default class DatasetsController {
|
|||
datasets: myDatasets.serialize(),
|
||||
filters: request.all(),
|
||||
can: {
|
||||
// create: await auth.user?.can(['dataset-submit']),
|
||||
receive: await auth.user?.can(['dataset-receive']),
|
||||
approve: await auth.user?.can(['dataset-approve']),
|
||||
edit: await auth.user?.can(['dataset-editor-edit']),
|
||||
edit: await auth.user?.can(['dataset-editor-update']),
|
||||
delete: await auth.user?.can(['dataset-editor-delete']),
|
||||
publish: await auth.user?.can(['dataset-publish']),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -211,6 +213,70 @@ export default class DatasetsController {
|
|||
}
|
||||
}
|
||||
|
||||
public async publish({ request, inertia, response }) {
|
||||
const id = request.param('id');
|
||||
|
||||
const dataset = await Dataset.query()
|
||||
.where('id', id)
|
||||
.preload('titles')
|
||||
.preload('authors')
|
||||
// .preload('persons', (builder) => {
|
||||
// builder.wherePivot('role', 'author')
|
||||
// })
|
||||
.firstOrFail();
|
||||
|
||||
const validStates = ['reviewed'];
|
||||
if (!validStates.includes(dataset.server_state)) {
|
||||
// session.flash('errors', 'Invalid server state!');
|
||||
return response
|
||||
.flash(
|
||||
'warning',
|
||||
`Invalid server state. Dataset with id ${id} cannot be published. Datset has server state ${dataset.server_state}.`,
|
||||
)
|
||||
.redirect()
|
||||
.back();
|
||||
}
|
||||
|
||||
return inertia.render('Editor/Dataset/Publish', {
|
||||
dataset,
|
||||
});
|
||||
}
|
||||
|
||||
public async publishUpdate({ request, response }) {
|
||||
const publishDatasetSchema = schema.create({
|
||||
publisher_name: schema.string({ trim: true }),
|
||||
});
|
||||
try {
|
||||
await request.validate({ schema: publishDatasetSchema, messages: this.messages });
|
||||
} catch (error) {
|
||||
// return response.badRequest(error.messages);
|
||||
throw error;
|
||||
}
|
||||
const id = request.param('id');
|
||||
const dataset = await Dataset.findOrFail(id);
|
||||
|
||||
// let test = await Dataset.getMax('publish_id');
|
||||
// const maxPublishId = await Database.from('documents').max('publish_id as max_publish_id').first();
|
||||
// const max = maxPublishId.max_publish_id;
|
||||
const max = await Dataset.getMax('publish_id');
|
||||
let publish_id = 0;
|
||||
if (max != null) {
|
||||
publish_id = max + 1;
|
||||
} else {
|
||||
publish_id = publish_id + 1;
|
||||
}
|
||||
dataset.publish_id = publish_id;
|
||||
dataset.server_state = 'published';
|
||||
dataset.server_date_published = DateTime.now();
|
||||
|
||||
const publisherName = request.input('publisher_name', 'Tethys');
|
||||
dataset.publisher_name = publisherName;
|
||||
|
||||
if (await dataset.save()) {
|
||||
return response.toRoute('editor.dataset.list').flash('message', 'You have successfully published the dataset!');
|
||||
}
|
||||
}
|
||||
|
||||
public async create({}: HttpContextContract) {}
|
||||
|
||||
public async store({}: HttpContextContract) {}
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue