Parcourir la source

Merge branch 'feat/transplant-tabs-to-modal-for-master-merge' into imprv/transplant-gw3702

# Conflicts:
#	src/client/js/components/PageTimeline.jsx
白石誠 il y a 5 ans
Parent
commit
151423c0f6

+ 52 - 20
src/client/js/components/PageTimeline.jsx

@@ -5,6 +5,7 @@ import { withTranslation } from 'react-i18next';
 
 import AppContainer from '../services/AppContainer';
 import PageContainer from '../services/PageContainer';
+import PaginationWrapper from './PaginationWrapper';
 import { withUnstatedContainers } from './UnstatedUtils';
 
 import RevisionLoader from './Page/RevisionLoader';
@@ -15,18 +16,39 @@ class PageTimeline extends React.Component {
   constructor(props) {
     super(props);
     this.showPages = this.showPages.bind(this);
+    this.handlePage = this.handlePage.bind(this);
     this.state = {
+<<<<<<< HEAD
       pages: [],
+=======
+      activePage: 1,
+      totalPages: 0,
+      limit: appContainer.getConfig().recentCreatedLimit,
+      isEnabled: appContainer.getConfig().isEnabledTimeline,
+      // TODO: remove after when timeline is implemented with React and inject data with props
+      pages: this.props.pages,
+>>>>>>> feat/transplant-tabs-to-modal-for-master-merge
     };
 
   }
 
-  async showPages() {
+  async handlePage(selectedPage) {
+    await this.showPages(selectedPage);
+  }
+
+  async showPages(selectedPage) {
     const { appContainer, pageContainer } = this.props;
     const { path } = pageContainer.state;
-    const res = await appContainer.apiv3Get('/pages/list', { path });
+    const limit = this.state.limit;
+    const offset = (selectedPage - 1) * limit;
+    const res = await appContainer.apiv3Get('/pages/list', { path, limit, offset });
+    const activePage = selectedPage;
+    const totalPages = res.data.totalCount;
+    const pages = res.data.pages;
     this.setState({
-      pages: res.data.pages,
+      activePage,
+      totalPages,
+      pages,
     });
   }
 
@@ -35,7 +57,7 @@ class PageTimeline extends React.Component {
 
     // initialize GrowiRenderer
     this.growiRenderer = appContainer.getRenderer('timeline');
-    this.showPages();
+    this.showPages(1);
   }
 
   render() {
@@ -45,23 +67,33 @@ class PageTimeline extends React.Component {
       return <React.Fragment></React.Fragment>;
     }
 
-    return pages.map((page) => {
-      return (
-        <div className="timeline-body" key={`key-${page.id}`}>
-          <div className="card card-timeline">
-            <div className="card-header"><a href={page.path}>{page.path}</a></div>
-            <div className="card-body">
-              <RevisionLoader
-                lazy
-                growiRenderer={this.growiRenderer}
-                pageId={page.id}
-                revisionId={page.revision}
-              />
+    return (
+      <div>
+        { pages.map((page) => {
+          return (
+            <div className="timeline-body" key={`key-${page.id}`}>
+              <div className="card card-timeline">
+                <div className="card-header"><a href={page.path}>{page.path}</a></div>
+                <div className="card-body">
+                  <RevisionLoader
+                    lazy
+                    growiRenderer={this.growiRenderer}
+                    pageId={page.id}
+                    revisionId={page.revision}
+                  />
+                </div>
+              </div>
             </div>
-          </div>
-        </div>
-      );
-    });
+          );
+        }) }
+        <PaginationWrapper
+          activePage={this.state.activePage}
+          changePage={this.handlePage}
+          totalItemsCount={this.state.totalPages}
+          pagingLimit={this.state.limit}
+        />
+      </div>
+    );
 
   }
 

+ 38 - 0
src/migrations/20200903080025-remove-timeline-type.js.js

@@ -0,0 +1,38 @@
+require('module-alias/register');
+const logger = require('@alias/logger')('growi:migrate:remove-behavior-type');
+
+const mongoose = require('mongoose');
+const config = require('@root/config/migrate');
+
+const { getModelSafely } = require('@commons/util/mongoose-utils');
+
+module.exports = {
+  async up(db, client) {
+    logger.info('Apply migration');
+    mongoose.connect(config.mongoUri, config.mongodb.options);
+
+    const Config = getModelSafely('Config') || require('@server/models/config')();
+
+    await Config.findOneAndDelete({ key: 'customize:timeline' }); // remove timeline
+
+    logger.info('Migration has successfully applied');
+  },
+
+  async down(db, client) {
+    // do not rollback
+    logger.info('Rollback migration');
+    mongoose.connect(config.mongoUri, config.mongodb.options);
+
+    const Config = getModelSafely('Config') || require('@server/models/config')();
+
+    const insertConfig = new Config({
+      ns: 'crowi',
+      key: 'customize:timeline',
+      value: true,
+    });
+
+    await insertConfig.save();
+
+    logger.info('Migration has been successfully rollbacked');
+  },
+};