diff --git a/back/api/cron.ts b/back/api/cron.ts index 7b69b005..b2435464 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -28,7 +28,7 @@ export default (app: Router) => { celebrate({ body: Joi.object({ name: Joi.string().required(), - sorts: Joi.array().optional(), + sorts: Joi.array().optional().allow(null), filters: Joi.array().optional(), }), }), @@ -49,7 +49,7 @@ export default (app: Router) => { body: Joi.object({ name: Joi.string().required(), id: Joi.number().required(), - sorts: Joi.array().optional(), + sorts: Joi.array().optional().allow(null), filters: Joi.array().optional(), }), }), diff --git a/back/services/cron.ts b/back/services/cron.ts index 50744b3d..c6ea3e3f 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -115,18 +115,25 @@ export default class CronService { private formatViewQuery(query: any, viewQuery: any) { if (viewQuery.filters && viewQuery.filters.length > 0) { + if (!query[Op.and]) { + query[Op.and] = []; + } for (const col of viewQuery.filters) { const { property, value, operation } = col; + let q: any = {}; + let operate2 = null; let operate = null; switch (operation) { case 'Reg': operate = Op.like; + operate2 = Op.or; break; case 'NotReg': operate = Op.notLike; + operate2 = Op.and; break; case 'In': - query[Op.or] = [ + q[Op.or] = [ { [property]: value, }, @@ -136,7 +143,7 @@ export default class CronService { ]; break; case 'Nin': - query[Op.and] = [ + q[Op.and] = [ { [property]: { [Op.notIn]: value, @@ -150,20 +157,25 @@ export default class CronService { default: break; } - if (operate) { - query[property] = { - [Op.or]: [ + if (operate && operate2) { + q[property] = { + [operate2]: [ { [operate]: `%${value}%` }, { [operate]: `%${encodeURIComponent(value)}%` }, ], }; } + query[Op.and].push(q); } } } private formatSearchText(query: any, searchText: string | undefined) { if (searchText) { + if (!query[Op.and]) { + query[Op.and] = []; + } + let q: any = {}; const textArray = searchText.split(':'); switch (textArray[0]) { case 'name': @@ -171,7 +183,7 @@ export default class CronService { case 'schedule': case 'label': const column = textArray[0] === 'label' ? 'labels' : textArray[0]; - query[column] = { + q[column] = { [Op.or]: [ { [Op.like]: `%${textArray[1]}%` }, { [Op.like]: `%${encodeURIComponent(textArray[1])}%` }, @@ -185,7 +197,7 @@ export default class CronService { { [Op.like]: `%${encodeURIComponent(searchText)}%` }, ], }; - query[Op.or] = [ + q[Op.or] = [ { name: reg, }, @@ -201,6 +213,7 @@ export default class CronService { ]; break; } + query[Op.and].push(q); } } diff --git a/src/pages/crontab/viewManageModal.tsx b/src/pages/crontab/viewManageModal.tsx index 066fbda9..f4030f65 100644 --- a/src/pages/crontab/viewManageModal.tsx +++ b/src/pages/crontab/viewManageModal.tsx @@ -231,7 +231,10 @@ const ViewManageModal = ({ @@ -258,8 +261,8 @@ const ViewManageModal = ({ view={editedView} visible={isCreateViewModalVisible} handleCancel={(data) => { - cronViewChange(data); setIsCreateViewModalVisible(false); + cronViewChange(data); }} />