Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nosus committed Nov 4, 2018
1 parent 449654b commit 6892561
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
39 changes: 30 additions & 9 deletions ui/src/components/shared/GamesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
</el-table-column>
<el-table-column label="Operations" fixed="right">
<template slot-scope="scope">
<el-button v-if="scope.row.status == 0 && type == 'audit'" @click="openDialog(scope.$index, 'Approve')" type="success" size="mini">Approve</el-button>
<div class="gameActionButton" v-if="scope.row.status == 1"><el-button @click="openDialog(scope.$index, 'Deny Game')" type="danger" size="mini" v-if="type == 'report' || type == 'live'">Deny Game</el-button></div>
<div class="gameActionButton" v-if="scope.row.report == 1"><el-button @click="openDialog(scope.$index, 'Dismiss Report')" type="primary" size="mini" v-if="type == 'report'">Dismiss Report</el-button></div>
<div class="gameActionButton" v-if="scope.row.status == 1 && type == 'recommended'"><el-button @click="removeGameFromRecomended(scope.$index)" type="danger" size="mini" v-if="type == 'recommended'">Remove</el-button></div>
<el-button v-if="scope.row.status == 0 && type == 'audit'" @click="openDialog(scope.$index, 'approve', 'Approve the game')" type="success" size="mini">Approve</el-button>
<el-button v-if="scope.row.status == 0 && type == 'stale'" @click="openDialog(scope.$index, 'delete', 'Delete the game')" type="danger" size="mini">Delete</el-button>
<div class="gameActionButton" v-if="scope.row.status == 1"><el-button @click="openDialog(scope.$index, 'deny', 'Deny Game')" type="danger" size="mini" v-if="type == 'report' || type == 'live'">Deny Game</el-button></div>
<div class="gameActionButton" v-if="scope.row.report == 1"><el-button @click="openDialog(scope.$index, 'dismiss', 'Dismiss Report')" type="primary" size="mini" v-if="type == 'report'">Dismiss Report</el-button></div>
<div class="gameActionButton" v-if="scope.row.status == 0 && type == 'stale' "><el-button @click="openDialog(scope.$index, 'Dismiss Report')" type="primary" size="mini" v-if="type == 'report'">Dismiss Report</el-button></div>
</template>
</el-table-column>
</el-table>
Expand Down Expand Up @@ -68,6 +69,7 @@
dialogFormVisible: false,
activeIndex: null,
actionTitle: '',
actionType: '',
form: {
comment: ''
},
Expand All @@ -85,10 +87,11 @@
}
})
},
openDialog (index, type) {
openDialog (index, type, title) {
this.dialogFormVisible = true
this.activeIndex = index
this.actionTitle = type
this.actionType = type
this.actionTitle = title
},
confirmDialogCancel () {
this.dialogFormVisible = false
Expand All @@ -98,11 +101,13 @@
if (this.form.comment.trim().length === 0) {
this.$alert('Comment cannot be empty!')
} else {
if (this.actionTitle === 'Approve') {
if (this.actionType === 'approve') {
this.approve()
} else if (this.actionTitle === 'Deny Game') {
} else if (this.actionType === 'delete') {
this.delete()
} else if (this.actionType === 'deny') {
this.deny()
} else if (this.actionTitle === 'Dismiss Report') {
} else if (this.actionType === 'dismiss') {
this.clear()
}
this.form.comment = ''
Expand All @@ -124,6 +129,22 @@
this.loading = false
})
},
delete () {
this.dialogFormVisible = false
console.log(`delete game of ${this.activeIndex} with comment`)
this.loading = true
gameService.delete(this.items[this.activeIndex].id, this.form.comment).then(() => {
this.$message.success('Game is deleted.')
this.items.splice(this.activeIndex, 1)
this.$emit('gameDeleted')
}).catch(error => {
console.log(error)
this.$message.error('Approve action failed.')
}).finally(() => {
this.form.comment = ''
this.loading = false
})
},
deny () {
this.dialogFormVisible = false
console.log(`deny details of ${this.activeIndex}`)
Expand Down
16 changes: 13 additions & 3 deletions ui/src/components/views/GameAudit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div class="listContainer">
<el-tabs v-model="activeTab" type="border-card" v-loading="loading">
<el-tab-pane label="Pending Game" name="audit"><app-game-table :items="auditItems" type="audit" @gameApproved="updateLiveGames" class="audit-table"></app-game-table></el-tab-pane>
<el-tab-pane label="Stale Pending Game" name="stale"><app-game-table :items="stalePendingItems" type="stale" @gameDeleted="updatePendingGames" class="audit-table"></app-game-table></el-tab-pane>
<el-tab-pane label="Reported Game" name="report"><app-game-table :items="reportItems" type="report" @gameDenied="updatePendingGames" class="audit-table"></app-game-table></el-tab-pane>
<el-tab-pane label="Live Game" name="live"><app-game-table :items="liveItems" type="live" @gameDenied="updatePendingGames" class="audit-table"></app-game-table></el-tab-pane>
<el-tab-pane v-if="$store.getters.isAdmin" label="Recommended Game" type="recommend">
Expand All @@ -29,6 +30,7 @@
import GamesTable from '../shared/GamesTable.vue'
import CommonHeader from '../common/CommonHeader'
import CommonFooter from '../common/CommonFooter'
import moment from 'moment'
const gameService = new GameService()
export default {
Expand All @@ -42,6 +44,7 @@
data () {
return {
auditItems: null,
stalePendingItems: [],
reportItems: null,
liveItems: null,
recommendedItems: null,
Expand All @@ -56,15 +59,13 @@
methods: {
updateLiveGames () {
gameService.query({status: 1, limit: 1000, includeComment: true}).then(result => {
console.log(result)
this.liveItems = result.items
console.log('get the game item list', this.reportItems)
})
},
updateReportGames () {
gameService.query({report: 1, limit: 1000, includeComment: true}).then(result => {
console.log(result)
this.reportItems = result.items
console.log('get the game item list', this.reportItems)
})
Expand All @@ -73,9 +74,9 @@
updatePendingGames () {
this.loading = true
gameService.query({status: 0, limit: 1000, includeComment: true}).then(result => {
console.log(result)
this.auditItems = result.items
console.log('get the pending game list', this.auditItems)
this.updateStalePendingGames()
}).catch(error => {
this.$message.error('Fail to load pending game data')
console.log(error.response)
Expand All @@ -84,6 +85,15 @@
})
},
updateStalePendingGames () {
this.stalePendingItems = this.auditItems.map(item => {
if ( moment().diff(item.lastModified, 'days') > 30) {
return item
}
})
console.log('get the stale pending item list', this.stalePendingItems)
},
updateRecommendedGames () {
this.loading = true
gameService.query({status: 1, limit: 1000, includeComment: true, recommend: 1}).then(result => {
Expand Down
10 changes: 6 additions & 4 deletions ui/src/service/game.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export default class GameService {
})
}

delete (id) {
return axiosInstance.delete('/api/v1/game/' + id)
}

update (game) {
return axiosInstance.put('/api/v1/game/' + game.id, this.convertGameToJson(game))
}
Expand Down Expand Up @@ -64,6 +60,12 @@ export default class GameService {
})
}

delete (gameId, comment) {
return axiosInstance.delete(`/api/v1/game/${gameId}`, {
comment: comment
})
}

deny (gameId, comment) {
return axiosInstance.post(`/api/v1/audit/${gameId}`, {
status: 0,
Expand Down

0 comments on commit 6892561

Please sign in to comment.