yusuketk 7 лет назад
Родитель
Сommit
784c9692bb
3 измененных файлов с 31 добавлено и 3 удалено
  1. 10 3
      src/client/js/components/Page/TagLabel.jsx
  2. 1 0
      src/server/routes/index.js
  3. 20 0
      src/server/routes/tag.js

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

@@ -44,9 +44,15 @@ class TagLabel extends React.Component {
     this.setState({ isOpenModal: true });
   }
 
-  handleSubmit() {
-    this.props.sendTagData(this.state.newPageTags);
-    this.setState({ currentPageTags: this.state.newPageTags, isOpenModal: false });
+  async handleSubmit() {
+    if (this.props.isPageEditor) {
+      this.props.sendTagData(this.state.newPageTags);
+      this.setState({ currentPageTags: this.state.newPageTags, isOpenModal: false });
+    }
+    else {
+      await this.props.crowi.apiPost('/tags.update', { pageId: this.props.pageId, tags: this.state.newPageTags });
+      this.setState({ currentPageTags: this.state.newPageTags, isOpenModal: false });
+    }
   }
 
   render() {
@@ -97,6 +103,7 @@ TagLabel.propTypes = {
   crowi: PropTypes.object.isRequired,
   pageId: PropTypes.string,
   sendTagData: PropTypes.func.isRequired,
+  isPageEditor: PropTypes.bool,
 };
 
 export default withTranslation()(TagLabel);

+ 1 - 0
src/server/routes/index.js

@@ -205,6 +205,7 @@ module.exports = function(crowi, app) {
   app.get('/tags'                     , loginRequired(crowi, app, false), tag.showPage);
   app.get('/_api/tags.list'           , accessTokenParser, loginRequired(crowi, app, false), tag.api.list);
   app.get('/_api/tags.search'         , accessTokenParser, loginRequired(crowi, app, false), tag.api.search);
+  app.post('/_api/tags.update'         , accessTokenParser, loginRequired(crowi, app, false), tag.api.update);
   app.get('/_api/comments.get'        , accessTokenParser , loginRequired(crowi, app, false) , comment.api.get);
   app.post('/_api/comments.add'       , form.comment, accessTokenParser , loginRequired(crowi, app) , csrf, comment.api.add);
   app.post('/_api/comments.remove'    , accessTokenParser , loginRequired(crowi, app) , csrf, comment.api.remove);

+ 20 - 0
src/server/routes/tag.js

@@ -25,6 +25,26 @@ module.exports = function(crowi, app) {
     return res.json(ApiResponse.success({ tags }));
   };
 
+  /**
+   * @api {post} /tags.update update tags
+   * @apiName UpdateTag
+   * @apiGroup Tag
+   *
+   * @apiParam {String} PageId
+   * @apiParam {array} tags
+   */
+  api.update = async function(req, res) {
+    const Page = crowi.model('Page');
+    try {
+      const page = await Page.findById(req.body.pageId);
+      await page.updateTags(req.body.tags);
+    }
+    catch (err) {
+      return res.json(ApiResponse.error(err));
+    }
+    return res.json(ApiResponse.success());
+  };
+
   /**
    * @api {get} /tags.list get tagnames and count pages relate each tag
    * @apiName tagList