All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This update introduces a new route for formatting document templates, utilizing the `formatTemplateContent` function to beautify HTML and JavaScript within templates. The `formatDocumentTemplateRouteHandler` is added to handle formatting requests, and the content is processed to maintain EJS blocks. Additionally, a new `templateformatter.js` file is created, containing the logic for formatting templates, along with corresponding tests to ensure functionality. This enhancement improves the usability and presentation of document templates in the application.
121 lines
3.7 KiB
JavaScript
121 lines
3.7 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'name',
|
|
'tags',
|
|
'active',
|
|
'global',
|
|
'parent',
|
|
'parent._id',
|
|
'documentSize',
|
|
'documentSize._id',
|
|
'objectType',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = [
|
|
'name',
|
|
'parent',
|
|
'documentSize',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'active',
|
|
'global',
|
|
'objectType',
|
|
];
|
|
const propertiesAllowedFilters = ['documentSize', 'tags'];
|
|
import {
|
|
listDocumentTemplatesRouteHandler,
|
|
getDocumentTemplateRouteHandler,
|
|
editDocumentTemplateRouteHandler,
|
|
newDocumentTemplateRouteHandler,
|
|
deleteDocumentTemplateRouteHandler,
|
|
listDocumentTemplatesByPropertiesRouteHandler,
|
|
getDocumentTemplateStatsRouteHandler,
|
|
getDocumentTemplateHistoryRouteHandler,
|
|
getDocumentTemplatePropertyValuesRouteHandler,
|
|
searchDocumentTemplatesRouteHandler,
|
|
getDocumentTemplateNeighborsRouteHandler,
|
|
previewDocumentTemplateRouteHandler,
|
|
downloadDocumentTemplateRouteHandler,
|
|
formatDocumentTemplateRouteHandler,
|
|
} from '../../services/management/documenttemplates.js';
|
|
|
|
// list of document templates
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listDocumentTemplatesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order);
|
|
});
|
|
|
|
router.get('/properties', isAuthenticated, async (req, res) => {
|
|
let properties = convertPropertiesString(req.query.properties);
|
|
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
|
var masterFilter = {};
|
|
if (req.query.masterFilter) {
|
|
masterFilter = JSON.parse(req.query.masterFilter);
|
|
}
|
|
listDocumentTemplatesByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getDocumentTemplatePropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
|
|
router.get('/search', isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchDocumentTemplatesRouteHandler(req, res, search);
|
|
});
|
|
|
|
router.post('/', isAuthenticated, async (req, res) => {
|
|
newDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
router.post('/format', isAuthenticated, async (req, res) => {
|
|
formatDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
// get document template stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getDocumentTemplateStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get document template history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getDocumentTemplateHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getDocumentTemplateNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id);
|
|
});
|
|
|
|
router.post('/:id/preview', isAuthenticated, async (req, res) => {
|
|
previewDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
router.post('/:id/download', isAuthenticated, async (req, res) => {
|
|
downloadDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deleteDocumentTemplateRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|