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

changed template path; for added template function on crowi behavior

sou 7 лет назад
Родитель
Сommit
acae5e4dfb
4 измененных файлов с 29 добавлено и 23 удалено
  1. 7 5
      lib/models/page.js
  2. 3 1
      lib/routes/page.js
  3. 17 15
      lib/views/modal/create_page.html
  4. 2 2
      lib/views/modal/create_template.html

+ 7 - 5
lib/models/page.js

@@ -531,7 +531,7 @@ module.exports = function(crowi) {
   pageSchema.statics.checkIfTemplatesExist = function(path) {
     const Page = this;
     const pathList = generatePathsOnTree(path, []);
-    const regexpList = pathList.map(path => new RegExp(`${path}/[_@]template`));
+    const regexpList = pathList.map(path => new RegExp(`${path}/_{1,2}template`));
     let templateInfo = {
       localTemplateExists: false,
       globalTemplateExists: false,
@@ -540,19 +540,21 @@ module.exports = function(crowi) {
     return Page
       .find({path: {$in: regexpList}})
       .then(templates => {
-        templateInfo.localTemplateExists = (assignTemplateByType(templates, path, '@') ? true : false);
+        templateInfo.localTemplateExists = (assignTemplateByType(templates, path, '__') ? true : false);
         templateInfo.globalTemplateExists = (assignGlobalTemplate(templates, path) ? true : false);
 
         return templateInfo;
       });
   };
 
-  // find all templates applicable to the new page
+  /**
+   * find all templates applicable to the new page
+   */
   pageSchema.statics.findTemplate = function(path) {
     const Page = this;
     const templatePath = cutOffLastSlash(path);
     const pathList = generatePathsOnTree(templatePath, []);
-    const regexpList = pathList.map(path => new RegExp(`${path}/[_@]template`));
+    const regexpList = pathList.map(path => new RegExp(`${path}/_{1,2}template`));
 
     return Page
       .find({path: {$in: regexpList}})
@@ -605,7 +607,7 @@ module.exports = function(crowi) {
      * get local template
      * @tempate: applicable only to immediate decendants
      */
-    const localTemplate = assignTemplateByType(templates, templatePath, '@');
+    const localTemplate = assignTemplateByType(templates, templatePath, '__');
 
     /**
      * get global templates

+ 3 - 1
lib/routes/page.js

@@ -451,11 +451,14 @@ module.exports = function(crowi, app) {
           userRelatedGroups = groupRelations.map(relation => relation.relatedGroup);
           return Promise.resolve();
         }).then(() => {
+          return Page.findTemplate(getPathFromRequest(req));
+        }).then((template) => {
           debug('not found page user group resolver : ', userRelatedGroups);
           return res.render('customlayout-selector/not_found', {
             author: {},
             page: false,
             userRelatedGroups: userRelatedGroups,
+            template: template,
           });
         });
     }
@@ -568,7 +571,6 @@ module.exports = function(crowi, app) {
           return res.redirect(pagePathUtil.encodePagePath(path) + '/');
         }
         else {
-
           var fixed = Page.fixToCreatableName(path);
           if (fixed !== path) {
             debug('fixed page name', fixed);

+ 17 - 15
lib/views/modal/create_page.html

@@ -44,14 +44,14 @@
           </fieldset>
         </form>
 
-        <form class="row form-horizontal m-t-15">
+        <div class="row form-horizontal m-t-15">
           <fieldset class="col-xs-12">
             <legend>Create template under <code>{{ parentPath(path) }}</code></legend>
             <div class="d-flex create-page-input-container">
               <div class="create-page-input-row d-flex align-items-center">
                 <select id="template-type" class="page-name-input form-control">
                   <option value="" disabled selected>Select tempate type</option>
-                  <option value="local">Local Template(/@template) - Applies only to immediate decendant pages</option>
+                  <option value="local">Local Template(/__template) - Applies only to immediate decendant pages</option>
                   <option value="global">Global Template(/_template) - Applies to all decendant pages</option>
                 </select>
               </div>
@@ -60,7 +60,7 @@
               </div>
             </div>
           </fieldset>
-        </form>
+        </div>
 
       </div><!-- /.modal-body -->
 
@@ -68,16 +68,18 @@
   </div><!-- /.modal-dialog -->
 </div><!-- /.modal -->
 <script>
-  const pagePath = $("#link-to-template").attr("href");
+  if($('#create-page')) {
+    const pagePath = $("#link-to-template").attr("href");
 
-  $('#template-type').on('change', () => {
-    if ($('#template-type').val() === 'local') {
-      href = pagePath + "/@template#edit-form";
-      $("#link-to-template").attr("href", href);
-    }
-    else if ($('#template-type').val() === 'global') {
-      href = pagePath + "/_template#edit-form";
-      $("#link-to-template").attr("href", href);
-    }
-  })
-  </script>
+    $('#template-type').on('change', () => {
+      if ($('#template-type').val() === 'local') {
+        href = pagePath + "/__template#edit-form";
+        $("#link-to-template").attr("href", href);
+      }
+      else if ($('#template-type').val() === 'global') {
+        href = pagePath + "/_template#edit-form";
+        $("#link-to-template").attr("href", href);
+      };
+    });
+  };
+</script>

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

@@ -16,9 +16,9 @@
               <br>
               <div class="d-flex justify-content-center">
                 {% if localTemplateExists %}
-                <a href="{{ page.path }}/@template#edit-form"><button class="btn btn-xs btn-primary">Edit</button></a>
+                <a href="{{ page.path }}/__template#edit-form"><button class="btn btn-xs btn-primary">Edit</button></a>
                 {% else %}
-                <a href="{{ page.path }}/@template#edit-form"><button class="btn btn-xs btn-primary">Create</button></a>
+                <a href="{{ page.path }}/__template#edit-form"><button class="btn btn-xs btn-primary">Create</button></a>
                 {% endif %}
               </div>
             </div>