/
message.js
101 lines (85 loc) · 2.39 KB
/
message.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { ajax } from "client-app/lib/utilities";
import Preload from "client-app/lib/preload";
import { computed } from "@ember/object";
export default Em.Object.extend({
MAX_LEN: 200,
fetchEnv() {
return ajax(`/fetch-env/${this.key}.json`).then(env =>
this.set("env", env)
);
},
expand() {
this.set("expanded", true);
},
solve() {
return ajax(`/solve/${this.key}`, { type: "PUT" });
},
destroy() {
return ajax(`/message/${this.key}`, { type: "DELETE" });
},
protect() {
this.set("protected", true);
return ajax(`/protect/${this.key}`, { type: "PUT" });
},
unprotect() {
this.set("protected", false);
return ajax(`/unprotect/${this.key}`, { type: "DELETE" });
},
showCount: computed("count", function() {
return this.count > 1;
}),
hasMore: computed("message", "expanded", function() {
return !this.expanded && this.message.length > this.MAX_LEN;
}),
shareUrl: computed("key", function() {
return `${Preload.get("rootPath")}/show/${this.key}`;
}),
displayMessage: computed("message", "expanded", function() {
let message = this.message;
if (!this.expanded && this.message.length > this.MAX_LEN) {
message = this.message.substr(0, this.MAX_LEN);
}
return message;
}),
updateFromObject(other) {
// XXX Only updatable property is count right now
this.set("count", other.get("count"));
},
canSolve: computed("env.{application_version,length}", function() {
const appVersion = Array.isArray(this.env)
? this.env
.map(e => e.application_version)
.compact()
.join("")
: this.env && this.env.application_version;
return appVersion && this.backtrace && this.backtrace.length > 0;
}),
rowClass: computed("severity", function() {
switch (this.get("severity")) {
case 0:
return "debug";
case 1:
return "info";
case 2:
return "warn";
case 3:
return "error";
case 4:
return "fatal";
}
}),
glyph: computed("severity", function() {
switch (this.get("severity")) {
case 0:
return "";
case 1:
return "";
case 2:
return "<i class='fa fa-exclamation-circle warning'></i>";
case 3:
return "<i class='fa fa-times-circle error'></i>";
case 4:
return "<i class='fa fa-times-circle fatal'></i>";
}
})
});