/
application.js
80 lines (68 loc) · 2.43 KB
/
application.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
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
import ReloadableRoute from 'ares-webportal/mixins/reloadable-route';
export default Route.extend(ApplicationRouteMixin, ReloadableRoute, {
gameApi: service(),
session: service(),
flashMessages: service(),
gameSocket: service(),
favicon: service(),
doReload: function() {
this.loadModel().then( newModel => {
this.controllerFor('application').set('sidebar', newModel);
this.controllerFor('application').set('refreshSidebar', newModel.timestamp);
});
},
loadModel: function() {
let api = this.get('gameApi');
return api.requestOne('sidebarInfo')
.then( (response) => {
if (response.error) {
return { game_down: true };
}
response['socketConnected'] = this.get('gameSocket.connected');
if (response.token_expiry_warning) {
this.get('flashMessages').warning(`Your login expires today (in ${response.token_expiry_warning}). You should log out and back in before that happens so you don't lose any work.'`);
}
return response;
})
.catch(() => {
return { game_down: true };
});
},
model: function() {
let gameSocket = this.get('gameSocket');
gameSocket.checkSession(this.get('session.data.authenticated.id'));
$(window).focus( () => {
this.get('favicon').changeFavicon(false);
});
return this.loadModel();
},
sessionAuthenticated: function() {
//Do nothing.
},
sessionInvalidated: function() {
this.get('flashMessages').info('You have been logged out.');
this.transitionTo('/');
this.refresh();
},
title: function(tokens) {
var gameName = aresconfig.game_name;
if (tokens.length > 0) {
let tokenString = tokens.reverse().join(' - ');
return `${tokenString} - ${gameName}`
}
else {
return gameName;
}
},
actions: {
willTransition() {
this.doReload();
},
error(error) {
this.get('gameApi').reportError({ message: error });
}
}
});