Browse Source

Merge pull request #2471 from weseek/create-endpoint2

Create endpoint2
shizuma yoshimatsu 5 years ago
parent
commit
874f6f65f6

+ 1 - 0
resource/locales/en_US/translation.json

@@ -56,6 +56,7 @@
   "Include Subordinated Page": "Include Subordinated Page",
   "All Subordinated Page": "All Subordinated Page",
   "Specify Hierarchy": "Specify Hierarchy",
+  "Submitted the request to create the archive": "Submitted the request to create the archive",
   "username": "Username",
   "Created": "Created",
   "Last updated": "Updated",

+ 1 - 0
resource/locales/ja_JP/translation.json

@@ -56,6 +56,7 @@
   "Include Subordinated Page": "配下ページも含める",
   "All Subordinated Page": "全ての配下ページ",
   "Specify Hierarchy": "階層の深さを指定",
+  "Submitted the request to create the archive": "アーカイブ作成のリクエストを正常に送信しました",
   "username": "ユーザー名",
   "Created": "作成日",
   "Last updated": "最終更新",

+ 30 - 8
src/client/js/components/ArchiveCreateModal.jsx

@@ -4,12 +4,15 @@ import { withTranslation } from 'react-i18next';
 import {
   Modal, ModalHeader, ModalBody, ModalFooter,
 } from 'reactstrap';
+import AppContainer from '../services/AppContainer';
+import { withUnstatedContainers } from './UnstatedUtils';
+import { toastSuccess, toastError } from '../util/apiNotification';
 
 
 const ArchiveCreateModal = (props) => {
-  const { t } = props;
+  const { t, appContainer } = props;
   const [isCommentDownload, setIsCommentDownload] = useState(false);
-  const [isFileDownload, setIsFileDownload] = useState(false);
+  const [isAttachmentFileDownload, setIsAttachmentFileDownload] = useState(false);
   const [isSubordinatedPageDownload, setIsSubordinatedPageDownload] = useState(false);
   const [fileType, setFileType] = useState('markDown');
   const [hierarchyType, setHierarchyType] = useState('allSubordinatedPage');
@@ -19,8 +22,8 @@ const ArchiveCreateModal = (props) => {
     setIsCommentDownload(!isCommentDownload);
   }
 
-  function changeIsFileDownloadHandler() {
-    setIsFileDownload(!isFileDownload);
+  function changeIsAttachmentFileDownloadHandler() {
+    setIsAttachmentFileDownload(!isAttachmentFileDownload);
   }
 
   function changeIsSubordinatedPageDownloadHandler() {
@@ -50,6 +53,23 @@ const ArchiveCreateModal = (props) => {
     setHierarchyValue(hierarchyValue);
   }
 
+  async function done() {
+
+    try {
+      await appContainer.apiv3Post('/page/archive', {
+        isCommentDownload,
+        isAttachmentFileDownload,
+        isSubordinatedPageDownload,
+        fileType,
+        hierarchyType,
+        hierarchyValue,
+      });
+      toastSuccess(t('Submitted the request to create the archive'));
+    }
+    catch (e) {
+      toastError(e);
+    }
+  }
 
   return (
     <Modal isOpen={props.isOpen} toggle={closeModalHandler}>
@@ -120,8 +140,8 @@ const ArchiveCreateModal = (props) => {
             className="custom-control-input"
             id="downloadFile"
             type="checkbox"
-            checked={isFileDownload}
-            onChange={changeIsFileDownloadHandler}
+            checked={isAttachmentFileDownload}
+            onChange={changeIsAttachmentFileDownloadHandler}
           />
           <label className="custom-control-label" htmlFor="downloadFile">
             {t('Include Attachment File')}
@@ -196,7 +216,7 @@ const ArchiveCreateModal = (props) => {
         </div>
       </ModalBody>
       <ModalFooter>
-        <button type="button" className="btn btn-primary">
+        <button type="button" className="btn btn-primary" onClick={done}>
           Done
         </button>
       </ModalFooter>
@@ -204,13 +224,15 @@ const ArchiveCreateModal = (props) => {
   );
 };
 
+const ArchiveCreateModalWrapper = withUnstatedContainers(ArchiveCreateModal, [AppContainer]);
 
 ArchiveCreateModal.propTypes = {
   t: PropTypes.func.isRequired, //  i18next
+  appContainer: PropTypes.instanceOf(AppContainer).isRequired,
   isOpen: PropTypes.bool.isRequired,
   onClose: PropTypes.func,
   path: PropTypes.string.isRequired,
 };
 
 
-export default withTranslation()(ArchiveCreateModal);
+export default withTranslation()(ArchiveCreateModalWrapper);

+ 31 - 0
src/server/routes/apiv3/page.js

@@ -124,6 +124,15 @@ module.exports = (crowi) => {
       body('pageId').isString(),
       body('bool').isBoolean(),
     ],
+
+    archive: [
+      body('isCommentDownload').isBoolean(),
+      body('isAttachmentFileDownload').isBoolean(),
+      body('isSubordinatedPageDownload').isBoolean(),
+      body('fileType').isString().isIn(['pdf', 'markDown']),
+      body('hierarchyType').isString().isIn(['allSubordinatedPage', 'decideHierarchy']),
+      body('hierarchyValue').isNumeric(),
+    ],
   };
 
   /**
@@ -182,5 +191,27 @@ module.exports = (crowi) => {
     return res.apiv3({ result });
   });
 
+  router.post('/archive', accessTokenParser, loginRequired, csrf, validator.archive, apiV3FormValidator, async(req, res) => {
+
+    const {
+      isCommentDownload,
+      isAttachmentFileDownload,
+      isSubordinatedPageDownload,
+      fileType,
+      hierarchyType,
+      hierarchyValue,
+    } = req.body;
+
+
+    console.log(isCommentDownload);
+    console.log(isAttachmentFileDownload);
+    console.log(fileType);
+    console.log(isSubordinatedPageDownload);
+    console.log(hierarchyType);
+    console.log(hierarchyValue);
+
+    return res.apiv3({});
+  });
+
   return router;
 };