Просмотр исходного кода

add the option for selecting behaviorType to AdminPage

Yuki Takei 8 лет назад
Родитель
Сommit
69965381b1

+ 9 - 0
lib/form/admin/custombehavior.js

@@ -0,0 +1,9 @@
+'use strict';
+
+var form = require('express-form')
+  , field = form.field
+  ;
+
+module.exports = form(
+  field('settingForm[customize:behavior]')
+);

+ 1 - 0
lib/form/index.js

@@ -19,6 +19,7 @@ module.exports = {
     plugin: require('./admin/plugin'),
     markdown: require('./admin/markdown'),
     customcss: require('./admin/customcss'),
+    custombehavior: require('./admin/custombehavior'),
     customlayout: require('./admin/customlayout'),
     userInvite: require('./admin/userInvite'),
     slackSetting: require('./admin/slackSetting'),

+ 6 - 0
lib/models/config.js

@@ -51,6 +51,7 @@ module.exports = function(crowi) {
       'plugin:isEnabledPlugins' : true,
 
       'customize:css' : '',
+      'customize:behavior' : 'crowi',
       'customize:layout' : 'crowi',
     };
   }
@@ -278,6 +279,11 @@ module.exports = function(crowi) {
     return this.uglifiedCustomCss;
   }
 
+  configSchema.statics.behaviorType = function(config)
+  {
+    return config.crowi['customize:behavior'] || 'crowi';
+  }
+
   configSchema.statics.layoutType = function(config)
   {
     return config.crowi['customize:layout'] || 'crowi';

+ 6 - 14
lib/routes/index.js

@@ -15,8 +15,6 @@ module.exports = function(crowi, app) {
     , bookmark  = require('./bookmark')(crowi, app)
     , revision  = require('./revision')(crowi, app)
     , search    = require('./search')(crowi, app)
-    , Config    = crowi.model('Config')
-    , config    = crowi.getConfig()
     , loginRequired = middleware.loginRequired
     , accessTokenParser = middleware.accessTokenParser(crowi, app)
     , csrf      = middleware.csrfVerify(crowi, app)
@@ -54,9 +52,10 @@ module.exports = function(crowi, app) {
   app.post('/admin/markdown/lineBreaksSetting', loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.markdown, admin.markdown.lineBreaksSetting);
 
   // markdown admin
-  app.get('/admin/customize'              , loginRequired(crowi, app) , middleware.adminRequired() , admin.customize.index);
-  app.post('/_api/admin/customize/css'    , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customcss, admin.api.customizeSetting);
-  app.post('/_api/admin/customize/layout' , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customlayout, admin.api.customizeSetting);
+  app.get('/admin/customize'                , loginRequired(crowi, app) , middleware.adminRequired() , admin.customize.index);
+  app.post('/_api/admin/customize/css'      , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customcss, admin.api.customizeSetting);
+  app.post('/_api/admin/customize/behavior' , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.custombehavior, admin.api.customizeSetting);
+  app.post('/_api/admin/customize/layout'   , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customlayout, admin.api.customizeSetting);
 
   // search admin
   app.get('/admin/search'              , loginRequired(crowi, app) , middleware.adminRequired() , admin.search.index);
@@ -142,13 +141,6 @@ module.exports = function(crowi, app) {
   app.get('/trash/$'                 , loginRequired(crowi, app, false) , page.deletedPageListShow);
   app.get('/trash/*/$'               , loginRequired(crowi, app, false) , page.deletedPageListShow);
 
-  // route for pages
-  if ('crowi-plus' === Config.layoutType(config)) {
-    app.get('/*/$'                   , loginRequired(crowi, app, false) , page.pageListShowForCrowiPlus);
-    app.get('/*'                     , loginRequired(crowi, app, false) , page.pageShowForCrowiPlus);
-  }
-  else {
-    app.get('/*/$'                   , loginRequired(crowi, app, false) , page.pageListShow);
-    app.get('/*'                     , loginRequired(crowi, app, false) , page.pageShow);
-  }
+  app.get('/*/$'                   , loginRequired(crowi, app, false) , page.pageListShowWrapper);
+  app.get('/*'                     , loginRequired(crowi, app, false) , page.pageShowWrapper);
 };

+ 29 - 0
lib/routes/page.js

@@ -4,6 +4,8 @@ module.exports = function(crowi, app) {
   var debug = require('debug')('crowi:routes:page')
     , Page = crowi.model('Page')
     , User = crowi.model('User')
+    , Config   = crowi.model('Config')
+    , config   = crowi.getConfig()
     , Revision = crowi.model('Revision')
     , Bookmark = crowi.model('Bookmark')
     , ApiResponse = require('../util/apiResponse')
@@ -61,6 +63,33 @@ module.exports = function(crowi, app) {
     };
   }
 
+  /**
+   * switch action by behaviorType
+   */
+  actions.pageListShowWrapper = function(req, res) {
+    const behaviorType = Config.behaviorType(config);
+
+    if ('crowi-plus' === behaviorType) {
+      return actions.pageListShowForCrowiPlus(req, res);
+    }
+    else {
+      return actions.pageListShow(req, res);
+    }
+  }
+  /**
+   * switch action by behaviorType
+   */
+  actions.pageShowWrapper = function(req, res) {
+    const behaviorType = Config.behaviorType(config);
+
+    if ('crowi-plus' === behaviorType) {
+      return actions.pageShowForCrowiPlus(req, res);
+    }
+    else {
+      return actions.pageShow(req, res);
+    }
+  }
+
   actions.pageListShow = function(req, res) {
     var path = getPathFromRequest(req);
     var limit = 50;

+ 5 - 0
lib/util/swigFunctions.js

@@ -55,6 +55,11 @@ module.exports = function(crowi, app, req, locals) {
     return Config.customCss();
   }
 
+  locals.behaviorType = function() {
+    var config = crowi.getConfig()
+    return Config.behaviorType(config);
+  }
+
   locals.layoutType = function() {
     var config = crowi.getConfig()
     return Config.layoutType(config);

+ 47 - 1
lib/views/admin/customize.html

@@ -45,6 +45,52 @@
     </div>
     <div class="col-md-9">
 
+      <form action="/_api/admin/customize/behavior" method="post" class="form-horizontal" id="cutombehaviorSettingForm" role="form">
+      <fieldset>
+        <legend>挙動</legend>
+
+        <div class="form-group">
+          <div class="col-xs-6">
+            <h4>
+              <input type="radio" name="settingForm[customize:behavior]" value="crowi"
+                  {% if !settingForm['customize:behavior'] || 'crowi' === settingForm['customize:behavior'] %}checked="checked"{% endif %}>
+              Official Crowi Behavior
+            </h4>
+            <ul>
+              <li><code>/page</code> shows the page</li>
+              <li><code>/page/</code> shows the list of sub pages</li>
+              <ul>
+                <li>If portal is applied to <code>/page/</code> , the portal and the list of sub pages are shown</li>
+              </ul>
+              <li><code>/nonexistent_page</code> shows editing form</li>
+              <li><code>/nonexistent_page/</code> the list of sub pages</li>
+            </ul>
+          </div>
+          <div class="col-xs-6">
+            <h4>
+              <input type="radio" name="settingForm[customize:behavior]" value="crowi-plus"
+                  {% if 'crowi-plus' === settingForm['customize:behavior'] %}checked="checked"{% endif %}>
+              crowi-plus Simplified Behavior <small class="text-success">(Recommended)</small>
+            </h4>
+            <ul>
+              <li><code>/page</code> and <code>/page/</code> both shows the page</li>
+              <li><code>/nonexistent_page</code> shows editing form</li>
+              <li>All pages shows the list of sub pages</li>
+            </ul>
+          </div>
+        </div>
+
+        <div class="form-group">
+          <div class="col-xs-offset-5 col-xs-6">
+            <input type="hidden" name="_csrf" value="{{ csrf() }}">
+            <button type="submit" class="btn btn-primary">更新</button>
+          </div>
+        </div>
+
+      </fieldset>
+      </form>
+
+
       <form action="/_api/admin/customize/layout" method="post" class="form-horizontal" id="cutomlayoutSettingForm" role="form">
       <fieldset>
         <legend>レイアウト</legend>
@@ -133,7 +179,7 @@
   </div>
 
   <script>
-    $('#cutomcssSettingForm, #cutomlayoutSettingForm').each(function() {
+    $('#cutomcssSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm').each(function() {
       $(this).submit(function()
       {
         function showMessage(formId, msg, status) {

+ 2 - 0
lib/views/crowi-plus/page.html

@@ -39,11 +39,13 @@
 
     </div>
 
+    {% if 'crowi-plus' === behaviorType() %}
     <div class="row page-list">
       <div class="col-md-12">
         {% include './widget/page_list_container.html' %}
       </div>
     </div>
+    {% endif %}
 
   </div>
 {% endblock %}