Repository: incubator-eagle
Updated Branches:
  refs/heads/master 2e5cb719c -> ab1c9b64f


[EAGLE-688] UI support Alert display

For backend will provide the alert api. UI will also support it.

Author: zombieJ <smith3...@gmail.com>

Closes #576 from zombieJ/EAGLE-688.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/ab1c9b64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/ab1c9b64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/ab1c9b64

Branch: refs/heads/master
Commit: ab1c9b64f6aec62d43e26dca2417e967b7740543
Parents: 2e5cb71
Author: zombieJ <smith3...@gmail.com>
Authored: Fri Oct 28 14:29:43 2016 +0800
Committer: zombieJ <smith3...@gmail.com>
Committed: Fri Oct 28 14:29:43 2016 +0800

----------------------------------------------------------------------
 .../webapp/app/dev/partials/alert/detail.html   | 63 +++++++++++++++
 .../webapp/app/dev/partials/alert/list.html     | 80 +++++++++++++++-----
 .../webapp/app/dev/partials/alert/main.html     |  2 +-
 .../src/main/webapp/app/dev/public/js/app.js    |  6 ++
 .../webapp/app/dev/public/js/ctrls/alertCtrl.js | 29 ++++++-
 .../app/dev/public/js/ctrls/alertEditCtrl.js    |  7 +-
 .../dev/public/js/services/applicationSrv.js    |  8 +-
 .../app/dev/public/js/services/entitySrv.js     | 37 ++++++---
 .../app/dev/public/js/services/pageSrv.js       |  2 +-
 9 files changed, 195 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/partials/alert/detail.html
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/partials/alert/detail.html 
b/eagle-server/src/main/webapp/app/dev/partials/alert/detail.html
new file mode 100644
index 0000000..7aac11e
--- /dev/null
+++ b/eagle-server/src/main/webapp/app/dev/partials/alert/detail.html
@@ -0,0 +1,63 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<div class="box box-primary">
+       <div class="box-header with-border">
+               <span class="fa fa-bell"></span>
+               <h3 class="box-title">
+                       ID: {{alert.alertId}}
+                       <span class="fa fa-refresh fa-spin no-animate" 
ng-show="!alertList._done"></span>
+               </h3>
+       </div>
+       <div class="box-body">
+               <table class="table">
+                       <tbody>
+                               <tr>
+                                       <th width="15%">Policy</th>
+                                       <td width="35%"><a 
ui-sref="policyDetail({name: item.policyId})">{{alert.policyId}}</a></td>
+                                       <th width="15%">Id</th>
+                                       <td width="35%">{{alert.alertId}}</td>
+                               </tr>
+                               <tr>
+                                       <th>Site</th>
+                                       <td>{{alert.siteId}}</td>
+                                       <th>Time</th>
+                                       
<td>{{Time.format(alert.alertTimestamp)}}</td>
+                               </tr>
+                               <tr>
+                                       <th>Stream</th>
+                                       <td>{{alert.streamId}}</td>
+                                       <th>Applications</th>
+                                       <td>
+                                               <ul class="list-unstyled">
+                                                       <li ng-repeat="app in 
alert.appIds track by $index" class="label label-sm label-primary">
+                                                               
{{Application.findProvider(app).type || app}}
+                                                       </li>
+                                               </ul>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <th>Alert Content</th>
+                                       <td colspan="3">
+                                               <pre>{{alert.alertData | 
json}}</pre>
+                                       </td>
+                               </tr>
+                       </tbody>
+               </table>
+       </div>
+</div>

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/partials/alert/list.html
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/partials/alert/list.html 
b/eagle-server/src/main/webapp/app/dev/partials/alert/list.html
index d493976..182f749 100644
--- a/eagle-server/src/main/webapp/app/dev/partials/alert/list.html
+++ b/eagle-server/src/main/webapp/app/dev/partials/alert/list.html
@@ -1,21 +1,59 @@
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-
-<div class="box-body">
-       Good!
-</div>
\ No newline at end of file
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<div class="box-body">
+       <div sort-table="alertList" is-sorting="isSorting">
+               <table class="table table-bordered">
+                       <thead>
+                               <tr>
+                                       <th sortpath="alertTimestamp" 
width="135">
+                                               Alert Time
+                                               <span class="fa fa-refresh 
fa-spin no-animate" ng-show="!alertList._done || isSorting"></span>
+                                       </th>
+                                       <th sortpath="siteId" 
width="75">Site</th>
+                                       <th sortpath="policyId" 
width="75">Policy</th>
+                                       <!--th sortpath="streamId" 
width="75">Stream</th-->
+                                       <th width="100">Application</th>
+                                       <th>Alert Data</th>
+                                       <th width="10"></th>
+                               </tr>
+                       </thead>
+                       <tbody>
+                               <tr>
+                                       
<td>{{Time.format(item.alertTimestamp)}}</td>
+                                       <td>{{item.siteId}}</td>
+                                       <td>
+                                               <a ui-sref="policyDetail({name: 
item.policyId})">{{item.policyId}}</a>
+                                       </td>
+                                       <!--td>{{item.streamId}}</td-->
+                                       <td>
+                                               <ul class="list-unstyled">
+                                                       <li ng-repeat="app in 
item.appIds track by $index" class="label label-sm label-primary">
+                                                               
{{Application.findProvider(app).type || app}}
+                                                       </li>
+                                               </ul>
+                                       </td>
+                                       <td 
class="text-break">{{item.alertData}}</td>
+                                       <td>
+                                               <a 
ui-sref="alertDetail({alertId: item.alertId})">Detail</a>
+                                       </td>
+                               </tr>
+                       </tbody>
+               </table>
+       </div>
+</div>

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/partials/alert/main.html
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/partials/alert/main.html 
b/eagle-server/src/main/webapp/app/dev/partials/alert/main.html
index 83db262..5d35893 100644
--- a/eagle-server/src/main/webapp/app/dev/partials/alert/main.html
+++ b/eagle-server/src/main/webapp/app/dev/partials/alert/main.html
@@ -18,7 +18,7 @@
 
 <div class="nav-tabs-custom">
        <ul class="nav nav-tabs">
-               <!--li ng-class="{active: getState() === 'alert.list'}"><a 
href="#/alert/">Alerts</a></li-->
+               <li ng-class="{active: getState() === 'alert.list'}"><a 
href="#/alert/">Alerts</a></li>
                <li ng-class="{active: getState() === 'alert.policyList'}"><a 
href="#/alert/policyList">Policies</a></li>
                <li ng-class="{active: getState() === 'alert.streamList'}"><a 
href="#/alert/streamList">Streams</a></li>
        </ul>

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/public/js/app.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/app.js 
b/eagle-server/src/main/webapp/app/dev/public/js/app.js
index 9b46e65..67b8487 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/app.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/app.js
@@ -155,6 +155,12 @@ var app = {};
                                        resolve: routeResolve()
                                })
 
+                               .state('alertDetail', {
+                                       url: "/alertDetail/{alertId}",
+                                       templateUrl: 
"partials/alert/detail.html?_=" + window._TRS(),
+                                       controller: "alertDetailCtrl",
+                                       resolve: routeResolve()
+                               })
                                .state('policyDetail', {
                                        url: "/policyDetail/{name}",
                                        templateUrl: 
"partials/alert/policyDetail.html?_=" + window._TRS(),

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertCtrl.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertCtrl.js 
b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertCtrl.js
index e52fc3c..ed3ca74 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertCtrl.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertCtrl.js
@@ -34,8 +34,33 @@
        // 
======================================================================================
        // =                                        Alert                       
                =
        // 
======================================================================================
-       eagleControllers.controller('alertListCtrl', function ($scope, 
$wrapState, PageConfig) {
+       eagleControllers.controller('alertListCtrl', function ($scope, 
$wrapState, $interval, PageConfig, Entity) {
                PageConfig.subTitle = "Explore Alerts";
+
+               $scope.alertList = Entity.queryMetadata("alerts", {size: 
10000});
+
+               // 
================================================================
+               // =                             Sync                           
  =
+               // 
================================================================
+               var refreshInterval = $interval($scope.alertList._refresh, 1000 
* 10);
+               $scope.$on('$destroy', function() {
+                       $interval.cancel(refreshInterval);
+               });
+       });
+
+       eagleControllers.controller('alertDetailCtrl', function ($scope, 
$wrapState, PageConfig, Entity) {
+               PageConfig.title = "Alert Detail";
+
+               $scope.alertList = Entity.queryMetadata("alerts/" + 
encodeURIComponent($wrapState.param.alertId));
+               $scope.alertList._then(function () {
+                       $scope.alert = $scope.alertList[0];
+                       if(!$scope.alert) {
+                               $.dialog({
+                                       title: "OPS",
+                                       content: "Alert '" + 
$wrapState.param.alertId + "' not found!"
+                               });
+                       }
+               });
        });
 
        // 
======================================================================================
@@ -77,7 +102,7 @@
                        UI.deleteConfirm(item.name)(function (entity, 
closeFunc) {
                                Entity.deleteMetadata("policies/" + 
item.name)._promise.finally(function () {
                                        closeFunc();
-                                       $scope.policyList._refresh();
+                                       updateList();
                                });
                        });
                };

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
----------------------------------------------------------------------
diff --git 
a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js 
b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
index 3629651..8b7d041 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
@@ -36,7 +36,12 @@
                        name: "Slack",
                        displayFields: ["channels"],
                        fields: ["token", "channels", "severitys", 
"urltemplate"]
-               }
+               },
+               
'org.apache.eagle.alert.engine.publisher.impl.AlertEagleStorePlugin': {
+                       name: "Storage",
+                       displayFields: [],
+                       fields: []
+               },
        };
 
        // 
======================================================================================

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/public/js/services/applicationSrv.js
----------------------------------------------------------------------
diff --git 
a/eagle-server/src/main/webapp/app/dev/public/js/services/applicationSrv.js 
b/eagle-server/src/main/webapp/app/dev/public/js/services/applicationSrv.js
index 31c6fb6..9e58a8a 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/services/applicationSrv.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/services/applicationSrv.js
@@ -58,7 +58,13 @@
                });
 
                Application.findProvider = function (type) {
-                       return common.array.find(type, 
Application.providerList, ["type"]);
+                       var provider = common.array.find(type, 
Application.providerList, ["type"]);
+                       if(provider) return provider;
+
+                       var app = common.array.find(type, Application.list, 
["appId"]);
+                       if(!app || !app.descriptor) return null;
+
+                       return common.array.find(app.descriptor.type, 
Application.providerList, ["type"]);
                };
 
                Application.getPromise = function () {

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/public/js/services/entitySrv.js
----------------------------------------------------------------------
diff --git 
a/eagle-server/src/main/webapp/app/dev/public/js/services/entitySrv.js 
b/eagle-server/src/main/webapp/app/dev/public/js/services/entitySrv.js
index 9dfba86..986e0d1 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/services/entitySrv.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/services/entitySrv.js
@@ -59,10 +59,12 @@
                        return _host;
                };
 
-               Entity.query = function (url) {
+               Entity.query = function (url, param) {
                        var list = [];
                        list._refresh = function () {
-                               return wrapList(list, $http.get(_host + 
"/rest/" + url));
+                               var config = {};
+                               if(param) config.params = param;
+                               return wrapList(list, $http.get(_host + 
"/rest/" + url, config));
                        };
 
                        return list._refresh();
@@ -118,17 +120,28 @@
                };
 
                // TODO: metadata will be removed
-               Entity.queryMetadata = function (url) {
-                       var metaList = Entity.query('metadata/' +  url);
-                       metaList._then(function (res) {
-                               var data = res.data;
-                               if(!$.isArray(data)) {
-                                       data = [data];
-                               }
+               Entity.queryMetadata = function (url, param) {
+                       var metaList = Entity.query('metadata/' +  url, param);
+                       var _refresh = metaList._refresh;
+
+                       function process() {
+                               metaList._then(function (res) {
+                                       var data = res.data;
+                                       if(!$.isArray(data)) {
+                                               data = [data];
+                                       }
+
+                                       metaList.splice(0);
+                                       Array.prototype.push.apply(metaList, 
data);
+                               });
+                       }
 
-                               metaList.splice(0);
-                               Array.prototype.push.apply(metaList, data);
-                       });
+                       metaList._refresh = function () {
+                               _refresh();
+                               process();
+                       };
+
+                       process();
 
                        return metaList;
                };

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ab1c9b64/eagle-server/src/main/webapp/app/dev/public/js/services/pageSrv.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/services/pageSrv.js 
b/eagle-server/src/main/webapp/app/dev/public/js/services/pageSrv.js
index 6327e22..be3281b 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/services/pageSrv.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/services/pageSrv.js
@@ -53,7 +53,7 @@
                var defaultPortalList = [
                        {name: "Home", icon: "home", path: "#/"},
                        {name: "Alert", icon: "bell", showFunc: 
checkApplication, list: [
-                               // {name: "Explore Alerts", path: "#/alert/"},
+                               {name: "Alerts", path: "#/alert/"},
                                {name: "Policies", path: "#/alert/policyList"},
                                {name: "Streams", path: "#/alert/streamList"},
                                {name: "Define Policy", path: 
"#/alert/policyCreate"}

Reply via email to