Procházet zdrojové kódy

Closes #123, you can now specify template (ie filter) values in url. ?fillterName=filterValue

Torkel Ödegaard před 12 roky
rodič
revize
75683c423d
2 změnil soubory, kde provedl 26 přidání a 14 odebrání
  1. 25 13
      src/app/services/filterSrv.js
  2. 1 1
      src/index.html

+ 25 - 13
src/app/services/filterSrv.js

@@ -8,7 +8,7 @@ define([
 
   var module = angular.module('kibana.services');
 
-  module.service('filterSrv', function(dashboard, $rootScope, $timeout) {
+  module.service('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) {
     // defaults
     var _d = {
       list: [],
@@ -26,16 +26,38 @@ define([
 
       self.list = dashboard.current.services.filter.list;
       self.time = dashboard.current.services.filter.time;
-      self.filterTemplateData = undefined;
 
       self.templateSettings = {
         interpolate : /\[\[([\s\S]+?)\]\]/g,
       };
+
+      if (self.list.length) {
+        this.updateTemplateData(true);
+      }
     };
 
+    this.updateTemplateData = function(initial) {
+      self.filterTemplateData = {};
+
+      _.each(self.list, function(filter) {
+        if (initial) {
+          var urlValue = $routeParams[filter.name];
+          if (urlValue) {
+            filter.current = { text: urlValue, value: urlValue };
+          }
+        }
+
+        if (!filter.current || !filter.current.value) {
+          return;
+        }
+
+        self.filterTemplateData[filter.name] = filter.current.value;
+      });
+    }
+
     this.filterOptionSelected = function(filter, option) {
       filter.current = option;
-      self.filterTemplateData = undefined;
+      this.updateTemplateData();
       dashboard.refresh();
     };
 
@@ -47,16 +69,6 @@ define([
       if (target.indexOf('[[') === -1) {
         return target;
       }
-      if (!self.filterTemplateData) {
-        self.filterTemplateData = {};
-        _.each(self.list, function(filter) {
-          if (!filter.current || !filter.current.value) {
-            return;
-          }
-
-          self.filterTemplateData[filter.name] = filter.current.value;
-        });
-      }
 
       return _.template(target, self.filterTemplateData, self.templateSettings);
     };

+ 1 - 1
src/index.html

@@ -21,7 +21,7 @@
 
   </head>
 
-  <body ng-cloak body-class >
+  <body ng-cloak body-class>
 
     <!--<link rel="stylesheet" ng-href="css/bootstrap.{{dashboard.current.style||'dark'}}.min.css">-->
     <link rel="stylesheet" ng-href="css/bootstrap.{{dashboard.current.style||'dark'}}.min.css">