Browse Source

Merge pull request #926 from weseek/imprv/take-over-tags-from-template-page

Imprv/take over tags from template page
Yuki Takei 7 năm trước cách đây
mục cha
commit
93a5f89288

+ 3 - 1
src/client/js/app.js

@@ -71,6 +71,7 @@ let pageContent = '';
 let markdown = '';
 let markdown = '';
 let slackChannels;
 let slackChannels;
 let pageTags = [];
 let pageTags = [];
+let templateTagData = '';
 if (mainContent !== null) {
 if (mainContent !== null) {
   pageId = mainContent.getAttribute('data-page-id') || null;
   pageId = mainContent.getAttribute('data-page-id') || null;
   pageRevisionId = mainContent.getAttribute('data-page-revision-id');
   pageRevisionId = mainContent.getAttribute('data-page-revision-id');
@@ -80,6 +81,7 @@ if (mainContent !== null) {
   hasDraftOnHackmd = !!mainContent.getAttribute('data-page-has-draft-on-hackmd');
   hasDraftOnHackmd = !!mainContent.getAttribute('data-page-has-draft-on-hackmd');
   pagePath = mainContent.attributes['data-path'].value;
   pagePath = mainContent.attributes['data-path'].value;
   slackChannels = mainContent.getAttribute('data-slack-channels') || '';
   slackChannels = mainContent.getAttribute('data-slack-channels') || '';
+  templateTagData = mainContent.getAttribute('data-template-tags') || '';
   const rawText = document.getElementById('raw-text-original');
   const rawText = document.getElementById('raw-text-original');
   if (rawText) {
   if (rawText) {
     pageContent = rawText.innerHTML;
     pageContent = rawText.innerHTML;
@@ -313,7 +315,7 @@ if (pageId) {
 if (pagePath) {
 if (pagePath) {
   componentMappings.page = <Page crowi={crowi} crowiRenderer={crowiRenderer} markdown={markdown} pagePath={pagePath} onSaveWithShortcut={saveWithShortcut} />;
   componentMappings.page = <Page crowi={crowi} crowiRenderer={crowiRenderer} markdown={markdown} pagePath={pagePath} onSaveWithShortcut={saveWithShortcut} />;
   componentMappings['revision-path'] = <I18nextProvider i18n={i18n}><RevisionPath pageId={pageId} pagePath={pagePath} crowi={crowi} /></I18nextProvider>;
   componentMappings['revision-path'] = <I18nextProvider i18n={i18n}><RevisionPath pageId={pageId} pagePath={pagePath} crowi={crowi} /></I18nextProvider>;
-  componentMappings['tag-label'] = <I18nextProvider i18n={i18n}><TagLabels crowi={crowi} pageId={pageId} sendTagData={setTagData} /></I18nextProvider>;
+  componentMappings['tag-label'] = <I18nextProvider i18n={i18n}><TagLabels crowi={crowi} pageId={pageId} sendTagData={setTagData} templateTagData={templateTagData} /></I18nextProvider>;
 }
 }
 
 
 Object.keys(componentMappings).forEach((key) => {
 Object.keys(componentMappings).forEach((key) => {

+ 8 - 1
src/client/js/components/Page/TagLabels.jsx

@@ -20,11 +20,17 @@ class TagLabels extends React.Component {
   async componentWillMount() {
   async componentWillMount() {
     // set pageTag on button
     // set pageTag on button
     const pageId = this.props.pageId;
     const pageId = this.props.pageId;
+
     if (pageId) {
     if (pageId) {
       const res = await this.props.crowi.apiGet('/pages.getPageTag', { pageId });
       const res = await this.props.crowi.apiGet('/pages.getPageTag', { pageId });
       this.setState({ tags: res.tags });
       this.setState({ tags: res.tags });
       this.props.sendTagData(res.tags);
       this.props.sendTagData(res.tags);
     }
     }
+    else if (this.props.templateTagData) {
+      const templateTags = this.props.templateTagData.split(',');
+      this.setState({ tags: templateTags });
+      this.props.sendTagData(templateTags);
+    }
   }
   }
 
 
   showEditor() {
   showEditor() {
@@ -51,7 +57,7 @@ class TagLabels extends React.Component {
     }
     }
 
 
     return (
     return (
-      <div className="tag-viewer">
+      <div className={`tag-viewer ${this.props.pageId ? 'existed-page' : 'new-page'}`}>
         {this.state.tags.length === 0 && (
         {this.state.tags.length === 0 && (
           <a className="btn btn-link btn-edit-tags no-tags p-0" onClick={this.showEditor}>
           <a className="btn btn-link btn-edit-tags no-tags p-0" onClick={this.showEditor}>
             { t('Add tags for this page') } <i className="manage-tags ml-2 icon-plus"></i>
             { t('Add tags for this page') } <i className="manage-tags ml-2 icon-plus"></i>
@@ -82,6 +88,7 @@ TagLabels.propTypes = {
   crowi: PropTypes.object.isRequired,
   crowi: PropTypes.object.isRequired,
   pageId: PropTypes.string,
   pageId: PropTypes.string,
   sendTagData: PropTypes.func.isRequired,
   sendTagData: PropTypes.func.isRequired,
+  templateTagData: PropTypes.string,
 };
 };
 
 
 export default withTranslation()(TagLabels);
 export default withTranslation()(TagLabels);

+ 2 - 7
src/client/styles/scss/_on-edit.scss

@@ -117,13 +117,8 @@ body.on-edit {
       }
       }
     }
     }
 
 
-    div#page-tag {
-      display: inline;
-      margin-right: auto;
-
-      .page-tag-form {
-        border-radius: 5px;
-      }
+    .tag-viewer.new-page {
+      display: block;
     }
     }
 
 
     // hide if screen size is less than tablet
     // hide if screen size is less than tablet

+ 4 - 0
src/client/styles/scss/_page.scss

@@ -89,6 +89,10 @@
         }
         }
       }
       }
     }
     }
+
+    .tag-viewer.new-page {
+      display: none;
+    }
   }
   }
 
 
   // alert component settings
   // alert component settings

+ 1 - 0
src/client/styles/scss/_search.scss

@@ -32,6 +32,7 @@
   }
   }
 
 
   .rbt-menu {
   .rbt-menu {
+    max-height: none !important;
     margin-top: 3px;
     margin-top: 3px;
 
 
     li a span {
     li a span {

+ 2 - 2
src/client/styles/scss/_tag.scss

@@ -19,8 +19,8 @@
   }
   }
 }
 }
 
 
-.tags-list {
-  .label.list-tag-count {
+#tags-page {
+  .list-tag-count {
     background: rgba(0, 0, 0, 0.08);
     background: rgba(0, 0, 0, 0.08);
   }
   }
 }
 }

+ 5 - 2
src/server/models/page.js

@@ -916,8 +916,9 @@ module.exports = function(crowi) {
     return assignDecendantsTemplate(decendantsTemplates, newPath);
     return assignDecendantsTemplate(decendantsTemplates, newPath);
   };
   };
 
 
-  const fetchTemplate = (templates, templatePath) => {
+  const fetchTemplate = async(templates, templatePath) => {
     let templateBody;
     let templateBody;
+    let templateTags;
     /**
     /**
      * get children template
      * get children template
      * __tempate: applicable only to immediate decendants
      * __tempate: applicable only to immediate decendants
@@ -932,12 +933,14 @@ module.exports = function(crowi) {
 
 
     if (childrenTemplate) {
     if (childrenTemplate) {
       templateBody = childrenTemplate.revision.body;
       templateBody = childrenTemplate.revision.body;
+      templateTags = await childrenTemplate.findRelatedTagsById();
     }
     }
     else if (decendantsTemplate) {
     else if (decendantsTemplate) {
       templateBody = decendantsTemplate.revision.body;
       templateBody = decendantsTemplate.revision.body;
+      templateTags = await decendantsTemplate.findRelatedTagsById();
     }
     }
 
 
-    return templateBody;
+    return { templateBody, templateTags };
   };
   };
 
 
   /**
   /**

+ 7 - 4
src/server/routes/page.js

@@ -416,10 +416,13 @@ module.exports = function(crowi, app) {
       view = 'customlayout-selector/not_found';
       view = 'customlayout-selector/not_found';
 
 
       // retrieve templates
       // retrieve templates
-      let template = await Page.findTemplate(path);
-      if (template != null) {
-        template = replacePlaceholdersOfTemplate(template, req);
-        renderVars.template = template;
+      const template = await Page.findTemplate(path);
+
+      if (template.templateBody) {
+        const body = replacePlaceholdersOfTemplate(template.templateBody, req);
+        const tags = template.templateTags;
+        renderVars.template = body;
+        renderVars.templateTags = tags;
       }
       }
 
 
       // add scope variables by ancestor page
       // add scope variables by ancestor page

+ 1 - 1
src/server/views/layout-crowi/not_found.html

@@ -10,7 +10,7 @@
       <div>
       <div>
         <div>
         <div>
           <h1 class="title" id="revision-path"></h1>
           <h1 class="title" id="revision-path"></h1>
-          {% if page and not forbidden and not isTrashPage() %}
+          {% if not forbidden and not isTrashPage() %}
             <div id="tag-label"></div>
             <div id="tag-label"></div>
           {% endif %}
           {% endif %}
         </div>
         </div>

+ 1 - 1
src/server/views/layout-growi/widget/header.html

@@ -8,7 +8,7 @@
       </div>
       </div>
       <div class="title-container">
       <div class="title-container">
         <h1 class="title" id="revision-path"></h1>
         <h1 class="title" id="revision-path"></h1>
-        {% if page and not forbidden and not isTrashPage() %}
+        {% if not forbidden and not isTrashPage() %}
           <div id="tag-label"></div>
           <div id="tag-label"></div>
         {% endif %}
         {% endif %}
       </div>
       </div>

+ 1 - 1
src/server/views/layout-kibela/widget/header.html

@@ -7,7 +7,7 @@
     </div>
     </div>
     <div class="title-container">
     <div class="title-container">
       <h1 class="title" id="revision-path"></h1>
       <h1 class="title" id="revision-path"></h1>
-      {% if page and not forbidden and not isTrashPage() %}
+      {% if not forbidden and not isTrashPage() %}
         <div id="tag-label"></div>
         <div id="tag-label"></div>
       {% endif %}
       {% endif %}
     </div>
     </div>

+ 1 - 0
src/server/views/widget/not_found_content.html

@@ -10,6 +10,7 @@
 <div id="content-main" class="content-main content-main-not-found page-list"
 <div id="content-main" class="content-main content-main-not-found page-list"
   data-path="{{ path | preventXss }}"
   data-path="{{ path | preventXss }}"
   data-current-user="{% if user %}{{ user._id.toString() }}{% endif %}"
   data-current-user="{% if user %}{{ user._id.toString() }}{% endif %}"
+  data-template-tags="{{ templateTags | '' }}"
   >
   >
 
 
   {% include 'not_found_tabs.html' %}
   {% include 'not_found_tabs.html' %}