Skip to content
Snippets Groups Projects
Commit af35db24 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

FE: Added Paginator Vue component

parent f8443b4c
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
</div> </div>
<div id="loading" v-if="loading"> <div id="loading" v-if="loading">
<div id="spinner-wrapper"> <div id="spinner-wrapper">
<font-awesome-icon icon="spinner" spin /> <b-spinner variant="primary" style="width: 3rem; height: 3rem;" label="Loading"></b-spinner>
</div> </div>
</div> </div>
</div> </div>
...@@ -61,7 +61,6 @@ export default { ...@@ -61,7 +61,6 @@ export default {
} }
#loading { #loading {
font-size: 40px;
position: absolute; position: absolute;
top: 0; top: 0;
bottom: 0; bottom: 0;
......
...@@ -55,10 +55,39 @@ export default { ...@@ -55,10 +55,39 @@ export default {
} }
}); });
}, },
fetchPanel (input) { fetchGroupsTab (input) {
let url = BASE_API_URL let url = BASE_API_URL
+ input.selectedTab + 'groups?groupId=' + input.selectedGroupId
+ '?groupId=' + input.selectedGroupId + '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
fetchMembersPanel (input) {
let url = BASE_API_URL
+ 'members?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
fetchPermissionsPanel (input) {
let url = BASE_API_URL
+ 'permissions?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize + '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage; + '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, { return apiRequest(url, {
......
...@@ -41,9 +41,9 @@ export default { ...@@ -41,9 +41,9 @@ export default {
changeBreadcrumb: function(groupId) { changeBreadcrumb: function(groupId) {
this.input.selectedGroupId = groupId; this.input.selectedGroupId = groupId;
if(this.input.selectedTab === 'groups') { if(this.input.selectedTab === 'groups') {
client.fetchPanel(this.input) client.fetchGroupsTab(this.input)
.then(model => { .then(model => {
this.$store.commit('updateGroupsPanel', model); this.$store.commit('updateGroups', model);
}); });
} else { } else {
this.$store.commit('setTabIndex', 0); this.$store.commit('setTabIndex', 0);
......
...@@ -20,33 +20,9 @@ ...@@ -20,33 +20,9 @@
</span> </span>
</b-list-group-item> </b-list-group-item>
</b-list-group> </b-list-group>
<p v-if="model.groupsPanel.items.length === 0">No groups</p>
</div> </div>
<div class="row" v-if="model.groupsPanel !== null"> <Paginator :paginatedPanel="model.groupsPanel" :onUpdate="updatePagination" />
<div class="col-md-9">
<b-pagination
v-model="model.groupsPanel.currentPage"
:total-rows="model.groupsPanel.totalItems"
:per-page="model.groupsPanel.pageSize"
aria-controls="groups-list"
align="center"
v-on:change="setPage"
></b-pagination>
</div>
<div class="col-md-3">
<b-container fluid>
<b-row>
<b-col sm="5">
<label for="page-size">Page size:</label>
</b-col>
<b-col sm="6">
<b-form-select id="page-size" v-model="input.paginatorPageSize" :options="pageSizeOptions" v-on:change="changePageSize"></b-form-select>
</b-col>
</b-row>
</b-container>
</div>
</div>
<div class="text-center">
</div>
<RenameGroupModal ref="renameGroupModal" /> <RenameGroupModal ref="renameGroupModal" />
<ConfirmRemoveGroupModal ref="confirmRemoveGroupModal" /> <ConfirmRemoveGroupModal ref="confirmRemoveGroupModal" />
</b-tab> </b-tab>
...@@ -55,6 +31,7 @@ ...@@ -55,6 +31,7 @@
<script> <script>
import RenameGroupModal from './modals/RenameGroupModal.vue'; import RenameGroupModal from './modals/RenameGroupModal.vue';
import ConfirmRemoveGroupModal from './modals/ConfirmRemoveGroupModal.vue'; import ConfirmRemoveGroupModal from './modals/ConfirmRemoveGroupModal.vue';
import Paginator from './Paginator.vue';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import client from 'api-client'; import client from 'api-client';
...@@ -62,7 +39,8 @@ export default { ...@@ -62,7 +39,8 @@ export default {
name: 'GroupsPanel', name: 'GroupsPanel',
components: { components: {
RenameGroupModal, RenameGroupModal,
ConfirmRemoveGroupModal ConfirmRemoveGroupModal,
Paginator
}, },
computed: mapState({ computed: mapState({
model: state => state.model, model: state => state.model,
...@@ -70,20 +48,15 @@ export default { ...@@ -70,20 +48,15 @@ export default {
}), }),
data: function() { data: function() {
return { return {
pageSizeOptions: [
{ value: 20, text: "20" },
{ value: 50, text: "50" },
{ value: 100, text: "100" }
],
groupFilter: '' groupFilter: ''
}; };
}, },
methods: { methods: {
openGroup: function(group) { openGroup: function(group) {
this.$store.state.input.selectedGroupId = group.groupId; this.$store.state.input.selectedGroupId = group.groupId;
client.fetchPanel(this.input) client.fetchGroupsTab(this.input)
.then(model => { .then(model => {
this.$store.commit('updateGroupsPanel', model); this.$store.commit('updateGroups', model);
}); });
}, },
openRenameGroupModal: function(group) { openRenameGroupModal: function(group) {
...@@ -92,14 +65,14 @@ export default { ...@@ -92,14 +65,14 @@ export default {
openRemoveGroupModal: function(group) { openRemoveGroupModal: function(group) {
this.$refs.confirmRemoveGroupModal.openRemoveGroupModal(group); this.$refs.confirmRemoveGroupModal.openRemoveGroupModal(group);
}, },
setPage: function(page) {
console.log('setPage ', page);
},
changePageSize: function(pageSize) {
console.log('changePageSize', pageSize);
},
filterGroups: function() { filterGroups: function() {
console.log('filterGroups', this.groupFilter); console.log('filterGroups', this.groupFilter);
},
updatePagination: function() {
client.fetchGroupsTab(this.input)
.then(model => {
this.$store.commit('updateGroupsPanel', model.groupsPanel);
});
} }
} }
} }
......
...@@ -66,20 +66,26 @@ export default { ...@@ -66,20 +66,26 @@ export default {
} }
if(this.input.selectedTab !== tab) { if(this.input.selectedTab !== tab) {
this.input.selectedTab = tab; this.input.selectedTab = tab;
client.fetchPanel(this.input)
.then(model => {
switch(this.input.selectedTab) { switch(this.input.selectedTab) {
case 'groups': case 'groups':
this.$store.commit('updateGroupsPanel', model); client.fetchGroupsTab(this.input)
.then(model => {
this.$store.commit('updateGroups', model);
});
break; break;
case 'members': case 'members':
this.$store.commit('updateMembersPanel', model); client.fetchMembersPanel(this.input)
.then(panel => {
this.$store.commit('updateMembersPanel', panel);
});
break; break;
case 'permissions': case 'permissions':
this.$store.commit('updatePermissionsPanel', model); client.fetchPermissionsPanel(this.input)
.then(panel => {
this.$store.commit('updatePermissionsPanel', panel);
});
break; break;
} }
});
} }
}, },
openAddGroupModal: function() { openAddGroupModal: function() {
......
<template> <template>
<b-tab title="Members"> <b-tab title="Members" v-if="model.permission === 'ADMIN' || model.permission === 'MANAGE_MEMBERS' || model.permission === 'VIEW_MEMBERS'">
<div v-if="model.membersPanel !== null"> <div v-if="model.membersPanel !== null">
<b-list-group v-for="member in model.membersPanel.items" id="members-list"> <b-list-group v-for="member in model.membersPanel.items" id="members-list">
<b-list-group-item href="#"> <b-list-group-item href="#">
...@@ -13,17 +13,9 @@ ...@@ -13,17 +13,9 @@
</span> </span>
</b-list-group-item> </b-list-group-item>
</b-list-group> </b-list-group>
<p v-if="model.membersPanel.items.length === 0">No direct members</p>
</div> </div>
<div class="text-center" v-if="model.membersPanel !== null"> <Paginator :paginatedPanel="model.membersPanel" :onUpdate="updatePagination" />
<b-pagination
v-model="model.membersPanel.page"
:total-rows="model.membersPanel.totalItems"
:per-page="model.membersPanel.pageSize"
aria-controls="members-list"
align="center"
v-on:change="setPage"
></b-pagination>
</div>
<ConfirmRemoveMemberModal ref="confirmRemoveMemberModal" /> <ConfirmRemoveMemberModal ref="confirmRemoveMemberModal" />
</b-tab> </b-tab>
</template> </template>
...@@ -31,17 +23,20 @@ ...@@ -31,17 +23,20 @@
<script> <script>
import client from 'api-client'; import client from 'api-client';
import User from './User.vue'; import User from './User.vue';
import ConfirmRemoveMemberModal from './modals/ConfirmRemoveMemberModal.vue' import Paginator from './Paginator.vue';
import ConfirmRemoveMemberModal from './modals/ConfirmRemoveMemberModal.vue';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
export default { export default {
name: 'MembersPanel', name: 'MembersPanel',
components: { components: {
User, User,
ConfirmRemoveMemberModal ConfirmRemoveMemberModal,
Paginator
}, },
computed: mapState({ computed: mapState({
model: state => state.model model: state => state.model,
input: state => state.input
}), }),
methods: { methods: {
openRemoveMemberModal: function(member) { openRemoveMemberModal: function(member) {
...@@ -50,8 +45,11 @@ export default { ...@@ -50,8 +45,11 @@ export default {
this.$refs.confirmRemoveMemberModal.openRemoveMemberModal(member, memberPermission); this.$refs.confirmRemoveMemberModal.openRemoveMemberModal(member, memberPermission);
}); });
}, },
setPage: function(page) { updatePagination: function() {
console.log('setPage ', page); client.fetchMembersPanel(this.input)
.then(panel => {
this.$store.commit('updateMembersPanel', panel);
});
} }
} }
} }
......
<template>
<div class="row mt-4" v-if="paginatedPanel !== null && paginatedPanel.totalItems > 0">
<div class="col-md-8">
<b-pagination
v-model="paginatedPanel.currentPage"
:total-rows="paginatedPanel.totalItems"
:per-page="paginatedPanel.pageSize"
aria-controls="groups-list"
align="center"
v-on:change="setPage"
></b-pagination>
<p>Total items: {{paginatedPanel.totalItems}}</p>
</div>
<div class="col-md-4">
<b-row>
<b-col sm="5">
<label for="page-size">Page size:</label>
</b-col>
<b-col sm="6">
<b-form-select id="page-size" v-model="input.paginatorPageSize" :options="pageSizeOptions" v-on:change="changePageSize"></b-form-select>
</b-col>
</b-row>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: 'Paginator',
props: {
paginatedPanel: Object,
onUpdate: Function
},
computed: mapState({
input: state => state.input
}),
data: function() {
return {
pageSizeOptions: [
{ value: 5, text: "5" },
{ value: 20, text: "20" },
{ value: 50, text: "50" },
{ value: 100, text: "100" }
]
};
},
methods: {
setPage: function(page) {
this.input.paginatorPage = page;
this.onUpdate();
},
changePageSize: function(pageSize) {
this.input.paginatorPageSize = pageSize;
this.onUpdate();
}
}
}
</script>
<template> <template>
<b-tab title="Permissions"> <b-tab title="Permissions" v-if="model.permission === 'ADMIN'">
<div v-if="model.permissionsPanel !== null"> <div v-if="model.permissionsPanel !== null">
<table class="table b-table table-striped table-hover"> <table class="table b-table table-striped table-hover">
<thead> <thead>
...@@ -23,23 +23,17 @@ ...@@ -23,23 +23,17 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p v-if="model.permissionsPanel.items.length === 0">No direct permissions</p>
</div> </div>
<div class="text-center" v-if="model.permissionsPanel !== null"> <Paginator :paginatedPanel="model.permissionsPanel" :onUpdate="updatePagination" />
<b-pagination
v-model="model.permissionsPanel.currentPage"
:total-rows="model.permissionsPanel.totalItems"
:per-page="model.permissionsPanel.pageSize"
aria-controls="permissions-list"
align="center"
v-on:change="setPage"
></b-pagination>
</div>
<ConfirmRemovePermissionModal ref="confirmRemovePermissionModal" /> <ConfirmRemovePermissionModal ref="confirmRemovePermissionModal" />
</b-tab> </b-tab>
</template> </template>
<script> <script>
import client from 'api-client';
import User from './User.vue'; import User from './User.vue';
import Paginator from './Paginator.vue';
import ConfirmRemovePermissionModal from './modals/ConfirmRemovePermissionModal.vue' import ConfirmRemovePermissionModal from './modals/ConfirmRemovePermissionModal.vue'
import { mapState } from 'vuex'; import { mapState } from 'vuex';
...@@ -47,17 +41,22 @@ export default { ...@@ -47,17 +41,22 @@ export default {
name: 'PermissionsPanel', name: 'PermissionsPanel',
components: { components: {
User, User,
ConfirmRemovePermissionModal ConfirmRemovePermissionModal,
Paginator
}, },
computed: mapState({ computed: mapState({
model: state => state.model, model: state => state.model,
input: state => state.input
}), }),
methods: { methods: {
openRemovePermissionModal: function(user) { openRemovePermissionModal: function(user) {
this.$refs.confirmRemovePermissionModal.openRemovePermissionModal(user); this.$refs.confirmRemovePermissionModal.openRemovePermissionModal(user);
}, },
setPage: function(page) { updatePagination: function() {
console.log('setPage ', page); client.fetchPermissionsPanel(this.input)
.then(panel => {
this.$store.commit('updatePermissionsPanel', panel);
});
} }
} }
} }
......
...@@ -33,11 +33,14 @@ export default new Vuex.Store({ ...@@ -33,11 +33,14 @@ export default new Vuex.Store({
this.state.model.permission = model.permission; this.state.model.permission = model.permission;
this.state.model.user = model.user; this.state.model.user = model.user;
}, },
updateGroupsPanel(state, model) { updateGroups(state, model) {
this.state.model.breadcrumbs = model.breadcrumbs; this.state.model.breadcrumbs = model.breadcrumbs;
this.state.model.groupsPanel = model.groupsPanel; this.state.model.groupsPanel = model.groupsPanel;
this.state.model.permission = model.permission; this.state.model.permission = model.permission;
}, },
updateGroupsPanel(state, groupsPanel) {
this.state.model.groupsPanel = groupsPanel;
},
updatePermissionsPanel(state, permissionsPanel) { updatePermissionsPanel(state, permissionsPanel) {
this.state.model.permissionsPanel = permissionsPanel; this.state.model.permissionsPanel = permissionsPanel;
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment