From 1c65bd8d0d86f095e0469439a0b06626e05c5395 Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Wed, 13 Apr 2016 12:01:21 +0000 Subject: [PATCH] Task #8887: selection of task/resource/claim/group/project via dataservice --- .../chartresourceusagecontroller.js | 30 +++++++++--- .../static/app/controllers/datacontroller.js | 6 ++- .../app/controllers/ganttprojectcontroller.js | 47 ++++++++++++++----- .../controllers/ganttresourcecontroller.js | 29 +++++++++--- .../static/app/controllers/gridcontroller.js | 39 +++++++++++---- .../lib/templates/index.html | 2 +- 6 files changed, 116 insertions(+), 37 deletions(-) diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/chartresourceusagecontroller.js b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/chartresourceusagecontroller.js index c028453a3a5..86e70e4398b 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/chartresourceusagecontroller.js +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/chartresourceusagecontroller.js @@ -43,6 +43,9 @@ chartResourceUsageControllerMod.controller('ChartResourceUsageController', ['$sc xAxis: { type: 'datetime', }, + yAxis: { + title: { text: '<unknown>' }, + }, series: $scope.chartSeries, title: { text: 'Resource usage' @@ -67,20 +70,33 @@ chartResourceUsageControllerMod.controller('ChartResourceUsageController', ['$sc $scope.$watch('dataService.lofarTime', updateChartLofarTime); function updateChartData() { + var selected_resource_id = $scope.dataService.selected_resource_id; + if(selected_resource_id === undefined) + return; + + var resourceDict = $scope.dataService.resourceDict; var resourceUsagesDict = $scope.dataService.resourceUsagesDict; var numResources = $scope.dataService.resources.length; - var resource = $scope.dataService.selected_resource; - if(!resource || numResources == 0 || !resourceUsagesDict[resource.id]) { + if(numResources == 0) { + $scope.chartSeries.splice(0, $scope.chartSeries.length); + $scope.chartConfig.title.text = "No resource available"; + return; + } + + var resource = resourceDict[selected_resource_id]; + + if(!resource || numResources == 0 || !resourceUsagesDict[selected_resource_id]) { $scope.chartSeries.splice(0, $scope.chartSeries.length); - $scope.chartConfig.title.text = "No resource selected"; + $scope.chartConfig.title.text = "No resource (usages) available"; return; } - //set title to resource name + //set title, axis etc $scope.chartConfig.title.text = resource.name; + $scope.chartConfig.yAxis.title.text = resource.units; - var status_usages = resourceUsagesDict[resource.id].usages; + var status_usages = resourceUsagesDict[selected_resource_id].usages; //first scan of all statuses and timestamps in usages for this resource var statuses = []; @@ -164,7 +180,7 @@ chartResourceUsageControllerMod.controller('ChartResourceUsageController', ['$sc $scope.chartSeries.splice(misc_used_cap_series_idx, 1); } - var misc_used_capacity = resourceUsagesDict[resource.id].misc_used_capacity; + var misc_used_capacity = resourceUsagesDict[selected_resource_id].misc_used_capacity; if(misc_used_capacity > 0) { misc_used_cap_series = {name: 'misc used capacity', type: 'area', color: '#aaaaff', lineWidth:1, marker:{enabled:false}, dashStyle:'Dash', animation:false }; $scope.chartSeries.push(misc_used_cap_series); @@ -201,7 +217,7 @@ chartResourceUsageControllerMod.controller('ChartResourceUsageController', ['$sc } }; - $scope.$watch('dataService.selected_resource', updateChartData); + $scope.$watch('dataService.selected_resource_id', updateChartData); $scope.$watch('dataService.resources', updateChartData, true); $scope.$watch('dataService.resourceUsagesDict', updateChartData, true); // $scope.$watch('dataService.lofarTime', function() {$scope.options.currentDateValue= $scope.dataService.lofarTime;}); diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/datacontroller.js b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/datacontroller.js index a1b1ee744d1..7a257f5b0ac 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/datacontroller.js +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/datacontroller.js @@ -29,7 +29,11 @@ angular.module('raeApp').factory("dataService", ['$http', '$q', function($http, self.taskTimes = {}; self.resourceClaimTimes = {}; - self.selected_resource; + self.selected_resource_id; + self.selected_resourceGroup_id; + self.selected_task_id; + self.selected_project_id; + self.selected_resourceClaim_id; self.initialLoadComplete = false; diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttprojectcontroller.js b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttprojectcontroller.js index 2df3e289364..3408db0ad7c 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttprojectcontroller.js +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttprojectcontroller.js @@ -59,6 +59,28 @@ ganttProjectControllerMod.controller('GanttProjectController', ['$scope', 'dataS api.tasks.on.resizeEnd($scope, moveHandler); } ); + + api.directives.on.new($scope, function(directiveName, directiveScope, element) { + if (directiveName === 'ganttRow' || directiveName === 'ganttRowLabel' ) { + element.bind('click', function(event) { + if(directiveScope.row.model.project) { + $scope.dataService.selected_project_id = directiveScope.row.model.project.id; + } + }); + } else if (directiveName === 'ganttTask') { + element.bind('click', function(event) { + if(directiveScope.task.model.raTask) { + $scope.dataService.selected_task_id = directiveScope.task.model.raTask.id; + } + }); + } + }); + + api.directives.on.destroy($scope, function(directiveName, directiveScope, element) { + if (directiveName === 'ganttRow' || directiveName === 'ganttRowLabel' || directiveName === 'ganttTask') { + element.unbind('click'); + } + }); } }; @@ -128,9 +150,10 @@ ganttProjectControllerMod.controller('GanttProjectController', ['$scope', 'dataS if(project) { ganntProjectRow = { - 'id': projectRowId, - 'name': project.name, - 'tasks': [] + id: projectRowId, + name: project.name, + project: project, + tasks: [] }; ganntRowsDict[projectRowId] = ganntProjectRow; @@ -146,10 +169,11 @@ ganttProjectControllerMod.controller('GanttProjectController', ['$scope', 'dataS if(tasktype) { ganntTypeRow = { - 'id': typeRowId, - 'parent': projectRowId, - 'name': tasktype, - 'tasks': [] + id: typeRowId, + parent: projectRowId, + name: tasktype, + project: project, + tasks: [] }; ganntRowsDict[typeRowId] = ganntTypeRow; @@ -160,10 +184,11 @@ ganttProjectControllerMod.controller('GanttProjectController', ['$scope', 'dataS var rowTask = { id: task.id.toString(), name: task.name, - 'from': task.starttime, - 'to': task.endtime, - 'color': self.taskStatusColors[task.status], - 'movable': $.inArray(task.status_id, editableTaskStatusIds) > -1 + from: task.starttime, + to: task.endtime, + raTask: task, + color: self.taskStatusColors[task.status], + movable: $.inArray(task.status_id, editableTaskStatusIds) > -1 }; if(task.predecessor_ids && task.predecessor_ids.length > 0) { diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttresourcecontroller.js b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttresourcecontroller.js index 68492190365..92d273741c7 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttresourcecontroller.js +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/ganttresourcecontroller.js @@ -48,15 +48,28 @@ ganttResourceControllerMod.controller('GanttResourceController', ['$scope', 'dat }); api.directives.on.new($scope, function(directiveName, directiveScope, element) { - if (directiveName === 'ganttRow') { + if (directiveName === 'ganttRow' || directiveName === 'ganttRowLabel' ) { element.bind('click', function(event) { - $scope.dataService.selected_resource = directiveScope.row.model.resource; + if(directiveScope.row.model.resource) { + $scope.dataService.selected_resource_id = directiveScope.row.model.resource.id; + } else if(directiveScope.row.model.resourceGroup) { + $scope.dataService.selected_resourceGroup_id = directiveScope.row.model.resourceGroup.id; + } + }); + } else if (directiveName === 'ganttTask') { + element.bind('click', function(event) { + if(directiveScope.task.model.raTask) { + $scope.dataService.selected_task_id = directiveScope.task.model.raTask.id; + } + if(directiveScope.task.model.claim) { + $scope.dataService.selected_resourceClaim_id = directiveScope.task.model.claim.id; + } }); } }); api.directives.on.destroy($scope, function(directiveName, directiveScope, element) { - if (directiveName === 'ganttRow') { + if (directiveName === 'ganttRow' || directiveName === 'ganttRowLabel' || directiveName === 'ganttTask') { element.unbind('click'); } }); @@ -134,10 +147,11 @@ ganttResourceControllerMod.controller('GanttResourceController', ['$scope', 'dat } var ganttRow = { - 'id': groupRowId, - 'parent': parentRow ? parentRow.id : null, - 'name': resourceGroup.name, - 'tasks': [] + id: groupRowId, + parent: parentRow ? parentRow.id : null, + name: resourceGroup.name, + resourceGroup: resourceGroup, + tasks: [] }; ganttRowsDict[groupRowId] = ganttRow; @@ -263,6 +277,7 @@ ganttResourceControllerMod.controller('GanttResourceController', ['$scope', 'dat to: claim.endtime, color: self.resourceClaimStatusColors[claim.status], raTask: task, + claim: claim, movable: $.inArray(task.status_id, editableTaskStatusIds) > -1 }; diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/gridcontroller.js b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/gridcontroller.js index be67022730f..8f507a7fae1 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/gridcontroller.js +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/static/app/controllers/gridcontroller.js @@ -2,21 +2,14 @@ var gridControllerMod = angular.module('GridControllerMod', ['ui.grid', 'ui.grid.edit', + 'ui.grid.selection', 'ui.grid.cellNav', - 'ui.grid.resizeColumns'/*, - 'ui.grid.datepicker'*/]); + 'ui.grid.resizeColumns']); gridControllerMod.controller('GridController', ['$scope', 'dataService', 'uiGridConstants', function($scope, dataService, uiGridConstants) { $scope.dataService = dataService; - $scope.$watch('dataService.tasks', function() { - if('tasks' in $scope.dataService && $scope.dataService.tasks.length > 0) - $scope.gridOptions.data = $scope.dataService.tasks; - else - $scope.gridOptions.data = [] - }, true); - $scope.columns = [ { field: 'name', enableCellEdit: false, @@ -81,6 +74,11 @@ gridControllerMod.controller('GridController', ['$scope', 'dataService', 'uiGrid enableSorting: true, enableFiltering: true, enableColumnResize: true, + enableRowSelection: true, + enableRowHeaderSelection: true, + enableFullRowSelection: false, + enableSelectionBatchEvent:false, + multiSelect:false, gridMenuShowHideColumns: false, columnDefs: $scope.columns, data: [], @@ -94,6 +92,12 @@ gridControllerMod.controller('GridController', ['$scope', 'dataService', 'uiGrid var newTask = { id: task.id, status: task.status }; $scope.dataService.putTask(newTask); }); + + gridApi.selection.on.rowSelectionChanged($scope,function(row){ + if(row.entity.id && row.isSelected) { + $scope.dataService.selected_task_id = row.entity.id; + } + }); } }; @@ -132,10 +136,17 @@ gridControllerMod.controller('GridController', ['$scope', 'dataService', 'uiGrid columnDef.filter.selectOptions = columnSelectOptions; }; + $scope.$watch('dataService.tasks', function() { + if('tasks' in $scope.dataService && $scope.dataService.tasks.length > 0) + $scope.gridOptions.data = $scope.dataService.tasks; + else + $scope.gridOptions.data = [] + }, true); + $scope.$watch('dataService.taskstatustypes', function() { taskstatustypenames = $scope.dataService.taskstatustypes.map(function(x) { return x.name; }); fillColumFilterSelectOptions(taskstatustypenames, $scope.columns[6]); - $scope.columns[4].editDropdownOptionsArray = $scope.dataService.taskstatustypes.map(function(x) { return {id:x.name, value:x.name}; }); + $scope.columns[6].editDropdownOptionsArray = $scope.dataService.taskstatustypes.map(function(x) { return {id:x.name, value:x.name}; }); }); $scope.$watch('dataService.tasktypes', function() { @@ -157,5 +168,13 @@ gridControllerMod.controller('GridController', ['$scope', 'dataService', 'uiGrid projectNames.sort(); fillColumFilterSelectOptions(projectNames, $scope.columns[1]); }); + + $scope.$watch('dataService.selected_task_id', function() { + var taskIdx = $scope.gridOptions.data.findIndex(function(row) {return row.id == dataService.selected_task_id}); + + if(taskIdx > -1) { + $scope.gridApi.selection.selectRow($scope.gridOptions.data[taskIdx]); + } + }); } ]); diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/templates/index.html b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/templates/index.html index c771e0af574..ed2979c945e 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/templates/index.html +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/templates/index.html @@ -54,7 +54,7 @@ <uib-tab heading="Tasks" index='0' active='true'> <div ng-controller="GridController as gridCtrl"> <strong>Tasks:</strong> - <div id="grid" ui-grid="gridOptions" ui-grid-edit ui-grid-cellnav ui-grid-resize-columns class="grid"> + <div id="grid" ui-grid="gridOptions" ui-grid-edit ui-grid-selection ui-grid-cellnav ui-grid-resize-columns class="grid"> </div> </div> </uib-tab> -- GitLab