File tree Expand file tree Collapse file tree 6 files changed +78
-60
lines changed Expand file tree Collapse file tree 6 files changed +78
-60
lines changed Original file line number Diff line number Diff line change 14
14
// default route
15
15
$urlRouterProvider . otherwise ( '/' ) ;
16
16
17
+ // decorator: set reasonable defaults for entity.* routes
18
+ $stateProvider . decorator ( 'views' , function ( state , parent ) {
19
+
20
+ var config = state . self ;
21
+
22
+ // console.log( config );
23
+
24
+ if ( config . name . match ( / ^ e n t i t y \. / ) ) {
25
+
26
+ config . templateUrl = config . templateUrl || 'states/entity/default.html' ;
27
+ config . controller = config . controller || 'DefaultEntityController' ;
28
+ config . controllerAs = 'vm' ;
29
+
30
+ }
31
+
32
+ return parent ( state ) ;
33
+
34
+ } ) ;
35
+
17
36
// app routes
18
37
$stateProvider
19
38
. state ( 'root' , {
36
55
} )
37
56
. state ( 'entity.artwork' , {
38
57
url : '/artworks/:id' ,
39
- // TODO: Create custom templates for each?
40
- templateUrl : 'states/entity/default.html' ,
41
- controller : 'ArtworkController' ,
42
- controllerAs : 'vm' ,
43
- data : {
44
- cssClassnames : 'aic-state-artwork'
58
+ params : {
59
+ model : 'ArtworkService'
45
60
}
46
61
} ) ;
47
62
Original file line number Diff line number Diff line change 50
50
51
51
<!-- States -->
52
52
< script src ="states/entity/entity.js "> </ script >
53
- < script src ="states/entity/artwork/artwork .js "> </ script >
53
+ < script src ="states/entity/default .js "> </ script >
54
54
55
55
<!-- Load the app itself last -->
56
56
< script src ="app.route.js "> </ script >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+
3
+ angular
4
+ . module ( 'app' )
5
+ . controller ( 'DefaultEntityController' , Controller ) ;
6
+
7
+ Controller . $inject = [ '$stateParams' , '$injector' ] ;
8
+
9
+ function Controller ( $stateParams , $injector ) {
10
+
11
+ var ModelService = $injector . get ( $stateParams . model ) ;
12
+
13
+ var vm = this ;
14
+
15
+ vm . entity = null ;
16
+ vm . route = null ;
17
+
18
+ activate ( ) ;
19
+
20
+ return vm ;
21
+
22
+ function activate ( ) {
23
+
24
+ if ( ! $stateParams . id ) {
25
+
26
+ // Just for testing: if id is omitted, get first one in the list
27
+ ModelService . list ( { limit : 1 } ) . promise . then ( function ( ) {
28
+
29
+ vm . entity = ModelService . list ( { limit : 1 } ) . cache . clean [ 0 ] ;
30
+ vm . route = ModelService . route ( vm . entity . id ) ;
31
+
32
+ } ) ;
33
+
34
+ } else {
35
+
36
+ vm . entity = ModelService . detail ( $stateParams . id ) . cache . clean ;
37
+ vm . route = ModelService . route ( $stateParams . id ) ;
38
+
39
+ }
40
+
41
+
42
+
43
+ }
44
+
45
+ }
46
+
47
+ } ) ( ) ;
Original file line number Diff line number Diff line change 1
- < div class ="aic-view-entity " ng-submit ="vm.open( vm.form.state , vm.form.id ) ">
1
+ < div class ="aic-view-entity " ng-submit ="vm.open( vm.form.model , vm.form.id ) ">
2
2
3
3
< form class ="form-horizontal ">
4
4
5
5
< div class ="input-group ">
6
6
7
- < select class ="form-control " ng-model ="vm.form.state ">
7
+ < select class ="form-control " ng-model ="vm.form.model ">
8
8
9
9
< option ng-repeat ="model in vm.models track by $index "
10
- value ="{{ model.states.entity}} "> {{model.name}}</ option >
10
+ ng- value ="model "> {{model.name}}</ option >
11
11
12
12
</ select >
13
13
Original file line number Diff line number Diff line change 31
31
] ;
32
32
33
33
vm . form = {
34
- state : vm . models [ 0 ] . states . entity ,
34
+ model : vm . models [ 0 ] ,
35
35
id : null ,
36
36
} ;
37
37
38
38
}
39
39
40
- function open ( state , id ) {
40
+ function open ( model , id ) {
41
41
42
- console . log ( arguments ) ;
43
-
44
- $state . go ( state , { id : id } ) ;
42
+ $state . go ( model . states . entity , {
43
+ // model is optional since it has a default
44
+ id : id ,
45
+ } ) ;
45
46
46
47
}
47
48
You can’t perform that action at this time.
0 commit comments