Przeglądaj źródła

change paginate

zahmis 5 lat temu
rodzic
commit
9601b12233

+ 7 - 5
src/client/js/components/PageAttachment.jsx

@@ -39,8 +39,8 @@ class PageAttachment extends React.Component {
 
   async showPage(selectedPage) {
     const { appContainer, pageContainer } = this.props;
-    const { pageId } = pageContainer;
-    const { limit } = this.state.limit;
+    const { pageId } = pageContainer.state;
+    const { limit } = this.state;
     const offset = (selectedPage - 1) * limit;
     const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
     const pagination = res.data.result.pagination;
@@ -55,17 +55,20 @@ class PageAttachment extends React.Component {
 
   async componentDidMount() {
 
+    this.showPage();
+
     const { appContainer } = this.props;
-    const { pageId } = this.props.pageContainer;
+    const { pageId } = this.props.pageContainer.state;
     const { limit } = this.state.limit;
     const offset = 0;
 
     if (!pageId) { return }
+
     const inUse = {};
     const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
     const attachments = res.data.result.attachments;
+    console.log(this.state.totalPages);
 
-    console.log('hoge');
 
     for (const attachment of attachments) {
       inUse[attachment._id] = this.checkIfFileInUse(attachment);
@@ -75,7 +78,6 @@ class PageAttachment extends React.Component {
       inUse,
     });
 
-    this.showPage();
   }
 
   checkIfFileInUse(attachment) {

+ 0 - 8
src/server/models/attachment.js

@@ -65,14 +65,6 @@ module.exports = function(crowi) {
     return attachment;
   };
 
-  attachmentSchema.static.paginateAttachments = function(opts) {
-    const query = {};
-    const options = Object.assign({ populate: 'user', opts });
-    if (options.page == null) {
-      options.page = 1;
-    }
-    return this.paginate(query, options);
-  };
 
   return mongoose.model('Attachment', attachmentSchema);
 };

+ 1 - 1
src/server/routes/apiv3/attachment.js

@@ -54,7 +54,7 @@ module.exports = (crowi) => {
       }
 
       const attachments = await Attachment.find({ page: pageId });
-      const pagination = await Attachment.paginate({}, { queryOptions });
+      const pagination = await Attachment.paginate({ page: pageId }, { queryOptions });
 
       const result = { attachments, pagination };
       return res.apiv3({ result });