Skip to content
Snippets Groups Projects
Commit da31f113 authored by Oda Alida Fønstelien Hjelljord's avatar Oda Alida Fønstelien Hjelljord
Browse files

Merge branch 'community-admin' into 'main'

Community admin

See merge request !88
parents 297c450f e43eedaa
No related branches found
No related tags found
Loading
Pipeline #180217 passed
......@@ -2,7 +2,5 @@ import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ws from "./services/ws";
createApp(App).use(router).use(store).mount("#app");
console.log("WS", ws.test);
......@@ -121,7 +121,7 @@ const routes = [
path: "/user/userItems",
name: "UserItems",
component: () => import("../views/UserProfileViews/UserItemsView.vue"),
}
},
];
const router = createRouter({
......
......@@ -46,7 +46,10 @@ class CommunityAdminService {
API_URL + "communities/" + communityID + "/kick",
null,
{
params: { userId: userID },
headers: tokenHeader(),
params: {
userId: userID,
},
}
);
}
......
// import { tokenHeader } from "@/utils/token-utils";
import { tokenHeader } from "@/utils/token-utils";
import axios from "axios";
const API_URL = process.env.VUE_APP_BASEURL;
......@@ -6,20 +7,24 @@ const API_URL = process.env.VUE_APP_BASEURL;
class UserService {
async getUserFromId(userId) {
return await axios
.get(API_URL + "/users/" + userId + "/profile")
.get(API_URL + "/users/" + userId + "/profile", {
headers: tokenHeader(),
})
.then((res) => {
return res.data;
})
.catch((err) => console.log(err));
.catch((err) => console.error(err));
}
async getUserRatingAverage(userId) {
return await axios
.get(API_URL + "rating/" + userId + "/average")
.get(API_URL + "rating/" + userId + "/average", {
headers: tokenHeader(),
})
.then((res) => {
return res.data;
})
.catch((err) => console.log(err));
.catch((err) => console.error(err));
}
//TODO
......
......@@ -17,18 +17,14 @@ const ws = (function () {
const onMessageReceived = (payload) => {
const data = JSON.parse(payload.body);
//console.log("New message!");
// Fire message event
fire("MESSAGE", JSON.parse(payload.body));
if (data.status == "NEW_MESSAGE")
fire("NEW_MESSAGE", JSON.parse(payload.body));
//console.log("Received message: " + payload);
};
const onConnected = () => {
//console.log("Websocket Connected");
stompClient.subscribe(
"/user/" + parseCurrentUser().accountId + "/queue/messages",
onMessageReceived
......@@ -57,7 +53,6 @@ const ws = (function () {
}
},
sendMessage: ({ sender, recipient /* , status */ }) => {
//if (status) console.log(status);
stompClient.send(
"/app/chat",
{},
......
......@@ -13,7 +13,7 @@ export function doLogin(loginRequest) {
return auth;
})
.catch((error) => {
console.log(error.response);
console.error(error.response);
return auth;
});
}
......@@ -30,7 +30,7 @@ export function registerUser(registerInfo) {
.then((response) => {
return response;
})
.catch((err) => console.log(err));
.catch((err) => console.error(err));
}
export async function getUser(userid) {
......@@ -97,7 +97,7 @@ export async function doNewPassword(password) {
return response;
})
.catch((error) => {
console.log(error);
console.error(error);
});
return res.data;
}
......@@ -108,11 +108,10 @@ export function postNewItem(itemInfo) {
headers: tokenHeader(),
})
.then((response) => {
//console.log("poster: " + response.data);
return response;
})
.catch((error) => {
console.log(error.response);
console.error(error.response);
return error;
});
}
......@@ -124,7 +123,7 @@ export function postNewgroup(groupInfo) {
return response;
})
.catch((error) => {
console.log(error.response);
console.error(error.response);
return error;
});
}
......@@ -134,11 +133,10 @@ export function postNewRent(rentInfo) {
headers: tokenHeader(),
})
.then((response) => {
//console.log("poster: " + response.data);
return response;
})
.catch((error) => {
console.log(error.response);
console.error(error.response);
return error;
});
}
......@@ -222,8 +220,6 @@ export async function GetListingsInCommunity(communityID) {
});
}
export async function GetMembersOfCommunity(communityID) {
return axios
.get(API_URL + "community/" + communityID + "/members", {
......@@ -252,7 +248,6 @@ export async function GetMemberRequestsOfCommunity(communityID) {
export function JoinOpenCommunity(communityId) {
if (tokenHeader().Authorization == "Bearer " + null) {
//console.log("ikke logget på!");
return "Login to join any community";
}
......@@ -264,7 +259,7 @@ export function JoinOpenCommunity(communityId) {
return response;
})
.catch((error) => {
console.log(error.response);
console.error(error.response);
return error;
});
}
......@@ -295,7 +290,7 @@ export async function LeaveCommunity(communityID) {
return response.data;
})
.catch((error) => {
console.log(error.data);
console.error(error.data);
return error;
});
}
......@@ -315,15 +310,14 @@ export async function GetUserListings() {
export function postNewRating(ratingInfo) {
return axios
.post(API_URL + "rating/save", ratingInfo, {
headers: tokenHeader(),
})
.then((response) => {
console.log("poster: " + response.data);
return response;
})
.catch((error) => {
console.log(error.response);
return error;
});
.post(API_URL + "rating/save", ratingInfo, {
headers: tokenHeader(),
})
.then((response) => {
return response;
})
.catch((error) => {
console.log(error.response);
return error;
});
}
......@@ -64,7 +64,6 @@ export default {
this.selected = this.conversations.find(
(conversation) => conversation.recipient.userId == userid
).recipient;
//console.log(this.selected);
},
},
async created() {
......
......@@ -13,8 +13,16 @@
{{ tab }}
</button>
</div>
<MemberList :requests ='false' :buttons="['chat', 'kick']" v-if="currentTab === 0" />
<MemberList :requests ='true' :buttons="['accept', 'reject']" v-if="currentTab === 1" />
<MemberList
:requests="false"
:buttons="['chat', 'kick']"
v-if="currentTab === 0"
/>
<MemberList
:requests="true"
:buttons="['accept', 'reject']"
v-if="currentTab === 1"
/>
<CommunitySettings v-if="currentTab === 2" />
</template>
......
......@@ -16,11 +16,11 @@
<!-- pagination my communities -->
<div class="flex justify-center">
<PaginationTemplate
v-bind:items="myCommunities"
v-on:page:update="updatePageMyCommunities"
v-bind:currentPage="currentPageMyCommunities"
v-bind:pageSize="pageSizeMyCommunities"
class="mt-10 mb-5"
v-bind:items="myCommunities"
v-on:page:update="updatePageMyCommunities"
v-bind:currentPage="currentPageMyCommunities"
v-bind:pageSize="pageSizeMyCommunities"
class="mt-10 mb-5"
/>
</div>
</div>
......@@ -31,25 +31,25 @@
</p>
<!-- Search field -->
<div class="relative mt-1 mx-2" id="searchComponent">
<span class="absolute inset-y-0 left-0 flex items-center pl-3">
<svg class="w-5 h-5 text-gray-400" viewBox="0 0 24 24" fill="none">
<path
d="M21 21L15 15M17 10C17 13.866 13.866 17 10 17C6.13401 17 3 13.866 3 10C3 6.13401 6.13401 3 10 3C13.866 3 17 6.13401 17 10Z"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
></path>
</svg>
</span>
<span class="absolute inset-y-0 left-0 flex items-center pl-3">
<svg class="w-5 h-5 text-gray-400" viewBox="0 0 24 24" fill="none">
<path
d="M21 21L15 15M17 10C17 13.866 13.866 17 10 17C6.13401 17 3 13.866 3 10C3 6.13401 6.13401 3 10 3C13.866 3 17 6.13401 17 10Z"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
></path>
</svg>
</span>
<input
type="text"
id="searchInput"
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"
type="text"
id="searchInput"
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>
......@@ -63,11 +63,11 @@
<!-- pagination Public communities -->
<div class="flex justify-center">
<PaginationTemplate
v-bind:items="publicCommunities"
v-on:page:update="updatePagePublicCommunities"
v-bind:currentPage="currentPagePublicCommunities"
v-bind:pageSize="pageSizePublicCommunities"
class="mt-10 mb-5"
v-bind:items="publicCommunities"
v-on:page:update="updatePagePublicCommunities"
v-bind:currentPage="currentPagePublicCommunities"
v-bind:pageSize="pageSizePublicCommunities"
class="mt-10 mb-5"
/>
</div>
</template>
......@@ -85,7 +85,7 @@ export default {
loggedIn: false,
myCommunities: [],
publicCommunities: [],
search: '',
search: "",
showSearched: false,
showPaginated: true,
......@@ -108,15 +108,15 @@ export default {
let filteredItems = [];
filteredItems = this.publicCommunities.filter(
(p) =>
p.name.toLowerCase().includes(this.search.toLowerCase()) ||
p.location.toLowerCase().includes(this.search.toLowerCase())
(p) =>
p.name.toLowerCase().includes(this.search.toLowerCase()) ||
p.location.toLowerCase().includes(this.search.toLowerCase())
);
return filteredItems;
},
},
methods:{
methods: {
//Pagination
updatePagePublicCommunities(pageNumber) {
this.currentPagePublicCommunities = pageNumber;
......@@ -127,25 +127,38 @@ export default {
this.updateVisibleCommunities();
},
updateVisibleCommunities() {
this.visiblePublicCommunities = this.publicCommunities.slice(this.currentPagePublicCommunities * this.pageSizePublicCommunities, (this.currentPagePublicCommunities * this.pageSizePublicCommunities) + this.pageSizePublicCommunities);
this.visibleMyCommunities = this.myCommunities.slice(this.currentPageMyCommunities * this.pageSizeMyCommunities, (this.currentPageMyCommunities * this.pageSizeMyCommunities) + this.pageSizeMyCommunities);
this.visiblePublicCommunities = this.publicCommunities.slice(
this.currentPagePublicCommunities * this.pageSizePublicCommunities,
this.currentPagePublicCommunities * this.pageSizePublicCommunities +
this.pageSizePublicCommunities
);
this.visibleMyCommunities = this.myCommunities.slice(
this.currentPageMyCommunities * this.pageSizeMyCommunities,
this.currentPageMyCommunities * this.pageSizeMyCommunities +
this.pageSizeMyCommunities
);
// if we have 0 visible communities, go back a page
if (this.visiblePublicCommunities.length === 0 && this.currentPagePublicCommunities > 0) {
this.updatePagePublicCommunities(this.currentPagePublicCommunities -1);
if (
this.visiblePublicCommunities.length === 0 &&
this.currentPagePublicCommunities > 0
) {
this.updatePagePublicCommunities(this.currentPagePublicCommunities - 1);
}
if (this.visibleMyCommunities.length === 0 && this.currentPageMyCommunities > 0) {
this.updatePageMyCommunities(this.currentPageMyCommunities -1);
if (
this.visibleMyCommunities.length === 0 &&
this.currentPageMyCommunities > 0
) {
this.updatePageMyCommunities(this.currentPageMyCommunities - 1);
}
},
//Triggers when search field input 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.showPaginated = false;
this.showSearched = true;
}
else{
} else {
this.showPaginated = true;
this.showSearched = false;
}
......@@ -155,15 +168,15 @@ export default {
this.publicCommunities = await getVisibleGroups();
this.loggedIn = this.$store.state.user.token !== null;
if (!this.loggedIn) return;
this.myCommunities = await getMyGroups();
// Double loop is bad; find a better way to do this
// Loops through both arrays and removes myCommunities from public
for (var i = 0; i < this.publicCommunities.length; i++) {
for (var j = 0; j < this.myCommunities.length; j++) {
if (
this.publicCommunities[i].communityId ===
this.myCommunities[j].communityId
this.publicCommunities[i].communityId ===
this.myCommunities[j].communityId
) {
this.publicCommunities.splice(i, 1);
}
......@@ -171,6 +184,6 @@ export default {
}
this.updateVisibleCommunities();
}
},
};
</script>
<template>
<div >
</div>
<div></div>
</template>
<script>
......@@ -11,8 +9,7 @@ export default {
show: false,
};
},
components: {
},
components: {},
methods: {
toggleModal() {
this.show = !this.show;
......
......@@ -3,16 +3,13 @@
</template>
<script>
import UserItems from "@/components/UserProfileComponents/UserItems.vue"
import UserItems from "@/components/UserProfileComponents/UserItems.vue";
export default {
name: "UserItemsView",
components:{
UserItems
}
}
name: "UserItemsView",
components: {
UserItems,
},
};
</script>
<style>
</style>
<style></style>
import {mount} from "@vue/test-utils";
import { mount } from "@vue/test-utils";
import Pagination from "@/components/BaseComponents/PaginationTemplate.vue";
describe("PaginationTemplate", () => {
let wrapper;
let wrapper;
beforeEach(() => {
wrapper = mount(Pagination, {
//passing prop to component
props: {
items: [],
currentPage: 0,
pageSize: 4,
},
});
beforeEach(() => {
wrapper = mount(Pagination, {
//passing prop to component
props: {
items: [],
currentPage: 0,
pageSize: 4,
},
});
});
it("is instantiated", () => {
expect(wrapper.exists()).toBeTruthy();
});
it("is instantiated", () => {
expect(wrapper.exists()).toBeTruthy();
});
});
import { shallowMount } from "@vue/test-utils";
import CommunityHamburger from "@/components/CommunityComponents/CommunityHamburger.vue";
import { route, router, $route, $router } from "../../mock-router";
import { store, $store } from "../../mock-store";
describe("CommunityHamburger elements rendering", () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(CommunityHamburger, {
//passing prop to component
props: {
adminStatus: true,
community: {
communityId: 1,
name: "String",
description: "String",
visibility: 0,
location: "String",
picture: "String",
},
},
global: {
mocks: {
store,
$store,
route,
router,
$route,
......@@ -33,7 +24,7 @@ describe("CommunityHamburger elements rendering", () => {
it("renders all li fields", () => {
expect(wrapper.find("#newItem").text()).toMatch("Opprett Utleie");
expect(wrapper.find("#getMembers").text()).toMatch("Se Medlemmer");
expect(wrapper.find("#adminGroup").text()).toMatch("Administrer Gruppe");
//expect(wrapper.find("#adminGroup").text()).toMatch("Administrer Gruppe");
expect(wrapper.find("#leaveGroup").text()).toMatch("Forlat Gruppe");
});
});
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