forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.js
More file actions
106 lines (102 loc) · 2.97 KB
/
routes.js
File metadata and controls
106 lines (102 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict'
import angular from 'angular'
import templateUrlForm from './views/form.html'
import templateUrlList from './views/list.html'
import templateUrlMain from './views/main.html'
import templateUrlView from './views/view.html'
import templateUrlProfile from './views/profile.html'
const app = angular.module('com.module.users.routes', [])
app.config($stateProvider => $stateProvider
.state('login', {
url: '/login',
template: '<login></login>',
})
.state('register', {
url: '/register',
template: '<register></register>',
controller: 'RegisterCtrl',
})
.state('app.users', {
abstract: true,
url: '/users',
templateUrl: templateUrlMain,
})
.state('app.users.list', {
url: '',
templateUrl: templateUrlList,
controllerAs: 'ctrl',
controller: function listCtrl (users) {
this.users = users
},
resolve: {
users: (UserService) => UserService.find(),
},
})
.state('app.users.add', {
url: '/add',
templateUrl: templateUrlForm,
controllerAs: 'ctrl',
controller: function addCtrl ($state, UserService, user) {
this.user = user
this.formFields = UserService.getFormFields('add')
this.formOptions = {}
this.submit = () => UserService.upsert(this.user)
.then(() => $state.go('^.list'))
.catch((err) => console.log(err))
},
resolve: {
user: () => {},
},
})
.state('app.users.edit', {
url: '/edit/:id',
templateUrl: templateUrlForm,
controllerAs: 'ctrl',
controller: function editCtrl ($state, UserService, user) {
this.user = user
this.formFields = UserService.getFormFields('edit')
this.formOptions = {}
this.submit = () => UserService.upsert(this.user)
.then(() => $state.go('^.list'))
.catch((err) => console.log(err))
},
resolve: {
user: ($stateParams, UserService) => UserService.findById($stateParams.id),
},
})
.state('app.users.view', {
url: '/view/:id',
templateUrl: templateUrlView,
controllerAs: 'ctrl',
controller: function viewCtrl (user) {
this.user = user
},
resolve: {
user: ($stateParams, UserService) => UserService.findById($stateParams.id),
},
})
.state('app.users.delete', {
url: '/:id/delete',
template: '',
controller: ($stateParams, $state, UserService) => UserService.delete($stateParams.id,
() => $state.go('^.list'),
() => $state.go('^.list')
),
})
.state('app.users.profile', {
url: '/profile',
templateUrl: templateUrlProfile,
controllerAs: 'ctrl',
controller: function profileCtrl ($state, UserService, user) {
this.user = user
this.formFields = UserService.getFormFields('edit')
this.formOptions = {}
this.submit = () => UserService.upsert(this.user)
.then(() => $state.go('^.profile'))
.catch((err) => console.log(err))
},
resolve: {
user: User => User.getCurrent((user) => user, (err) => console.log(err)),
},
})
)