WADA Takashi 8 лет назад
Родитель
Сommit
55bd2d6268
3 измененных файлов с 39 добавлено и 35 удалено
  1. 13 30
      lib/routes/page.js
  2. 24 0
      lib/util/pagePathUtil.js
  3. 2 5
      resource/js/legacy/crowi.js

+ 13 - 30
lib/routes/page.js

@@ -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));

+ 24 - 0
lib/util/pagePathUtil.js

@@ -0,0 +1,24 @@
+'use strict';
+
+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('/');
+}
+
+module.exports = {
+  encodePagePath: encodePagePath,
+  encodePagesPath: encodePagesPath
+};

+ 2 - 5
resource/js/legacy/crowi.js

@@ -15,6 +15,7 @@ require('bootstrap-sass');
 require('jquery.cookie');
 
 require('./thirdparty-js/agile-admin');
+const pagePathUtil = require('../../../lib/util/pagePathUtil');
 
 var Crowi = {};
 
@@ -233,11 +234,7 @@ $(function() {
     if (name.match(/.+\/$/)) {
       name = name.substr(0, name.length - 1);
     }
-    var names = name.split('/');
-    names.forEach(function(item, index) {
-      names[index] = encodeURIComponent(item);
-    });
-    top.location.href = names.join('/') + '#edit-form';
+    top.location.href = pagePathUtil.encodePagePath(name) + '#edit-form';
     return false;
   });