-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathProgress.js
88 lines (82 loc) · 1.92 KB
/
Progress.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
import PROGRESS from '@/graphql/progress/progress.gql'
import PROGRESS_CHANGED from '@/graphql/progress/progressChanged.gql'
import PROGRESS_REMOVED from '@/graphql/progress/progressRemoved.gql'
// @vue/component
export default {
props: {
progressId: {
type: String,
required: true
}
},
data () {
return {
progress: null
}
},
apollo: {
progress: {
query: PROGRESS,
variables () {
return {
id: this.progressId
}
},
fetchPolicy: 'network-only',
subscribeToMore: [
{
document: PROGRESS_CHANGED,
variables () {
return {
id: this.progressId
}
},
updateQuery: (previousResult, { subscriptionData }) => {
return {
progress: subscriptionData.data.progressChanged
}
}
},
{
document: PROGRESS_REMOVED,
variables () {
return {
id: this.progressId
}
},
updateQuery: () => {
return {
progress: null
}
}
}
]
}
},
computed: {
loading () {
return this.progress && !this.progress.error
},
statusMessage () {
if (!this.progress) return null
const { status } = this.progress
let message
if (status) {
const values = {}
if (this.progress.args) {
for (let i = 0, l = this.progress.args.length; i < l; i++) {
values[`arg${i}`] = this.progress.args[i]
}
}
const key = `org.vue.mixins.progress.${status}`
message = this.$t(key, values)
message = (message !== key && message)
if (!message) {
message = this.$t(status, values)
message = (message !== status && message)
}
}
return message || status || ''
}
}
}