Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106_2022_02
boco-frontend
Commits
65efe230
Commit
65efe230
authored
2 years ago
by
Erik Borgeteien Hansen
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' into community-admin
parents
59e49c84
7ad2e244
No related branches found
Branches containing commit
No related tags found
2 merge requests
!87
Community request
,
!86
Community admin
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/BaseComponents/PaginationTemplate.vue
+37
-0
37 additions, 0 deletions
src/components/BaseComponents/PaginationTemplate.vue
src/components/CommunityComponents/CommunityHome.vue
+71
-14
71 additions, 14 deletions
src/components/CommunityComponents/CommunityHome.vue
with
108 additions
and
14 deletions
src/components/BaseComponents/PaginationTemplate.vue
0 → 100644
+
37
−
0
View file @
65efe230
<
template
>
<div
v-if=
"totalPages() > 0"
>
<span
v-if=
"showPreviousLink()"
class=
"cursor-pointer inline-flex items-center p-2 text-sm font-medium text-gray-500 bg-white rounded-lg border border-gray-300 hover:bg-gray-100 hover:text-gray-700"
@
click=
"updatePage(currentPage - 1)"
>
Forrige
</span>
<label
class=
"mx-2"
>
{{
currentPage
+
1
}}
av
{{
totalPages
()
}}
</label>
<span
v-if=
"showNextLink()"
class=
"cursor-pointer inline-flex items-center p-2 text-sm font-medium text-gray-500 bg-white rounded-lg border border-gray-300 hover:bg-gray-100 hover:text-gray-700"
@
click=
"updatePage(currentPage + 1)"
>
Neste
</span>
</div>
</
template
>
<
script
>
export
default
{
name
:
'
paginationTemplate
'
,
props
:
[
'
items
'
,
'
currentPage
'
,
'
pageSize
'
],
methods
:
{
updatePage
(
pageNumber
)
{
this
.
$emit
(
'
page:update
'
,
pageNumber
);
},
totalPages
()
{
return
Math
.
ceil
(
this
.
items
.
length
/
this
.
pageSize
);
},
showPreviousLink
()
{
return
this
.
currentPage
==
0
?
false
:
true
;
},
showNextLink
()
{
return
this
.
currentPage
==
(
this
.
totalPages
()
-
1
)
?
false
:
true
;
}
}
}
</
script
>
This diff is collapsed.
Click to expand it.
src/components/CommunityComponents/CommunityHome.vue
+
71
−
14
View file @
65efe230
...
...
@@ -22,19 +22,39 @@
class=
"w-full py-3 pl-10 pr-4 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-primary-medium dark:focus:border-primary-medium focus:outline-none focus:ring"
placeholder=
"Search"
v-model=
"search"
@
change=
"searchWritten"
/>
</div>
<!-- Item cards -->
<div
class=
"absolute inset-x-0 px-6 py-3"
>
<div
class=
"grid grid-flow-row-dense grid-cols-2 md:grid-cols-4 lg:grid-cols-5 w-full place-items-center"
>
<ItemCard
v-for=
"item in searchedItems"
:key=
"item"
:item=
"item"
@
click=
"goToItemInfoPage(item.listingID)"
<div
class=
"absolute inset-x-0 px-5 py-3"
>
<!-- ItemCards -->
<div
class=
"flex items-center justify-center w-screen"
>
<!-- Shows items based on pagination -->
<div
class=
"grid grid-flow-row-dense grid-cols-2 md:grid-cols-4 lg:grid-cols-5 w-full"
v-if=
"showItems"
>
<ItemCard
v-for=
"item in visibleItems"
:key=
"item"
:item=
"item"
@
click=
"goToItemInfoPage(item.listingID)"
/>
</div>
<!-- Shows items based on search field input -->
<div
class=
"grid grid-flow-row-dense grid-cols-2 md:grid-cols-4 lg:grid-cols-5 w-full place-items-center"
v-if=
"showSearchedItems"
>
<ItemCard
v-for=
"item in searchedItems"
:key=
"item"
:item=
"item"
@
click=
"goToItemInfoPage(item.listingID)"
/>
</div>
</div>
<!-- pagination -->
<div
class=
"flex justify-center"
v-if=
"showItems"
>
<PaginationTemplate
v-bind:items=
"items"
v-on:page:update=
"updatePage"
v-bind:currentPage=
"currentPage"
v-bind:pageSize=
"pageSize"
class=
"mt-10"
/>
</div>
</div>
...
...
@@ -42,8 +62,10 @@
</
template
>
<
script
>
import
CommunityHeader
from
"
@/components/CommunityComponents/CommunityHeader.vue
"
;
import
ItemCard
from
"
@/components/ItemComponents/ItemCard
"
;
import
CommunityHeader
from
"
@/components/CommunityComponents/CommunityHeader
"
;
import
PaginationTemplate
from
"
@/components/BaseComponents/PaginationTemplate
"
;
import
{
GetCommunity
,
GetListingsInCommunity
,
...
...
@@ -54,6 +76,7 @@ export default {
components
:
{
CommunityHeader
,
ItemCard
,
PaginationTemplate
,
},
computed
:
{
searchedItems
()
{
...
...
@@ -87,6 +110,14 @@ export default {
search
:
""
,
communityID
:
-
1
,
community
:
{},
showItems
:
true
,
showSearchedItems
:
false
,
//Variables connected to pagination
currentPage
:
0
,
pageSize
:
12
,
visibleItems
:
[],
};
},
methods
:
{
...
...
@@ -113,10 +144,36 @@ export default {
let
res
=
await
getItemPictures
(
itemid
);
return
res
;
},
searchWritten
:
function
(){
//This method triggers when search input field is changed
if
(
this
.
search
.
length
>
0
){
this
.
showItems
=
false
;
this
.
showSearchedItems
=
true
;
}
else
{
this
.
showItems
=
true
;
this
.
showSearchedItems
=
false
;
}
},
//Pagination
updatePage
(
pageNumber
)
{
this
.
currentPage
=
pageNumber
;
this
.
updateVisibleTodos
();
},
updateVisibleTodos
()
{
this
.
visibleItems
=
this
.
items
.
slice
(
this
.
currentPage
*
this
.
pageSize
,
(
this
.
currentPage
*
this
.
pageSize
)
+
this
.
pageSize
);
// if we have 0 visible items, go back a page
if
(
this
.
visibleItems
.
length
===
0
&&
this
.
currentPage
>
0
)
{
this
.
updatePage
(
this
.
currentPage
-
1
);
}
},
},
beforeMount
()
{
this
.
getCommunityFromAPI
();
//To get the id of the community before mounting the view
this
.
getListingsOfCommunityFromAPI
();
async
beforeMount
()
{
await
this
.
getCommunityFromAPI
();
//To get the id of the community before mounting the view
await
this
.
getListingsOfCommunityFromAPI
();
this
.
updateVisibleTodos
();
},
};
</
script
>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment