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

add prefix filter when search tags

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

+ 1 - 1
src/client/js/components/Page/EditTagModal.jsx

@@ -49,7 +49,7 @@ export default class EditTagModal extends React.Component {
 
   handleSubmit() {
     try {
-      this.props.crowi.apiPost('/pages.updateTags', { pageId: this.props.pageId, newTags: this.state.newPageTags });
+      this.props.crowi.apiPost('/pages.updateTags', { pageId: this.props.pageId, newPageTags: this.state.newPageTags });
       this.setState({ currentPageTags: this.state.newPageTags, isOpenModal: false });
       toastr.success(undefined, 'Updated tags successfully', {
         closeButton: true,

+ 3 - 3
src/server/routes/page.js

@@ -676,15 +676,15 @@ module.exports = function(crowi, app) {
    * @apiGroup Page
    *
    * @apiParam {ObjectId} pageId
-   * @apiParam {Array} pageTags
+   * @apiParam {Array} newPageTags
    */
   api.updateTags = async function(req, res) {
     const pageId = req.body.pageId;
-    const newTags = req.body.newTags;
+    const newPageTags = req.body.newPageTags;
     try {
       const page = await Page.findOne({ _id: pageId });
       // update page tag
-      await page.updateTags(newTags);
+      await page.updateTags(newPageTags);
     }
     catch (err) {
       throw new Error('Error occured on updating tags');

+ 1 - 1
src/server/routes/tag.js

@@ -17,7 +17,7 @@ module.exports = function(crowi, app) {
    * @apiParam {String} q keyword
    */
   api.search = async function(req, res) {
-    let tags = await Tag.find({}).select('-_id name');
+    let tags = await Tag.find({ name: new RegExp(`^${req.query.q}`) }).select('-_id name');
     tags = tags.map((tag) => { return tag.name });
     return res.json(ApiResponse.success({ tags }));
   };