/
routes.js
82 lines (72 loc) · 1.92 KB
/
routes.js
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
import { _ } from 'meteor/underscore';
import { Config, Runner } from 'angular-ecmascript/module-helpers';
class RoutesConfig extends Config {
static $inject = ['$stateProvider', '$urlRouterProvider']
constructor() {
super(...arguments);
this.isAuthorized = ['$auth', this::this.isAuthorized];
}
configure() {
this.$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html',
resolve: {
user: this.isAuthorized
}
})
.state('tab.chats', {
url: '/chats',
views: {
'tab-chats': {
templateUrl: 'templates/chats.html',
controller: 'ChatsCtrl as chats'
}
}
})
.state('tab.chat', {
url: '/chats/:chatId',
views: {
'tab-chats': {
templateUrl: 'templates/chat.html',
controller: 'ChatCtrl as chat'
}
}
})
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl as logger'
})
.state('confirmation', {
url: '/confirmation/:phone',
templateUrl: 'templates/confirmation.html',
controller: 'ConfirmationCtrl as confirmation'
})
.state('profile', {
url: '/profile',
templateUrl: 'templates/profile.html',
controller: 'ProfileCtrl as profile',
resolve: {
user: this.isAuthorized
}
});
this.$urlRouterProvider.otherwise('tab/chats');
}
isAuthorized($auth) {
return $auth.awaitUser();
}
}
class RoutesRunner extends Runner {
static $inject = ['$rootScope', '$state']
run() {
this.$rootScope.$on('$stateChangeError', (...args) => {
const err = _.last(args);
if (err === 'AUTH_REQUIRED') {
this.$state.go('login');
}
});
}
}
export default [RoutesConfig, RoutesRunner];