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

Merge pull request #910 from weseek/add-TagLabel

Add tag label
Yuki Takei 7 лет назад
Родитель
Сommit
859afde6c9

+ 1 - 0
resource/locales/ja/translation.json

@@ -112,6 +112,7 @@
   "Shareable link": "このページの共有用URL",
   "Shareable link": "このページの共有用URL",
   "The whitelist of registration permission E-mail address": "登録許可メールアドレスの<br>ホワイトリスト",
   "The whitelist of registration permission E-mail address": "登録許可メールアドレスの<br>ホワイトリスト",
   "Selecting authentication mechanism": "認証機構選択",
   "Selecting authentication mechanism": "認証機構選択",
+  "Add tags for this page": "タグを付ける",
 
 
 
 
 
 

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

@@ -32,7 +32,7 @@ import CommentForm from './components/PageComment/CommentForm';
 import PageAttachment from './components/PageAttachment';
 import PageAttachment from './components/PageAttachment';
 import PageStatusAlert from './components/PageStatusAlert';
 import PageStatusAlert from './components/PageStatusAlert';
 import RevisionPath from './components/Page/RevisionPath';
 import RevisionPath from './components/Page/RevisionPath';
-import TagViewer from './components/Page/TagViewer';
+import TagLabel from './components/Page/TagLabel';
 import RevisionUrl from './components/Page/RevisionUrl';
 import RevisionUrl from './components/Page/RevisionUrl';
 import BookmarkButton from './components/BookmarkButton';
 import BookmarkButton from './components/BookmarkButton';
 import LikeButton from './components/LikeButton';
 import LikeButton from './components/LikeButton';
@@ -313,8 +313,9 @@ 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'] = <RevisionPath pagePath={pagePath} crowi={crowi} />;
   componentMappings['revision-path'] = <RevisionPath pagePath={pagePath} crowi={crowi} />;
-  componentMappings['tag-viewer'] = <TagViewer crowi={crowi} pageId={pageId} sendTagData={setTagData} />;
-  componentMappings['revision-url'] = <RevisionUrl pageId={pageId} pagePath={pagePath} />;
+  // [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>;
 }
 }
 
 
 Object.keys(componentMappings).forEach((key) => {
 Object.keys(componentMappings).forEach((key) => {

+ 27 - 32
src/client/js/components/Page/TagViewer.jsx → src/client/js/components/Page/TagLabel.jsx

@@ -1,16 +1,11 @@
 import React from 'react';
 import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
+import { withTranslation } from 'react-i18next';
 import Button from 'react-bootstrap/es/Button';
 import Button from 'react-bootstrap/es/Button';
-import OverlayTrigger from 'react-bootstrap/es/OverlayTrigger';
-import Tooltip from 'react-bootstrap/es/Tooltip';
 import Modal from 'react-bootstrap/es/Modal';
 import Modal from 'react-bootstrap/es/Modal';
 import PageTagForm from '../PageTagForm';
 import PageTagForm from '../PageTagForm';
 
 
-/**
- * show tag labels on view and edit tag button on edit
- * tag labels on view is not implemented yet(GC-1391)
- */
-export default class TagViewer extends React.Component {
+class TagLabel extends React.Component {
 
 
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
@@ -37,7 +32,6 @@ export default class TagViewer extends React.Component {
     }
     }
   }
   }
 
 
-  // receive new tag from PageTagForm component
   addNewTag(newPageTags) {
   addNewTag(newPageTags) {
     this.setState({ newPageTags });
     this.setState({ newPageTags });
   }
   }
@@ -56,31 +50,29 @@ export default class TagViewer extends React.Component {
   }
   }
 
 
   render() {
   render() {
-    const tagEditorButtonStyle = {
-      marginLeft: '0.2em',
-      padding: '0 2px',
-    };
+    const tags = [];
+    const { t } = this.props;
+
+    for (let i = 0; i < this.state.currentPageTags.length; i++) {
+      tags.push(
+        <i className="tag-icon icon-tag"></i>,
+        <a className="tag-name text-muted" href={`/_search?q=tag:${this.state.currentPageTags[i]}`} key={i.toString()}>{this.state.currentPageTags[i]}</a>,
+      );
+
+    }
 
 
     return (
     return (
-      <span className="btn-tag-container">
-        <OverlayTrigger
-          key="tooltip"
-          placement="bottom"
-          overlay={(
-            <Tooltip id="tag-edit-button-tooltip" className="tag-tooltip">
-              {this.state.currentPageTags.length !== 0 ? this.state.currentPageTags.join() : 'tag is not set' }
-            </Tooltip>
-          )}
+      <div className="tag-viewer text-muted">
+        {this.state.currentPageTags.length === 0 && (
+          <a className="display-of-notag text-muted" onClick={this.handleShowModal}>{ t('Add tags for this page') }</a>
+        )}
+        {tags}
+        <i
+          className="manage-tags icon-plus"
+          onClick={this.handleShowModal}
+
         >
         >
-          <Button
-            variant="primary"
-            onClick={this.handleShowModal}
-            className="btn btn-default btn-tag"
-            style={tagEditorButtonStyle}
-          >
-            <i className="fa fa-tags"></i>{this.state.currentPageTags.length}
-          </Button>
-        </OverlayTrigger>
+        </i>
         <Modal show={this.state.isOpenModal} onHide={this.handleCloseModal} id="editTagModal">
         <Modal show={this.state.isOpenModal} onHide={this.handleCloseModal} id="editTagModal">
           <Modal.Header closeButton className="bg-primary">
           <Modal.Header closeButton className="bg-primary">
             <Modal.Title className="text-white">Page Tag</Modal.Title>
             <Modal.Title className="text-white">Page Tag</Modal.Title>
@@ -94,14 +86,17 @@ export default class TagViewer extends React.Component {
             </Button>
             </Button>
           </Modal.Footer>
           </Modal.Footer>
         </Modal>
         </Modal>
-      </span>
+      </div>
     );
     );
   }
   }
 
 
 }
 }
 
 
-TagViewer.propTypes = {
+TagLabel.propTypes = {
+  t: PropTypes.func.isRequired, // i18next
   crowi: PropTypes.object.isRequired,
   crowi: PropTypes.object.isRequired,
   pageId: PropTypes.string,
   pageId: PropTypes.string,
   sendTagData: PropTypes.func.isRequired,
   sendTagData: PropTypes.func.isRequired,
 };
 };
+
+export default withTranslation()(TagLabel);

+ 25 - 0
src/client/styles/scss/_tag.scss

@@ -0,0 +1,25 @@
+.manage-tags {
+  margin-left: 5px;
+  font-size: 12px;
+  cursor: pointer;
+}
+
+.tag-icon:not(:first-child) {
+  margin-left: 5px;
+}
+
+.display-of-notag,
+.tag-icon {
+  font-size: 10px;
+}
+
+.tag-name {
+  margin-left: 1px;
+  font-size: 10px;
+}
+
+#editTagModal {
+  .form-control {
+    height: auto;
+  }
+}

+ 4 - 0
src/client/styles/scss/style-app.scss

@@ -39,6 +39,7 @@
 @import 'user_growi';
 @import 'user_growi';
 @import 'handsontable';
 @import 'handsontable';
 @import 'wiki';
 @import 'wiki';
+@import 'tag';
 
 
 /*
 /*
  * for Guest User Mode
  * for Guest User Mode
@@ -64,14 +65,17 @@
     width: 48px;
     width: 48px;
     height: 48px;
     height: 48px;
   }
   }
+
   &.picture-md {
   &.picture-md {
     width: 24px;
     width: 24px;
     height: 24px;
     height: 24px;
   }
   }
+
   &.picture-sm {
   &.picture-sm {
     width: 18px;
     width: 18px;
     height: 18px;
     height: 18px;
   }
   }
+
   &.picture-xs {
   &.picture-xs {
     width: 14px;
     width: 14px;
     height: 14px;
     height: 14px;

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

@@ -8,9 +8,11 @@
       </div>
       </div>
       <div class="title-container">
       <div class="title-container">
         <h1 class="title" id="revision-path"></h1>
         <h1 class="title" id="revision-path"></h1>
-        {# [TODO] GC-1391 activate #}
-        {# <h1 class="title" id="tag-viewer"></h1> #}
-        <div id="revision-url" class="url-line"></div>
+
+        <!-- [TODO] commentout Until the destination is decided -->
+        <!-- <div id="revision-url" class="url-line"></div> -->
+        <div class="title" id="tag-label"></div>
+
       </div>
       </div>
       {% if page %}
       {% if page %}
       {% include '../../widget/header-buttons.html' %}
       {% include '../../widget/header-buttons.html' %}