|
@@ -4,6 +4,8 @@ module.exports = function(crowi, app) {
|
|
|
var debug = require('debug')('crowi:routes:page')
|
|
var debug = require('debug')('crowi:routes:page')
|
|
|
, Page = crowi.model('Page')
|
|
, Page = crowi.model('Page')
|
|
|
, User = crowi.model('User')
|
|
, User = crowi.model('User')
|
|
|
|
|
+ , Config = crowi.model('Config')
|
|
|
|
|
+ , config = crowi.getConfig()
|
|
|
, Revision = crowi.model('Revision')
|
|
, Revision = crowi.model('Revision')
|
|
|
, Bookmark = crowi.model('Bookmark')
|
|
, Bookmark = crowi.model('Bookmark')
|
|
|
, ApiResponse = require('../util/apiResponse')
|
|
, ApiResponse = require('../util/apiResponse')
|
|
@@ -61,12 +63,39 @@ module.exports = function(crowi, app) {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // routing
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * switch action by behaviorType
|
|
|
|
|
+ */
|
|
|
|
|
+ actions.pageListShowWrapper = function(req, res) {
|
|
|
|
|
+ const behaviorType = Config.behaviorType(config);
|
|
|
|
|
+
|
|
|
|
|
+ if ('crowi-plus' === behaviorType) {
|
|
|
|
|
+ return actions.pageListShowForCrowiPlus(req, res);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return actions.pageListShow(req, res);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * switch action by behaviorType
|
|
|
|
|
+ */
|
|
|
|
|
+ actions.pageShowWrapper = function(req, res) {
|
|
|
|
|
+ const behaviorType = Config.behaviorType(config);
|
|
|
|
|
+
|
|
|
|
|
+ if ('crowi-plus' === behaviorType) {
|
|
|
|
|
+ return actions.pageShowForCrowiPlus(req, res);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return actions.pageShow(req, res);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
actions.pageListShow = function(req, res) {
|
|
actions.pageListShow = function(req, res) {
|
|
|
var path = getPathFromRequest(req);
|
|
var path = getPathFromRequest(req);
|
|
|
var limit = 50;
|
|
var limit = 50;
|
|
|
var offset = parseInt(req.query.offset) || 0;
|
|
var offset = parseInt(req.query.offset) || 0;
|
|
|
var SEENER_THRESHOLD = 10;
|
|
var SEENER_THRESHOLD = 10;
|
|
|
|
|
+ // add slash to the last
|
|
|
path = path + (path == '/' ? '' : '/');
|
|
path = path + (path == '/' ? '' : '/');
|
|
|
|
|
|
|
|
debug('Page list show', path);
|
|
debug('Page list show', path);
|
|
@@ -119,6 +148,122 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ actions.pageListShowForCrowiPlus = function(req, res) {
|
|
|
|
|
+ var path = getPathFromRequest(req);
|
|
|
|
|
+ // omit the slash of the last
|
|
|
|
|
+ path = path.replace((/\/$/), '');
|
|
|
|
|
+ // redirect
|
|
|
|
|
+ return res.redirect(path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ actions.pageShowForCrowiPlus = function(req, res) {
|
|
|
|
|
+ var path = getPathFromRequest(req);
|
|
|
|
|
+
|
|
|
|
|
+ var limit = 50;
|
|
|
|
|
+ var offset = parseInt(req.query.offset) || 0;
|
|
|
|
|
+ var SEENER_THRESHOLD = 10;
|
|
|
|
|
+
|
|
|
|
|
+ // index page
|
|
|
|
|
+ var pagerOptions = {
|
|
|
|
|
+ offset: offset,
|
|
|
|
|
+ limit : limit
|
|
|
|
|
+ };
|
|
|
|
|
+ var queryOptions = {
|
|
|
|
|
+ offset: offset,
|
|
|
|
|
+ limit : limit + 1
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var renderVars = {
|
|
|
|
|
+ path: path,
|
|
|
|
|
+ page: null,
|
|
|
|
|
+ revision: {},
|
|
|
|
|
+ author: false,
|
|
|
|
|
+ pages: [],
|
|
|
|
|
+ tree: [],
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var pageTeamplate = 'customlayout-selector/page';
|
|
|
|
|
+
|
|
|
|
|
+ Page.findPage(path, req.user, req.query.revision)
|
|
|
|
|
+ .then(function(page) {
|
|
|
|
|
+ renderVars.page = page;
|
|
|
|
|
+
|
|
|
|
|
+ if (page) {
|
|
|
|
|
+ renderVars.path = page.path;
|
|
|
|
|
+ renderVars.revision = page.revision;
|
|
|
|
|
+ renderVars.author = page.revision.author;
|
|
|
|
|
+
|
|
|
|
|
+ return Revision.findRevisionList(page.path, {})
|
|
|
|
|
+ .then(function(tree) {
|
|
|
|
|
+ renderVars.tree = tree;
|
|
|
|
|
+ return Promise.resolve();
|
|
|
|
|
+ }).then(function() {
|
|
|
|
|
+ var userPage = isUserPage(page.path);
|
|
|
|
|
+ var userData = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (userPage) {
|
|
|
|
|
+ // change template
|
|
|
|
|
+ pageTeamplate = 'customlayout-selector/user_page';
|
|
|
|
|
+
|
|
|
|
|
+ return User.findUserByUsername(User.getUsernameByPath(page.path))
|
|
|
|
|
+ .then(function(data) {
|
|
|
|
|
+ if (data === null) {
|
|
|
|
|
+ throw new Error('The user not found.');
|
|
|
|
|
+ }
|
|
|
|
|
+ userData = data;
|
|
|
|
|
+ renderVars.pageUser = userData;
|
|
|
|
|
+
|
|
|
|
|
+ return Bookmark.findByUser(userData, {limit: 10, populatePage: true, requestUser: req.user});
|
|
|
|
|
+ }).then(function(bookmarkList) {
|
|
|
|
|
+ renderVars.bookmarkList = bookmarkList;
|
|
|
|
|
+
|
|
|
|
|
+ return Page.findListByCreator(userData, {limit: 10}, req.user);
|
|
|
|
|
+ }).then(function(createdList) {
|
|
|
|
|
+ renderVars.createdList = createdList;
|
|
|
|
|
+ return Promise.resolve();
|
|
|
|
|
+ }).catch(function(err) {
|
|
|
|
|
+ debug('Error on finding user related entities', err);
|
|
|
|
|
+ // pass
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return Promise.resolve();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return Promise.resolve();
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(function(err) {
|
|
|
|
|
+ // page not exists
|
|
|
|
|
+ // change template
|
|
|
|
|
+ pageTeamplate = 'crowi-plus/new_page';
|
|
|
|
|
+ }).then(function() {
|
|
|
|
|
+ return Page.findListByStartWith(path, req.user, queryOptions)
|
|
|
|
|
+ .then(function(pageList) {
|
|
|
|
|
+ if (pageList.length > limit) {
|
|
|
|
|
+ pageList.pop();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ pagerOptions.length = pageList.length;
|
|
|
|
|
+
|
|
|
|
|
+ renderVars.viewConfig = {
|
|
|
|
|
+ seener_threshold: SEENER_THRESHOLD,
|
|
|
|
|
+ };
|
|
|
|
|
+ renderVars.pager = generatePager(pagerOptions);
|
|
|
|
|
+ renderVars.pages = pageList;
|
|
|
|
|
+
|
|
|
|
|
+ return Promise.resolve();
|
|
|
|
|
+ });
|
|
|
|
|
+ }).then(function() {
|
|
|
|
|
+ return interceptorManager.process('beforeRenderPage', req, res, renderVars);
|
|
|
|
|
+ }).then(function() {
|
|
|
|
|
+ res.render(req.query.presentation ? 'page_presentation' : pageTeamplate, renderVars);
|
|
|
|
|
+ }).catch(function(err) {
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ debug('Error on rendering pageListShowForCrowiPlus', err);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
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;
|