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
|
<template>
<div class="flex row no-wrap gutter-lg">
<div class="animateMaxWidth" :class="showList ? 'col-12' : 'gt-sm col-md-6'">
<h4>Available Mods</h4>
<q-table
no-data-label="No mods available"
row-key="name"
:data="uploads"
:config="tableConfig"
:columns="tableColumns"
:visible-columns="visibleColumns"
@refresh="refresh">
<q-td slot='body-cell-action' slot-scope="props" :props='props'>
<q-btn color="primary"
v-if="$route.params.uploadId !== props.row._id"
small
outline
icon="fa-info-circle"
label="Details"
@click="$router.push({name: 'upload-detail', params: {uploadId: props.row._id}})" />
<q-btn color="negative"
outline
small
icon="fa-trash-o"
label="Delete"
v-if="props.row.author.username === $store.state.user.decodedToken.username"
@click="deleteUpload(cell.row)" />
</q-td>
<q-td slot='body-cell-voting' slot-scope="props" :props='props'>
{{ props.value.sum }} <i class="fa" :class="{'fa-caret-up text-positive': props.value.sum > 0, 'fa-caret-down text-negative': props.value.sum < 0, 'fa-sort text-dark': props.value.sum === 0}"></i>
</q-td>
</q-table>
</div>
<transition appear name="grow-fade">
<div v-if="!showList" class="col-sm-12 col-md-6">
<router-view></router-view>
</div>
</transition>
</div>
</template>
<script>
import {
Dialog,
} from 'quasar'
import moment from 'moment'
export default {
computed: {
showList () {
return this.$route.name === 'upload-list'
},
visibleColumns () {
let that = this
let removeOnSmall = ['description']
return this.tableColumns.map(el => el.name).filter(el => that.showList || removeOnSmall.indexOf(el) === -1)
},
},
mounted () {
this.refresh()
},
watch: {
showList: {
handler (val, oldVal) {
if (val && val !== oldVal) {
this.refresh()
}
},
immediate: true,
}
},
data () {
return {
response: {},
uploads: [],
tableConfig: {
refresh: true,
leftStickyColumns: 1,
rightStickyColumns: 3,
rowHeight: '60px',
},
tableColumns: [
{name: 'title', label: 'Title', field: 'title'},
{
name: 'description',
label: 'Description',
field: 'description',
format: el => typeof el === 'string' && el.length > 150 ? el.slice(0, 150) + '...' : el,
},
{name: 'author', label: 'Author', field: row => row.author.username},
{name: 'voting', label: 'Voting', field: 'voting'},
{
name: 'updatedAt',
label: 'Last update',
field: 'updatedAt',
format: el => moment(el).from(),
},
{name: 'action', label: 'Actions', field: 'action'},
],
}
},
methods: {
refresh (done) {
let that = this
this.$http.get('/uploads').then((response) => {
that.response = response
that.uploads = response.data.uploads
if (done) {
done()
}
})
},
deleteUpload (upload) {
let that = this
Dialog.create({
title: 'Delete mod?',
message: `Do you really want to delete the mod ${upload.title}?<br>This cannot be undone!`,
buttons: [
'Cancel',
{
label: '<i class="fa fa-trash-o"></i> Yes, delete!',
color: 'negative',
outline: true,
handler () {
that.$http.delete(`/uploads/${upload._id}`).then(response => that.refresh())
}
}
]
})
},
},
}
</script>
<style lang="styl" type="text/stylus" scoped>
.animateMaxWidth
transition: max-width .5s ease-in-out
.grow-fade-enter-active
transition: all .5s ease-in-out
.grow-fade-leave-active
transition: all .5s ease-in-out
.grow-fade-enter, .grow-fade-leave-to
max-width: 0
opacity: 0
</style>
|