|
|
@@ -11,6 +11,7 @@ module.exports = function(crowi, app) {
|
|
|
, UserGroupRelation = crowi.model('UserGroupRelation')
|
|
|
, ApiResponse = require('../util/apiResponse')
|
|
|
, interceptorManager = crowi.getInterceptorManager()
|
|
|
+ , pagePathUtil = require('../util/pagePathUtil')
|
|
|
|
|
|
, actions = {};
|
|
|
|
|
|
@@ -64,24 +65,6 @@ module.exports = function(crowi, app) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- function encodePagesPath(pages) {
|
|
|
- pages.forEach(function(page) {
|
|
|
- if (!page.path) {
|
|
|
- return;
|
|
|
- }
|
|
|
- page.path = encodePagePath(page.path);
|
|
|
- });
|
|
|
- return pages;
|
|
|
- }
|
|
|
-
|
|
|
- function encodePagePath(path) {
|
|
|
- var paths = path.split('/');
|
|
|
- paths.forEach(function(item, index) {
|
|
|
- paths[index] = encodeURIComponent(item);
|
|
|
- });
|
|
|
- return paths.join('/');
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* switch action by behaviorType
|
|
|
*/
|
|
|
@@ -211,7 +194,7 @@ module.exports = function(crowi, app) {
|
|
|
seener_threshold: SEENER_THRESHOLD,
|
|
|
};
|
|
|
renderVars.pager = generatePager(pagerOptions);
|
|
|
- renderVars.pages = encodePagesPath(pageList);
|
|
|
+ renderVars.pages = pagePathUtil.encodePagesPath(pageList);
|
|
|
res.render('customlayout-selector/page_list', renderVars);
|
|
|
}).catch(function(err) {
|
|
|
debug('Error on rendering pageListShow', err);
|
|
|
@@ -266,7 +249,7 @@ module.exports = function(crowi, app) {
|
|
|
if (page.redirectTo) {
|
|
|
debug(`Redirect to '${page.redirectTo}'`);
|
|
|
isRedirect = true;
|
|
|
- return res.redirect(encodeURI(page.redirectTo + '?redirectFrom=' + encodePagePath(page.path)));
|
|
|
+ return res.redirect(encodeURI(page.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(page.path)));
|
|
|
}
|
|
|
|
|
|
renderVars.page = page;
|
|
|
@@ -338,7 +321,7 @@ module.exports = function(crowi, app) {
|
|
|
seener_threshold: SEENER_THRESHOLD,
|
|
|
};
|
|
|
renderVars.pager = generatePager(pagerOptions);
|
|
|
- renderVars.pages = encodePagesPath(pageList);
|
|
|
+ renderVars.pages = pagePathUtil.encodePagesPath(pageList);
|
|
|
|
|
|
return Promise.resolve();
|
|
|
})
|
|
|
@@ -397,7 +380,7 @@ module.exports = function(crowi, app) {
|
|
|
pagerOptions.length = pageList.length;
|
|
|
|
|
|
renderVars.pager = generatePager(pagerOptions);
|
|
|
- renderVars.pages = encodePagesPath(pageList);
|
|
|
+ renderVars.pages = pagePathUtil.encodePagesPath(pageList);
|
|
|
res.render('customlayout-selector/page_list', renderVars);
|
|
|
}).catch(function(err) {
|
|
|
debug('Error on rendering deletedPageListShow', err);
|
|
|
@@ -426,7 +409,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
res.render('customlayout-selector/page_list', {
|
|
|
path: '/',
|
|
|
- pages: encodePagesPath(pages),
|
|
|
+ pages: pagePathUtil.encodePagesPath(pages),
|
|
|
pager: generatePager({offset: 0, limit: 50})
|
|
|
});
|
|
|
}).catch(function(err) {
|
|
|
@@ -444,7 +427,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
if (pageData.redirectTo) {
|
|
|
- return res.redirect(encodeURI(pageData.redirectTo + '?redirectFrom=' + encodePagePath(pageData.path)));
|
|
|
+ return res.redirect(encodeURI(pageData.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(pageData.path)));
|
|
|
}
|
|
|
|
|
|
var renderVars = {
|
|
|
@@ -537,7 +520,7 @@ module.exports = function(crowi, app) {
|
|
|
return ;
|
|
|
}
|
|
|
if (req.query.revision) {
|
|
|
- return res.redirect(encodePagePath(path));
|
|
|
+ return res.redirect(pagePathUtil.encodePagePath(path));
|
|
|
}
|
|
|
|
|
|
if (isMarkdown) {
|
|
|
@@ -547,13 +530,13 @@ module.exports = function(crowi, app) {
|
|
|
Page.hasPortalPage(path + '/', req.user)
|
|
|
.then(function(page) {
|
|
|
if (page) {
|
|
|
- return res.redirect(encodePagePath(path) + '/');
|
|
|
+ return res.redirect(pagePathUtil.encodePagePath(path) + '/');
|
|
|
} else {
|
|
|
|
|
|
var fixed = Page.fixToCreatableName(path)
|
|
|
if (fixed !== path) {
|
|
|
debug('fixed page name', fixed)
|
|
|
- res.redirect(encodePagePath(fixed));
|
|
|
+ res.redirect(pagePathUtil.encodePagePath(fixed));
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
@@ -586,7 +569,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
debug('notify: ', notify);
|
|
|
|
|
|
- var redirectPath = encodePagePath(path);
|
|
|
+ var redirectPath = pagePathUtil.encodePagePath(path);
|
|
|
var pageData = {};
|
|
|
var updateOrCreate;
|
|
|
var previousRevision = false;
|
|
|
@@ -675,7 +658,7 @@ module.exports = function(crowi, app) {
|
|
|
return Promise.resolve(pageData);
|
|
|
}).then(function(page) {
|
|
|
|
|
|
- return res.redirect(encodePagePath(page.path));
|
|
|
+ return res.redirect(pagePathUtil.encodePagePath(page.path));
|
|
|
}).catch(function(err) {
|
|
|
return res.redirect('/');
|
|
|
});
|
|
|
@@ -727,7 +710,7 @@ module.exports = function(crowi, app) {
|
|
|
pagerOptions.length = pages.length;
|
|
|
|
|
|
var result = {};
|
|
|
- result.pages = encodePagesPath(pages);
|
|
|
+ result.pages = pagePathUtil.encodePagesPath(pages);
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
}).catch(function(err) {
|
|
|
return res.json(ApiResponse.error(err));
|