|
|
@@ -307,44 +307,49 @@ module.exports = function(crowi, app) {
|
|
|
return Promise.resolve();
|
|
|
}
|
|
|
})
|
|
|
- // page not exists
|
|
|
+ // look for templates if page not exists
|
|
|
.catch(function(err) {
|
|
|
- const rootPageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
|
|
|
+ // use not_found pageTempalte for both a new page with either tempalte and a new page with no templates
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
|
|
|
- const getGlobalTemplate = Page.findPage(`/${rootPageName}/_template`)
|
|
|
- .then(function(page) {
|
|
|
- //use not_found template and read template into editor if it exists
|
|
|
- renderVars.template = page.revision.body;
|
|
|
+ const lastSlash = originalUrl.lastIndexOf('/');
|
|
|
+ const templateUrl = `${originalUrl.substr(0, lastSlash)}/@template`;
|
|
|
|
|
|
- return Promise.resolve();
|
|
|
+ // @tempate: applicable only to immediate decendants
|
|
|
+ const getLocalTemplate = Page.findPage(templateUrl)
|
|
|
+ .then(function(page) {
|
|
|
+ return Promise.resolve(page.path);
|
|
|
})
|
|
|
.catch(function(err) {
|
|
|
- return Promise.reject(err);
|
|
|
+ console.log('no @template for you');
|
|
|
+ return Promise.resolve();
|
|
|
});
|
|
|
|
|
|
- return getGlobalTemplate;
|
|
|
-
|
|
|
- // const lastSlash = originalUrl.lastIndexOf('/');
|
|
|
- // const templateUrl = `${originalUrl.substr(0, lastSlash)}/@template`;
|
|
|
-
|
|
|
- // pageTeamplate = 'customlayout-selector/not_found';
|
|
|
-
|
|
|
- // const getLocalTemplate = Page.findPage(templateUrl)
|
|
|
- // .then(function(page) {
|
|
|
- // //use not_found template and read template into editor if it exists
|
|
|
- // renderVars.template = page.revision.body;
|
|
|
-
|
|
|
- // return Promise.resolve();
|
|
|
- // })
|
|
|
- // .catch(function(err) {
|
|
|
- // console.log('no @template for you');
|
|
|
- // return Promise.reject(err);
|
|
|
- // });
|
|
|
+ //FIXME
|
|
|
+ const rootPageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
|
|
|
|
|
|
- // return getLocalTemplate;
|
|
|
+ // _tempate: applicable to all pages under
|
|
|
+ const getGlobalTemplate = Page.findPage(`/${rootPageName}/_template`)
|
|
|
+ .then(function(page) {
|
|
|
+ return Promise.resolve(page.path);
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ console.log('no _template for you');
|
|
|
+ return Promise.resolve();
|
|
|
+ });
|
|
|
|
|
|
+ return Promise.all([getGlobalTemplate, getLocalTemplate])
|
|
|
+ .then(function(templates) {
|
|
|
+ const globalTemplate = templates[0];
|
|
|
+ const localTemplate = templates[1];
|
|
|
|
|
|
+ if (globalTemplate) {
|
|
|
+ renderVars.template = globalTemplate.revision.body;
|
|
|
+ }
|
|
|
+ else if (localTemplate) {
|
|
|
+ renderVars.template = localTemplate.revision.body;
|
|
|
+ }
|
|
|
+ });
|
|
|
})
|
|
|
// get list pages
|
|
|
.then(function() {
|
|
|
@@ -394,6 +399,18 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const pathGenerator = (path, pathList) => {
|
|
|
+ const lastSlash = path.lastIndexOf('/');
|
|
|
+ const newPath = path.substr(0, lastSlash);
|
|
|
+
|
|
|
+ if (newPath === '') {
|
|
|
+ return pathList;
|
|
|
+ }
|
|
|
+
|
|
|
+ pathList.push(newPath);
|
|
|
+ return pathGenerator(newPath, pathList);
|
|
|
+ };
|
|
|
+
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
|
var limit = 50;
|