This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.es6
68 lines (56 loc) · 2.02 KB
/
main.es6
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
require('./styles/main.header.scss');
require('./styles/main.footer.scss');
import "regenerator-runtime/runtime";
import interstellarCore, {App, Intent} from "interstellar-core";
import interstellarNetwork from "interstellar-network";
import interstellarSessions from "interstellar-sessions";
import interstellarUiMessages from "interstellar-ui-messages";
import { logEvent } from './metrics.es6'
logEvent('page: account viewer loaded')
let config;
if (INTERSTELLAR_ENV === 'prd') {
config = require('./config-prd.json');
} else {
config = require('./config.json');
}
const app = new App("interstellar-basic-client", config);
app.use(interstellarCore);
app.use(interstellarNetwork);
app.use(interstellarSessions);
app.use(interstellarUiMessages);
app.templates = require.context("raw!./templates", true);
app.controllers = require.context("./controllers", true);
app.routes = ($stateProvider) => {
$stateProvider.state('login', {
url: "/",
templateUrl: "interstellar-basic-client/login"
});
$stateProvider.state('dashboard', {
url: "/dashboard",
templateUrl: "interstellar-basic-client/dashboard",
requireSession: true
});
};
// Register BroadcastReceivers
let registerBroadcastReceivers = ($state, IntentBroadcast) => {
IntentBroadcast.registerReceiver(Intent.TYPES.SHOW_DASHBOARD, intent => {
$state.go('dashboard');
});
IntentBroadcast.registerReceiver(Intent.TYPES.LOGOUT, intent => {
$state.go('login');
});
};
registerBroadcastReceivers.$inject = ["$state", "interstellar-core.IntentBroadcast"];
app.run(registerBroadcastReceivers);
let goToMainStateWithoutSession = ($state, $rootScope, Sessions) => {
$rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
let hasDefault = Sessions.hasDefault();
if (toState.requireSession && !hasDefault) {
event.preventDefault();
$state.go('login');
}
})
};
goToMainStateWithoutSession.$inject = ["$state", "$rootScope", "interstellar-sessions.Sessions"];
app.run(goToMainStateWithoutSession);
app.bootstrap();