diff --git a/apps/steward-app/src/main/js/src/app/dashboard/history/history-table/history-table.tpl.html b/apps/steward-app/src/main/js/src/app/dashboard/history/history-table/history-table.tpl.html index c9cbe7aba..b33790f7b 100644 --- a/apps/steward-app/src/main/js/src/app/dashboard/history/history-table/history-table.tpl.html +++ b/apps/steward-app/src/main/js/src/app/dashboard/history/history-table/history-table.tpl.html @@ -1,87 +1,87 @@
- + ID - + Query Topic - + Username - + Query Text - + Status - + Date
{{query.stewardId}} {{query.topic.name}} {{query.user.userName}} {{query.name}} {{query.stewardResponse}} {{formatDate(query.date)}}
\ No newline at end of file diff --git a/apps/steward-app/src/main/js/src/app/dashboard/history/history.js b/apps/steward-app/src/main/js/src/app/dashboard/history/history.js index aea311503..40f3ac57f 100644 --- a/apps/steward-app/src/main/js/src/app/dashboard/history/history.js +++ b/apps/steward-app/src/main/js/src/app/dashboard/history/history.js @@ -1,170 +1,187 @@ /** * Query History * @author Ben Carmen * @date 04/04/2015 * Edit Log: * @todo: bdc -- 04-04-15 -- consider making steward role default a utils. method. * @todo: bdc -- 04-06-15 -- change $scope.data.queries to $scope.queries. */ angular.module('stewardApp') .directive('queryHistory', function (HistoryMdl, $app, $modal) { return { restrict: 'E', scope: { topic: "=" }, templateUrl: 'src/app/dashboard/history/history.tpl.html', controller: function ($scope) { //private var roles = $app.globals.UserRoles, user = $app.globals.currentUser, utils = $app.utils, model, role; //steward by default. role = (utils.hasAccess(user, [roles.ROLE2])) ? roles.ROLE2 : roles.ROLE1; model = HistoryMdl.getInstance(role); $scope.queries = []; $scope.formatDate = $app.utils.utcToMMDDYYYY; $scope.sort = { currentColumn: 'date', descending: false } $scope.getTopicTitle = function (topic) { return (topic !== undefined)? topic.name + ' Query History' : 'Query History'; }; $scope.getQueryTitle = function (queryXml) { var queryAsJson = utils.xmlToJson(queryXml); return queryAsJson.queryDefinition.name; }; /** * Modal Configuration for creating a new topic. * @type {{templateUrl: string, controller: Function}} */ $scope.modalConfig = { templateUrl: 'src/app/history/query-detail/query-detail.tpl.html', controller: function ($scope, $modalInstance, modalData) { $scope.query = modalData; $scope.prettify = function (queryData) { var array = queryData.split('<'), tab = '\t', enter = '\n'; //traverse array var ret = array.join(enter + tab + '<'); return ret; }; $scope.ok = function () { $modalInstance.dismiss('cancel'); }; $scope.queryContents = $scope.prettify($scope.query.queryContents); } }; //set pagination values. $scope.range = $app.globals.ViewConfig.RANGE;//range of paging numbers at bottom $scope.length = 0; //total number of results $scope.pageIndex = $app.globals.ViewConfig.INDEX;//current page $scope.limit = $app.globals.ViewConfig.LIMIT;//number of results to show in table at per page. $scope.skip = 0; //number of results to skip. /* * Refresh Query History - get a range of query history results. * @param: skip - number of result to skip * @param: limit - number of results. */ $scope.refreshHistory = function () { var topicId = ($scope.topic !== undefined) ? $scope.topic.id : undefined, sortBy, sortDirection; if ($scope.sort && $scope.sort.currentColumn !== "") { sortBy = $scope.sort.currentColumn; sortDirection = ($scope.sort.descending) ? "descending" : "ascending"; } $scope.queryRecords = model.getHistory($scope.skip, $scope.limit, sortBy, sortDirection, topicId) .then(function (result) { $scope.queries = result.queryRecords; $scope.length = result.totalCount; }); }; /* * Handler for when pagination page is changed. */ $scope.onPageSelected = function () { var mult; mult = ($scope.pageIndex > 0) ? $scope.pageIndex - 1 : 0; $scope.skip = $scope.limit * mult; $scope.refreshHistory($scope.skip, $scope.limit); }; + /** + * + * @param columnId + */ + $scope.setSort = function (columnId) { + + //change direction if same column is clicked. + if($scope.sort.currentColumn == columnId) { + $scope.sort.descending = !$scope.sort.descending; + return; + } + + //start out the sorting as ascending. + $scope.sort.descending = false; + $scope.sort.currentColumn = columnId; + } + /** * */ $scope.showQuery = function (query) { var model = $scope.model; var modalInstance = $modal.open({ animation: true, templateUrl: 'src/app/dashboard/history/history-table/query-detail.tpl.html', controller: function ($scope, $modalInstance, query) { $scope.query = query; $scope.prettify = function (queryData) { var array = queryData.split('<'), tab = '\t', enter = '\n'; var ret = array.join(enter + tab + '<'); return ret; }; $scope.ok = function () { $modalInstance.dismiss('cancel'); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; $scope.queryContents = $scope.prettify($scope.query.queryContents); }, //size: undefined, resolve: { query: function () { return query; } } }); }; $scope.refreshHistory(); } }; }) .directive("historyTable", function () { return { restrict: "E", templateUrl: "src/app/dashboard/history/history-table/history-table.tpl.html", replace: true }; }); \ No newline at end of file diff --git a/apps/steward-app/src/main/js/src/app/dashboard/topics/topic-table/topic-table.tpl.html b/apps/steward-app/src/main/js/src/app/dashboard/topics/topic-table/topic-table.tpl.html index c30086bb7..8d4cb19fc 100644 --- a/apps/steward-app/src/main/js/src/app/dashboard/topics/topic-table/topic-table.tpl.html +++ b/apps/steward-app/src/main/js/src/app/dashboard/topics/topic-table/topic-table.tpl.html @@ -1,114 +1,109 @@
- + ID - + Topic Name - + Username - + Date Created - + Last Updated - + State
{{topic.id}} {{topic.name}} {{topic.createdBy.userName}} {{formatDate(topic.createDate)}} {{formatDate(topic.changeDate)}} {{topic.state}} view
-
diff --git a/apps/steward-app/src/main/js/src/app/dashboard/topics/topics.js b/apps/steward-app/src/main/js/src/app/dashboard/topics/topics.js index a283f05c8..662a695b5 100644 --- a/apps/steward-app/src/main/js/src/app/dashboard/topics/topics.js +++ b/apps/steward-app/src/main/js/src/app/dashboard/topics/topics.js @@ -1,266 +1,283 @@ 'use strict'; /** * @ngdoc function * @name sbAdminApp.controller:MainCtrl * @description * # MainCtrl * Controller of the sbAdminApp * https://scotch.io/tutorials/sort-and-filter-a-table-using-angular */ angular.module('stewardApp') .controller("NewTopicCtrl", function ($scope, $modalInstance, model, refreshTopics) { $scope.newTopic = {name: "", description: ""}; $scope.ok = function () { var name = $scope.newTopic.name, description = $scope.newTopic.description; model.requestNewTopic({"name": name, "description": description}) .then(function () { refreshTopics(); $modalInstance.close(); }); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }) .controller('TopicsCtrl', function ($scope, $position, $app, TopicsModelFactory, $modal) { //private vars var roles = $app.globals.UserRoles, user = $app.globals.currentUser, utils = $app.utils, scope = $scope, ModelFactory = TopicsModelFactory, role, model, initState; //determine role of user. role = (utils.hasAccess(user, [roles.ROLE2])) ? roles.ROLE2 : roles.ROLE1; initState = (role === roles.ROLE2) ? $app.globals.States.STATE1 : "ALL"; model = ModelFactory.getInstance(role); $scope.model = model; $scope.roles = roles; $scope.userRole = role; $scope.formatDate = $app.utils.utcToMMDDYYYY; $scope.states = $app.globals.States; $scope.topics = []; $scope.filterBy = 'topicName'; $scope.sort = { currentColumn: 'changeDate', descending: false }; $scope.selectedTab = initState; /** * Parent scope data referenced by children. * @type {{topics: Array, name: string, description: string, sort: {column: string, descending: boolean}}} */ $scope.data = { name: 'name', description: 'description' }; //set pagination values. $scope.range = $app.globals.ViewConfig.RANGE;//range of paging numbers at bottom $scope.length = 0; //total number of results $scope.pageIndex = $app.globals.ViewConfig.INDEX;//current page $scope.limit = $app.globals.ViewConfig.LIMIT;//number of results to show in table at per page. $scope.skip = 0; //number of results to skip. /* * Handler for when pagination page is changed. */ $scope.onPageSelected = function () { var mult; mult = ($scope.pageIndex > 0) ? $scope.pageIndex - 1 : 0; $scope.skip = $scope.limit * mult; $scope.refreshTopics($scope.skip, $scope.limit); }; $scope.setStateAndRefresh = function (state) { $scope.state = state; $scope.refreshTopics(); }; + /** + * + * @param columnId + */ + $scope.setSort = function (columnId) { + + //change direction if same column is clicked. + if($scope.sort.currentColumn == columnId) { + $scope.sort.descending = !$scope.sort.descending; + return; + } + + //start out the sorting as ascending. + $scope.sort.descending = false; + $scope.sort.currentColumn = columnId; + } + $scope.refreshTopics = function () { var state, sortBy, sortDirection; if ($scope.state !== "ALL") { state = $scope.state; } if ($scope.sort && $scope.sort.currentColumn !== "") { sortBy = $scope.sort.currentColumn; sortDirection = ($scope.sort.descending) ? "descending" : "ascending"; } $scope.model.getTopics($scope.skip, $scope.limit, state, sortBy, sortDirection) .then(function (result) { scope.topics = result.topics; $scope.length = result.totalCount; }); }; $scope.getTitle = function (state) { var title = " Query Topics"; return (role === roles.ROLE2) ? ($scope.state + title) : title; }; //method wrapper for scope resolution in modal context. function requestNewTopic(topic) { if (model.requestNewTopic !== undefined) { return model.requestNewTopic(topic); } } //method wrapper for scope resolution in modal context. function refreshTopics() { return $scope.refreshTopics(); } $scope.createTopic = function () { var model = $scope.model; var modalInstance = $modal.open({ animation: true, templateUrl: 'src/app/dashboard/topics/new-topic/new-topic.tpl.html', controller: function ($scope, $modalInstance) { $scope.newTopic = {name: "", description: ""}; $scope.ok = function () { var name = $scope.newTopic.name, description = $scope.newTopic.description; requestNewTopic({"name": name, "description": description}) .then(function () { refreshTopics(); $modalInstance.close(); }); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }, //size: undefined, resolve: { model: model, refreshTopics: $scope.refreshTopics } }); }; $scope.open = function (topic) { var modalInstance = $modal.open({ animation: true, templateUrl: 'src/app/dashboard/topics/topic-table/topic-detail.tpl.html', controller: function ($scope, $modalInstance, topic, $app, Role2TopicDetailMdl, Role1TopicDetailMdl){ $scope.roles = $app.globals.UserRoles; $scope.userRole = $app.globals.currentUser.roles[0]; $scope.topic = topic; $scope.tabState = 'description'; $scope.formatDate = $app.utils.utcToMMDDYYYY; $scope.loadedState = $scope.topic.state; $scope.topicName = topic.name; $scope.topicDescription = topic.description; $scope.data = {topicState: topic.state}; $scope.ok = function (id) { $scope.topic.state = $scope.data.topicState; if ($scope.topic.state === "Pending") { $modalInstance.close($scope.topic); return; } (($scope.topic.state == "Approved") ? Role2TopicDetailMdl.approveTopic(id) : Role2TopicDetailMdl.rejectTopic(id)) .then(function (result) { refreshTopics(); $modalInstance.close(result); }); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; $scope.isEditable = function () { return ($app.globals.currentUser.roles[0] === $scope.roles.ROLE2) || ($scope.topic.state === "Pending"); }; $scope.setState = function (state) { if ($scope.isEditable() === true) { $scope.tabState = state; } }; $scope.update = function (id, name, description) { Role1TopicDetailMdl.updateTopic(id, name, description) .then( function (result) { refreshTopics(); $modalInstance.close(result); }); }; $scope.canViewHistory = function () { var canView = (($app.globals.currentUser.roles[0] === $scope.roles.ROLE2 && $scope.loadedState !== "Pending") || ($scope.loadedState === "Approved")) && $scope.tabState != 'edit'; return canView; }; }, //size: undefined, resolve: { topic: function () { return topic; } } }); }; $scope.setStateAndRefresh(initState); }) .directive("topicTable", function () { return { restrict: "E", templateUrl: "src/app/dashboard/topics/topic-table/topic-table.tpl.html", replace: true }; }) .directive("role1Description", function () { return { restrict: "E", templateUrl: "src/app/dashboard/topics/topic-table/topic-detail/role1-description.tpl.html", replace: true }; }) .directive("role2Description", function () { return { restrict: "E", templateUrl: "src/app/dashboard/topics/topic-table/topic-detail/role2-description.tpl.html", replace: true }; }) .directive("role1Edit", function () { return { restrict: "E", templateUrl: "src/app/dashboard/topics/topic-table/topic-detail/role1-edit.tpl.html", replace: true }; }) .directive("role2Edit", function () { return { restrict: "E", templateUrl: "src/app/dashboard/topics/topic-table/topic-detail/role2-edit.tpl.html", replace: true }; });