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

GW 36 wip updateAfterTagAdded mostly ready

Mao 4 лет назад
Родитель
Сommit
e9789ac9db

+ 6 - 3
packages/app/src/client/services/PageContainer.js

@@ -343,10 +343,13 @@ export default class PageContainer extends Container {
     }
   }
 
-  // TODO  : params
+  // TODO : takes tagsRelation/tags models or date
   updateStateAfterTagAdded() {
-    console.log('params to get for updateStateTadAdded is...');
-    // this.setState();
+    // const newState = {
+    //   updatedAt: new Date().getTime(),
+    // };
+    // console.log(`date is :${newState.updatedAt}`);
+    // this.setState(newState);
   }
 
   /**

+ 3 - 6
packages/app/src/components/Page/TagLabels.jsx

@@ -12,7 +12,6 @@ import EditorContainer from '~/client/services/EditorContainer';
 import RenderTagLabels from './RenderTagLabels';
 import TagEditModal from './TagEditModal';
 
-
 class TagLabels extends React.Component {
 
   constructor(props) {
@@ -56,10 +55,10 @@ class TagLabels extends React.Component {
     if (editorMode === 'edit') {
       return editorContainer.setState({ tags: newTags });
     }
-
+    // const newUpdatedAt;
     try {
-      const { tags, updatedBy } = await appContainer.apiPost('/tags.update', { pageId, tags: newTags });
-      console.log(`tags object is :${tags} and ${updatedBy}`);
+      const { tags, updatedAt } = await appContainer.apiPost('/tags.update', { pageId, tags: newTags });
+      // newUpdatedAt = updatedAt;
       // update pageContainer.state
       pageContainer.setState({ tags });
       // update editorContainer.state
@@ -71,8 +70,6 @@ class TagLabels extends React.Component {
       toastError(err, 'fail to update tags');
     }
     pageContainer.updateStateAfterTagAdded();
-    // TODO あとで消す
-    console.log('Tag is added');
   }
 
 

+ 2 - 0
packages/app/src/server/models/page-tag-relation.js

@@ -25,6 +25,8 @@ const schema = new mongoose.Schema({
     ref: 'Tag',
     required: true,
   },
+  created: { type: Date, default: Date.now },
+  updated: { type: Date, default: Date.now },
 });
 // define unique compound index
 schema.index({ relatedPage: 1, relatedTag: 1 }, { unique: true });

+ 6 - 2
packages/app/src/server/routes/tag.js

@@ -140,14 +140,18 @@ module.exports = function(crowi, app) {
     const tagEvent = crowi.event('tag');
     const pageId = req.body.pageId;
     const tags = req.body.tags;
-
+    // TODO : あとで消す
+    // console.log(`tag is : ${tags}`); // thisistag,another-tag,new-tag
     const result = {};
     try {
       // TODO GC-1921 consider permission
       const page = await Page.findById(pageId);
       await PageTagRelation.updatePageTags(pageId, tags);
       result.tags = await PageTagRelation.listTagNamesByPage(pageId);
-      result.updatedBy = 'this is string passed from api.update';
+      // TODO :
+      // 1. find pageTagRelation based on 'tags'
+      // 2. set its updatedAt to result.updatedAt
+      // result.updatedAt = ...
       tagEvent.emit('update', page, tags);
     }
     catch (err) {