Skip to content

Commit f0aa023

Browse files
committed
Add project management actions for QF Rounds
Implemented new functionalities to add and remove projects from the active QF Round. Introduced `addProjectsToQfRound` and `addSingleProjectToQfRound` methods to handle bulk and single project actions, respectively. Enhanced the projects tab with new action handlers for adding and removing projects, ensuring proper accessibility checks for admin users. Updated the project view refresh logic to maintain data consistency.
1 parent 850b62f commit f0aa023

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

src/server/adminJs/tabs/projectsTab.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ import {
5050
makeFormVerified,
5151
} from '../../../repositories/projectVerificationRepository';
5252
import { FeaturedUpdate } from '../../../entities/featuredUpdate';
53+
import { findActiveQfRound } from '../../../repositories/qfRoundRepository';
5354
import { User } from '../../../entities/user';
55+
import { refreshProjectEstimatedMatchingView } from '../../../services/projectViewsService';
5456
import { extractAdminJsReferrerUrlParams } from '../adminJs';
57+
import { relateManyProjectsToQfRound } from '../../../repositories/qfRoundRepository2';
5558
import { Category } from '../../../entities/category';
5659
import { getRedirectUrl } from '../adminJsUtils';
5760
import { ProjectVerificationForm } from '../../../entities/projectVerificationForm';
@@ -497,13 +500,77 @@ export const exportEmails = async (
497500
};
498501
};
499502

503+
export const addProjectsToQfRound = async (
504+
context: AdminJsContextInterface,
505+
request: AdminJsRequestInterface,
506+
add: boolean = true,
507+
) => {
508+
const { records } = context;
509+
let message = messages.PROJECTS_RELATED_TO_ACTIVE_QF_ROUND_SUCCESSFULLY;
510+
const projectIds = request?.query?.recordIds
511+
?.split(',')
512+
?.map(strId => Number(strId)) as number[];
513+
const qfRound = await findActiveQfRound(true);
514+
if (qfRound) {
515+
await relateManyProjectsToQfRound({
516+
projectIds,
517+
qfRound,
518+
add,
519+
});
520+
await refreshProjectEstimatedMatchingView();
521+
} else {
522+
message = messages.THERE_IS_NOT_ANY_ACTIVE_QF_ROUND;
523+
}
524+
return {
525+
redirectUrl: '/admin/resources/Project',
526+
records: records.map(record => {
527+
record.toJSON(context.currentAdmin);
528+
}),
529+
notice: {
530+
message,
531+
type: 'success',
532+
},
533+
};
534+
};
535+
500536
export const extractCategoryIds = (payload: any) => {
501537
if (!payload) return;
502538
return Object.keys(payload)
503539
.filter(key => key.startsWith('categoryIds.'))
504540
.map(key => payload[key]);
505541
};
506542

543+
export const addSingleProjectToQfRound = async (
544+
context: AdminJsContextInterface,
545+
request: AdminJsRequestInterface,
546+
add: boolean = true,
547+
) => {
548+
const redirectUrl = getRedirectUrl(request, 'Project');
549+
const { record, currentAdmin } = context;
550+
let message = messages.PROJECTS_RELATED_TO_ACTIVE_QF_ROUND_SUCCESSFULLY;
551+
const projectId = Number(request?.params?.recordId);
552+
const qfRound = await findActiveQfRound(true);
553+
if (qfRound) {
554+
await relateManyProjectsToQfRound({
555+
projectIds: [projectId],
556+
qfRound,
557+
add,
558+
});
559+
560+
await refreshProjectEstimatedMatchingView();
561+
} else {
562+
message = messages.THERE_IS_NOT_ANY_ACTIVE_QF_ROUND;
563+
}
564+
return {
565+
redirectUrl: redirectUrl,
566+
record: record.toJSON(currentAdmin),
567+
notice: {
568+
message,
569+
type: 'success',
570+
},
571+
};
572+
};
573+
507574
export const fillSocialProfileAndQfRounds: After<
508575
ActionResponse
509576
> = async response => {
@@ -1403,6 +1470,64 @@ export const projectsTab = {
14031470
component: false,
14041471
},
14051472

1473+
addProjectToQfRound: {
1474+
// https://docs.adminjs.co/basics/action#record-type-actions
1475+
actionType: 'record',
1476+
isVisible: true,
1477+
isAccessible: ({ currentAdmin }) =>
1478+
canAccessProjectAction(
1479+
{ currentAdmin },
1480+
ResourceActions.ADD_PROJECT_TO_QF_ROUND,
1481+
),
1482+
guard: 'Do you want to add this project to current active qf round?',
1483+
handler: async (request, response, context) => {
1484+
return addSingleProjectToQfRound(context, request, true);
1485+
},
1486+
component: false,
1487+
},
1488+
removeProjectFromQfRound: {
1489+
// https://docs.adminjs.co/basics/action#record-type-actions
1490+
actionType: 'record',
1491+
isVisible: true,
1492+
isAccessible: ({ currentAdmin }) =>
1493+
canAccessProjectAction(
1494+
{ currentAdmin },
1495+
ResourceActions.REMOVE_PROJECT_FROM_QF_ROUND,
1496+
),
1497+
guard:
1498+
'Do you want to remove this project from current active qf round?',
1499+
handler: async (request, response, context) => {
1500+
return addSingleProjectToQfRound(context, request, false);
1501+
},
1502+
component: false,
1503+
},
1504+
1505+
addToQfRound: {
1506+
actionType: 'bulk',
1507+
isVisible: true,
1508+
isAccessible: ({ currentAdmin }) =>
1509+
canAccessProjectAction(
1510+
{ currentAdmin },
1511+
ResourceActions.ADD_PROJECT_TO_QF_ROUND,
1512+
),
1513+
handler: async (request, response, context) => {
1514+
return addProjectsToQfRound(context, request, true);
1515+
},
1516+
component: false,
1517+
},
1518+
removeFromQfRound: {
1519+
actionType: 'bulk',
1520+
isVisible: true,
1521+
isAccessible: ({ currentAdmin }) =>
1522+
canAccessProjectAction(
1523+
{ currentAdmin },
1524+
ResourceActions.REMOVE_PROJECT_FROM_QF_ROUND,
1525+
),
1526+
handler: async (request, response, context) => {
1527+
return addProjectsToQfRound(context, request, false);
1528+
},
1529+
component: false,
1530+
},
14061531
exportEmails: {
14071532
actionType: 'bulk',
14081533
isVisible: true,

0 commit comments

Comments
 (0)