diff --git a/app/controllers/projects_controller.ts b/app/controllers/projects_controller.ts new file mode 100644 index 0000000..21e20df --- /dev/null +++ b/app/controllers/projects_controller.ts @@ -0,0 +1,54 @@ +// 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'); + } +} diff --git a/app/validators/project.ts b/app/validators/project.ts new file mode 100644 index 0000000..bad6c7c --- /dev/null +++ b/app/validators/project.ts @@ -0,0 +1,28 @@ +// app/validators/project.ts +import vine from '@vinejs/vine'; + +export const createProjectValidator = vine.compile( + vine.object({ + label: vine.string().trim().minLength(1).maxLength(50), + name: vine + .string() + .trim() + .minLength(3) + .maxLength(255) + .regex(/^[a-z0-9-]+$/), + description: vine.string().trim().maxLength(255).minLength(5).optional(), + }), +); + +export const updateProjectValidator = vine.compile( + vine.object({ + // label is NOT included since it's readonly + name: vine + .string() + .trim() + .minLength(3) + .maxLength(255) + .regex(/^[a-z0-9-]+$/), + description: vine.string().trim().maxLength(255).minLength(5).optional(), + }), +); diff --git a/resources/js/Components/TablePersons.vue b/resources/js/Components/TablePersons.vue index 3dd6d3b..c119d8c 100644 --- a/resources/js/Components/TablePersons.vue +++ b/resources/js/Components/TablePersons.vue @@ -2,8 +2,8 @@ import { computed, ref, watch } from 'vue'; import { mdiTrashCan } from '@mdi/js'; import { mdiDragVariant, mdiChevronLeft, mdiChevronRight } from '@mdi/js'; +import { mdiAccount, mdiDomain } from '@mdi/js'; import BaseIcon from '@/Components/BaseIcon.vue'; -import BaseButtons from '@/Components/BaseButtons.vue'; import BaseButton from '@/Components/BaseButton.vue'; import { Person } from '@/Dataset'; import Draggable from 'vuedraggable'; @@ -21,25 +21,6 @@ interface Props { canReorder?: boolean; } -// const props = defineProps({ -// checkable: Boolean, -// persons: { -// type: Array, -// default: () => [], -// }, -// relation: { -// type: String, -// required: true, -// }, -// contributortypes: { -// type: Object, -// default: () => ({}), -// }, -// errors: { -// type: Object, -// default: () => ({}), -// }, -// }); const props = withDefaults(defineProps(), { checkable: false, persons: () => [], @@ -63,15 +44,18 @@ const perPage = ref(5); const currentPage = ref(0); const dragEnabled = ref(props.canReorder); +// Name type options +const nameTypeOptions = { + 'Personal': 'Personal', + 'Organizational': 'Org' +}; + // Computed properties const items = computed({ get() { return props.persons; }, - // setter set(value) { - // Note: we are using destructuring assignment syntax here. - props.persons.length = 0; props.persons.push(...value); }, @@ -122,19 +106,19 @@ const pagesList = computed(() => { return pages; }); -// const removeAuthor = (key: number) => { -// items.value.splice(key, 1); -// }; // Methods const removeAuthor = (index: number) => { const actualIndex = perPage.value * currentPage.value + index; const person = items.value[actualIndex]; - if (confirm(`Are you sure you want to remove ${person.first_name || ''} ${person.last_name || person.email}?`)) { + const displayName = person.name_type === 'Organizational' + ? person.last_name || person.email + : `${person.first_name || ''} ${person.last_name || person.email}`.trim(); + + if (confirm(`Are you sure you want to remove ${displayName}?`)) { items.value.splice(actualIndex, 1); emit('remove-person', actualIndex, person); - // Adjust current page if needed if (itemsPaginated.value.length === 0 && currentPage.value > 0) { currentPage.value--; } @@ -144,6 +128,12 @@ const removeAuthor = (index: number) => { const updatePerson = (index: number, field: keyof Person, value: any) => { const actualIndex = perPage.value * currentPage.value + index; const person = items.value[actualIndex]; + + // Handle name_type change - clear first_name if switching to Organizational + if (field === 'name_type' && value === 'Organizational') { + person.first_name = ''; + } + (person as any)[field] = value; emit('person-updated', actualIndex, person); }; @@ -170,7 +160,6 @@ const handleDragEnd = (evt: any) => { watch( () => props.persons.length, () => { - // Reset to first page if current page is out of bounds if (currentPage.value >= numPages.value && numPages.value > 0) { currentPage.value = numPages.value - 1; } @@ -189,18 +178,16 @@ const perPageOptions = [ @@ -481,7 +558,6 @@ const perPageOptions = [ @apply bg-white dark:bg-slate-900 rounded-lg shadow-sm; } -/* Improve table responsiveness */ @media (max-width: 768px) { table { font-size: 0.875rem; @@ -492,4 +568,4 @@ const perPageOptions = [ padding: 0.5rem !important; } } - + \ No newline at end of file diff --git a/resources/js/Layouts/LayoutAuthenticated.vue b/resources/js/Layouts/LayoutAuthenticated.vue index 15a117c..c077c7b 100644 --- a/resources/js/Layouts/LayoutAuthenticated.vue +++ b/resources/js/Layouts/LayoutAuthenticated.vue @@ -14,11 +14,11 @@ const props = defineProps({ showAsideMenu: { type: Boolean, default: true // Set default value to true + }, + hasProgressBar: { + type: Boolean, + default: false // New prop to indicate if progress bar is shown } - // user: { - // type: Object, - // default: () => ({}), - // } }); @@ -29,9 +29,18 @@ const props = defineProps({ }">
- + 'xl:pl-60': props.showAsideMenu==true, + 'pt-14': !props.hasProgressBar, + 'pt-24': props.hasProgressBar // Increased padding when progress bar is present (pt-14 + height of progress bar) + }" + class="min-h-screen w-screen transition-position lg:w-auto bg-gray-50 dark:bg-slate-800 dark:text-slate-100"> +