Explorar el Código

Merge branch 'reactify-admin/CustomizePage' into create-api-v3-update-custom-header

# Conflicts:
#	src/server/routes/apiv3/customize-setting.js
itizawa hace 6 años
padre
commit
30a93affe9

+ 6 - 1
src/client/js/services/AdminCustomizeContainer.js

@@ -225,7 +225,12 @@ export default class AdminCustomizeContainer extends Container {
    * @return {Array} Code highlight
    * @return {Array} Code highlight
    */
    */
   async updateHighlightJsStyle() {
   async updateHighlightJsStyle() {
-    // TODO GW-515 create apiV3
+    const response = await this.appContainer.apiv3.put('/customize-setting/highlight', {
+      highlightJsStyle: this.state.currentHighlightJsStyleId,
+      highlightJsStyleBorder: this.state.isHighlightJsStyleBorderEnabled,
+    });
+    const { customizedParams } = response.data;
+    return customizedParams;
   }
   }
 
 
   /**
   /**

+ 61 - 0
src/server/routes/apiv3/customize-setting.js

@@ -42,6 +42,12 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
  *            type: boolean
  *            type: boolean
  *          recentCreatedLimit:
  *          recentCreatedLimit:
  *            type: number
  *            type: number
+ *      CustomizeHighlight:
+ *        type: object
+ *          styleName:
+ *            type: string
+ *          styleBorder:
+ *            type: boolean
  *      CustomizeHeader:
  *      CustomizeHeader:
  *        type: object
  *        type: object
  *          customizeHeader:
  *          customizeHeader:
@@ -80,6 +86,10 @@ module.exports = (crowi) => {
     customizeHeader: [
     customizeHeader: [
       body('customizeHeader').isString(),
       body('customizeHeader').isString(),
     ],
     ],
+    highlight: [
+      body('highlightJsStyle').isString(),
+      body('highlightJsStyleBorder').isBoolean(),
+    ],
     customizeCss: [
     customizeCss: [
       body('customizeCss').isString(),
       body('customizeCss').isString(),
     ],
     ],
@@ -253,6 +263,57 @@ module.exports = (crowi) => {
     }
     }
   });
   });
 
 
+  /**
+   * @swagger
+   *
+   *    /customize-setting/highlight:
+   *      put:
+   *        tags: [CustomizeSetting]
+   *        description: Update highlight
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schama:
+   *                type: object
+   *                properties:
+   *                  highlightJsStyle:
+   *                    description: style name of highlight
+   *                    type: string
+   *                  highlightJsStyleBorder:
+   *                    description: enable border of highlight
+   *                    type: boolean
+   *      responses:
+   *          200:
+   *            description: Succeeded to update highlight
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    customizedParams:
+   *                      $ref: '#/components/schemas/CustomizeHighlight'
+   */
+  router.put('/highlight', loginRequiredStrictly, adminRequired, csrf, validator.highlight, ApiV3FormValidator, async(req, res) => {
+    const requestParams = {
+      'customize:highlightJsStyle': req.body.highlightJsStyle,
+      'customize:highlightJsStyleBorder': req.body.highlightJsStyleBorder,
+    };
+
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
+      const customizedParams = {
+        styleName: await crowi.configManager.getConfig('crowi', 'customize:highlightJsStyle'),
+        styleBorder: await crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
+      };
+      return res.apiv3({ customizedParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating highlight';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-highlight-failed'));
+    }
+  });
+
   /**
   /**
    * @swagger
    * @swagger
    *
    *