Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More pagination #132

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions src/components/MatchesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
{{ item.team2_string }}
</div>
</template>
<template v-slot:top>
<div v-if="isMyMatches && isThereCancelledMatches">
<v-toolbar flat>
<v-toolbar-title>
<v-btn primary @click="deleteCancelled" :loading="deletePending">
{{ $t("Matches.DeleteButton") }}
</v-btn>
</v-toolbar-title>
</v-toolbar>
</div>
<div v-else />
</template>
</v-data-table>
</template>

Expand All @@ -62,7 +74,8 @@ export default {
isLoading: true,
isThereCancelledMatches: false,
totalMatches: -1,
options: {}
options: {},
deletePending: false
};
},
computed: {
Expand All @@ -84,20 +97,24 @@ export default {
},
{
text: this.$t("Matches.Status"),
value: "match_status"
value: "match_status",
sortable: false
},
{
text: this.$t("Matches.Owner"),
value: "owner",
sortable: false
}
];
},
isMyMatches() {
return this.$route.path == "/mymatches";
}
},
watch: {
options: {
handler() {
this.pageUpdate();
async handler() {
await this.pageUpdate();
},
deep: true
}
Expand All @@ -118,14 +135,16 @@ export default {
this.isLoading = false;
},
async pageUpdate() {
let count = await this.GetAllMatches();
let count =
this.$route.path == "/mymatches"
? await this.GetMyMatches()
: await this.GetAllMatches();
const { sortBy, sortDesc, page, itemsPerPage } = this.options;
if (typeof count == "string") count = [];
if (sortBy.length === 1 && sortDesc.length === 1) {
count = count.sort((a, b) => {
const sortA = a[sortBy[0]];
const sortB = b[sortBy[0]];

if (sortDesc[0]) {
if (sortA < sortB) return 1;
if (sortA > sortB) return -1;
Expand All @@ -144,11 +163,14 @@ export default {
await this.pushMatchData(count);
return;
},
async checkRoute(offset, amount) {
let res;
if (offset < 0) res = await this.GetAllMatches();
else res = await this.GetPagedMatches(offset, amount);
return res;
async deleteCancelled() {
this.deletePending = true;
await this.DeleteMyCancelledMatches();
this.deletePending = false;
this.matches = [];
this.isLoading = true;
this.isThereCancelledMatches = false;
await this.pageUpdate();
}
}
};
Expand Down
85 changes: 59 additions & 26 deletions src/components/TeamsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
:loading-text="$t('misc.LoadText')"
:headers="headers"
:items="teams"
:sort-by="['id']"
:options.sync="options"
:server-items-length="totalTeams"
ref="TeamsTable"
>
<template v-slot:top>
Expand Down Expand Up @@ -112,12 +113,11 @@ export default {
tournament_id: ""
},
responseSheet: false,
response: ""
response: "",
options: {},
totalTeams: -1
};
},
mounted() {
this.GetTeams();
},
watch: {
newImportDialog(val) {
if (!val) {
Expand All @@ -126,6 +126,12 @@ export default {
tournament_id: ""
};
}
},
options: {
handler() {
this.GetTeams();
},
deep: true
}
},
computed: {
Expand All @@ -143,50 +149,77 @@ export default {
},
{
text: this.$t("Team.TeamTag"),
value: "tag"
value: "tag",
sortable: false
},
{
text: this.$t("Team.Flag"),
value: "flag"
},
{
text: this.$t("Team.Owner"),
value: "owner"
value: "owner",
sortable: false
}
];
}
},
methods: {
async GetTeams() {
try {
const res =
this.$route.path == "/teams"
? await this.GetAllTeams()
: await this.GetMyTeams();
await res.forEach(async team => {
const ownerRes = await this.GetUserData(team.user_id);
team.owner = ownerRes.name;
if (
team.user_id == this.user.id ||
team.public_team == 1 ||
(await this.IsAnyAdmin(this.user))
) {
this.teams.push(team);
this.isLoading = true;
this.teams = [];
let count =
this.$route.path == "/teams"
? await this.GetAllTeams()
: await this.GetMyTeams();

const { sortBy, sortDesc, page, itemsPerPage } = this.options;
if (typeof count == "string") count = [];
if (sortBy.length === 1 && sortDesc.length === 1) {
count = count.sort((a, b) => {
const sortA = a[sortBy[0]];
const sortB = b[sortBy[0]];
if (sortDesc[0]) {
if (sortA < sortB) return 1;
if (sortA > sortB) return -1;
return 0;
} else {
if (sortA < sortB) return -1;
if (sortA > sortB) return 1;
return 0;
}
});
} catch (err) {
console.error(err);
} finally {
this.isLoading = false;
}

this.totalTeams = count.length;
if (itemsPerPage > 0) {
count = count.slice((page - 1) * itemsPerPage, page * itemsPerPage);
}

await count.forEach(async team => {
const ownerRes = await this.GetUserData(team.user_id);
team.owner = ownerRes.name;
if (
team.user_id == this.user.id ||
team.public_team == 1 ||
(await this.IsAnyAdmin(this.user))
) {
this.teams.push(team);
}
});
this.isLoading = false;
return;
},
async importChallongeTeams() {
let importData = [this.challongeInfo];
let isImport = await this.ImportChallongeTeams(importData);
if (isImport.includes("successfully")) {
console.log(isImport);
if (isImport.message.includes("successfully")) {
this.teams = [];
this.GetTeams();
this.response = isImport.message;
this.responseSheet = true;
this.newImportDialog = false;
} else {
this.response = this.$t("Seasons.ImportError");
this.responseSheet = true;
Expand Down