Some checks failed
build.yaml / feat: Enhance Dataset Edit Page with Unsaved Changes Indicator and Improved Structure (push) Failing after 0s
- Added a progress indicator for unsaved changes at the top of the dataset edit page. - Enhanced the title section with a dataset status badge and improved layout. - Introduced collapsible sections for better organization of form fields. - Improved notifications for success/error messages. - Refactored form fields into distinct sections: Basic Information, Licenses, Titles, Descriptions, Creators & Contributors, Additional Metadata, Geographic Coverage, and Files. - Enhanced loading spinner with a more visually appealing overlay. - Added new project validation logic in the backend with create and update validators.
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
// app/controllers/projects_controller.ts
|
|
import Project from '#models/project';
|
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
import { createProjectValidator, updateProjectValidator } from '#validators/project';
|
|
|
|
export default class ProjectsController {
|
|
// GET /settings/projects
|
|
public async index({ inertia, auth }: HttpContext) {
|
|
const projects = await Project.all();
|
|
// return inertia.render('Admin/Project/Index', { projects });
|
|
return inertia.render('Admin/Project/Index', {
|
|
projects: projects,
|
|
can: {
|
|
edit: await auth.user?.can(['settings']),
|
|
create: await auth.user?.can(['settings']),
|
|
},
|
|
});
|
|
}
|
|
|
|
// GET /settings/projects/create
|
|
public async create({ inertia }: HttpContext) {
|
|
return inertia.render('Admin/Project/Create');
|
|
}
|
|
|
|
// POST /settings/projects
|
|
public async store({ request, response, session }: HttpContext) {
|
|
// Validate the request data
|
|
const data = await request.validateUsing(createProjectValidator);
|
|
|
|
await Project.create(data);
|
|
|
|
session.flash('success', 'Project created successfully');
|
|
return response.redirect().toRoute('settings.project.index');
|
|
}
|
|
|
|
// GET /settings/projects/:id/edit
|
|
public async edit({ params, inertia }: HttpContext) {
|
|
const project = await Project.findOrFail(params.id);
|
|
return inertia.render('Admin/Project/Edit', { project });
|
|
}
|
|
|
|
// PUT /settings/projects/:id
|
|
public async update({ params, request, response, session }: HttpContext) {
|
|
const project = await Project.findOrFail(params.id);
|
|
|
|
// Validate the request data
|
|
const data = await request.validateUsing(updateProjectValidator);
|
|
|
|
await project.merge(data).save();
|
|
|
|
session.flash('success', 'Project updated successfully');
|
|
return response.redirect().toRoute('settings.project.index');
|
|
}
|
|
}
|