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

added the ability to edit filters, added field filter and modified table to use it

Rashid Khan 12 лет назад
Родитель
Сommit
333704237b
4 измененных файлов с 37 добавлено и 11 удалено
  1. 2 0
      js/services.js
  2. 22 7
      panels/filtering/module.html
  3. 9 0
      panels/filtering/module.js
  4. 4 4
      panels/table/module.js

+ 2 - 0
js/services.js

@@ -352,6 +352,8 @@ angular.module('kibana.services', [])
         .to(filter.to);
     case 'querystring':
       return ejs.QueryFilter(ejs.QueryStringQuery(filter.query)).cache(true);
+    case 'field':
+      return ejs.QueryFilter(ejs.FieldQuery(filter.field,filter.query)).cache(true);
     case 'terms':
       return ejs.TermsFilter(filter.field,filter.value);
     case 'exists':

+ 22 - 7
panels/filtering/module.html

@@ -7,7 +7,7 @@
       display:inline-block;
       vertical-align: top;
       margin-left: 10px;
-      width: 200px;
+      width: 220px;
       padding: 5px 5px 0px 5px;
       border: #555 1px solid;
       margin: 0px 5px 5px 0px;
@@ -36,7 +36,10 @@
       text-decoration: underline;
       cursor: pointer;
     }
-
+    .filter-apply {
+      float:right;
+      margin-bottom: 5px;
+    }
   </style>
 
   <div class='filtering-container'>
@@ -47,17 +50,29 @@
         <span ng-show="!filterSrv.list[id].editing" class="filter-mandate" ng-click="filterSrv.list[id].editing = true">{{filterSrv.list[id].mandate}}</span>
 
         <span ng-show="filterSrv.list[id].editing">
-          <select class="input-small" ng-model="filterSrv.list[id].mandate" ng-options="f for f in ['must','mustNot','either']" ng-change='filterSrv.list[id].editing=undefined;refresh()' ng-blur="filterSrv.list[id].editing=undefined"></select>
-          <i class="pointer icon-remove" bs-tooltip="'Cancel '" ng-click="filterSrv.list[id].editing=undefined"></i>
+          <select class="input-small" ng-model="filterSrv.list[id].mandate" ng-options="f for f in ['must','mustNot','either']"></select>
         </span>
 
         <i class="filter-action pointer icon-remove" bs-tooltip="'Remove'" ng-click="remove(id)"></i>
         <i class="filter-action pointer" ng-class="{'icon-check': filterSrv.list[id].active,'icon-check-empty': !filterSrv.list[id].active}" bs-tooltip="'Toggle'" ng-click="toggle(id)"></i>
+        <i class="filter-action pointer icon-edit" ng-hide="filterSrv.list[id].editing" bs-tooltip="'Edit'" ng-click="filterSrv.list[id].editing = true"></i>
 
       </div>
-      <ul class="unstyled">
-        <li ng-repeat="(key,value) in filterSrv.list[id]" ng-show="show_key(key)"><strong>{{key}}</strong> : {{value}}</li>
-      </ul>
+
+      <div ng-hide="filterSrv.list[id].editing && isEditable(filterSrv.list[id])">
+        <ul class="unstyled">
+          <li ng-repeat="(key,value) in filterSrv.list[id]" ng-show="show_key(key)"><strong>{{key}}</strong> : {{value}}</li>
+        </ul>
+      </div>
+      <div ng-show="filterSrv.list[id].editing && isEditable(filterSrv.list[id])">
+        <ul class="unstyled">
+          <li ng-repeat="key in _.keys(filterSrv.list[id])" ng-show="show_key(key)"><strong>{{key}}</strong> : <input type='text' ng-model="filterSrv.list[id][key]"></li>
+        </ul>
+      </div>
+      <div class="filter-apply" ng-show="filterSrv.list[id].editing">
+        <button ng-click="filterSrv.list[id].editing=undefined" class="btn btn-mini" bs-tooltip="'Save without refresh'">Save</button>
+        <button ng-click="filterSrv.list[id].editing=undefined;refresh()" class="btn btn-success btn-mini" bs-tooltip="'Save and refresh'">Apply</button>
+      </div>
     </div>
   </div>
 </kibana-panel>

+ 9 - 0
panels/filtering/module.js

@@ -48,4 +48,13 @@ angular.module('kibana.filtering', [])
     return !_.contains(['type','id','alias','mandate','active','editing'],key);
   };
 
+  $scope.isEditable = function(filter) {
+    var uneditable = ['time'];
+    if(_.contains(uneditable,filter.type)) {
+      return false;
+    } else {
+      return true;
+    }
+  };
+
 });

+ 4 - 4
panels/table/module.js

@@ -108,14 +108,14 @@ angular.module('kibana.table', [])
   };
 
   $scope.build_search = function(field,value,negate) {
-    var query = field+":";
+    var query;
     // This needs to be abstracted somewhere
     if(_.isArray(value)) {
-      query = query+"(" + _.map(value,function(v){return angular.toJson(v);}).join(" AND ") + ")";
+      query = "(" + _.map(value,function(v){return angular.toJson(v);}).join(" AND ") + ")";
     } else {
-      query = query+angular.toJson(value);
+      query = angular.toJson(value);
     }
-    filterSrv.set({type:'querystring',query:query,mandate:(negate ? 'mustNot':'must')});
+    filterSrv.set({type:'field',field:field,query:query,mandate:(negate ? 'mustNot':'must')});
     $scope.panel.offset = 0;
     dashboard.refresh();
   };