Merge "RIFT-14856: launchpad UI - Logging - default category severity"
[osm/UI.git] / skyquake / plugins / logging / src / loggingStore.js
index 860ff9f..d8f0d70 100644 (file)
@@ -26,10 +26,12 @@ class LoggingStore {
     this.loggingConfig = {};
     // initialLoggingConfig is the saved state
     this.initialLoggingConfig = {};
+    this.nulledCategories = [];
     this.bindActions(LoggingActions);
     this.registerAsync(LoggingSource);
     this.exportPublicMethods({
       updateCategoryDefaultSeverity: this.updateCategoryDefaultSeverity,
+      updateCategoryDefaultSyslogSeverity: this.updateCategoryDefaultSyslogSeverity,
       updateAllowDuplicateEvents: this.updateAllowDuplicateEvents,
       addDenyEvent: this.addDenyEvent,
       updateDenyEvent: this.updateDenyEvent,
@@ -97,6 +99,60 @@ class LoggingStore {
     }
   }
 
+  updateCategoryDefaultSyslogSeverity = (catsev) => {
+    console.log("LoggingStore.updateCategoryDefaultSyslogSeverity:", catsev);
+    // find the category (name) in the syslog sink
+
+    let self = this;
+    let loggingConfig = _.cloneDeep(this.loggingConfig);
+    let syslogSinkIndex = -1;
+    let nulledCategories = this.nulledCategories;
+
+    loggingConfig.sinks && loggingConfig.sinks.map((sink, sinkIndex) => {
+      if (sink.name == 'syslog') {
+        if (sink.filter) {
+          if (sink.filter.category) {
+            let catIndex = _.findIndex(sink.filter.category, {
+              name: catsev.name
+            });
+            if (catIndex != -1) {
+              // found it
+              if (catsev.severity == "") {
+                // blank was selected
+                nulledCategories.push(catsev.name);
+                this.setState({
+                  nulledCategories: nulledCategories
+                });
+                // TODO/NOTE: Can't delete from model as sending a top-level payload with
+                // missing elements is not allowed!
+                // When backend supports it, in loggingSource change the order of operations
+                // Delete first followed by save/put.
+                // _.remove(loggingConfig.sinks[sinkIndex].filter.category, {
+                //   name: catsev.name
+                // });
+              } else {
+                sink.filter.category[catIndex] = catsev;
+              }
+            } else {
+              sink.filter.category.push(catsev);
+            }
+          } else {
+            sink.filter.category = [];
+            sink.filter.category.push(catsev);
+          }
+        } else {
+          sink.filter = {};
+          sink.filter.category = [];
+          sink.filter.category.push(catsev);
+        }
+      }
+    });
+
+    this.setState({
+      loggingConfig: loggingConfig
+    });
+  }
+
   updateAllowDuplicateEvents = (allowFlag) => {
     console.log("LoggingStore.updateAllowDuplicateEvents called. allowFlag=", allowFlag);
     const loggingConfig = this.loggingConfig;