1
1
import Controller from '@ember/controller' ;
2
+ import sortBy from 'lodash/sortBy' ;
2
3
3
4
export default class TargetProfileDetailsController extends Controller {
4
5
get areas ( ) {
5
- return this . model . areas . sortBy ( 'frameworkId' , 'code' ) . map ( ( area ) => this . buildAreaViewModel ( area ) ) ;
6
+ return sortBy ( this . model . areas , [ 'frameworkId' , 'code' ] ) . map ( ( area ) => this . buildAreaViewModel ( area ) ) ;
6
7
}
7
8
8
9
buildAreaViewModel ( area ) {
9
10
return {
10
11
title : `${ area . code } · ${ area . title } ` ,
11
12
color : area . color ,
12
- competences : area
13
- . hasMany ( 'competences' )
14
- . value ( )
15
- . sortBy ( 'index' )
16
- . map ( ( competence ) => this . buildCompetenceViewModel ( competence ) ) ,
13
+ competences : sortBy ( area . hasMany ( 'competences' ) . value ( ) , 'index' ) . map ( ( competence ) =>
14
+ this . buildCompetenceViewModel ( competence ) ,
15
+ ) ,
17
16
} ;
18
17
}
19
18
20
19
buildCompetenceViewModel ( competence ) {
21
20
return {
22
21
id : competence . id ,
23
22
title : `${ competence . index } ${ competence . name } ` ,
24
- thematics : competence
25
- . hasMany ( 'thematics' )
26
- . value ( )
27
- . sortBy ( 'index' )
28
- . map ( ( thematic ) => this . buildThematicViewModel ( thematic ) ) ,
23
+ thematics : sortBy ( competence . hasMany ( 'thematics' ) . value ( ) , 'index' ) . map ( ( thematic ) =>
24
+ this . buildThematicViewModel ( thematic ) ,
25
+ ) ,
29
26
} ;
30
27
}
31
28
32
29
buildThematicViewModel ( thematic ) {
33
30
return {
34
31
name : thematic . name ,
35
32
nbTubes : thematic . hasMany ( 'tubes' ) . value ( ) . length ,
36
- tubes : thematic
37
- . hasMany ( 'tubes' )
38
- . value ( )
39
- . sortBy ( 'practicalTitle' )
40
- . map ( ( tube ) => this . buildTubeViewModel ( tube ) ) ,
33
+ tubes : sortBy ( thematic . hasMany ( 'tubes' ) . value ( ) , 'practicalTitle' ) . map ( ( tube ) => this . buildTubeViewModel ( tube ) ) ,
41
34
} ;
42
35
}
43
36
@@ -48,11 +41,7 @@ export default class TargetProfileDetailsController extends Controller {
48
41
level : tube . level ,
49
42
mobile : tube . mobile ,
50
43
tablet : tube . tablet ,
51
- skills : tube
52
- . hasMany ( 'skills' )
53
- . value ( )
54
- . sortBy ( 'difficulty' )
55
- . map ( ( skill ) => this . buildSkillViewModel ( skill ) ) ,
44
+ skills : sortBy ( tube . hasMany ( 'skills' ) . value ( ) , 'difficulty' ) . map ( ( skill ) => this . buildSkillViewModel ( skill ) ) ,
56
45
} ;
57
46
}
58
47
0 commit comments