update pagination

This commit is contained in:
2021-02-09 17:52:25 +02:00
parent 78a119826f
commit 2689db23b8
5 changed files with 142 additions and 116 deletions

View File

@@ -238,7 +238,13 @@ module.exports = {
tags: {
typeName: 'BlogTag',
create: true
},
category: {
typeName: 'BlogCategory',
create: true
}
}
}
},
@@ -253,6 +259,11 @@ module.exports = {
tags: {
typeName: 'NewsTag',
create: true
},
category: {
typeName: 'NewsCategory',
create: true
}
}
}

View File

@@ -5,10 +5,9 @@
v-for="(slide, index) in slides"
:key="index"
:href="`#${index}`"
class="mt-1 capitalize group flex items-center px-3 py-2 text-sm leading-5 font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-50 focus:outline-none focus:text-gray-900 focus:bg-gray-50 transition ease-in-out duration-150"
class="mt-1 capitalize group flex items-center px-3 py-2 text-sm leading-5 font-medium hover:text-gray-900 hover:bg-gray-400 focus:outline-none transition border-blue-500 hover:bg-gray-100 transition ease-in-out duration-150"
:class="{
'text-gray-900 border-r-3 border-blue-500 hover:bg-gray-100':
activeIndex === index,
'border-r-3 border-blue-500 hover:bg-gray-100': activeIndex === index,
}"
@click="setActive(index)"
>
@@ -20,12 +19,14 @@
class="content inline-block h-full w-3/4 align-top p-5 transition ease-in-out duration-150"
>
<div :id="slides[activeIndex]" class="hidden" style="display: block">
<img
v-if="slides[activeIndex].img"
:src="slides[activeIndex].img.src"
<g-image
v-if="slides[activeIndex].image"
:src="
require(`!!assets-loader!@images/sliders/${slides[activeIndex].image}`)
"
:alt="slides[activeIndex].title"
/>
<p v-html="slides[activeIndex].content"></p>
<div v-html="slides[activeIndex].content"></div>
</div>
</div>
</div>
@@ -46,4 +47,3 @@ export default {
},
};
</script>

View File

@@ -9,6 +9,11 @@
>filter:</span
>
</div>
<div class="sm:block md:hidden">
<ul class="list-none inline-flex justify-center md:justify-end">
<li class="py-1 mx-5 cursor-pointer" @click="resetAll()">Reset</li>
</ul>
</div>
</div>
<nav
@@ -70,6 +75,11 @@
</li>
</ul>
</nav>
<div class="hidden md:ml-auto md:inline-block md:order-last">
<ul class="list-none inline-flex justify-center md:justify-end">
<li class="py-1 mx-5 cursor-pointer" @click="resetAll()">Reset</li>
</ul>
</div>
</header>
</div>
</template>
@@ -105,6 +115,9 @@ export default {
this.open = false;
}
},
resetAll() {
this.$emit("resetAll", true);
},
},
mounted() {
document.addEventListener("click", this.close);

View File

@@ -23,21 +23,20 @@
<div class="pagination flex justify-center mb-8">
<Pagination
baseUrl=""
:baseUrl="baseurl"
:currentPage="blogs.pageInfo.currentPage"
:totalPages="blogs.pageInfo.totalPages"
:maxVisibleButtons="5"
v-if="blogs.pageInfo.totalPages > 1"
v-if="blogs.pageInfo.totalPages > 1 && blogs.edges.length > 0"
/>
</div>
</div>
</Layout>
</template>
<page-query>
query{
entries: allBlog(sortBy: "created", order: DESC) {
query($page: Int){
entries: allBlog(perPage: 10, page: $page, sortBy: "created", order: DESC, filter: {category: { id: {in: ["farming"]}}}) @paginate{
totalCount
pageInfo {
totalPages
@@ -52,6 +51,10 @@ query{
path
}
excerpt
category{
id
title
}
image(width:800)
path
humanTime : created(format:"DD MMM YYYY")
@@ -84,7 +87,7 @@ import NewsFilterHeader from "~/components/custom/NewsFilterHeader.vue";
export default {
data() {
const allMonths = [
"All",
"All Months",
"January",
"February",
"March",
@@ -99,23 +102,23 @@ export default {
"December",
];
const currYear = new Date().getFullYear();
var years = ["All"]
var r = this.range(2019, currYear)
var years = ["All Years"];
var r = this.range(2019, currYear);
r.forEach((year) => years.push(String(year)));
return {
selectedTopic: "All",
selectedYear: "All",
selectedMonth: "All",
selectedTopic: "All Topics",
selectedYear: "All Years",
selectedMonth: "All Months",
months: allMonths,
years: years,
listArchive: false,
archiveButtonText : "Archive"
archiveButtonText: "Archive",
};
},
metaInfo: {
title: "Newsroom",
title: "Blog",
},
components: {
PostListItem,
@@ -133,9 +136,9 @@ export default {
this.selectedMonth = month;
},
resetAll() {
this.selectedTopic = "All";
this.selectedYear = "All";
this.selectedMonth = "All";
this.selectedTopic = "All Topics";
this.selectedYear = "All Years";
this.selectedMonth = "All Months";
},
range(start, end, step) {
var range = [];
@@ -159,14 +162,11 @@ export default {
}
if (typeofStart == "number") {
while (step > 0 ? end >= start : end <= start) {
range.push(start);
start += step;
}
} else if (typeofStart == "string") {
if (start.length != 1 || end.length != 1) {
throw TypeError("Only strings with one character are supported.");
}
@@ -178,19 +178,16 @@ export default {
range.push(String.fromCharCode(start));
start += step;
}
} else {
throw TypeError("Only string and number types are supported");
}
return range;
}
},
},
computed: {
topics: function () {
var res = ["All"];
var res = ["All Topics"];
this.$page.topics.edges.forEach((edge) => res.push(edge.node.title));
return res;
},
@@ -200,7 +197,6 @@ export default {
}
},
blogs() {
var res = {};
var old = this.$page.entries;
@@ -212,25 +208,27 @@ export default {
var node = old.edges[i].node;
// Now check topic
var topics = ["All"];
var topics = ["All Topics"];
node.tags.forEach((tag) => topics.push(tag.title));
var nodeDate = new Date(node.datetime);
if (!topics.includes(this.selectedTopic)) continue;
// Check year
var years = ["All", String(nodeDate.getFullYear())];
var years = ["All Years", String(nodeDate.getFullYear())];
if (!years.includes(this.selectedYear)) continue;
// Check Month
var months = ["All", this.months[nodeDate.getMonth() + 1]];
// Check Month
var months = ["All Months", this.months[nodeDate.getMonth() + 1]];
if (!months.includes(this.selectedMonth)) continue;
res.edges.push({ node: node, id: node.id });
}
return res;
},
baseurl() {
return "/blog/";
},
},
};
</script>

View File

@@ -32,15 +32,15 @@
:currentPage="$page.entries.pageInfo.currentPage"
:totalPages="$page.entries.pageInfo.totalPages"
:maxVisibleButtons="5"
v-if="$page.entries.pageInfo.totalPages > 1"
v-if="$page.entries.pageInfo.totalPages > 1 && news.edges.length > 0"
/>
</div>
</Layout>
</template>
<page-query>
query{
entries: allNews(sortBy: "created", order: DESC) {
query($page: Int){
entries: allNews(perPage: 10, page: $page, sortBy: "created", order: DESC, filter: {category: { id: {in: ["farming"]}}}) @paginate{
totalCount
pageInfo {
totalPages
@@ -55,6 +55,10 @@ query{
path
}
excerpt
category{
id
title
}
image(width:800)
path
humanTime : created(format:"DD MMM YYYY")
@@ -82,7 +86,7 @@ import Pagination from "~/components/custom/Pagination.vue";
export default {
data() {
const allMonths = [
"All",
"All Months",
"January",
"February",
"March",
@@ -97,14 +101,14 @@ export default {
"December",
];
const currYear = new Date().getFullYear();
var years = ["All"];
var years = ["All Years"];
var r = this.range(2019, currYear);
r.forEach((year) => years.push(String(year)));
return {
selectedTopic: "All",
selectedYear: "All",
selectedMonth: "All",
selectedTopic: "All Topics",
selectedYear: "All Years",
selectedMonth: "All Months",
months: allMonths,
years: years,
listArchive: false,
@@ -131,9 +135,9 @@ export default {
this.selectedMonth = month;
},
resetAll() {
this.selectedTopic = "All";
this.selectedYear = "All";
this.selectedMonth = "All";
this.selectedTopic = "All Topics";
this.selectedYear = "All Years";
this.selectedMonth = "All Months";
},
toggleListArchive() {
if (this.listArchive) {
@@ -198,13 +202,13 @@ export default {
},
computed: {
topics: function () {
var res = ["All"];
var res = ["All Topics"];
this.$page.topics.edges.forEach((edge) => res.push(edge.node.title));
return res;
},
baseurl: function () {
return "";
return "/news/";
},
news() {
@@ -221,26 +225,26 @@ export default {
const diffDays = Math.ceil(diff / (1000 * 60 * 60 * 24));
var selected = false;
if (!this.listArchive && diffDays <= 30) {
selected = true;
} else if (this.listArchive && diffDays > 30) {
selected = true;
}
// if (!this.listArchive && diffDays <= 180) {
// selected = true;
// } else if (this.listArchive && diffDays > 180) {
// selected = true;
// }
if (!selected) continue;
// if (!selected) continue;
// Now check topic
var topics = ["All"];
var topics = ["All Topics"];
node.tags.forEach((tag) => topics.push(tag.title));
if (!topics.includes(this.selectedTopic)) continue;
// Check year
var years = ["All", String(nodeDate.getFullYear())];
var years = ["All Years", String(nodeDate.getFullYear())];
if (!years.includes(this.selectedYear)) continue;
// Check Month
var months = ["All", this.months[nodeDate.getMonth() + 1]];
var months = ["All Months", this.months[nodeDate.getMonth() + 1]];
if (!months.includes(this.selectedMonth)) continue;
res.edges.push({ node: node, id: node.id });