Skip to content

Commit db6cd72

Browse files
committed
1) Injected angularjs dependencies
2) Implemented Pub/Sub Model 3) Implemented event list view in react Signed-off-by: Neha Gupta <[email protected]>
1 parent 079eef8 commit db6cd72

File tree

10 files changed

+303
-161
lines changed

10 files changed

+303
-161
lines changed

gulpfile.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ gulp.task("jsLibraries", function() {
9898
"node_modules/jquery/dist/jquery.min.js",
9999
"node_modules/bootstrap/dist/js/bootstrap.min.js", // For dropdown : temporary
100100
"node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.js",
101+
"node_modules/angular/angular.js",
101102
"node_modules/react/umd/react.production.min.js",
102103
"node_modules/react-dom/umd/react-dom.production.min.js",
103-
"node_modules/angular/angular.js",
104+
"node_modules/ngreact/ngReact.min.js",
104105
"node_modules/angular-ui-bootstrap/dist/ui-bootstrap.min.js",
105106
"node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js",
106107
"node_modules/angular-sanitize/angular-sanitize.min.js",
@@ -115,7 +116,10 @@ gulp.task("jsLibraries", function() {
115116
"node_modules/angular-bootstrap-switch/dist/angular-bootstrap-switch.min.js",
116117
"node_modules/angular-patternfly/node_modules/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js",
117118
"node_modules/datatables/media/js/jquery.dataTables.js",
118-
"node_modules/angular-patternfly/node_modules/angularjs-datatables/dist/angular-datatables.js"
119+
"node_modules/angular-patternfly/node_modules/angularjs-datatables/dist/angular-datatables.js",
120+
"node_modules/q/q.js",
121+
"node_modules/moment/min/moment.min.js",
122+
"node_modules/react-datepicker/dist/react-datepicker.min.js"
119123
])
120124
.pipe(uglify())
121125
.pipe(concat("libraries.js"))
@@ -128,7 +132,8 @@ gulp.task("cssLibraries", function() {
128132
"node_modules/patternfly/dist/css/patternfly.css",
129133
"node_modules/patternfly/dist/css/patternfly-additions.css",
130134
"node_modules/angular-patternfly/styles/angular-patternfly.css",
131-
"node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css"
135+
"node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css",
136+
"node_modules/react-datepicker/dist/react-datepicker.min.css"
132137
])
133138
.pipe(postCss([autoprefixer({ browsers: browsers })]))
134139
.pipe(buildMode === "dev" ? noop() : minifyCSS())
@@ -215,8 +220,8 @@ gulp.task("resource", function(done) {
215220
gulp.task("jsbundle", ["eslint"], function() {
216221

217222
return gulp.src(paths.jsFiles, { cwd: paths.src })
218-
.pipe(babel({ presets: ["es2015"] }))
219223
.pipe(concat("plugin-bundle.js"))
224+
.pipe(babel({ presets: ["es2015", "react"] }))
220225
.pipe(gulp.dest(paths.dest));
221226
});
222227

@@ -256,7 +261,7 @@ gulp.task("watcher", ["browser-sync", "common"], function(done) {
256261

257262
gulp.watch(filters.js, { cwd: paths.src }, function(event) {
258263
log("Modified:", colors.yellow(event.path));
259-
runSequence("preload", "jsbundle");
264+
runSequence("preload", "jsbundle", "transform");
260265
});
261266

262267
gulp.watch([filters.css, filters.scss], { cwd: paths.src }, function(event) {
@@ -300,7 +305,8 @@ gulp.task("dev", ["common", "watcher"], function(done) {
300305

301306
// production mode task
302307
gulp.task("release", ["common"], function(done) {
303-
runSequence("ut", done);
308+
/* TODO: uncomment it once migrated the testing framework too */
309+
//runSequence("ut", done);
304310
});
305311

306312
//default task is common

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,24 @@
2626
"font-awesome": "^4.7.0",
2727
"idb-wrapper": "~1.7.1",
2828
"jquery": "~3.1.1",
29+
"moment": "^2.22.1",
2930
"ngreact": "^0.5.1",
3031
"numeral": "~1.5.3",
3132
"patternfly": "~3.29.13",
3233
"patternfly-react": "^2.3.0",
3334
"react": "^16.3.2",
35+
"react-datepicker": "^1.5.0",
3436
"react-dom": "^16.3.2",
3537
"redux": "^4.0.0"
3638
},
3739
"devDependencies": {
3840
"angular-mocks": "~1.5.8",
3941
"ansi-colors": "^1.1.0",
4042
"autoprefixer": "^7.1.3",
43+
"babel-cli": "^6.26.0",
4144
"babel-core": "^6.26.3",
4245
"babel-preset-es2015": "^6.24.1",
46+
"babel-preset-react": "^6.24.1",
4347
"babelify": "^8.0.0",
4448
"browser-sync": "^2.18.13",
4549
"browserify": "^16.2.0",

src/commons/js/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"patternfly.form",
1212
"patternfly.notification",
1313
"patternfly.table",
14-
"patternfly.filters"
14+
"patternfly.filters",
15+
"react"
1516
]);
1617

1718
/* Setting up provider for getting config data */

src/commons/js/ng-react-ng-deps.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ export const ngDeps = {};
44

55
export function injectNgDeps(deps) {
66
Object.assign(ngDeps, deps);
7+
window.ngDeps = ngDeps;
78
};
89

910
export default ngDeps;
1011

1112
var storageModule = angular.module("TendrlModule");
1213

1314
storageModule.run([
14-
"$rootScope",
15-
"$state",
16-
"$q",
17-
($rootScope, $state, $q) => {
18-
injectNgDeps({ $rootScope, $state, $q });
15+
"$stateParams",
16+
"utils",
17+
"config",
18+
($stateParams, utils, config) => {
19+
injectNgDeps({ $stateParams, utils, config });
1920
},
2021
]);

src/commons/services/pub-sub.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const PubSubService = {
2+
topics: {},
3+
subscribe: function(topic, listener) {
4+
var that = this;
5+
6+
// Create the topic's object if not yet created
7+
if (!that.topics.hasOwnProperty.call(that.topics, topic)) {
8+
that.topics[topic] = [];
9+
}
10+
11+
// Add the listener to queue
12+
var index = that.topics[topic].push(listener) - 1;
13+
14+
// Provide handle back for removal of topic
15+
return {
16+
remove: function() {
17+
delete that.topics[topic][index];
18+
}
19+
};
20+
},
21+
publish: function(topic, info) {
22+
var that = this;
23+
24+
// If the topic doesn't exist, or there's no listeners in queue, just leave
25+
if (!that.topics.hasOwnProperty.call(that.topics, topic)) return;
26+
27+
// Cycle through topics queue, fire!
28+
that.topics[topic].forEach(function(item) {
29+
item(info != undefined ? info : {});
30+
});
31+
}
32+
};
33+
34+
35+
angular
36+
.module("TendrlModule")
37+
.service("pubSubService", pubSubService);
38+
39+
/*@ngInject*/
40+
function pubSubService() {
41+
return PubSubService;
42+
}

src/commons/services/vendor.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React, { Component } from "react";
2+
import moment from "moment";
3+
import DatePicker from 'react-datepicker';
4+
require("ngreact");

src/commons/stores/events-store.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import React, { Component } from "react";
2-
import ngDeps from "../js/ng-react-ng-deps.js";
31

42
const EventStore = {
3+
showAlertIndication: false,
54
getAlertList: function() {
65
var list,
7-
deferred;
6+
deferred,
7+
utils = window.ngDeps.utils,
8+
that = this;
9+
10+
deferred = Q.defer();
811

9-
deferred = $q.defer();
1012
utils.getAlertList()
1113
.then(function(data) {
12-
$rootScope.showAlertIndication = false;
14+
15+
that.showAlertIndication = false;
1316
list = data ? _formatAlertData(data) : [];
1417
deferred.resolve(list);
1518
});
@@ -28,8 +31,8 @@ const EventStore = {
2831
i;
2932

3033
for (i = 0; i < len; i++) {
31-
temp = {},
32-
temp.alertId = data[i].alert_id;
34+
temp = {};
35+
temp.alertId = data[i].alert_id;
3336
temp.timeStamp = new Date(data[i].time_stamp);
3437
temp.severity = severity[data[i].severity];
3538
temp.nodeId = data[i].node_id;
@@ -39,8 +42,9 @@ const EventStore = {
3942
temp.clusterName = data[i].tags.integration_id ? data[i].tags.integration_id : "";
4043
temp.sdsName = data[i].tags.sds_name ? data[i].tags.sds_name : "";
4144

42-
if ((temp.severity === "error" || temp.severity === "warning") && !$rootScope.showAlertIndication) {
43-
$rootScope.showAlertIndication = true;
45+
if ((temp.severity === "error" || temp.severity === "warning") && !that.showAlertIndication) {
46+
that.showAlertIndication = true;
47+
PubSubService.publish("alertIndicationChanged", that.showAlertIndication);
4448
}
4549
res.push(temp);
4650
}
@@ -49,9 +53,10 @@ const EventStore = {
4953
},
5054
getEventList: function(clusterId) {
5155
var list,
52-
deferred;
56+
deferred,
57+
utils = window.ngDeps.utils;
5358

54-
deferred = $q.defer();
59+
deferred = Q.defer();
5560
utils.getEventList(clusterId)
5661
.then(function(data) {
5762
list = data ? _formatEventData(data) : [];
@@ -69,8 +74,8 @@ const EventStore = {
6974
i;
7075

7176
for (i = 0; i < len; i++) {
72-
temp = {},
73-
temp.timeStamp = new Date(data[i].timestamp);
77+
temp = {};
78+
temp.timeStamp = moment(new Date(data[i].timestamp)).format('DD-MMM-YY HH:mm:ss');
7479
temp.priority = data[i].priority;
7580
temp.message = data[i].message;
7681
temp.message_id = data[i].message_id;
@@ -81,13 +86,11 @@ const EventStore = {
8186
}
8287
};
8388

84-
export default EventStore;
85-
8689
angular
8790
.module("TendrlModule")
8891
.service("eventStore", eventStore);
8992

9093
/*@ngInject*/
91-
function eventStore($state, $q, $rootScope, utils) {
94+
function eventStore() {
9295
return EventStore;
9396
}

src/modules/base/header/header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<li class="dropdown">
3434
<a data-toggle="dropdown" class="dropdown-toggle nav-item-iconic" href="" data-template="" data-animation="am-fade-and-slide-top" bs-dropdown="dropdown" title="Alerts" id="notifications" ng-click="header.setNotificationFlag()">
3535
<i class="fa fa-bell"></i>
36-
<span ng-class="{'badge badge-pf-bordered':$root.showAlertIndication}"> </span>
36+
<span ng-class="{'badge badge-pf-bordered':header.showAlertIndication}"> </span>
3737
<!-- in order to show the empty badge this requires a space, otherwise add a value -->
3838
</a>
3939
</li>

src/modules/base/header/header.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
});
1212

1313
/*@ngInject*/
14-
function headerController($rootScope, $state, $scope, $uibModal, AuthManager, utils, Notifications, userStore) {
14+
function headerController($rootScope, $state, $scope, $uibModal, AuthManager, utils, Notifications, userStore, eventStore, pubSubService) {
1515

1616
var vm = this,
1717
currentUser;
@@ -20,6 +20,7 @@
2020
vm.searchBy = {};
2121
vm.filterBy = "";
2222
vm.severity = "";
23+
vm.showAlertIndication = eventStore.showAlertIndication;
2324

2425
vm.notificationClose = notificationClose;
2526
vm.logout = logout;
@@ -47,6 +48,10 @@
4748
}
4849
});
4950

51+
var subscription = pubSubService.subscribe("alertIndicationChanged", function(flag) {
52+
vm.showAlertIndication = flag;
53+
});
54+
5055
init();
5156

5257
function init() {
@@ -84,7 +89,7 @@
8489
vm.showAlerts = false;
8590
}
8691

87-
function updateViewing (viewing, data) {
92+
function updateViewing(viewing, data) {
8893
Notifications.setViewing(data, viewing);
8994
}
9095

0 commit comments

Comments
 (0)