Skip to content
Snippets Groups Projects
Commit 5d86c719 authored by Zara Mudassar's avatar Zara Mudassar
Browse files

added doc and cleaned code

parent 8bb5c465
No related branches found
No related tags found
1 merge request!158Doc user profile components views
Showing with 106 additions and 41 deletions
<template> <template>
<!-- Shows rating, if no rating found, tells the user that no rating is registered -->
<ul v-if="isNaN(rating)" class="flex justify-center"> <ul v-if="isNaN(rating)" class="flex justify-center">
<li> <li>
<p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400">
...@@ -29,12 +30,6 @@ ...@@ -29,12 +30,6 @@
></path> ></path>
</svg> </svg>
</li> </li>
<li>
<!-- Trenger vi å vise i tekst når vi har stjerner? -->
<!-- <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400">
{{ rating }} out of 5
</p> -->
</li>
</ul> </ul>
</template> </template>
...@@ -46,6 +41,7 @@ export default { ...@@ -46,6 +41,7 @@ export default {
ratingType: String, ratingType: String,
}, },
methods: { methods: {
//Fills the rating stars
getFill(i) { getFill(i) {
if (i <= this.rating) { if (i <= this.rating) {
return "w-5 h-5 text-warn-medium"; return "w-5 h-5 text-warn-medium";
......
<template> <template>
<!-- Shows all the items a user has posted with search and pagination.
Includes a dropdown menu for editing or deleting an item. -->
<div id="headline" class="text-xl md:text-2xl text-primary-light font-medium"> <div id="headline" class="text-xl md:text-2xl text-primary-light font-medium">
Mine gjenstander Mine gjenstander
</div> </div>
...@@ -40,13 +42,15 @@ ...@@ -40,13 +42,15 @@
:key="item" :key="item"
> >
<div class="w-full"> <div class="w-full">
<ItemCard <ItemCard
id="ItemCardPage" id="ItemCardPage"
class="ItemCard w-full h-full" class="ItemCard w-full h-full"
:item="item" :item="item"
/> />
</div> </div>
<TripleDotButton class="DotButton" @click="openDotMenu(item)" />
<!-- Dropdown menu with options for editing an item and deleting an item -->
<TripleDotButton class="DotButton" @click="openDotMenu(item)"/>
<div <div
v-show="item.toggle" v-show="item.toggle"
...@@ -78,6 +82,8 @@ ...@@ -78,6 +82,8 @@
</div> </div>
</div> </div>
<!-- A waring asking the user if it is sure it wants to delete the item
with options to go ahead with the deleting or to cancel the delete. -->
<CustomFooterModal <CustomFooterModal
@close="this.readyToDelete = false" @close="this.readyToDelete = false"
:visible="readyToDelete" :visible="readyToDelete"
...@@ -86,14 +92,14 @@ ...@@ -86,14 +92,14 @@
> >
<div class="flex justify-center p-2"> <div class="flex justify-center p-2">
<ColoredButton <ColoredButton
id="#cancelDeleteButton" id="#cancelDeleteButton1"
:text="'Avbryt'" :text="'Avbryt'"
@click="cancelDelete" @click="cancelDelete"
class="bg-gray-500 m-2" class="bg-gray-500 m-2"
></ColoredButton> ></ColoredButton>
<ColoredButton <ColoredButton
id="confirmDeleteButton" id="confirmDeleteButton1"
@click="deleteItem" @click="deleteItem"
:text="'Slett'" :text="'Slett'"
class="m-2 bg-error-medium" class="m-2 bg-error-medium"
...@@ -116,8 +122,9 @@ ...@@ -116,8 +122,9 @@
:item="item" :item="item"
/> />
</div> </div>
<TripleDotButton class="DotButton" @click="openDotMenu(item)" />
<!-- Dropdown menu with options for editing an item and deleting an item -->
<TripleDotButton class="DotButton" @click="openDotMenu(item)"/>
<div <div
v-show="item.toggle" v-show="item.toggle"
class="options z-10 w-44 text-base list-none bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700" class="options z-10 w-44 text-base list-none bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700"
...@@ -147,6 +154,9 @@ ...@@ -147,6 +154,9 @@
</ul> </ul>
</div> </div>
</div> </div>
<!-- A waring asking the user if it is sure it wants to delete the item
with options to go ahead with the deleting or to cancel the delete. -->
<CustomFooterModal <CustomFooterModal
@close="this.readyToDelete = false" @close="this.readyToDelete = false"
:visible="readyToDelete" :visible="readyToDelete"
...@@ -172,6 +182,7 @@ ...@@ -172,6 +182,7 @@
</CustomFooterModal> </CustomFooterModal>
</div> </div>
</div> </div>
<!-- pagination --> <!-- pagination -->
<div class="flex justify-center" v-if="showItems"> <div class="flex justify-center" v-if="showItems">
<PaginationTemplate <PaginationTemplate
...@@ -220,6 +231,7 @@ export default { ...@@ -220,6 +231,7 @@ export default {
search: "", search: "",
readyToDelete: false, readyToDelete: false,
dropdown: false, dropdown: false,
//Variables connected to pagination //Variables connected to pagination
currentPage: 0, currentPage: 0,
pageSize: 12, pageSize: 12,
...@@ -227,6 +239,9 @@ export default { ...@@ -227,6 +239,9 @@ export default {
}; };
}, },
computed: { computed: {
/**
* Searchs items based on their title, address and price per day.
*/
searchedItems() { searchedItems() {
let filteredItems = []; let filteredItems = [];
...@@ -264,7 +279,10 @@ export default { ...@@ -264,7 +279,10 @@ export default {
cancelDelete() { cancelDelete() {
this.readyToDelete = false; this.readyToDelete = false;
}, },
//Pagination /**
* 2 methods related to pagination. Updates page and updates
* visible items on page.
*/
updatePage(pageNumber) { updatePage(pageNumber) {
this.currentPage = pageNumber; this.currentPage = pageNumber;
this.updateVisibleTodos(); this.updateVisibleTodos();
...@@ -280,6 +298,7 @@ export default { ...@@ -280,6 +298,7 @@ export default {
this.updatePage(this.currentPage - 1); this.updatePage(this.currentPage - 1);
} }
}, },
goToDeleteItem(item) { goToDeleteItem(item) {
this.chosenItem = item; this.chosenItem = item;
this.readyToDelete = true; this.readyToDelete = true;
...@@ -288,8 +307,11 @@ export default { ...@@ -288,8 +307,11 @@ export default {
await UserService.setListingToDeleted(this.chosenItem); await UserService.setListingToDeleted(this.chosenItem);
this.$router.go(0); this.$router.go(0);
}, },
/**
* This method triggers when search input field is changed
*/
searchWritten: function () { searchWritten: function () {
//This method triggers when search input field is changed
if (this.search.length > 0) { if (this.search.length > 0) {
this.showItems = false; this.showItems = false;
this.showSearchedItems = true; this.showSearchedItems = true;
...@@ -299,6 +321,11 @@ export default { ...@@ -299,6 +321,11 @@ export default {
} }
}, },
}, },
/**
* Gets userlistings and prepares the pagination by
* updating the items to be visible.
*/
async beforeMount() { async beforeMount() {
await this.getUserListingsFromAPI(); await this.getUserListingsFromAPI();
this.updateVisibleTodos(); this.updateVisibleTodos();
......
<template> <template>
<!-- A card for displaying a user in a list.
Displays a user's profile picture, name, rating and some
buttons based on where the list is being shown. -->
<div <div
class="bg-white shadow dark:bg-gray-800 select-none cursor-pointer hover:bg-gray-50 flex items-center p-4" class="bg-white shadow dark:bg-gray-800 select-none cursor-pointer hover:bg-gray-50 flex items-center p-4"
> >
...@@ -96,6 +99,10 @@ export default { ...@@ -96,6 +99,10 @@ export default {
buttons: Array, buttons: Array,
}, },
computed: { computed: {
/**
* returns the user's profile picture. If the user does not have any
* profile picture the default profile picture is returned.
*/
getProfilePicture() { getProfilePicture() {
if (this.user.picture !== "" && this.user.picture != null) { if (this.user.picture !== "" && this.user.picture != null) {
return this.user.picture; return this.user.picture;
...@@ -104,18 +111,25 @@ export default { ...@@ -104,18 +111,25 @@ export default {
}, },
}, },
methods: { methods: {
/**
* If chat button clicked, the user's gets redirected to chat page.
*/
openChatWithUser() { openChatWithUser() {
this.$router.push({ this.$router.push({
name: "messages", name: "messages",
query: { userID: this.user.userId }, query: { userID: this.user.userId },
}); });
}, },
/**
* Admin related methods for kicking a user from a community,
* accepting and rejecting a user's join community request
*/
kickUserFromCommunity() { kickUserFromCommunity() {
CommunityAdminService.removeUserFromCommunity( CommunityAdminService.removeUserFromCommunity(
this.communityID, this.communityID,
this.user.userId this.user.userId
); );
//Find a better way to do this
window.location.reload(); window.location.reload();
}, },
acceptMemberRequest() { acceptMemberRequest() {
...@@ -131,6 +145,9 @@ export default { ...@@ -131,6 +145,9 @@ export default {
); );
}, },
}, },
/**
* Gets the user's rating before mounting the page
*/
async beforeMount() { async beforeMount() {
const maybeRating = await UserService.getUserRatingAverage( const maybeRating = await UserService.getUserRatingAverage(
this.user.userId this.user.userId
......
<template> <template>
<!-- User profile with the logged in user's info and a dropdown menu-->
<div <div
class="w-full max-w-xl m-auto md:ring-1 ring-gray-300 overflow-hidden rounded-xl p-4" class="w-full max-w-xl m-auto md:ring-1 ring-gray-300 overflow-hidden rounded-xl p-4"
> >
<!-- A warning when deleting a user account to ask the user
if it is sure -->
<DeleteUserModal <DeleteUserModal
:visible="show" :visible="show"
@close="this.show = false" @close="this.show = false"
@deleteUser="deleteUser" @deleteUser="deleteUser"
/> />
<!-- dropdown icon button to toggle(open/close) the dropdown menu -->
<div v-show="isCurrentUser" class="float-right px-4 pt-4"> <div v-show="isCurrentUser" class="float-right px-4 pt-4">
<button <button
id="dropdownDefault" id="dropdownDefault"
...@@ -27,6 +32,8 @@ ...@@ -27,6 +32,8 @@
</svg> </svg>
</button> </button>
<!-- Dropdown menu containing options for seeing user's items, user's communities,
renting history, logging out, changing password and deleting account -->
<div <div
id="dropdown" id="dropdown"
v-show="dropdown" v-show="dropdown"
...@@ -84,6 +91,7 @@ ...@@ -84,6 +91,7 @@
</div> </div>
</div> </div>
<!-- User info (name, rating and profile picture) -->
<div class="flex flex-col items-center pb-10 mt-16 z-5"> <div class="flex flex-col items-center pb-10 mt-16 z-5">
<img <img
class="mb-3 w-24 h-24 rounded-full shadow-lg" class="mb-3 w-24 h-24 rounded-full shadow-lg"
...@@ -153,6 +161,9 @@ export default { ...@@ -153,6 +161,9 @@ export default {
}, },
}, },
methods: { methods: {
/**
* Gets the user and it's ratings
*/
async getUser() { async getUser() {
this.currentUser = await parseCurrentUser(); this.currentUser = await parseCurrentUser();
this.id = await this.$router.currentRoute.value.params.id; this.id = await this.$router.currentRoute.value.params.id;
...@@ -174,6 +185,10 @@ export default { ...@@ -174,6 +185,10 @@ export default {
this.renterRating = ratingAsRenter; this.renterRating = ratingAsRenter;
} }
}, },
/**
* Logs out the user and sets token in state to be null.
*/
logout() { logout() {
this.$store.commit("logout"); this.$store.commit("logout");
this.$router.push("/"); this.$router.push("/");
......
<template> <template>
<!-- A view for showing all the communities a user is part of -->
<div> <div>
<div v-if="loading" class="flex place-content-center p-8"> <div v-if="loading" class="flex place-content-center p-8">
<LoaderSpinner /> <LoaderSpinner />
......
<template> <template>
<!-- A view for the user profile card -->
<div> <div>
<LargeProfileCard :isCurrentUser="true" class="md:mt-8" /> <LargeProfileCard :isCurrentUser="true" class="md:mt-8" />
</div> </div>
......
<template> <template>
<!-- A view for showing rating and rent history -->
<rating-modal <rating-modal
:visible="modal.show" :visible="modal.show"
:name="modal.name" :name="modal.name"
...@@ -58,9 +59,6 @@ export default { ...@@ -58,9 +59,6 @@ export default {
fullHistory.sort(compareHistoryItems); fullHistory.sort(compareHistoryItems);
return fullHistory; return fullHistory;
}, },
hasNoHistory() {
return this.renterHistory.length == 0 && this.ownerHistory.length == 0;
},
}, },
methods: { methods: {
openModal(modal) { openModal(modal) {
......
<template> <template>
<!-- A view for showing all the items the user has posted/added -->
<user-items> </user-items> <user-items> </user-items>
</template> </template>
...@@ -11,5 +12,3 @@ export default { ...@@ -11,5 +12,3 @@ export default {
}, },
}; };
</script> </script>
<style></style>
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Rating component renders correctly 1`] = ` exports[`Rating component renders correctly 1`] = `
<ul <div
class="flex justify-center" data-v-app=""
> >
<li>
<p <!-- Shows rating, if no rating found, tells the user that no rating is registered -->
class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400" <ul
> class="flex justify-center"
: >
</p> <li>
</li> <p
<li> class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"
<p >
class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400" :
> </p>
Ingen vurderinger </li>
</p> <li>
</li> <p
</ul> class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"
>
Ingen vurderinger
</p>
</li>
</ul>
</div>
`; `;
...@@ -5,6 +5,8 @@ exports[`UserItems component renders correctly 1`] = ` ...@@ -5,6 +5,8 @@ exports[`UserItems component renders correctly 1`] = `
data-v-app="" data-v-app=""
> >
<!-- Shows all the items a user has posted with search and pagination.
Includes a dropdown menu for editing or deleting an item. -->
<div <div
class="text-xl md:text-2xl text-primary-light font-medium" class="text-xl md:text-2xl text-primary-light font-medium"
id="headline" id="headline"
...@@ -53,6 +55,8 @@ exports[`UserItems component renders correctly 1`] = ` ...@@ -53,6 +55,8 @@ exports[`UserItems component renders correctly 1`] = `
> >
<!-- A waring asking the user if it is sure it wants to delete the item
with options to go ahead with the deleting or to cancel the delete. -->
<!-- Main modal --> <!-- Main modal -->
<!--v-if--> <!--v-if-->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment