sou 7 лет назад
Родитель
Сommit
b6bde3ef23
4 измененных файлов с 21 добавлено и 49 удалено
  1. 6 0
      lib/models/config.js
  2. 8 49
      lib/routes/page.js
  3. 5 0
      lib/util/swigFunctions.js
  4. 2 0
      lib/views/widget/not_found_content.html

+ 6 - 0
lib/models/config.js

@@ -92,6 +92,7 @@ module.exports = function(crowi) {
       'customize:isEnabledTimeline' : true,
       'customize:isSavedStatesOfTabChanges' : true,
       'customize:isEnabledAttachTitleHeader' : false,
+      'customize:templateExists' : true,
     };
     /* eslint-enable */
   }
@@ -404,6 +405,11 @@ module.exports = function(crowi) {
     return getValueForCrowiNS(config, key);
   };
 
+  configSchema.statics.templateExists = function(config) {
+    const key = 'customize:templateExists';
+    return getValueForCrowiNS(config, key);
+  };
+
   configSchema.statics.fileUploadEnabled = function(config) {
     const Config = this;
 

+ 8 - 49
lib/routes/page.js

@@ -240,6 +240,7 @@ module.exports = function(crowi, app) {
       tree: [],
       userRelatedGroups: [],
       pageRelatedGroup: null,
+      template: null,
     };
 
     var pageTeamplate = 'customlayout-selector/page';
@@ -308,57 +309,15 @@ module.exports = function(crowi, app) {
     })
     // page not exists
     .catch(function(err) {
-      const pageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
-      Page.findPage(`/${pageName}/_template`)
-      .then(function(page) {
-        //new page object and do as when found
-        var templateRevision = page.revision;
-
-        var templatePage = new Page();
-        templatePage.path = originalUrl;
-        templatePage.creator = req.user;
-        templatePage.lastUpdateUser = req.user;
-        templatePage.createdAt = Date.now();
-        templatePage.updatedAt = Date.now();
-        templatePage.redirectTo = null;
-        templatePage.grant = 1;
-        templatePage.status = 'published';
-        templatePage.grantedUsers = [];
-        templatePage.grantedUsers.push(req.user);
-
-        renderVars.page = templatePage;
-        renderVars.path = templatePage.path;
-        renderVars.revision = templateRevision;
-        renderVars.author = templatePage.revision.author;
-
-        // redirect
-        if (page.redirectTo) {
-          debug(`Redirect to '${page.redirectTo}'`);
-          isRedirect = true;
-          return res.redirect(encodeURI(page.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(page.path)));
-        }
+      const rootPageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
+      pageTeamplate = 'customlayout-selector/not_found';
 
-        renderVars.page = templatePage;
+      return Page.findPage(`/${rootPageName}/_template`)
+      .then(function(page) {
+        //use not_found template and read template into editor if it exists
+        renderVars.template = page.revision.body;
 
-        if (page) {
-          renderVars.path = templatePage.path;
-          renderVars.revision = templateRevision;
-          renderVars.author = templatePage.revision.author;
-
-          // これいる??
-          return Revision.findRevisionList(page.path, {})
-          .then(function(tree) {
-            renderVars.tree = tree;
-            return Promise.resolve();
-          }).then(function() {
-            return Promise.resolve();
-          });
-        }
-      })
-      .catch(function(err) {
-        debug('Page not found', path);
-        // change template
-        pageTeamplate = 'customlayout-selector/not_found';
+        return Promise.resolve();
       });
 
 

+ 5 - 0
lib/util/swigFunctions.js

@@ -180,6 +180,11 @@ module.exports = function(crowi, app, req, locals) {
     return Config.isEnabledAttachTitleHeader(config);
   };
 
+  locals.templateExists = function() {
+    var config = crowi.getConfig();
+    return Config.templateExists(config);
+  };
+
   locals.parentPath = function(path) {
     if (path == '/') {
       return path;

+ 2 - 0
lib/views/widget/not_found_content.html

@@ -18,6 +18,8 @@
   <div class="tab-content">
     {% if isEnabledAttachTitleHeader() %}
     <script type="text/template" id="raw-text-original"># {{ path|path2name }}</script>
+    {% elseif templateExists() %}
+    <script type="text/template" id="raw-text-original">{{ template }}</script>
     {% endif %}
     {# list view #}
     <div class="p-t-10 active tab-pane page-list-container" id="revision-body">