2021-08-21 14:17:14 +00:00
|
|
|
<template>
|
2021-08-21 14:25:23 +00:00
|
|
|
<div id="content" class="app-upschooling">
|
2021-12-18 15:49:53 +00:00
|
|
|
<AppNavigation>
|
|
|
|
<AppNavigationCaption title="Meine Support-Tickets" />
|
|
|
|
<template>
|
|
|
|
<AppNavigationItem v-for="item in tickets" :key="item.ticketId" v-bind:title="item.title" @click="openTicket(item.ticketId)" />
|
|
|
|
<!-- TODO: show only proper tickets -->
|
|
|
|
</template>
|
|
|
|
</AppNavigation>
|
2021-08-21 14:17:14 +00:00
|
|
|
<AppContent>
|
2021-08-22 16:01:29 +00:00
|
|
|
<div v-if="currentTicket">
|
2021-09-18 12:50:21 +00:00
|
|
|
<Ticket :ticket="currentTicket" @save-ticket="saveTicket" @show-ticket-list="deselectTicket" />
|
2021-08-22 16:01:29 +00:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
2021-12-18 15:49:53 +00:00
|
|
|
<TicketList :tickets="tickets" @open-ticket="openTicket" @new-ticket="newTicket" />
|
2021-08-22 16:01:29 +00:00
|
|
|
</div>
|
2021-08-21 14:17:14 +00:00
|
|
|
</AppContent>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
|
2021-12-18 15:49:53 +00:00
|
|
|
import { AppNavigation } from '@nextcloud/vue'
|
|
|
|
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
|
|
|
|
import AppNavigationCaption from '@nextcloud/vue/dist/Components/AppNavigationCaption'
|
2021-08-22 16:01:29 +00:00
|
|
|
import TicketList from './components/TicketList'
|
2021-08-21 18:04:05 +00:00
|
|
|
import Ticket from './Ticket'
|
2021-08-22 16:01:29 +00:00
|
|
|
import '@nextcloud/dialogs/styles/toast.scss'
|
2021-09-18 19:15:03 +00:00
|
|
|
import axios from '@nextcloud/axios'
|
2021-08-21 14:17:14 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
|
|
|
components: {
|
2021-08-21 18:04:05 +00:00
|
|
|
Ticket,
|
2021-08-22 16:01:29 +00:00
|
|
|
TicketList,
|
2021-08-21 14:17:14 +00:00
|
|
|
AppContent,
|
|
|
|
AppNavigation,
|
2021-12-18 15:49:53 +00:00
|
|
|
AppNavigationItem,
|
|
|
|
AppNavigationCaption
|
2021-08-21 14:17:14 +00:00
|
|
|
},
|
2021-09-18 19:15:03 +00:00
|
|
|
|
2021-08-22 16:01:29 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2021-09-18 12:50:21 +00:00
|
|
|
/**
|
|
|
|
* Return the currently selected ticket object or null, if none is selected.
|
|
|
|
*
|
|
|
|
* @type {object|null|undefined}
|
|
|
|
*/
|
|
|
|
currentTicket: undefined,
|
|
|
|
|
2021-09-19 14:55:30 +00:00
|
|
|
ticketsFetched: false,
|
2021-09-18 19:15:03 +00:00
|
|
|
tickets: [],
|
2021-08-22 16:01:29 +00:00
|
|
|
}
|
|
|
|
},
|
2021-09-18 19:15:03 +00:00
|
|
|
watch: {
|
|
|
|
$route: 'fetchTickets',
|
|
|
|
},
|
|
|
|
created() {
|
2022-02-26 16:09:56 +00:00
|
|
|
this.createExampleContent().finally(() => {
|
|
|
|
this.fetchTickets()
|
|
|
|
})
|
2021-09-18 12:50:21 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2022-02-26 16:09:56 +00:00
|
|
|
async createExampleContent() {
|
2021-09-19 14:55:30 +00:00
|
|
|
// this obviously shouldn't survive version 1.0
|
2022-02-26 16:09:56 +00:00
|
|
|
await axios.post(
|
2021-09-19 14:55:30 +00:00
|
|
|
'api/v1/tickets',
|
2022-02-19 12:17:40 +00:00
|
|
|
{ title: 'Ein Ticket', content: 'Ein Beispiel' },
|
2021-09-19 14:55:30 +00:00
|
|
|
{ headers: { 'Content-Type': 'application/json', Accept: 'application/json' } },
|
|
|
|
).then((response) => {
|
|
|
|
if (this.ticketsFetched === false) {
|
|
|
|
this.tickets.push(response.data)
|
|
|
|
}
|
|
|
|
}).catch(console.error)
|
2021-10-10 17:01:00 +00:00
|
|
|
axios.get(
|
|
|
|
'api/v1/tickets/1',
|
2022-02-26 18:40:21 +00:00
|
|
|
{ headers: { Accept: 'application/json' } },
|
2021-10-10 17:01:00 +00:00
|
|
|
).catch(console.error)
|
2021-10-10 17:12:26 +00:00
|
|
|
axios.put(
|
|
|
|
'api/v1/tickets/1',
|
|
|
|
{},
|
|
|
|
{ headers: { 'Content-Type': 'application/json', Accept: 'application/json' } }
|
2021-10-10 18:21:42 +00:00
|
|
|
).catch(console.error)
|
2021-09-19 14:55:30 +00:00
|
|
|
},
|
2021-09-18 19:15:03 +00:00
|
|
|
fetchTickets() {
|
|
|
|
axios.get(
|
|
|
|
'api/v1/tickets',
|
|
|
|
{ headers: { Accept: 'application/json' } }
|
|
|
|
).then((response) => {
|
|
|
|
if (Array.isArray(response.data)) {
|
2021-09-19 14:55:30 +00:00
|
|
|
this.ticketsFetched = true
|
2021-09-18 19:15:03 +00:00
|
|
|
if (response.data.length !== 0) {
|
2021-09-19 14:55:30 +00:00
|
|
|
this.tickets = response.data
|
|
|
|
console.debug(this.tickets) // FIXME
|
2021-09-18 19:15:03 +00:00
|
|
|
} else {
|
2021-09-19 14:55:30 +00:00
|
|
|
console.debug('Empty ticket list :(')
|
2021-09-18 19:15:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.error('API did not return array: ', response)
|
|
|
|
}
|
|
|
|
}).catch(console.error)
|
|
|
|
},
|
2021-09-18 12:50:21 +00:00
|
|
|
saveTicket(ticketId, data) {
|
|
|
|
// TODO send to API (dont forget permission check in API)
|
|
|
|
console.debug('upschooling', 'saveTicket', ticketId, data)
|
|
|
|
},
|
|
|
|
openTicket(ticketId) {
|
2021-09-19 14:55:30 +00:00
|
|
|
this.currentTicket = this.tickets.find((obj) => obj.ticketId === ticketId)
|
2021-09-18 12:50:21 +00:00
|
|
|
},
|
|
|
|
deselectTicket() {
|
|
|
|
this.currentTicket = null
|
2021-08-22 16:01:29 +00:00
|
|
|
},
|
2021-12-18 15:49:53 +00:00
|
|
|
newTicket(){
|
|
|
|
//TODO generate new empty ticket
|
|
|
|
}
|
2021-08-22 16:01:29 +00:00
|
|
|
},
|
2021-08-21 14:17:14 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
#app-content > div {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
padding: 20px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type='text'] {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
textarea {
|
|
|
|
flex-grow: 1;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|