Explorar o código

WIP: refactor models/page.js

* extract action for presentation
Yuki Takei %!s(int64=7) %!d(string=hai) anos
pai
achega
f8a32ff303
Modificáronse 1 ficheiros con 26 adicións e 8 borrados
  1. 26 8
      src/server/routes/page.js

+ 26 - 8
src/server/routes/page.js

@@ -187,9 +187,16 @@ module.exports = function(crowi, app) {
     }
   };
   /**
-   * switch action by behaviorType
+   * switch action
+   *   - presentation mode
+   *   - by behaviorType
    */
   actions.pageShowWrapper = function(req, res, next) {
+    // presentation mode
+    if (req.query.presentation) {
+      return actions.showPageForPresentation(req, res, next);
+    }
+
     const behaviorType = Config.behaviorType(config);
 
     if (!behaviorType || 'crowi' === behaviorType) {
@@ -269,6 +276,24 @@ module.exports = function(crowi, app) {
     return res.render(view, renderVars);
   };
 
+  actions.showPageForPresentation = async function(req, res, next) {
+    let path = getPathFromRequest(req);
+    const revisionId = req.query.revision;
+
+    let page = await Page.findPageByPathAndViewer(path, req.user);
+
+    if (page == null) {
+      next();
+    }
+
+    const renderVars = {};
+
+    // populate
+    page = await page.populateDataToMakePresentation(revisionId);
+    addRendarVarsForPage(renderVars, page);
+    return res.render('page_presentation', renderVars);
+  };
+
   actions.pageListShow = async function(req, res) {
     let path = getPathFromRequest(req);
     const revisionId = req.query.revision;
@@ -328,13 +353,6 @@ module.exports = function(crowi, app) {
     const offset = parseInt(req.query.offset)  || 0;
     const renderVars = {};
 
-    // Presentation Mode
-    if (req.query.presentation) {
-      page = await page.populateDataToMakePresentation(revisionId);
-      addRendarVarsForPage(renderVars, page);
-      return res.render('page_presentation', renderVars);
-    }
-
     let view = 'customlayout-selector/page';
 
     // populate