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

hand out globalNotification from sever into client

itizawa 6 лет назад
Родитель
Сommit
da2ee00ea3

+ 20 - 28
src/client/js/components/Admin/Notification/ManageGlobalNotification.jsx

@@ -18,33 +18,20 @@ class ManageGlobalNotification extends React.Component {
   constructor() {
     super();
 
+    const globalNotification = JSON.parse(document.getElementById('admin-global-notification-setting').getAttribute('data-global-notification'));
+
     this.state = {
-      retrieveError: null,
-      triggerPath: '',
-      notifyToType: 'mail',
-      emailToSend: '',
-      slackChannelToSend: '',
-      triggerEvents: new Set([]),
+      globalNotificationId: globalNotification._id || null,
+      triggerPath: globalNotification.triggerPath || '',
+      notifyToType: globalNotification.__t || 'mail',
+      emailToSend: globalNotification.toEmail || '',
+      slackChannelToSend: globalNotification.slackChannels || '',
+      triggerEvents: new Set(globalNotification.triggerEvents),
     };
 
     this.submitHandler = this.submitHandler.bind(this);
   }
 
-  componentDidMount() {
-    this.retrieveTriggerEvent();
-  }
-
-  async retrieveTriggerEvent() {
-    try {
-      // TODO GW-913 create apiV3
-    }
-    catch (err) {
-      toastError(err);
-      logger.error(err);
-      this.setState({ retrieveError: err });
-    }
-  }
-
   onChangeTriggerPath(inputValue) {
     this.setState({ triggerPath: inputValue });
   }
@@ -77,13 +64,18 @@ class ManageGlobalNotification extends React.Component {
   async submitHandler() {
 
     try {
-      await this.props.appContainer.apiv3.post('/notification-setting/global-notification', {
-        triggerPath: this.state.triggerPath,
-        notifyToType: this.state.notifyToType,
-        toEmail: this.state.emailToSend,
-        slackChannels: this.state.slackChannelToSend,
-        triggerEvents: [...this.state.triggerEvents],
-      });
+      if (this.state.globalNotificationId != null) {
+        // TODO put
+      }
+      else {
+        await this.props.appContainer.apiv3.post('/notification-setting/global-notification', {
+          triggerPath: this.state.triggerPath,
+          notifyToType: this.state.notifyToType,
+          toEmail: this.state.emailToSend,
+          slackChannels: this.state.slackChannelToSend,
+          triggerEvents: [...this.state.triggerEvents],
+        });
+      }
     }
     catch (err) {
       toastError(err);

+ 3 - 3
src/server/routes/admin.js

@@ -267,18 +267,18 @@ module.exports = function(crowi, app) {
   actions.globalNotification = {};
   actions.globalNotification.detail = async(req, res) => {
     const notificationSettingId = req.params.id;
-    const renderVars = {};
+    let globalNotification;
 
     if (notificationSettingId) {
       try {
-        renderVars.setting = await GlobalNotificationSetting.findOne({ _id: notificationSettingId });
+        globalNotification = await GlobalNotificationSetting.findOne({ _id: notificationSettingId });
       }
       catch (err) {
         logger.error(`Error in finding a global notification setting with {_id: ${notificationSettingId}}`);
       }
     }
 
-    return res.render('admin/global-notification-detail', renderVars);
+    return res.render('admin/global-notification-detail', { globalNotification });
   };
 
   actions.globalNotification.create = (req, res) => {

+ 3 - 1
src/server/views/admin/global-notification-detail.html

@@ -31,7 +31,9 @@
       {% include './widget/menu.html' with {current: 'notification'} %}
     </div>
 
-    <div class="col-md-9" id="admin-global-notification-setting" />
+    <div class="col-md-9" id="admin-global-notification-setting"
+      data-global-notification="{{ globalNotification|json }}">
+    </div>
     <!-- <a href="/admin/notification#global-notification" class="btn btn-default">
         <i class="icon-fw ti-arrow-left" aria-hidden="true"></i>
         {{ t('notification_setting.back_to_list') }}