|
@@ -13,6 +13,8 @@ module.exports = function(crowi, app) {
|
|
|
, ApiResponse = require('../util/apiResponse')
|
|
, ApiResponse = require('../util/apiResponse')
|
|
|
, interceptorManager = crowi.getInterceptorManager()
|
|
, interceptorManager = crowi.getInterceptorManager()
|
|
|
, pagePathUtil = require('../util/pagePathUtil')
|
|
, pagePathUtil = require('../util/pagePathUtil')
|
|
|
|
|
+ , swig = require('swig-templates')
|
|
|
|
|
+ , getToday = require('../util/getToday')
|
|
|
|
|
|
|
|
, actions = {};
|
|
, actions = {};
|
|
|
|
|
|
|
@@ -252,14 +254,11 @@ module.exports = function(crowi, app) {
|
|
|
tree: [],
|
|
tree: [],
|
|
|
pageRelatedGroup: null,
|
|
pageRelatedGroup: null,
|
|
|
template: null,
|
|
template: null,
|
|
|
- localTemplateExists: false,
|
|
|
|
|
- globalTemplateExists: false,
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
var pageTeamplate = 'customlayout-selector/page';
|
|
var pageTeamplate = 'customlayout-selector/page';
|
|
|
|
|
|
|
|
var isRedirect = false;
|
|
var isRedirect = false;
|
|
|
- var originalPath = path;
|
|
|
|
|
Page.findPage(path, req.user, req.query.revision)
|
|
Page.findPage(path, req.user, req.query.revision)
|
|
|
.then(function(page) {
|
|
.then(function(page) {
|
|
|
debug('Page found', page._id, page.path);
|
|
debug('Page found', page._id, page.path);
|
|
@@ -283,11 +282,7 @@ module.exports = function(crowi, app) {
|
|
|
renderVars.tree = tree;
|
|
renderVars.tree = tree;
|
|
|
})
|
|
})
|
|
|
.then(function() {
|
|
.then(function() {
|
|
|
- return Page.checkIfTemplatesExist(originalPath);
|
|
|
|
|
- })
|
|
|
|
|
- .then(function(templateInfo) {
|
|
|
|
|
- renderVars.localTemplateExists = templateInfo.localTemplateExists;
|
|
|
|
|
- renderVars.globalTemplateExists = templateInfo.globalTemplateExists;
|
|
|
|
|
|
|
+ return Page.checkIfTemplatesExist(path);
|
|
|
})
|
|
})
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
return PageGroupRelation.findByPage(renderVars.page);
|
|
return PageGroupRelation.findByPage(renderVars.page);
|
|
@@ -333,8 +328,12 @@ module.exports = function(crowi, app) {
|
|
|
.catch(function(err) {
|
|
.catch(function(err) {
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
|
|
|
|
|
- return Page.findTemplate(originalPath)
|
|
|
|
|
|
|
+ return Page.findTemplate(path)
|
|
|
.then(template => {
|
|
.then(template => {
|
|
|
|
|
+ if (template) {
|
|
|
|
|
+ template = replacePlaceholders(template, req);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
renderVars.template = template;
|
|
renderVars.template = template;
|
|
|
});
|
|
});
|
|
|
})
|
|
})
|
|
@@ -371,6 +370,17 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const replacePlaceholders = (template, req) => {
|
|
|
|
|
+ const definitions = {
|
|
|
|
|
+ pagepath: getPathFromRequest(req),
|
|
|
|
|
+ username: req.user.name,
|
|
|
|
|
+ today: getToday(),
|
|
|
|
|
+ };
|
|
|
|
|
+ const compiledTemplate = swig.compile(template);
|
|
|
|
|
+
|
|
|
|
|
+ return compiledTemplate(definitions);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
|
var limit = 50;
|
|
var limit = 50;
|
|
@@ -443,16 +453,22 @@ module.exports = function(crowi, app) {
|
|
|
function renderPage(pageData, req, res) {
|
|
function renderPage(pageData, req, res) {
|
|
|
// create page
|
|
// create page
|
|
|
if (!pageData) {
|
|
if (!pageData) {
|
|
|
- Page.findTemplate(getPathFromRequest(req))
|
|
|
|
|
- .then((template) => {
|
|
|
|
|
- return res.render('customlayout-selector/not_found', {
|
|
|
|
|
- author: {},
|
|
|
|
|
- page: false,
|
|
|
|
|
- template: template,
|
|
|
|
|
|
|
+ const path = getPathFromRequest(req);
|
|
|
|
|
+ return Page.findTemplate(path)
|
|
|
|
|
+ .then(template => {
|
|
|
|
|
+ if (template) {
|
|
|
|
|
+ template = replacePlaceholders(template, req);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return res.render('customlayout-selector/not_found', {
|
|
|
|
|
+ author: {},
|
|
|
|
|
+ page: false,
|
|
|
|
|
+ template,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
if (pageData.redirectTo) {
|
|
if (pageData.redirectTo) {
|
|
|
return res.redirect(encodeURI(pageData.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(pageData.path)));
|
|
return res.redirect(encodeURI(pageData.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(pageData.path)));
|
|
|
}
|
|
}
|
|
@@ -462,8 +478,6 @@ module.exports = function(crowi, app) {
|
|
|
page: pageData,
|
|
page: pageData,
|
|
|
revision: pageData.revision || {},
|
|
revision: pageData.revision || {},
|
|
|
author: pageData.revision.author || false,
|
|
author: pageData.revision.author || false,
|
|
|
- localTemplateExists: false,
|
|
|
|
|
- globalTemplateExists: false,
|
|
|
|
|
};
|
|
};
|
|
|
var userPage = isUserPage(pageData.path);
|
|
var userPage = isUserPage(pageData.path);
|
|
|
var userData = null;
|
|
var userData = null;
|
|
@@ -508,12 +522,6 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
}
|
|
|
}).then(function() {
|
|
}).then(function() {
|
|
|
return interceptorManager.process('beforeRenderPage', req, res, renderVars);
|
|
return interceptorManager.process('beforeRenderPage', req, res, renderVars);
|
|
|
- }).then(function() {
|
|
|
|
|
- return Page.checkIfTemplatesExist(pageData.path)
|
|
|
|
|
- .then(function(templateInfo) {
|
|
|
|
|
- renderVars.localTemplateExists = templateInfo.localTemplateExists;
|
|
|
|
|
- renderVars.globalTemplateExists = templateInfo.globalTemplateExists;
|
|
|
|
|
- });
|
|
|
|
|
}).then(function() {
|
|
}).then(function() {
|
|
|
var defaultPageTeamplate = 'customlayout-selector/page';
|
|
var defaultPageTeamplate = 'customlayout-selector/page';
|
|
|
if (userData) {
|
|
if (userData) {
|
|
@@ -669,13 +677,6 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return res.redirect(redirectPath);
|
|
|
|
|
- }).catch(function(err) {
|
|
|
|
|
- debug('Page create or edit error.', err);
|
|
|
|
|
- if (pageData && !req.form.isValid) {
|
|
|
|
|
- return renderPage(pageData, req, res);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
return res.redirect(redirectPath);
|
|
return res.redirect(redirectPath);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
@@ -1105,9 +1106,10 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
|
|
Page.findPageByPath(newPagePath)
|
|
Page.findPageByPath(newPagePath)
|
|
|
.then(function(page) {
|
|
.then(function(page) {
|
|
|
- // if page found, cannot cannot rename to that path
|
|
|
|
|
- return res.json(ApiResponse.error(`このページ名は作成できません (${newPagePath})。ページが存在します。`));
|
|
|
|
|
- }).catch(function(err) {
|
|
|
|
|
|
|
+ if (page != null) {
|
|
|
|
|
+ // if page found, cannot cannot rename to that path
|
|
|
|
|
+ return res.json(ApiResponse.error(`このページ名は作成できません (${newPagePath})。ページが存在します。`));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
Page.findPageById(pageId)
|
|
Page.findPageById(pageId)
|
|
|
.then(function(pageData) {
|
|
.then(function(pageData) {
|
|
@@ -1123,12 +1125,14 @@ module.exports = function(crowi, app) {
|
|
|
return Page.rename(pageData, newPagePath, req.user, options);
|
|
return Page.rename(pageData, newPagePath, req.user, options);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }).then(function() {
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function() {
|
|
|
var result = {};
|
|
var result = {};
|
|
|
result.page = page;
|
|
result.page = page;
|
|
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|
|
return res.json(ApiResponse.success(result));
|
|
|
- }).catch(function(err) {
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(function(err) {
|
|
|
return res.json(ApiResponse.error('Failed to update page.'));
|
|
return res.json(ApiResponse.error('Failed to update page.'));
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -1185,5 +1189,23 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @api {get} /pages.templates Check if templates exist for page
|
|
|
|
|
+ * @apiName FindTemplates
|
|
|
|
|
+ * @apiGroup Page
|
|
|
|
|
+ *
|
|
|
|
|
+ * @apiParam {String} path
|
|
|
|
|
+ */
|
|
|
|
|
+ api.templates = function(req, res) {
|
|
|
|
|
+ const pagePath = req.query.path;
|
|
|
|
|
+ const templateFinder = Page.checkIfTemplatesExist(pagePath);
|
|
|
|
|
+
|
|
|
|
|
+ templateFinder.then(function(templateInfo) {
|
|
|
|
|
+ return res.json(ApiResponse.success(templateInfo));
|
|
|
|
|
+ }).catch(function(err) {
|
|
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return actions;
|
|
return actions;
|
|
|
};
|
|
};
|