1010 * You must not remove this notice, or any other, from this software.
1111 *
1212 */
13- import _ from "lodash" ;
14- import d3 from "d3" ;
1513import EventDispatcher from "../common/EventDispatcher" ;
16- import { perhaps } from "../common/index" ;
17- import { calculateGroupSummary } from "../ratings/directives/common" ;
18-
19-
20- function indexCapabilities ( appCapabilities ) {
21- return _ . chain ( appCapabilities )
22- . map ( 'capability' )
23- . keyBy ( 'id' )
24- . value ( ) ;
25- }
26-
27-
28- function calculateGroupData ( apps , appCapabilities , measurables , allRatings ) {
29- const appsById = _ . keyBy ( apps , 'id' ) ;
30-
31- const capabilitiesById = indexCapabilities ( appCapabilities ) ;
32-
33- const byCapabilityThenAppThenMeasurable = d3 . nest ( )
34- . key ( r => r . capability . id )
35- . key ( r => r . parent . id )
36- . key ( r => r . measurable . code )
37- . map ( allRatings ) ;
38-
39- const mkRatings = ( appId , rawRatings , capabilityId ) => {
40- const ratings = _ . map (
41- measurables ,
42- m => {
43- const ragRating = perhaps ( ( ) => rawRatings [ m . code ] [ 0 ] . ragRating , 'Z' ) ;
44- return { current : ragRating , measurable : m . code || m . id } ;
45- }
46- ) ;
47- return {
48- subject : appsById [ appId ] ,
49- capabilityId,
50- ratings
51- } ;
52- } ;
53-
54- const mkGroup = ( capabilityId ) => {
55- const capabilityGroup = byCapabilityThenAppThenMeasurable [ capabilityId ] ;
56-
57- const raw = _ . chain ( capabilityGroup )
58- . keys ( )
59- . map ( appId => mkRatings ( appId , capabilityGroup [ appId ] , capabilityId ) )
60- . sortBy ( 'subject.name' )
61- . value ( ) ;
62-
63- return {
64- groupRef : capabilitiesById [ capabilityId ] ,
65- raw,
66- measurables,
67- summaries : calculateGroupSummary ( raw ) ,
68- collapsed : true
69- } ;
70- } ;
71-
72- return _ . chain ( byCapabilityThenAppThenMeasurable )
73- . keys ( )
74- . map ( mkGroup )
75- . sortBy ( 'groupRef.name' )
76- . value ( ) ;
77- }
78-
79-
80- function calculateCapabilityRatings ( orgUnitId , apps , appCapabilities , perspective , allRatings , $state ) {
81-
82- const measurables = perspective . measurables ;
83- const groups = calculateGroupData ( apps , appCapabilities , measurables , allRatings ) ;
84-
85- function isPrimary ( app , capabilityId ) {
86- const c = _ . find ( appCapabilities , ac => ac . capability . id === Number ( capabilityId ) ) ;
87- if ( ! c ) return false ;
88- const a = _ . find ( c . applications , { id : app . id } ) ;
89- if ( ! a ) return false ;
90- return a . primary ;
91- }
92-
93- const data = {
94- groups,
95- tweakers : {
96- subjectLabel : {
97- enter : selection =>
98- selection
99- . on ( 'click.go' , d => $state . go ( 'main.app.view' , { id : d . subject . id } ) )
100- . attr ( 'font-style' , d => d . subject . organisationalUnitId === orgUnitId ? 'none' : 'italic' )
101- . text ( d => isPrimary ( d . subject , d . capabilityId )
102- ? '\u2605 ' + _ . truncate ( d . subject . name , 24 )
103- : _ . truncate ( d . subject . name , 26 ) )
104-
105- } ,
106- ratingRow : {
107- enter : selection =>
108- selection . attr ( 'opacity' , d => d . subject . organisationalUnitId === orgUnitId ? 1 : 0.6 )
109- }
110- } ,
111- measurables
112- } ;
113-
114- function showDirectsOnly ( ) {
115- const directApps = _ . filter ( apps , { organisationalUnitId : orgUnitId } ) ;
116- const directAppIds = _ . map ( directApps , 'id' ) ;
117-
118- data . groups = calculateGroupData (
119- directApps ,
120- appCapabilities ,
121- measurables ,
122- _ . filter ( allRatings , r => _ . includes ( directAppIds , r . parent . id ) ) ) ;
123- }
124-
125- function showAll ( ) {
126- data . groups = calculateGroupData ( apps , appCapabilities , measurables , allRatings ) ;
127- }
128-
129- function expandAll ( ) {
130- _ . map ( data . groups , g => g . collapsed = false ) ;
131- }
132-
133- function collapseAll ( ) {
134- _ . map ( data . groups , g => g . collapsed = true ) ;
135- }
136-
137- data . actions = {
138- expandAll,
139- collapseAll,
140- showDirectsOnly,
141- showAll
142- } ;
143-
144-
145- return data ;
146- }
14714
14815
14916function controller ( $stateParams ,
150- $state ,
15117 $scope ,
15218 viewDataService ,
15319 viewOptions ,
@@ -163,13 +29,6 @@ function controller($stateParams,
16329 historyStore . put ( orgUnit . name , 'ORG_UNIT' , 'main.org-unit.view' , { id : orgUnit . id } ) ;
16430
16531 vm . viewData = viewOptions . filter ( vm . rawViewData ) ;
166- vm . ratings = calculateCapabilityRatings (
167- id ,
168- vm . viewData . apps ,
169- vm . viewData . appCapabilities ,
170- vm . viewData . perspective ,
171- vm . viewData . capabilityRatings ,
172- $state ) ;
17332 } ;
17433
17534 $scope . $watch (
@@ -181,8 +40,6 @@ function controller($stateParams,
18140
18241 vm . eventDispatcher = new EventDispatcher ( ) ;
18342
184- const getAppIds = ( ) => _ . map ( vm . rawViewData . apps , "id" ) ;
185-
18643 viewDataService
18744 . loadAll ( id )
18845 . then ( data => vm . rawViewData = data )
@@ -197,7 +54,6 @@ function controller($stateParams,
19754
19855controller . $inject = [
19956 '$stateParams' ,
200- '$state' ,
20157 '$scope' ,
20258 'OrgUnitViewDataService' ,
20359 'OrgUnitViewOptionsService' ,
0 commit comments