diff --git a/gulpfile.js b/gulpfile.js index 1dc0b9a8..c10a1cd0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -98,9 +98,10 @@ gulp.task("jsLibraries", function() { "node_modules/jquery/dist/jquery.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js", // For dropdown : temporary "node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", + "node_modules/angular/angular.js", "node_modules/react/umd/react.production.min.js", "node_modules/react-dom/umd/react-dom.production.min.js", - "node_modules/angular/angular.js", + "node_modules/ngreact/ngReact.min.js", "node_modules/angular-ui-bootstrap/dist/ui-bootstrap.min.js", "node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js", "node_modules/angular-sanitize/angular-sanitize.min.js", @@ -115,7 +116,10 @@ gulp.task("jsLibraries", function() { "node_modules/angular-bootstrap-switch/dist/angular-bootstrap-switch.min.js", "node_modules/angular-patternfly/node_modules/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js", "node_modules/datatables/media/js/jquery.dataTables.js", - "node_modules/angular-patternfly/node_modules/angularjs-datatables/dist/angular-datatables.js" + "node_modules/angular-patternfly/node_modules/angularjs-datatables/dist/angular-datatables.js", + "node_modules/q/q.js", + "node_modules/moment/min/moment.min.js", + "node_modules/react-datepicker/dist/react-datepicker.min.js" ]) .pipe(uglify()) .pipe(concat("libraries.js")) @@ -128,7 +132,8 @@ gulp.task("cssLibraries", function() { "node_modules/patternfly/dist/css/patternfly.css", "node_modules/patternfly/dist/css/patternfly-additions.css", "node_modules/angular-patternfly/styles/angular-patternfly.css", - "node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css" + "node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css", + "node_modules/react-datepicker/dist/react-datepicker.min.css" ]) .pipe(postCss([autoprefixer({ browsers: browsers })])) .pipe(buildMode === "dev" ? noop() : minifyCSS()) @@ -215,8 +220,8 @@ gulp.task("resource", function(done) { gulp.task("jsbundle", ["eslint"], function() { return gulp.src(paths.jsFiles, { cwd: paths.src }) - .pipe(babel({ presets: ["es2015"] })) .pipe(concat("plugin-bundle.js")) + .pipe(babel({ presets: ["es2015", "react"] })) .pipe(gulp.dest(paths.dest)); }); @@ -256,7 +261,7 @@ gulp.task("watcher", ["browser-sync", "common"], function(done) { gulp.watch(filters.js, { cwd: paths.src }, function(event) { log("Modified:", colors.yellow(event.path)); - runSequence("preload", "jsbundle"); + runSequence("preload", "jsbundle", "transform"); }); gulp.watch([filters.css, filters.scss], { cwd: paths.src }, function(event) { diff --git a/package.json b/package.json index fb215f5b..fc6f5a1e 100644 --- a/package.json +++ b/package.json @@ -1,112 +1,116 @@ { - "name": "Tendrl", - "description": "Dashboard", - "version": "1.6.3", - "dependencies": { - "@uirouter/angularjs": "^1.0.7", - "angular": "~1.5.8", - "angular-animate": "~1.5.8", - "angular-bootstrap-switch": "~0.5.2", - "angular-cookies": "~1.5.8", - "angular-growl-v2": "~0.7.5", - "angular-motion": "~0.4.4", - "angular-patternfly": "^4.0.0", - "angular-resource": "~1.5.8", - "angular-route": "~1.5.8", - "angular-sanitize": "~1.5.8", - "angular-strap": "~2.3.10", - "angular-ui-bootstrap": "~2.2.0", - "bootstrap": "^3.3.7", - "bootstrap-datepicker": "~1.6.4", - "bootstrap-tooltip": "~3.1.1", - "c3": "~0.4.11", - "c3-angular": "git://github.com/jettro/c3-angular-directive#1.3.1", - "d3": "~3.5.17", - "es6-shim": "~0.35.1", - "font-awesome": "^4.7.0", - "idb-wrapper": "~1.7.1", - "jquery": "~3.1.1", - "ngreact": "^0.5.1", - "numeral": "~1.5.3", - "patternfly": "~3.29.13", - "patternfly-react": "^2.3.0", - "react": "^16.3.2", - "react-dom": "^16.3.2", - "redux": "^4.0.0" + "name": "Tendrl", + "description": "Dashboard", + "version": "1.6.3", + "dependencies": { + "@uirouter/angularjs": "^1.0.7", + "angular": "~1.5.8", + "angular-animate": "~1.5.8", + "angular-bootstrap-switch": "~0.5.2", + "angular-cookies": "~1.5.8", + "angular-growl-v2": "~0.7.5", + "angular-motion": "~0.4.4", + "angular-patternfly": "^4.0.0", + "angular-resource": "~1.5.8", + "angular-route": "~1.5.8", + "angular-sanitize": "~1.5.8", + "angular-strap": "~2.3.10", + "angular-ui-bootstrap": "~2.2.0", + "bootstrap": "^3.3.7", + "bootstrap-datepicker": "~1.6.4", + "bootstrap-tooltip": "~3.1.1", + "c3": "~0.4.11", + "c3-angular": "git://github.com/jettro/c3-angular-directive#1.3.1", + "d3": "~3.5.17", + "es6-shim": "~0.35.1", + "font-awesome": "^4.7.0", + "idb-wrapper": "~1.7.1", + "jquery": "~3.1.1", + "moment": "^2.22.1", + "ngreact": "^0.5.1", + "numeral": "~1.5.3", + "patternfly": "~3.29.13", + "patternfly-react": "^2.3.0", + "react": "^16.3.2", + "react-datepicker": "^1.5.0", + "react-dom": "^16.3.2", + "redux": "^4.0.0" + }, + "devDependencies": { + "angular-mocks": "~1.5.8", + "ansi-colors": "^1.1.0", + "autoprefixer": "^7.1.3", + "babel-cli": "^6.26.0", + "babel-core": "^6.26.3", + "babel-preset-es2015": "^6.24.1", + "babel-preset-react": "^6.24.1", + "babelify": "^8.0.0", + "browser-sync": "^2.18.13", + "browserify": "^16.2.0", + "chai": "^3.5.0", + "datatables": "^1.10.13", + "del": "*", + "fancy-log": "^1.3.2", + "glob": "~7.1.1", + "gulp": "^3.9.1", + "gulp-babel": "^7.0.1", + "gulp-browserify": "^0.5.1", + "gulp-clean-css": "^3.9.3", + "gulp-concat": "^2.6.0", + "gulp-cssimport": "^4.0.1", + "gulp-debug": "*", + "gulp-eslint": "^2.0.1", + "gulp-if": "^2.0.2", + "gulp-ignore": "^2.0.2", + "gulp-inject": "^4.1.0", + "gulp-load-plugins": "*", + "gulp-ng-annotate": "^2.0.0", + "gulp-noop": "^1.0.0", + "gulp-postcss": "^6.0.10", + "gulp-react": "^3.1.0", + "gulp-rename": "^1.2.2", + "gulp-sass": "^2.3.2", + "gulp-sourcemaps": "^2.6.4", + "gulp-uglify": "^2.0.0", + "http-proxy": "^1.16.2", + "karma": "~1.3.0", + "karma-chai": "~0.1.0", + "karma-coverage": "~1.1.1", + "karma-mocha": "~1.2.0", + "karma-mocha-reporter": "~2.2.0", + "karma-ng-html2js-preprocessor": "^1.0.0", + "karma-phantomjs-launcher": "^1.0.2", + "karma-sinon": "^1.0.5", + "merge-stream": "^1.0.0", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "mocha": "^3.1.2", + "request": "^2.78.0", + "run-sequence": "^1.2.2", + "sinon": "^1.17.6", + "vinyl-source-stream": "^2.0.0" + }, + "TendrlProps": { + "preloads": [], + "resources": { + "../node_modules/patternfly/dist/fonts/*.*": "fonts/", + "../node_modules/font-awesome/fonts/*.*": "fonts/", + "../node_modules/patternfly/node_modules/font-awesome/fonts/*.*": "dist/components/font-awesome/fonts" }, - "devDependencies": { - "angular-mocks": "~1.5.8", - "ansi-colors": "^1.1.0", - "autoprefixer": "^7.1.3", - "babel-core": "^6.26.3", - "babel-preset-es2015": "^6.24.1", - "babelify": "^8.0.0", - "browser-sync": "^2.18.13", - "browserify": "^16.2.0", - "chai": "^3.5.0", - "datatables": "^1.10.13", - "del": "*", - "fancy-log": "^1.3.2", - "glob": "~7.1.1", - "gulp": "^3.9.1", - "gulp-babel": "^7.0.1", - "gulp-browserify": "^0.5.1", - "gulp-clean-css": "^3.9.3", - "gulp-concat": "^2.6.0", - "gulp-cssimport": "^4.0.1", - "gulp-debug": "*", - "gulp-eslint": "^2.0.1", - "gulp-if": "^2.0.2", - "gulp-ignore": "^2.0.2", - "gulp-inject": "^4.1.0", - "gulp-load-plugins": "*", - "gulp-ng-annotate": "^2.0.0", - "gulp-noop": "^1.0.0", - "gulp-postcss": "^6.0.10", - "gulp-react": "^3.1.0", - "gulp-rename": "^1.2.2", - "gulp-sass": "^2.3.2", - "gulp-sourcemaps": "^2.6.4", - "gulp-uglify": "^2.0.0", - "http-proxy": "^1.16.2", - "karma": "~1.3.0", - "karma-chai": "~0.1.0", - "karma-coverage": "~1.1.1", - "karma-mocha": "~1.2.0", - "karma-mocha-reporter": "~2.2.0", - "karma-ng-html2js-preprocessor": "^1.0.0", - "karma-phantomjs-launcher": "^1.0.2", - "karma-sinon": "^1.0.5", - "merge-stream": "^1.0.0", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "mocha": "^3.1.2", - "request": "^2.78.0", - "run-sequence": "^1.2.2", - "sinon": "^1.17.6", - "vinyl-source-stream": "^2.0.0" - }, - "TendrlProps": { - "preloads": [], - "resources": { - "../node_modules/patternfly/dist/fonts/*.*": "fonts/", - "../node_modules/font-awesome/fonts/*.*": "fonts/", - "../node_modules/patternfly/node_modules/font-awesome/fonts/*.*": "dist/components/font-awesome/fonts" - }, - "targetBrowsers": [ - "last 2 version" - ], - "cssMain": "commons/scss/main.scss", - "jsFiles": [ - "commons/js/index.js", - "commons/**/*.js", - "modules/**/*.js" - ], - "htmlFiles": [ - "index.html" - ], - "config": "config.json", - "buildDestination": "./dist/", - "archiveExtension": ".tar.gz" - } + "targetBrowsers": [ + "last 2 version" + ], + "cssMain": "commons/scss/main.scss", + "jsFiles": [ + "commons/js/index.js", + "commons/**/*.js", + "modules/**/*.js" + ], + "htmlFiles": [ + "index.html" + ], + "config": "config.json", + "buildDestination": "./dist/", + "archiveExtension": ".tar.gz" + } } diff --git a/src/commons/js/index.js b/src/commons/js/index.js index af715be0..f5a120cb 100755 --- a/src/commons/js/index.js +++ b/src/commons/js/index.js @@ -11,7 +11,8 @@ "patternfly.form", "patternfly.notification", "patternfly.table", - "patternfly.filters" + "patternfly.filters", + "react" ]); /* Setting up provider for getting config data */ diff --git a/src/commons/js/ng-react-ng-deps.js b/src/commons/js/ng-react-ng-deps.js index b4333c2b..9a18f3e7 100644 --- a/src/commons/js/ng-react-ng-deps.js +++ b/src/commons/js/ng-react-ng-deps.js @@ -4,6 +4,7 @@ export const ngDeps = {}; export function injectNgDeps(deps) { Object.assign(ngDeps, deps); + window.ngDeps = ngDeps; }; export default ngDeps; @@ -11,10 +12,10 @@ export default ngDeps; var storageModule = angular.module("TendrlModule"); storageModule.run([ - "$rootScope", - "$state", - "$q", - ($rootScope, $state, $q) => { - injectNgDeps({ $rootScope, $state, $q }); + "$stateParams", + "utils", + "config", + ($stateParams, utils, config) => { + injectNgDeps({ $stateParams, utils, config }); }, ]); diff --git a/src/commons/services/pub-sub.js b/src/commons/services/pub-sub.js new file mode 100644 index 00000000..31fa66f7 --- /dev/null +++ b/src/commons/services/pub-sub.js @@ -0,0 +1,42 @@ +const PubSubService = { + topics: {}, + subscribe: function(topic, listener) { + var that = this; + + // Create the topic's object if not yet created + if (!that.topics.hasOwnProperty.call(that.topics, topic)) { + that.topics[topic] = []; + } + + // Add the listener to queue + var index = that.topics[topic].push(listener) - 1; + + // Provide handle back for removal of topic + return { + remove: function() { + delete that.topics[topic][index]; + } + }; + }, + publish: function(topic, info) { + var that = this; + + // If the topic doesn't exist, or there's no listeners in queue, just leave + if (!that.topics.hasOwnProperty.call(that.topics, topic)) return; + + // Cycle through topics queue, fire! + that.topics[topic].forEach(function(item) { + item(info != undefined ? info : {}); + }); + } +}; + + +angular + .module("TendrlModule") + .service("pubSubService", pubSubService); + +/*@ngInject*/ +function pubSubService() { + return PubSubService; +} diff --git a/src/commons/services/utils.js b/src/commons/services/utils.js index de9000b0..53bb6ecd 100644 --- a/src/commons/services/utils.js +++ b/src/commons/services/utils.js @@ -235,8 +235,8 @@ getEventListRequest, request; - //url = "/api/events.json"; - url = config.baseUrl + "clusters/" + clusterId + "/notifications"; + url = "/api/events.json"; + //url = config.baseUrl + "clusters/" + clusterId + "/notifications"; getEventListRequest = { method: "GET", diff --git a/src/commons/services/vendor.js b/src/commons/services/vendor.js new file mode 100644 index 00000000..225391be --- /dev/null +++ b/src/commons/services/vendor.js @@ -0,0 +1,4 @@ +import React, { Component } from "react"; +import moment from "moment"; +import DatePicker from 'react-datepicker'; +require("ngreact"); \ No newline at end of file diff --git a/src/commons/stores/events-store.js b/src/commons/stores/events-store.js index aaec0e7b..55801303 100644 --- a/src/commons/stores/events-store.js +++ b/src/commons/stores/events-store.js @@ -1,15 +1,18 @@ -import React, { Component } from "react"; -import ngDeps from "../js/ng-react-ng-deps.js"; const EventStore = { + showAlertIndication: false, getAlertList: function() { var list, - deferred; + deferred, + utils = window.ngDeps.utils, + that = this; + + deferred = Q.defer(); - deferred = $q.defer(); utils.getAlertList() .then(function(data) { - $rootScope.showAlertIndication = false; + + that.showAlertIndication = false; list = data ? _formatAlertData(data) : []; deferred.resolve(list); }); @@ -28,8 +31,8 @@ const EventStore = { i; for (i = 0; i < len; i++) { - temp = {}, - temp.alertId = data[i].alert_id; + temp = {}; + temp.alertId = data[i].alert_id; temp.timeStamp = new Date(data[i].time_stamp); temp.severity = severity[data[i].severity]; temp.nodeId = data[i].node_id; @@ -39,8 +42,9 @@ const EventStore = { temp.clusterName = data[i].tags.integration_id ? data[i].tags.integration_id : ""; temp.sdsName = data[i].tags.sds_name ? data[i].tags.sds_name : ""; - if ((temp.severity === "error" || temp.severity === "warning") && !$rootScope.showAlertIndication) { - $rootScope.showAlertIndication = true; + if ((temp.severity === "error" || temp.severity === "warning") && !that.showAlertIndication) { + that.showAlertIndication = true; + PubSubService.publish("alertIndicationChanged", that.showAlertIndication); } res.push(temp); } @@ -49,9 +53,10 @@ const EventStore = { }, getEventList: function(clusterId) { var list, - deferred; + deferred, + utils = window.ngDeps.utils; - deferred = $q.defer(); + deferred = Q.defer(); utils.getEventList(clusterId) .then(function(data) { list = data ? _formatEventData(data) : []; @@ -69,8 +74,8 @@ const EventStore = { i; for (i = 0; i < len; i++) { - temp = {}, - temp.timeStamp = new Date(data[i].timestamp); + temp = {}; + temp.timeStamp = moment(new Date(data[i].timestamp)).format('DD-MMM-YY HH:mm:ss'); temp.priority = data[i].priority; temp.message = data[i].message; temp.message_id = data[i].message_id; @@ -81,13 +86,11 @@ const EventStore = { } }; -export default EventStore; - angular .module("TendrlModule") .service("eventStore", eventStore); /*@ngInject*/ -function eventStore($state, $q, $rootScope, utils) { +function eventStore() { return EventStore; } diff --git a/src/modules/base/header/header.html b/src/modules/base/header/header.html index 3933b0ca..b3196ff0 100644 --- a/src/modules/base/header/header.html +++ b/src/modules/base/header/header.html @@ -33,7 +33,7 @@