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

imprv/115673-128224-create-presentationfile15.2

Meiri Kikuta 2 лет назад
Родитель
Сommit
4c88dce17d

+ 3 - 22
apps/app/src/client/services/AdminCustomizeContainer.js

@@ -204,7 +204,6 @@ export default class AdminCustomizeContainer extends Container {
         isEnabledStaleNotification: this.state.isEnabledStaleNotification,
         isAllReplyShown: this.state.isAllReplyShown,
         isSearchScopeChildrenAsDefault: this.state.isSearchScopeChildrenAsDefault,
-        isEnabledMarp: this.state.isEnabledMarp,
       });
       const { customizedParams } = response.data;
       this.setState({
@@ -217,7 +216,6 @@ export default class AdminCustomizeContainer extends Container {
         isEnabledStaleNotification: customizedParams.isEnabledStaleNotification,
         isAllReplyShown: customizedParams.isAllReplyShown,
         isSearchScopeChildrenAsDefault: customizedParams.isSearchScopeChildrenAsDefault,
-        isEnabledMarp: customizedParams.state.isEnabledMarp,
       });
     }
     catch (err) {
@@ -226,35 +224,18 @@ export default class AdminCustomizeContainer extends Container {
     }
   }
   /**
-   * Update function
+   * Update presentation
    * @memberOf AdminCustomizeContainer
    */
   async updateCustomizePresentation() {
     try {
       const response = await apiv3Put('/customize-setting/presentation', {
-        isEnabledTimeline: this.state.isEnabledTimeline,
-        isEnabledAttachTitleHeader: this.state.isEnabledAttachTitleHeader,
-        pageLimitationS: this.state.pageLimitationS,
-        pageLimitationM: this.state.pageLimitationM,
-        pageLimitationL: this.state.pageLimitationL,
-        pageLimitationXL: this.state.pageLimitationXL,
-        isEnabledStaleNotification: this.state.isEnabledStaleNotification,
-        isAllReplyShown: this.state.isAllReplyShown,
-        isSearchScopeChildrenAsDefault: this.state.isSearchScopeChildrenAsDefault,
         isEnabledMarp: this.state.isEnabledMarp,
       });
+
       const { customizedParams } = response.data;
       this.setState({
-        isEnabledTimeline: customizedParams.isEnabledTimeline,
-        isEnabledAttachTitleHeader: customizedParams.isEnabledAttachTitleHeader,
-        pageLimitationS: customizedParams.pageLimitationS,
-        pageLimitationM: customizedParams.pageLimitationM,
-        pageLimitationL: customizedParams.pageLimitationL,
-        pageLimitationXL: customizedParams.pageLimitationXL,
-        isEnabledStaleNotification: customizedParams.isEnabledStaleNotification,
-        isAllReplyShown: customizedParams.isAllReplyShown,
-        isSearchScopeChildrenAsDefault: customizedParams.isSearchScopeChildrenAsDefault,
-        isEnabledMarp: customizedParams.state.isEnabledMarp,
+        isEnabledMarp: customizedParams.isEnabledMarp,
       });
     }
     catch (err) {

+ 1 - 1
apps/app/src/components/Admin/Customize/Customize.jsx

@@ -15,7 +15,7 @@ import CustomizeFunctionSetting from './CustomizeFunctionSetting';
 import CustomizeLayoutSetting from './CustomizeLayoutSetting';
 import CustomizeLogoSetting from './CustomizeLogoSetting';
 import CustomizeNoscriptSetting from './CustomizeNoscriptSetting';
-import { CustomizePresentationSetting } from './CustomizePresentationSetting';
+import CustomizePresentationSetting from './CustomizePresentationSetting';
 import CustomizeScriptSetting from './CustomizeScriptSetting';
 import CustomizeSidebarSetting from './CustomizeSidebarSetting';
 import CustomizeThemeSetting from './CustomizeThemeSetting';

+ 10 - 6
apps/app/src/components/Admin/Customize/CustomizePresentationSetting.tsx

@@ -1,6 +1,6 @@
 import React, { useCallback } from 'react';
 
-import { t } from 'i18next';
+import { useTranslation } from 'next-i18next';
 
 import AdminCustomizeContainer from '~/client/services/AdminCustomizeContainer';
 import { toastSuccess, toastError } from '~/client/util/toastr';
@@ -14,12 +14,16 @@ type Props = {
   adminCustomizeContainer: AdminCustomizeContainer
 }
 
-export const CustomizePresentationSetting = (props: Props): JSX.Element => {
+const CustomizePresentationSetting = (props: Props): JSX.Element => {
   const { adminCustomizeContainer } = props;
+
+  console.log(adminCustomizeContainer);
+
+  const { t } = useTranslation();
   const onClickSubmit = useCallback(async() => {
     try {
-      await adminCustomizeContainer.updateCustomizeFunction();
-      toastSuccess(t('toaster.update_successed', { target: t('admin:customize_settings.function'), ns: 'commons' }));
+      await adminCustomizeContainer.updateCustomizePresentation();
+      toastSuccess(t('toaster.update_successed', { target: t('admin:customize_settings.presentation'), ns: 'commons' }));
     }
     catch (err) {
       toastError(err);
@@ -27,12 +31,12 @@ export const CustomizePresentationSetting = (props: Props): JSX.Element => {
   }, [adminCustomizeContainer]);
   return (
     <React.Fragment>
-      <h2 className="admin-setting-header">{t('presentation')}</h2>
+      <h2 className="admin-setting-header">{t('admin:customize_settings.custom_presentation')}</h2>
       <div className="form-group row">
         <div className="offset-md-3 col-md-6 text-left">
           <CustomizePresentationOption
             optionId="isEnabledMarp"
-            label={t('admin:customize_settings.function_options.enable_marp')}
+            label={t('admin:customize_settings.presentation_options.enable_marp')}
             isChecked={adminCustomizeContainer?.state.isEnabledMarp || false}
             onChecked={() => { adminCustomizeContainer.switchIsEnabledMarp() }}
           >

+ 22 - 0
apps/app/src/server/routes/apiv3/customize-setting.js

@@ -442,6 +442,28 @@ module.exports = (crowi) => {
     }
   });
 
+
+  router.put('/presentation', loginRequiredStrictly, adminRequired, addActivity, validator.CustomizePresentation, apiV3FormValidator, async(req, res) => {
+    const requestParams = {
+      'customize:isEnabledMarp': req.body.isEnabledMarp,
+    };
+
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
+      const customizedParams = {
+        isEnabledMarp: await crowi.configManager.getConfig('crowi', 'customize:isEnabledMarp'),
+      };
+      const parameters = { action: SupportedAction.ACTION_ADMIN_FUNCTION_UPDATE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+      return res.apiv3({ customizedParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating presentaion';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-presentation-failed'));
+    }
+  });
+
   /**
    * @swagger
    *