diff --git a/apps/steward-app/src/main/js/app/client/statistics/query-counts-table.tpl.html b/apps/steward-app/src/main/js/app/client/statistics/query-counts-table.tpl.html new file mode 100644 index 000000000..306e51f6c --- /dev/null +++ b/apps/steward-app/src/main/js/app/client/statistics/query-counts-table.tpl.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+ Query Counts By User +
UserQuery Count
{{user._1.userName}}{{user._2}}
Total: {{queriesPerUser.total}}
+ + diff --git a/apps/steward-app/src/main/js/app/client/statistics/query-topic-status-table.tpl.html b/apps/steward-app/src/main/js/app/client/statistics/query-topic-status-table.tpl.html new file mode 100644 index 000000000..8382eefdc --- /dev/null +++ b/apps/steward-app/src/main/js/app/client/statistics/query-topic-status-table.tpl.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+ Query Topics By Status +
+ Status + + Query Topic Count +
{{parseStateTitle(state)}}{{parseStateCount(state)}}
Total: {{topicsPerState.total}}
\ No newline at end of file diff --git a/apps/steward-app/src/main/js/app/client/statistics/statistics-model.js b/apps/steward-app/src/main/js/app/client/statistics/statistics-model.js new file mode 100644 index 000000000..318b9be8d --- /dev/null +++ b/apps/steward-app/src/main/js/app/client/statistics/statistics-model.js @@ -0,0 +1,69 @@ +(function() { + 'use strict'; + + StatisticsModel.$inject = ['$http','StewardService']; + function StatisticsModel($http, StewardService) { + var service = StewardService; + var urls = { + queriesPerUser: 'steward/statistics/queriesPerUser', + topicsPerState: 'steward/statistics/topicsPerState' + }; + + // -- public -- // + return { + getQueriesPerUser: getQueriesPerUser, + getTopicsPerState: getTopicsPerState + }; + + // -- private -- // + function getQueriesPerUser(startDate, endDate) { + + // -- make sure undefined is passed in -- // + var skip, limit, state, sortBy, sortDirection; + var url = service.getUrl(urls.queriesPerUser, skip, limit, state, + sortBy, sortDirection, startDate, endDate); + + return $http.get(url) + .then(parseQueriesPerUser, onFail); + } + + function getTopicsPerState(startDate, endDate) { + + // -- make sure undefined is passed in -- // + var skip, limit, state, sortBy, sortDirection; + var url = service.getUrl(urls.topicsPerState, skip, limit, state, + sortBy, sortDirection, startDate, endDate); + + return $http.get(url) + .then(parseTopicsPerState, onFail); + } + + // -- private -- // + function onFail(result) { + alert('HTTP Request Fail: ' + result); + } + + function parseQueriesPerUser(result) { + + var total = result.data.total, + users = result.data.queriesPerUser; + + return { + total: total, + users: users + }; + } + + function parseTopicsPerState(result) { + + var total = result.data.total, + states = result.data.topicsPerState; + + return { + total: total, + states: states + }; + } + } + +})(); diff --git a/apps/steward-app/src/main/js/app/client/statistics/statistics.controller.js b/apps/steward-app/src/main/js/app/client/statistics/statistics.controller.js deleted file mode 100644 index a419dd582..000000000 --- a/apps/steward-app/src/main/js/app/client/statistics/statistics.controller.js +++ /dev/null @@ -1,10 +0,0 @@ -(function() { - 'use strict'; - - angular.module('shrine.steward.statistics') - .controller('StatisticsController', StatisticsController); - - function StatisticsController() { - var statistics = this; - } -})(); \ No newline at end of file diff --git a/apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js b/apps/steward-app/src/main/js/app/client/statistics/statistics.js similarity index 99% copy from apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js copy to apps/steward-app/src/main/js/app/client/statistics/statistics.js index f84adae48..d242e920c 100644 --- a/apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js +++ b/apps/steward-app/src/main/js/app/client/statistics/statistics.js @@ -1,132 +1,130 @@ 'use strict'; /** * @ngdoc function * @name sbAdminApp.controller:MainCtrl * @description * # MainCtrl * Controller of the sbAdminApp */ angular.module('stewardApp') .controller('StatisticsCtrl', ['$scope', '$timeout', '$app', 'StatisticsModel', function ($scope, $timeout, $app, model) { - - //existing date range logic. var startDate = new Date(), endDate = new Date(); startDate.setDate(endDate.getDate() - 7); $scope.getDateString = function (date) { return $app.utils.utcToMMDDYYYY(date); }; $scope.startDate = $scope.getDateString(startDate); $scope.endDate = $scope.getDateString(endDate); $scope.isValid = true; $scope.startOpened = false; $scope.endOpened = false; $scope.queriesPerUser = {}; $scope.topicsPerState = {}; $scope.format = 'MM/dd/yyyy'; //http://angular-ui.github.io/bootstrap/ $scope.openStart = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.startOpened = true; }; $scope.openEnd = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.endOpened = true; }; $scope.validateRange = function () { var startUtc, endUtc, secondsPerDay = 86400000; if ($scope.startDate === undefined || $scope.endDate === undefined) { $scope.isValid = false; return; } //can validate date range here. startUtc = $app.utils.timestampToUtc($scope.startDate); endUtc = $app.utils.timestampToUtc($scope.endDate) + secondsPerDay; if (endUtc - startUtc <= 0) { $scope.isValid = false; } else { $scope.isValid = true; } return $scope.isValid; }; $scope.addDateRange = function () { if (!$scope.validateRange()) { return; } var secondsPerDay = 86400000; $scope.getResults($app.utils.timestampToUtc($scope.startDate), $app.utils.timestampToUtc($scope.endDate) + secondsPerDay); }; //@todo: this is workaround logic. $scope.parseStateTitle = function (state) { var title = ""; if (state.Approved !== undefined) { title = "Approved"; } else { title = (state.Rejected !== undefined) ? "Rejected" : "Pending"; } return title; }; //@todo: this is workaround logic. $scope.parseStateCount = function (state) { var member = $scope.parseStateTitle(state); return state[member]; }; $scope.getResults = function (startUtc, endUtc) { model.getQueriesPerUser(startUtc, endUtc) .then(function (result) { $scope.queriesPerUser = result; }); model.getTopicsPerState(startUtc, endUtc) .then(function (result) { $scope.topicsPerState = result; }); }; $scope.addDateRange(); // -- end existing statistics logic --// }]) .directive("queryCounts", function () { return { restrict: "E", templateUrl: "app/client/dashboard/statistics/query-counts-table.tpl.html", replace: true }; }) .directive("topicStatus", function () { return { restrict: "E", templateUrl: "app/client/dashboard/statistics/query-topic-status-table.tpl.html", replace: true }; }); diff --git a/apps/steward-app/src/main/js/app/client/statistics/statistics.tpl.html b/apps/steward-app/src/main/js/app/client/statistics/statistics.tpl.html index e69de29bb..c620ecdd2 100644 --- a/apps/steward-app/src/main/js/app/client/statistics/statistics.tpl.html +++ b/apps/steward-app/src/main/js/app/client/statistics/statistics.tpl.html @@ -0,0 +1,61 @@ +
+
+
+
+ +
+ + +
+ +
+ + +
+ + + +
+
+
+ +
+
+
+ +
+ +
+
+ +
diff --git a/apps/steward-app/src/main/js/app/server/.gitignore b/apps/steward-app/src/main/js/app/server/.gitignore deleted file mode 100644 index 951828625..000000000 --- a/apps/steward-app/src/main/js/app/server/.gitignore +++ /dev/null @@ -1,18 +0,0 @@ -*.class -*.log - -# mvn -target/ - -# emacs cruft -*.*~ - -# javascript artifacts -./node_modules/ - -# idea -.idea/ -*.iml - -# osx cruft -.DS_Store \ No newline at end of file diff --git a/apps/steward-app/src/main/js/app/server/package.json b/apps/steward-app/src/main/js/app/server/package.json deleted file mode 100644 index 8cb5a00f7..000000000 --- a/apps/steward-app/src/main/js/app/server/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "steward-mock-api", - "main": "server-mock.js", - "scripts":{ - "start": "node server-mock" - }, - "dependencies": { - "body-parser": "~1.0.1", - "cors": "^2.7.1", - "express": "~4.0.0", - "mongoose": "~3.6.13" - } -} diff --git a/apps/steward-app/src/main/js/app/server/server-mock.js b/apps/steward-app/src/main/js/app/server/server-mock.js deleted file mode 100644 index dbe2e353e..000000000 --- a/apps/steward-app/src/main/js/app/server/server-mock.js +++ /dev/null @@ -1,297 +0,0 @@ - -// BASE SETUP -// ============================================================================= -//https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4 -// call the packages we need -var express = require('express'); // call express -var cors = require('cors'); -var app = express(); // define our app using express -var bodyParser = require('body-parser'); - -// configure app to use bodyParser() -// this will let us get the data from a POST -app.use(bodyParser.urlencoded({ extended: true })); -app.use(bodyParser.json()); -app.use(cors()); - -var port = process.env.PORT || 8080; // set our port - -// ROUTES FOR OUR API -// ============================================================================= -var router = express.Router(); // get an instance of the express Router - - - -// test route to make sure everything is working (accessed at GET http://localhost:8080/api) -router.get('/user/whoami', function (req, res) { - var user = parseAuthHeader(req); - var response = "AuthenticationFailed"; - - if (user.username == 'ben' && user.password == 'kapow') { - response = { userName: 'ben', fullName: "ben", roles: ["Researcher"] }; - } - - else if (user.username == 'dave' && user.password == 'kablam') { - response = { userName: 'dave', fullName: "dave", roles: ["Researcher", "DataSteward"] }; - } - - res.json(response); -}); - -//"https://shrine-dev1.catalyst:6443/steward/steward/topics?skip=0&limit=20&state=Pending&sortBy=changeDate&sortDirection=ascending" -//"https://shrine-dev1.catalyst:6443/steward/steward/topics?skip=0&limit=20&state=Approved&sortBy=changeDate&sortDirection=ascending" -//"https://shrine-dev1.catalyst:6443/steward/steward/topics?skip=0&limit=20&state=Rejected&sortBy=changeDate&sortDirection=ascending" -// more routes for our API will happen here -/* -*/ - -// test route to make sure everything is working (accessed at GET http://localhost:8080/api) -router.get('/steward/topics', function (req, res) { - var user = parseAuthHeader(req); - var response = { - skipped: 0, - totalCount: 5, - userId: user.username - }; - - var topics = getMockStewardTopics(response.totalCount, 'Pending'); - - response.topics = topics; - res.json(response); -}); - -router.get('/researcher/topics', function (req, res) { - var user = parseAuthHeader(req); - var response = { - skipped: 0, - totalCount: 5, - userId: user.username - }; - - var topics = getMockStewardTopics(response.totalCount, 'Pending', 'Researcher'); - - response.topics = topics; - res.json(response); -}); - - -//https://shrine-dev1.catalyst:6443/steward/researcher/editTopicRequest/17 - -// test route to make sure everything is working (accessed at GET http://localhost:8080/api) -//https://codeforgeek.com/2014/09/handle-get-post-request-express-4/ -router.post('/researcher/editTopicRequest/:id', function (req, res) { - res.end('ok'); -}); - -// test route to make sure everything is working (accessed at GET http://localhost:8080/api) -router.post('/researcher/requestTopicAccess', function (req, res) { - var topic = req.body.topic; - res.end('ok'); -}); - -//https://codeforgeek.com/2014/09/handle-get-post-request-express-4/ -router.post('/steward/approveTopic/topic/:id', function (req, res) { - res.end('ok'); -}); - -router.post('/steward/rejectTopic/topic/:id', function (req, res) { - res.end('ok'); -}); - -//Query History Methods: -//"https://shrine-dev1.catalyst:6443/steward/researcher/queryHistory/topic/8?skip=0&limit=20&sortBy=date&sortDirection=ascending" -router.get('/researcher/queryHistory/topic/:id', function (req, res){ - var response = { - skipped: 0, - totalCount: 5 - }; - var queryRecords = getResearcherMockQueryHistory(response.totalCount); - response.queryRecords = queryRecords; - - res.json(response); -}); - - -//"https://shrine-dev1.catalyst:6443/steward/researcher/queryHistory?skip=0&limit=20&sortBy=date&sortDirection=ascending" -//Query History Methods: -//"https://shrine-dev1.catalyst:6443/steward/researcher/queryHistory/topic/8?skip=0&limit=20&sortBy=date&sortDirection=ascending" -router.get('/researcher/queryHistory/', function (req, res){ - var response = { - skipped: 0, - totalCount: 5 - }; - var queryRecords = getResearcherMockQueryHistory(response.totalCount); - response.queryRecords = queryRecords; - - res.json(response); -}); - - -//"https://shrine-dev1.catalyst:6443/steward/researcher/queryHistory/topic/8?skip=0&limit=20&sortBy=date&sortDirection=ascending" -router.get('/steward/queryHistory/topic/:id', function (req, res){ - var response = { - skipped: 0, - totalCount: 5 - }; - var queryRecords = getStewardMockQueryHistory(response.totalCount); - response.queryRecords = queryRecords; - - res.json(response); -}); - -//"https://shrine-dev1.catalyst:6443/steward/researcher/queryHistory/topic/8?skip=0&limit=20&sortBy=date&sortDirection=ascending" -router.get('/steward/queryHistory/', function (req, res){ - var response = { - skipped: 0, - totalCount: 5 - }; - var queryRecords = getStewardMockQueryHistory(response.totalCount); - response.queryRecords = queryRecords; - - res.json(response); -}); - - -// REGISTER OUR ROUTES ------------------------------- -// all of our routes will be prefixed with /api -app.use('/steward', router); - -// START THE SERVER -// ============================================================================= -app.listen(port); -console.log('Magic happens on port ' + port); - -/** - * http://stackoverflow.com/questions/5951552/basic-http-authentication-in-node-js - */ -function parseAuthHeader(req) { - var header = req.headers['authorization'] || '', // get the header - token = header.split(/\s+/).pop() || '', // and the encoded auth token - auth = new Buffer(token, 'base64').toString(), // convert from base64 - parts = auth.split(/:/), // split on colon - username = parts[0], - password = parts[1]; - - return { - username: username, - password: password - }; -} - -function getMockStewardTopics(numberOfResults, state, role) { - state = state || 'Pending'; - role = role || 'DataSteward'; - var mockResult; - - var results = []; - for (var i = 0; i < numberOfResults; i++) { - - if (role == 'DataSteward') { - mockResult = getMockStewardTopicResult(); - } else { - mockResult = getMockResearcherTopicResult(); - } - - mockResult.name = i + ' ' + mockResult.name; - mockResult.state = state; - mockResult.description = i + ' ' + mockResult.description; - - results.push(mockResult); - } - - return results; -} - -function getStewardMockQueryHistory(numberOfResults) { - var results = []; - var topic = getMockStewardTopicResult() - var user = getMockDave(); - - for(var i = 0; i < numberOfResults; i ++) { - var result = getMockQueryResult(user, topic); - results.push(result); - } - - return results; -} - - -function getResearcherMockQueryHistory(numberOfResults) { - var results = [] - var topic = getMockResearcherTopicResult(); - var user = getMockBen(); - - - for(var i = 0; i < numberOfResults; i ++) { - var result = getMockQueryResult(user, topic); - results.push(result); - } - - return results; -} - -function getMockQueryResult(user, topic) { - return { - date: 1440773077637, - externalId: -1, - name: '3 years old@10:44:20', - queryContents: '3 years old@10:44:20\\SHRINE\SHRINE\Demographics\Age\0-9 years old\3 years old\', - stewardId: 2, - stewardResponse: 'Approved', - topic: topic, - user: user - }; -} - -function getMockBen() { - return { - fullName: 'Steward Test Researcher Ben', - roles: ['Researcher'], - userName: 'ben' - }; -} - -function getMockDave() { - return { - fullName: 'Steward Test Steward Dave', - roles: ['DataSteward', 'Researcher'], - userName: 'dave' - }; -} - -function getMockStewardTopicResult(user, creator) { - var ben = getMockBen(); - var dave = getMockDave(); - - return { - changeDate: 1444234776566, - fullName: dave.fullName, - roles: dave.roles, - userName: dave.userName, - createDate: 1443816532550, - createdBy: ben, - description: 'Dave\'s non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', - id: 8, - name: 'Dave\'s Phantom Limb Pain in Recent Amputees', - state: 'Approved' - }; -} - - -function getMockResearcherTopicResult() { - var ben = getMockBen(); - var dave = getMockDave(); - - return { - changeDate: 1444234776566, - fullName: ben.fullName, - roles: ben.roles, - userName: ben.userName, - createDate: 1443816532550, - createdBy: dave, - description: 'Ben\'s non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', - id: 8, - name: 'Ben\'s Phantom Limb Pain in Recent Amputees', - state: 'Approved' - }; -} diff --git a/apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js b/apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js index f84adae48..d242e920c 100644 --- a/apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js +++ b/apps/steward-app/src/main/js/src/app/dashboard/statistics/statistics.js @@ -1,132 +1,130 @@ 'use strict'; /** * @ngdoc function * @name sbAdminApp.controller:MainCtrl * @description * # MainCtrl * Controller of the sbAdminApp */ angular.module('stewardApp') .controller('StatisticsCtrl', ['$scope', '$timeout', '$app', 'StatisticsModel', function ($scope, $timeout, $app, model) { - - //existing date range logic. var startDate = new Date(), endDate = new Date(); startDate.setDate(endDate.getDate() - 7); $scope.getDateString = function (date) { return $app.utils.utcToMMDDYYYY(date); }; $scope.startDate = $scope.getDateString(startDate); $scope.endDate = $scope.getDateString(endDate); $scope.isValid = true; $scope.startOpened = false; $scope.endOpened = false; $scope.queriesPerUser = {}; $scope.topicsPerState = {}; $scope.format = 'MM/dd/yyyy'; //http://angular-ui.github.io/bootstrap/ $scope.openStart = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.startOpened = true; }; $scope.openEnd = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.endOpened = true; }; $scope.validateRange = function () { var startUtc, endUtc, secondsPerDay = 86400000; if ($scope.startDate === undefined || $scope.endDate === undefined) { $scope.isValid = false; return; } //can validate date range here. startUtc = $app.utils.timestampToUtc($scope.startDate); endUtc = $app.utils.timestampToUtc($scope.endDate) + secondsPerDay; if (endUtc - startUtc <= 0) { $scope.isValid = false; } else { $scope.isValid = true; } return $scope.isValid; }; $scope.addDateRange = function () { if (!$scope.validateRange()) { return; } var secondsPerDay = 86400000; $scope.getResults($app.utils.timestampToUtc($scope.startDate), $app.utils.timestampToUtc($scope.endDate) + secondsPerDay); }; //@todo: this is workaround logic. $scope.parseStateTitle = function (state) { var title = ""; if (state.Approved !== undefined) { title = "Approved"; } else { title = (state.Rejected !== undefined) ? "Rejected" : "Pending"; } return title; }; //@todo: this is workaround logic. $scope.parseStateCount = function (state) { var member = $scope.parseStateTitle(state); return state[member]; }; $scope.getResults = function (startUtc, endUtc) { model.getQueriesPerUser(startUtc, endUtc) .then(function (result) { $scope.queriesPerUser = result; }); model.getTopicsPerState(startUtc, endUtc) .then(function (result) { $scope.topicsPerState = result; }); }; $scope.addDateRange(); // -- end existing statistics logic --// }]) .directive("queryCounts", function () { return { restrict: "E", templateUrl: "app/client/dashboard/statistics/query-counts-table.tpl.html", replace: true }; }) .directive("topicStatus", function () { return { restrict: "E", templateUrl: "app/client/dashboard/statistics/query-topic-status-table.tpl.html", replace: true }; });