frontend/src/views/Transaction.vue

206 lines
5.5 KiB
Vue
Raw Normal View History

2021-01-20 00:03:47 +11:00
<template>
2021-04-09 16:01:28 +10:00
<div id="transactions">
<section class="section">
<div class="container" v-if="$store.state.user.username">
<div class="columns is-centered">
<div class="column is-6">
<div class="box">
<div class="title">Transaction Log</div>
<hr />
<NoItems v-if="!transactions.length" type="transactions"></NoItems>
<b-table
v-else
:detail-key="'log-' + transactions.id"
:data="transactions"
:paginated="isPaginated"
:per-page="perPage"
:current-page.sync="currentPage"
:pagination-simple="isPaginationSimple"
:pagination-position="paginationPosition"
:default-sort-direction="defaultSortDirection"
:pagination-rounded="isPaginationRounded"
:sort-icon="sortIcon"
:opened-detailed="defaultOpenedDetails"
:sort-icon-size="sortIconSize"
default-sort="user.first_name"
aria-next-label="Next page"
aria-previous-label="Previous page"
aria-page-label="Page"
>
<b-table-column
field="props.row.text"
label="Message"
sortable
v-slot="props"
>
{{ props.row.text }}
</b-table-column>
2021-01-20 00:03:47 +11:00
2021-04-09 16:01:28 +10:00
<b-table-column
field="props.row.priceOfPurchase"
label="Price"
sortable
v-slot="props"
>
{{ props.row.priceOfPurchase }}
</b-table-column>
2021-01-20 00:03:47 +11:00
2021-04-09 16:01:28 +10:00
<b-table-column
field="props.row.createdAt"
label="Date"
sortable
centered
v-slot="props"
>
<span class="tag is-success">
2021-01-20 00:03:47 +11:00
{{ new Date(props.row.createdAt).toLocaleDateString() }}
2021-04-09 16:01:28 +10:00
</span>
</b-table-column>
</b-table>
</div>
</div>
</div>
2021-01-20 00:03:47 +11:00
</div>
2021-04-09 16:01:28 +10:00
<div class="container" v-else>
<div class="columns is-centered">
<div class="column is-6">
<div class="box has-text-centered">
<i class="far fa-times-square large-icon"></i>
<div class="subtitle">{{ $t("generic.notLoggedIn") }}</div>
</div>
</div>
</div>
</div>
</section>
</div>
2021-01-20 00:03:47 +11:00
</template>
<script>
2021-04-09 16:01:28 +10:00
import AjaxErrorHandler from ".././assets/js/errorHandler";
import NoItems from "../components/NoItems";
2021-01-20 00:03:47 +11:00
export default {
2021-04-09 16:01:28 +10:00
name: "Transactions",
2021-01-20 00:03:47 +11:00
components: {
2021-04-09 16:01:28 +10:00
NoItems,
2021-01-20 00:03:47 +11:00
},
2021-04-09 16:01:28 +10:00
data() {
2021-01-20 00:03:47 +11:00
return {
2021-04-09 16:01:28 +10:00
search: "",
2021-01-20 00:03:47 +11:00
transactions: [],
isPaginated: true,
isPaginationSimple: false,
isPaginationRounded: false,
2021-04-09 16:01:28 +10:00
paginationPosition: "bottom",
defaultSortDirection: "desc",
sortIcon: "arrow-up",
sortIconSize: "is-small",
2021-01-20 00:03:47 +11:00
currentPage: 1,
perPage: 30,
defaultOpenedDetails: [1],
showDetailIcon: true,
loading: true,
offset: 0,
limit: 15,
showTeamTab: 0,
tcreateProd: {
2021-04-09 16:01:28 +10:00
username: "",
name: "",
2021-01-20 00:03:47 +11:00
loading: false,
errors: {
2021-04-09 16:01:28 +10:00
username: "",
name: "",
},
2021-01-20 00:03:47 +11:00
},
roleOptions: [
2021-04-09 16:01:28 +10:00
{ name: "Admins", value: "admin" },
{ name: "transactions", value: "user" },
2021-01-20 00:03:47 +11:00
],
2021-04-09 16:01:28 +10:00
roleSelected: ["admin", "user"],
2021-01-20 00:03:47 +11:00
tableSort: {
2021-04-09 16:01:28 +10:00
column: "username",
sort: "desc",
},
};
2021-01-20 00:03:47 +11:00
},
methods: {
2021-04-09 16:01:28 +10:00
fetchData() {
if (this.offset === null) return;
2021-01-20 00:03:47 +11:00
2021-04-09 16:01:28 +10:00
let url =
process.env.VUE_APP_APIENDPOINT +
process.env.VUE_APP_APIVERSION +
`/` +
`transactions?
2021-01-20 00:03:47 +11:00
sort=${this.tableSort.column}
&order=${this.tableSort.sort}
&offset=${this.offset}
`;
2021-04-09 16:01:28 +10:00
if (this.roleSelected.length === 1) {
url += "&role=" + this.roleSelected[0];
2021-01-20 00:03:47 +11:00
}
2021-04-09 16:01:28 +10:00
if (this.search.length) {
url += "&search=" + encodeURIComponent(this.search.trim());
2021-01-20 00:03:47 +11:00
}
this.loading = true;
this.axios
2021-04-09 16:01:28 +10:00
.get(url)
.then((res) => {
this.transactions.push(...res.data);
this.loading = /*loading =*/ false;
2021-01-20 00:03:47 +11:00
2021-04-09 16:01:28 +10:00
//If returned data is less than the limit
//then there must be no more pages to paginate
if (res.data.length < this.limit) {
this.offset = null;
} else {
this.offset += this.limit;
}
})
.catch((e) => {
AjaxErrorHandler(this.$store)(e);
this.loading = /*loading =*/ false;
});
2021-01-20 00:03:47 +11:00
},
2021-04-09 16:01:28 +10:00
resetFetchData() {
2021-01-20 00:03:47 +11:00
this.offset = 0;
this.transactions = [];
this.fetchData();
2021-04-09 16:01:28 +10:00
},
2021-01-20 00:03:47 +11:00
},
2021-04-09 16:01:28 +10:00
getNewertransactions() {
this.loadingNewer = true;
2021-01-20 00:03:47 +11:00
this.axios
2021-04-09 16:01:28 +10:00
.get(
process.env.VUE_APP_APIENDPOINT +
process.env.VUE_APP_APIVERSION +
"/" +
"transactions" +
"?limit=" +
this.newtransactions
)
.then((res) => {
this.loadingNewer = false;
this.newtransactions = 0;
2021-01-20 00:03:47 +11:00
2021-04-09 16:01:28 +10:00
this.threads.unshift(...res.data.Threads);
})
.catch((e) => {
this.loadingNewer = false;
AjaxErrorHandler(this.$store)(e);
});
},
mounted() {
if (this.$store.state.user.username) {
this.fetchData();
}
2021-01-20 00:03:47 +11:00
},
2021-04-09 16:01:28 +10:00
};
2021-01-20 00:03:47 +11:00
</script>