-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics.ts
80 lines (75 loc) · 2.14 KB
/
Statistics.ts
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 Log = require("./proto/Log");
class Statistics {
/** l'id de la statistique étant en jeu */
private static idStats: number;
/** le degré actuel */
private static degre: string;
/**
* Requête ajax pour sauvegarder une nouvelle ligne dans l'historique
* @method addStats
* @param mode le mode de jeu (1: Entrainer, 2: Évaluer)
*/
public static addStats(mode: number) {
$.ajax({
type: 'POST',
url: '/addStats',
dataType: 'json',
timeout: 2000,
data: {
mode: mode,
harmos: Statistics.degre
},
success: function (xhr: any) {
if (!xhr.data.id) {
new Log('error', xhr.message).show();
} else {
Statistics.idStats = xhr.data.id;
new Log('success', xhr.message).show();
}
},
error: function (xhr: any) {
console.log(xhr);
try {
new Log('error', JSON.parse(xhr.responseText).message).show();
} catch (error) {
new Log('error', 'Timeout -> addStats (classe Statistics)').show();
}
}
});
}
/**
* Requête ajax pour mettre à jour les statistiques
* @method updateStats
* @param evaluation l'evaluation donnée (0, 1 ou 2)
*/
public static updateStats(evaluation: number) {
if (!(evaluation === 0 || evaluation === 1 || evaluation === 2)) {
new Log('error', `Valeur de l'évaluation incorrecte -> evaluation`).show();
return;
}
$.ajax({
type: 'POST',
url: '/updateStats',
dataType: 'json',
timeout: 2000,
data: {
id: Statistics.idStats,
evaluation: evaluation
},
success: function (xhr: any) {
Statistics.idStats = xhr.data.id;
new Log('success', xhr.message).show();
},
error: function (xhr: any) {
console.log(xhr);
try {
new Log('error', JSON.parse(xhr.responseText).message).show();
} catch (error) {
new Log('error', 'Timeout -> updateStats (classe Statistics)').show();
}
}
});
}
public static setDegre(degre: string) { Statistics.degre = degre; };
}
export = Statistics;