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

Merge pull request #1363 from weseek/create-apiV3-update-codehighlight

Create api v3 update codehighlight
Yuki Takei 6 лет назад
Родитель
Сommit
13bc66c018

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

@@ -225,7 +225,12 @@ export default class AdminCustomizeContainer extends Container {
    * @return {Array} Code highlight
    */
   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;
   }
 
   /**

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

@@ -69,6 +69,10 @@ module.exports = (crowi) => {
       body('isEnabledAttachTitleHeader').isBoolean(),
       body('recentCreatedLimit').isInt(),
     ],
+    highlight: [
+      body('highlightJsStyle').isString(),
+      body('highlightJsStyleBorder').isBoolean(),
+    ],
     customizeCss: [
       body('customizeCss').isString(),
     ],
@@ -242,6 +246,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/CustomizeStatus'
+   */
+  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
    *