Quellcode durchsuchen

Passing local_config from server

Sotaro KARASAWA vor 9 Jahren
Ursprung
Commit
df604e85a8
5 geänderte Dateien mit 34 neuen und 1 gelöschten Zeilen
  1. 1 0
      lib/crowi/express-init.js
  2. 18 0
      lib/models/config.js
  3. 4 0
      lib/views/layout/layout.html
  4. 1 0
      resource/js/app.js
  5. 10 1
      resource/js/util/Crowi.js

+ 1 - 0
lib/crowi/express-init.js

@@ -71,6 +71,7 @@ module.exports = function(crowi, app) {
         language:   User.getLanguageLabels(),
         language:   User.getLanguageLabels(),
         registrationMode: Config.getRegistrationModeLabels(),
         registrationMode: Config.getRegistrationModeLabels(),
     };
     };
+    res.locals.local_config = Config.getLocalconfig(config); // config for browser context
 
 
     next();
     next();
   });
   });

+ 18 - 0
lib/models/config.js

@@ -217,6 +217,24 @@ module.exports = function(crowi) {
     return true;
     return true;
   };
   };
 
 
+  configSchema.statics.getLocalconfig = function(config)
+  {
+    const Config = this;
+
+    const local_config = {
+      crowi: {
+        title: config.crowi['app:title'],
+        url: config.crowi['app:url'] || '',
+      },
+      upload: {
+        image: Config.isUploadable(config),
+        file: Config.fileUploadEnabled(config),
+      },
+    };
+
+    return local_config;
+  }
+
   /*
   /*
   configSchema.statics.isInstalled = function(config)
   configSchema.statics.isInstalled = function(config)
   {
   {

+ 4 - 0
lib/views/layout/layout.html

@@ -142,6 +142,10 @@
 </body>
 </body>
 {% endblock %}
 {% endblock %}
 
 
+<script type="application/json" id="crowi-context-hydrate">
+{{ local_config|json|safe }}
+</script>
+
 <script src="{{ assets('/js/crowi.js') }}"></script>
 <script src="{{ assets('/js/crowi.js') }}"></script>
 <script src="{{ assets('/js/app.js') }}"></script>
 <script src="{{ assets('/js/app.js') }}"></script>
 </html>
 </html>

+ 1 - 0
resource/js/app.js

@@ -33,6 +33,7 @@ const crowi = new Crowi({
   csrfToken: $('#content-main').data('csrftoken'),
   csrfToken: $('#content-main').data('csrftoken'),
 }, window);
 }, window);
 window.crowi = crowi;
 window.crowi = crowi;
+crowi.setConfig(JSON.parse(document.getElementById('crowi-context-hydrate').textContent || '{}'));
 crowi.fetchUsers();
 crowi.fetchUsers();
 
 
 const crowiRenderer = new CrowiRenderer();
 const crowiRenderer = new CrowiRenderer();

+ 10 - 1
resource/js/util/Crowi.js

@@ -7,6 +7,7 @@ import axios from 'axios'
 export default class Crowi {
 export default class Crowi {
   constructor(context, window) {
   constructor(context, window) {
     this.context = context;
     this.context = context;
+    this.config = {};
     this.csrfToken = context.csrfToken;
     this.csrfToken = context.csrfToken;
 
 
     this.location = window.location || {};
     this.location = window.location || {};
@@ -33,8 +34,16 @@ export default class Crowi {
     return context;
     return context;
   }
   }
 
 
+  setConfig(config) {
+    this.config = config;
+  }
+
+  getConfig() {
+    return this.config;
+  }
+
   recoverData() {
   recoverData() {
-    const keys = [
+  const keys = [
       'userByName',
       'userByName',
       'userById',
       'userById',
       'users',
       'users',