yusuketk 7 лет назад
Родитель
Сommit
0ab454f60f

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

@@ -71,6 +71,7 @@ let pageContent = '';
 let markdown = '';
 let slackChannels;
 let pageTags = [];
+let templateTags = '';
 if (mainContent !== null) {
   pageId = mainContent.getAttribute('data-page-id') || null;
   pageRevisionId = mainContent.getAttribute('data-page-revision-id');
@@ -80,6 +81,7 @@ if (mainContent !== null) {
   hasDraftOnHackmd = !!mainContent.getAttribute('data-page-has-draft-on-hackmd');
   pagePath = mainContent.attributes['data-path'].value;
   slackChannels = mainContent.getAttribute('data-slack-channels') || '';
+  templateTags = mainContent.getAttribute('data-template-tags') || '';
   const rawText = document.getElementById('raw-text-original');
   if (rawText) {
     pageContent = rawText.innerHTML;
@@ -315,7 +317,7 @@ if (pagePath) {
   componentMappings['revision-path'] = <RevisionPath pagePath={pagePath} crowi={crowi} />;
   // [TODO] there is a need to decide the destination of RevisionUrl
   componentMappings['revision-url'] = <RevisionUrl crowi={crowi} pageId={pageId} pagePath={pagePath} sendTagData={setTagData} />;
-  componentMappings['tag-label'] = <I18nextProvider i18n={i18n}><TagLabel crowi={crowi} pageId={pageId} sendTagData={setTagData} /></I18nextProvider>;
+  componentMappings['tag-label'] = <I18nextProvider i18n={i18n}><TagLabel crowi={crowi} pageId={pageId} sendTagData={setTagData} templateTags={templateTags} /></I18nextProvider>;
 }
 
 Object.keys(componentMappings).forEach((key) => {

+ 9 - 3
src/client/js/components/Page/TagLabel.jsx

@@ -23,13 +23,18 @@ class TagLabel extends React.Component {
   }
 
   async componentWillMount() {
-    // set pageTag on button
+    // set default pageTag on button
+    let tags = this.props.templateTags.split(',') || [];
+
+    // tags of existed page override template tags
     const pageId = this.props.pageId;
     if (pageId) {
       const res = await this.props.crowi.apiGet('/pages.getPageTag', { pageId });
-      this.setState({ currentPageTags: res.tags });
-      this.props.sendTagData(res.tags);
+      tags = res.tags;
     }
+
+    this.setState({ currentPageTags: tags });
+    this.props.sendTagData(tags);
   }
 
   addNewTag(newPageTags) {
@@ -97,6 +102,7 @@ TagLabel.propTypes = {
   crowi: PropTypes.object.isRequired,
   pageId: PropTypes.string,
   sendTagData: PropTypes.func.isRequired,
+  templateTags: PropTypes.string,
 };
 
 export default withTranslation()(TagLabel);

+ 4 - 1
src/server/models/page.js

@@ -918,6 +918,7 @@ module.exports = function(crowi) {
 
   const fetchTemplate = async(templates, templatePath) => {
     let templateBody;
+    let templateTags;
     /**
      * get children template
      * __tempate: applicable only to immediate decendants
@@ -937,7 +938,9 @@ module.exports = function(crowi) {
       templateBody = decendantsTemplate.revision.body;
     }
 
-    const templateTags = await templates[0].getRelatedTagsById();
+    if (templates > 0) {
+      templateTags = await templates[0].getRelatedTagsById();
+    }
 
     return { templateBody, templateTags };
   };

+ 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"
   data-path="{{ path | preventXss }}"
   data-current-user="{% if user %}{{ user._id.toString() }}{% endif %}"
+  data-template-tags="{{ templateTags | '' }}"
   >
 
   {% include 'not_found_tabs.html' %}