forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoggerView.vue
143 lines (131 loc) · 3.35 KB
/
LoggerView.vue
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
<template>
<div class="logger-view">
<div class="toolbar">
<VueIcon
icon="dvr"
/>
<div class="title">
{{ $t('components.logger-view.title') }}
</div>
<VueButton
class="icon-button"
icon-left="delete_forever"
v-tooltip="$t('components.logger-view.buttons.clear')"
@click="clearLogs()"
/>
<VueIcon
icon="lens"
class="separator"
/>
<VueButton
class="icon-button"
icon-left="subdirectory_arrow_left"
v-tooltip="$t('components.logger-view.buttons.scroll')"
@click="scrollToBottom()"
/>
<VueButton
class="icon-button"
icon-left="close"
v-tooltip="$t('components.logger-view.buttons.close')"
@click="close()"
/>
</div>
<ApolloQuery
ref="logs"
:query="require('../graphql/consoleLogs.gql')"
fetch-policy="cache-and-network"
class="logs"
@result="scrollToBottom()"
>
<ApolloSubscribeToMore
:document="require('../graphql/consoleLogAdded.gql')"
:update-query="onConsoleLogAdded"
/>
<template slot-scope="{ result: { data } }">
<template v-if="data && data.consoleLogs">
<LoggerMessage
v-for="log of data.consoleLogs"
:key="log.id"
:message="log"
pre
/>
<div
v-if="!data.consoleLogs.length"
class="vue-ui-empty"
>
<VueIcon icon="wifi" class="large"/>
<div>{{ $t('components.logger-view.empty') }}</div>
</div>
</template>
</template>
</ApolloQuery>
</div>
</template>
<script>
import CONSOLE_LOGS from '../graphql/consoleLogs.gql'
import CONSOLE_LOG_LAST from '../graphql/consoleLogLast.gql'
import CONSOLE_LOGS_CLEAR from '../graphql/consoleLogsClear.gql'
export default {
methods: {
onConsoleLogAdded (previousResult, { subscriptionData }) {
this.scrollToBottom()
return {
consoleLogs: [
...previousResult.consoleLogs,
subscriptionData.data.consoleLogAdded
]
}
},
async scrollToBottom () {
await this.$nextTick()
const list = this.$refs.logs.$el
list.scrollTop = list.scrollHeight
},
async clearLogs () {
await this.$apollo.mutate({
mutation: CONSOLE_LOGS_CLEAR,
update: store => {
store.writeQuery({ query: CONSOLE_LOGS, data: { consoleLogs: [] }})
store.writeQuery({ query: CONSOLE_LOG_LAST, data: { consoleLogLast: null }})
}
})
this.close()
},
close () {
this.$emit('close')
}
}
}
</script>
<style lang="stylus" scoped>
@import "~@/style/imports"
.logger-view
background $vue-ui-color-light-neutral
height 174px
display grid
grid-template-columns 1fr
grid-template-rows auto 1fr
grid-template-areas "toolbar" "logs"
.toolbar
grid-area toolbar
h-box()
align-items center
padding 6px 6px 6px $padding-item
> :not(.separator)
space-between-x(6px)
> * + .separator
margin-left 6px
.title
flex 100% 1 1
width 0
ellipsis()
.logs
grid-area logs
padding 0 $padding-item
overflow-x hidden
overflow-y auto
.logger-message
font-size 12px
&:hover
background lighten(@background, 40%)
</style>