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

Merge pull request #444 from weseek/feat/auto-tempalte-UI

Feat/auto tempalte ui
Yuki Takei 7 лет назад
Родитель
Сommit
c8dfbc8991
4 измененных файлов с 40 добавлено и 40 удалено
  1. 18 18
      lib/models/page.js
  2. 8 8
      lib/routes/page.js
  3. 6 6
      lib/views/modal/create_page.html
  4. 8 8
      lib/views/modal/create_template.html

+ 18 - 18
lib/models/page.js

@@ -527,21 +527,21 @@ module.exports = function(crowi) {
     });
     });
   };
   };
 
 
-  // check if a given page has a local and global tempalte
+  // check if a given page has a children and decendants tempalte
   pageSchema.statics.checkIfTemplatesExist = function(path) {
   pageSchema.statics.checkIfTemplatesExist = function(path) {
     const Page = this;
     const Page = this;
     const pathList = generatePathsOnTree(path, []);
     const pathList = generatePathsOnTree(path, []);
     const regexpList = pathList.map(path => new RegExp(`${path}/_{1,2}template`));
     const regexpList = pathList.map(path => new RegExp(`${path}/_{1,2}template`));
     let templateInfo = {
     let templateInfo = {
-      localTemplateExists: false,
-      globalTemplateExists: false,
+      childrenTemplateExists: false,
+      decendantsTemplateExists: false,
     };
     };
 
 
     return Page
     return Page
       .find({path: {$in: regexpList}})
       .find({path: {$in: regexpList}})
       .then(templates => {
       .then(templates => {
-        templateInfo.localTemplateExists = (assignTemplateByType(templates, path, '__') ? true : false);
-        templateInfo.globalTemplateExists = (assignGlobalTemplate(templates, path) ? true : false);
+        templateInfo.childrenTemplateExists = (assignTemplateByType(templates, path, '_') ? true : false);
+        templateInfo.decendantsTemplateExists = (assignTemplateByType(templates, path, '__') ? true : false);
 
 
         return templateInfo;
         return templateInfo;
       });
       });
@@ -588,10 +588,10 @@ module.exports = function(crowi) {
     }
     }
   };
   };
 
 
-  const assignGlobalTemplate = (globalTemplates, path) => {
-    const globalTemplate = assignTemplateByType(globalTemplates, path, '_');
-    if (globalTemplate) {
-      return globalTemplate;
+  const assignDecendantsTemplate = (decendantsTemplates, path) => {
+    const decendantsTemplate = assignTemplateByType(decendantsTemplates, path, '__');
+    if (decendantsTemplate) {
+      return decendantsTemplate;
     }
     }
 
 
     if (path === '') {
     if (path === '') {
@@ -599,28 +599,28 @@ module.exports = function(crowi) {
     }
     }
 
 
     const newPath = cutOffLastSlash(path);
     const newPath = cutOffLastSlash(path);
-    return assignGlobalTemplate(globalTemplates, newPath);
+    return assignDecendantsTemplate(decendantsTemplates, newPath);
   };
   };
 
 
   const fetchTemplate = (templates, templatePath) => {
   const fetchTemplate = (templates, templatePath) => {
     let templateBody;
     let templateBody;
     /**
     /**
-     * get local template
+     * get children template
      * __tempate: applicable only to immediate decendants
      * __tempate: applicable only to immediate decendants
      */
      */
-    const localTemplate = assignTemplateByType(templates, templatePath, '__');
+    const childrenTemplate = assignTemplateByType(templates, templatePath, '_');
 
 
     /**
     /**
-     * get global templates
+     * get decendants templates
      * _tempate: applicable to all pages under
      * _tempate: applicable to all pages under
      */
      */
-    const globalTemplate = assignGlobalTemplate(templates, templatePath);
+    const decendantsTemplate = assignDecendantsTemplate(templates, templatePath);
 
 
-    if (localTemplate) {
-      templateBody =  localTemplate.revision.body;
+    if (childrenTemplate) {
+      templateBody =  childrenTemplate.revision.body;
     }
     }
-    else if (globalTemplate) {
-      templateBody = globalTemplate.revision.body;
+    else if (decendantsTemplate) {
+      templateBody = decendantsTemplate.revision.body;
     }
     }
 
 
     return templateBody;
     return templateBody;

+ 8 - 8
lib/routes/page.js

@@ -252,8 +252,8 @@ module.exports = function(crowi, app) {
       tree: [],
       tree: [],
       pageRelatedGroup: null,
       pageRelatedGroup: null,
       template: null,
       template: null,
-      localTemplateExists: false,
-      globalTemplateExists: false,
+      childrenTemplateExists: false,
+      decendantsTemplateExists: false,
     };
     };
 
 
     var pageTeamplate = 'customlayout-selector/page';
     var pageTeamplate = 'customlayout-selector/page';
@@ -286,8 +286,8 @@ module.exports = function(crowi, app) {
           return Page.checkIfTemplatesExist(originalPath);
           return Page.checkIfTemplatesExist(originalPath);
         })
         })
         .then(function(templateInfo) {
         .then(function(templateInfo) {
-          renderVars.localTemplateExists = templateInfo.localTemplateExists;
-          renderVars.globalTemplateExists = templateInfo.globalTemplateExists;
+          renderVars.childrenTemplateExists = templateInfo.childrenTemplateExists;
+          renderVars.decendantsTemplateExists = templateInfo.decendantsTemplateExists;
         })
         })
         .then(() => {
         .then(() => {
           return PageGroupRelation.findByPage(renderVars.page);
           return PageGroupRelation.findByPage(renderVars.page);
@@ -462,8 +462,8 @@ module.exports = function(crowi, app) {
       page: pageData,
       page: pageData,
       revision: pageData.revision || {},
       revision: pageData.revision || {},
       author: pageData.revision.author || false,
       author: pageData.revision.author || false,
-      localTemplateExists: false,
-      globalTemplateExists: false,
+      childrenTemplateExists: false,
+      decendantsTemplateExists: false,
     };
     };
     var userPage = isUserPage(pageData.path);
     var userPage = isUserPage(pageData.path);
     var userData = null;
     var userData = null;
@@ -511,8 +511,8 @@ module.exports = function(crowi, app) {
     }).then(function() {
     }).then(function() {
       return Page.checkIfTemplatesExist(pageData.path)
       return Page.checkIfTemplatesExist(pageData.path)
         .then(function(templateInfo) {
         .then(function(templateInfo) {
-          renderVars.localTemplateExists = templateInfo.localTemplateExists;
-          renderVars.globalTemplateExists = templateInfo.globalTemplateExists;
+          renderVars.childrenTemplateExists = templateInfo.childrenTemplateExists;
+          renderVars.decendantsTemplateExists = templateInfo.decendantsTemplateExists;
         });
         });
     }).then(function() {
     }).then(function() {
       var defaultPageTeamplate = 'customlayout-selector/page';
       var defaultPageTeamplate = 'customlayout-selector/page';

+ 6 - 6
lib/views/modal/create_page.html

@@ -51,8 +51,8 @@
               <div class="create-page-input-row d-flex align-items-center">
               <div class="create-page-input-row d-flex align-items-center">
                 <select id="template-type" class="page-name-input form-control">
                 <select id="template-type" class="page-name-input form-control">
                   <option value="" disabled selected>{{ t('template.option_label.select') }}</option>
                   <option value="" disabled selected>{{ t('template.option_label.select') }}</option>
-                  <option value="local">{{ t('template.local.label') }}(__template) - {{ t('template.local.desc') }}</option>
-                  <option value="global">{{ t('template.global.label') }}(_template) - {{ t('template.global.desc') }}</option>
+                  <option value="children">{{ t('template.local.label') }}(_template) - {{ t('template.local.desc') }}</option>
+                  <option value="decentants">{{ t('template.global.label') }}(__template) - {{ t('template.global.desc') }}</option>
                 </select>
                 </select>
               </div>
               </div>
               <div class="create-page-button-container">
               <div class="create-page-button-container">
@@ -76,12 +76,12 @@
     };
     };
 
 
     $("#template-type").on("change", () => {
     $("#template-type").on("change", () => {
-      if ($("#template-type").val() === "local") {
-        href = pagePath + "/__template#edit-form";
+      if ($("#template-type").val() === "children") {
+        href = pagePath + "/_template#edit-form";
         $("#link-to-template").attr("href", href);
         $("#link-to-template").attr("href", href);
       }
       }
-      else if ($("#template-type").val() === "global") {
-        href = pagePath + "/_template#edit-form";
+      else if ($("#template-type").val() === "decentants") {
+        href = pagePath + "/__template#edit-form";
         $("#link-to-template").attr("href", href);
         $("#link-to-template").attr("href", href);
       };
       };
     });
     });

+ 8 - 8
lib/views/modal/create_template.html

@@ -14,14 +14,14 @@
               <div class="panel panel-default">
               <div class="panel panel-default">
                 <div class="panel-heading">{{ t('template.local.label') }}</div>
                 <div class="panel-heading">{{ t('template.local.label') }}</div>
                 <div class="panel-body">
                 <div class="panel-body">
-                  <p class="text-center"><code>__template</code></p>
+                  <p class="text-center"><code>_template</code></p>
                   <p class="help-block text-center"><small>{{ t('template.local.desc') }}</small></p>
                   <p class="help-block text-center"><small>{{ t('template.local.desc') }}</small></p>
                 </div>
                 </div>
                 <div class="panel-footer text-center">
                 <div class="panel-footer text-center">
-                  {% if localTemplateExists %}
-                  <a href="{{ page.path }}/__template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Edit') }}</button></a>
+                  {% if childrenTemplateExists %}
+                  <a href="{{ page.path }}/_template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Edit') }}</button></a>
                   {% else %}
                   {% else %}
-                  <a href="{{ page.path }}/__template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Create') }}</button></a>
+                  <a href="{{ page.path }}/_template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Create') }}</button></a>
                   {% endif %}
                   {% endif %}
                 </div>
                 </div>
               </div>
               </div>
@@ -30,14 +30,14 @@
               <div class="panel panel-default">
               <div class="panel panel-default">
                 <div class="panel-heading">{{ t('template.global.label') }}</div>
                 <div class="panel-heading">{{ t('template.global.label') }}</div>
                 <div class="panel-body">
                 <div class="panel-body">
-                  <p class="text-center"><code>_template</code></p>
+                  <p class="text-center"><code>__template</code></p>
                   <p class="help-block text-center"><small>{{ t('template.global.desc') }}</small></p>
                   <p class="help-block text-center"><small>{{ t('template.global.desc') }}</small></p>
                 </div>
                 </div>
                 <div class="panel-footer text-center">
                 <div class="panel-footer text-center">
-                  {% if globalTemplateExists %}
-                  <a href="{{ page.path }}/_template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Edit') }}</button></a>
+                  {% if decendantsTemplateExists %}
+                  <a href="{{ page.path }}/__template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Edit') }}</button></a>
                   {% else %}
                   {% else %}
-                  <a href="{{ page.path }}/_template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Create') }}</button></a>
+                  <a href="{{ page.path }}/__template#edit-form"><button class="btn btn-sm btn-primary">{{ t('Create') }}</button></a>
                   {% endif %}
                   {% endif %}
                 </div>
                 </div>
               </div>
               </div>