forked from ivanseidel/tournamenter-obr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
155 lines (128 loc) · 4.33 KB
/
index.js
File metadata and controls
155 lines (128 loc) · 4.33 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
Default view module
*/
var _ = require('lodash');
var path = require('path');
var request = require('request')
var auth = app.helpers.isAuthenticated
var package = require('./package.json')
var SyncModule = require('./SyncModule')
var hasUpdate = null
module.exports = {
type: ['menu'],
getAssets: function (app){
return {
css: [],
js: [],
jst: [],
serve: [
`${__dirname}/public`,
]
}
},
menus: [
{
name: 'Plugin OBR',
childs: [
{
path: '/tournamenter-obr',
name: 'Pontuador',
},
{
path: '/obr-desafio',
name: 'Desafio Surpresa',
},
{
path: '/obr-config',
name: 'Configurar (Importar/Exportar)',
},
{
path: '/obr-rounds',
name: 'Gerar Tabela de Horários',
},
{
path: '/ManualOBRTournamenter.pdf',
name: 'Manual (.pdf)',
},
],
order: 6
},
// Realtime badge for Sincronization with Sistema Olimpo
SyncModule.statusMenu
// {name: 'Pontuador', path: '/tournamenter-obr', order: 6},
// {name: 'Importador Sistema Olimpo', path: '/tournamenter-obr/importar.html', order: 7},
],
initialize: function(app){
// Get 'Table' model from App
var tournamenterRoot = app.config.root;
var tableModelPath = path.join(tournamenterRoot, './models/Table');
var TableModel = require(tableModelPath)
// Inject OBR Scoring systems
TableModel.evaluateMethods.obr2017 = require('./sorters/obr2017');
TableModel.evaluateMethods.obr2018nacional = require('./sorters/obr2018nacional');
// Set 'obr2017' as default sorting algorithm
TableModel.attributes.evaluateMethod.defaultsTo = 'obr2017';
// Set columns count to 6 as default, with names
TableModel.attributes.columns.defaultsTo = 6;
TableModel.attributes.headerScore.defaultsTo =
'Round 1, Tempo 1, Round 2, Tempo 2, Round 3, Tempo 3';
// Set default to Portugese on columns
TableModel.attributes.headerTeam.defaultsTo = 'Equipe';
// Update Default Tournamenter Logo
app.config.appLogo = path.join(__dirname, '/public/tournamenter-obr/obr.png')
// Add views path to view engine
var viewsFolder = path.join(__dirname, '/public/tournamenter-obr')
var views = app.server.get('views').push(viewsFolder)
// Add route to change configs/get
app.server.all('/obr-sync', auth, SyncModule.updateConfig)
app.server.all('/obr-last-sync', auth, SyncModule.getLastSync)
// Render Configuration screen
app.server.get('/obr-config', auth, function (req, res) {
return res.render('obr-config', { path: req.route.path });
})
// Render desafio screen
app.server.get('/obr-desafio', auth, function (req, res) {
return res.render('obr-desafio', { path: req.route.path });
})
// Render Gerador de rounds screen
app.server.get('/obr-rounds', auth, function (req, res) {
return res.render('obr-rounds', { path: req.route.path });
})
// Set home screen to show a big huge button to guide judges
app.server.get('/', auth, function (req, res) {
return res.render('obr-home', { path: req.route.path, newestVersion: hasUpdate});
})
// Init SyncModule
SyncModule.init(app)
// Check uptades on this package
request({
url: 'http://registry.npmjs.org/' + package.name,
json: true,
}, function (err, response, body){
if (err){
// Just check for updates if internet...
return;
}
if (response.statusCode != 200 || !body) {
// No problem. Just ignore
return;
}
var currentVersion = package.version
var newestVersion = body && body['dist-tags'] && body['dist-tags'].latest
if (newestVersion != currentVersion) {
hasUpdate = newestVersion
console.log()
console.log('>>>>>>>>>> NOVO UPDATE PARA O tournamenter-obr')
console.log('>>>>>>>>>> Versão: '+newestVersion)
console.log()
}
})
},
render: function(req, res, next, locals){
var viewPath = __dirname+'/index';
var relViewPath = path.relative(path.resolve(__dirname+'/../../views'), viewPath);
res.render(relViewPath, _.extend(locals, {
layout: path.join(__dirname, 'layout.ejs'),
}));
},
}