Fixes pagination implementation for bg-process. Begins moving processes page from separate page to evetns page on a new tab.

This commit is contained in:
Mateus Machado Luna 2018-07-23 16:15:07 -03:00
parent 6d4ff28f2d
commit 701a2b4b67
6 changed files with 158 additions and 30 deletions

View File

@ -85,11 +85,11 @@
:aria-label="$i18n.get('label_name') + ': ' + bgProcess.name"> :aria-label="$i18n.get('label_name') + ': ' + bgProcess.name">
<p <p
v-tooltip="{ v-tooltip="{
content: bgProcess.name, content: bgProcess.name ? bgProcess.name : $i18n.get('label_unamed_process'),
autoHide: false, autoHide: false,
placement: 'auto-start' placement: 'auto-start'
}"> }">
{{ bgProcess.name }}</p> {{ bgProcess.name ? bgProcess.name : $i18n.get('label_unamed_process') }}</p>
</td> </td>
<!-- Progress --> <!-- Progress -->
<td <td
@ -144,23 +144,23 @@
v-if="bgProcess.done <= 0" v-if="bgProcess.done <= 0"
class="icon has-text-gray action-icon" class="icon has-text-gray action-icon"
@click="pauseProcess(index)"> @click="pauseProcess(index)">
<i class="mdi mdi-24px mdi-pause-circle"/> <i class="mdi mdi-18px mdi-pause-circle"/>
</span> </span>
<span <span
v-if="bgProcess.done <= 0" v-if="bgProcess.done <= 0"
class="icon has-text-gray action-icon" class="icon has-text-gray action-icon"
@click="pauseProcess(index)"> @click="pauseProcess(index)">
<i class="mdi mdi-24px mdi-close-circle-outline"/> <i class="mdi mdi-18px mdi-close-circle-outline"/>
</span> </span>
<span <span
v-tooltip="{ v-tooltip="{
content: $i18n.get('label_process_conpleted'), content: $i18n.get('label_process_completed'),
autoHide: false, autoHide: false,
placement: 'auto-start' placement: 'auto-start'
}" }"
v-if="bgProcess.done > 0" v-if="bgProcess.done > 0"
class="icon has-text-success"> class="icon has-text-success">
<i class="mdi mdi-24px mdi-checkbox-marked-circle"/> <i class="mdi mdi-18px mdi-checkbox-marked-circle"/>
</span> </span>
</div> </div>
</td> </td>

View File

@ -43,7 +43,7 @@
class="mdi mdi-18px" class="mdi mdi-18px"
:class="{ 'mdi-menu-down': processesColapses[index], 'mdi-menu-right': !processesColapses[index] }" /> :class="{ 'mdi-menu-down': processesColapses[index], 'mdi-menu-right': !processesColapses[index] }" />
</span> </span>
<p>Name of Process</p> <p>{{ bgProcess.name ? bgProcess.name : $i18n.get('label_unamed_process') }}</p>
</div> </div>
<span <span
v-if="bgProcess.done <= 0" v-if="bgProcess.done <= 0"
@ -139,7 +139,7 @@ export default {
getUnfinishedProcesses() { getUnfinishedProcesses() {
let nUnfinishedProcesses = 0 let nUnfinishedProcesses = 0
for(let i = 0; i < this.bgProcesses.length; i++) { for(let i = 0; i < this.bgProcesses.length; i++) {
if (this.bgProcesses[i].done > 0) if (this.bgProcesses[i].done <= 0)
nUnfinishedProcesses++; nUnfinishedProcesses++;
} }
return nUnfinishedProcesses; return nUnfinishedProcesses;
@ -156,7 +156,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.fetchProcesses(); this.fetchProcesses({ page: 1, processesPerPage: 12 });
this.showProcessesList = false; this.showProcessesList = false;
} }
} }

View File

@ -8,23 +8,59 @@
<tainacan-title /> <tainacan-title />
<div :class="{ 'above-subheader': isRepositoryLevel }"> <div :class="{ 'above-subheader': isRepositoryLevel }">
<div
v-if="isRepositoryLevel"
class="tabs">
<ul>
<li
@click="onChangeTab('')"
:class="{ 'is-active': tab == undefined || tab == ''}"><a>{{ $i18n.get('events') }}</a></li>
<li
@click="onChangeTab('processes')"
:class="{ 'is-active': tab == 'processes'}"><a>{{ $i18n.get('processes') }}</a></li>
</ul>
</div>
<b-loading <b-loading
:active.sync="isLoading" :active.sync="isLoading"
:can-cancel="false"/> :can-cancel="false"/>
<events-list <events-list
v-if="tab != 'processes'"
:is-loading="isLoading" :is-loading="isLoading"
:total-events="totalEvents" :total-events="totalEvents"
:page="page" :page="eventsPage"
:events-per-page="eventsPerPage" :events-per-page="eventsPerPage"
:events="events"/> :events="events"/>
<processes-list
v-if="tab == 'processes'"
:is-loading="isLoading"
:total="total"
:page="processesPage"
:processes-per-page="processesPerPage"
:processes="processes"/>
<!-- Empty state processes image -->
<div v-if="tab == 'processes' && processes.length <= 0 && !isLoading">
<section class="section">
<div class="content has-text-grey has-text-centered">
<p>
<b-icon
icon="inbox"
size="is-large"/>
</p>
<p v-if="status == undefined || status == ''">{{ $i18n.get('info_no_process') }}</p>
</div>
</section>
</div>
<!-- Footer --> <!-- Footer -->
<div <div
class="pagination-area" class="pagination-area"
v-if="totalEvents > 0"> v-if="tab != 'processes' && totalEvents > 0">
<div class="shown-items"> <div class="shown-items">
{{ {{
$i18n.get('info_showing_events') + $i18n.get('info_showing_events') +
(eventsPerPage * (page - 1) + 1) + (eventsPerPage * (eventsPage - 1) + 1) +
$i18n.get('info_to') + $i18n.get('info_to') +
getLastEventNumber() + getLastEventNumber() +
$i18n.get('info_of') + totalEvents + '.' $i18n.get('info_of') + totalEvents + '.'
@ -49,12 +85,49 @@
<b-pagination <b-pagination
@change="onPageChange" @change="onPageChange"
:total="totalEvents" :total="totalEvents"
:current.sync="page" :current.sync="eventsPage"
order="is-centered" order="is-centered"
size="is-small" size="is-small"
:per-page="eventsPerPage"/> :per-page="eventsPerPage"/>
</div> </div>
</div> </div>
<div
class="pagination-area"
v-if="tab == 'processes' && processes.length > 0">
<div class="shown-items">
{{
$i18n.get('info_showing_processes') +
(processesPerPage * (processesPage - 1) + 1) +
$i18n.get('info_to') +
getLastProcessesNumber() +
$i18n.get('info_of') + total + '.'
}}
</div>
<div class="items-per-page">
<b-field
horizontal
:label="$i18n.get('label_processes_per_page')">
<b-select
:value="processesPerPage"
@input="onChangeProcessesPerPage"
:disabled="processes.length <= 0">
<option value="12">12</option>
<option value="24">24</option>
<option value="48">48</option>
<option value="96">96</option>
</b-select>
</b-field>
</div>
<div class="pagination">
<b-pagination
@change="onPageChange"
:total="total"
:current.sync="processesPage"
order="is-centered"
size="is-small"
:per-page="processesPerPage"/>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -62,6 +135,7 @@
<script> <script>
import EventsList from "../../components/lists/events-list.vue"; import EventsList from "../../components/lists/events-list.vue";
import ProcessesList from "../../components/lists/processes-list.vue";
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import moment from 'moment' import moment from 'moment'
@ -71,13 +145,17 @@
return { return {
isLoading: false, isLoading: false,
totalEvents: 0, totalEvents: 0,
page: 1, eventsPage: 1,
processesPage: 1,
eventsPerPage: 12, eventsPerPage: 12,
isRepositoryLevel: false processesPerPage: 12,
isRepositoryLevel: false,
tab: ''
} }
}, },
components: { components: {
EventsList EventsList,
ProcessesList
}, },
methods: { methods: {
...mapActions('event', [ ...mapActions('event', [
@ -87,6 +165,19 @@
...mapGetters('event', [ ...mapGetters('event', [
'getEvents' 'getEvents'
]), ]),
...mapActions('bgprocess', [
'fetchProcesses',
]),
...mapGetters('bgprocess', [
'getProcesses'
]),
onChangeTab(tab) {
this.tab = tab;
if (this.tab == 'processes')
this.loadProcesses();
else
this.loadEvents();
},
onChangeEventsPerPage(value) { onChangeEventsPerPage(value) {
this.eventsPerPage = value; this.eventsPerPage = value;
this.$userPrefs.set('events_per_page', value) this.$userPrefs.set('events_per_page', value)
@ -98,15 +189,32 @@
}); });
this.loadEvents(); this.loadEvents();
}, },
onChangeProcessesPerPage(value) {
this.processesPerPage = value;
this.$userPrefs.set('processes_per_page', value)
.then((newValue) => {
this.processesPerPage = newValue;
})
.catch(() => {
this.$console.log("Error settings user prefs for processes per page")
});
this.load();
},
onPageChange(page) { onPageChange(page) {
this.page = page;
this.loadEvents(); if (this.tab == 'processes') {
this.processesPage = page;
this.loadProcesses();
} else {
this.eventsPage = page;
this.loadEvents();
}
}, },
loadEvents() { loadEvents() {
this.isLoading = true; this.isLoading = true;
if(this.isRepositoryLevel) { if(this.isRepositoryLevel) {
this.fetchEvents({'page': this.page, 'eventsPerPage': this.eventsPerPage}) this.fetchEvents({'page': this.eventsPage, 'eventsPerPage': this.eventsPerPage})
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
this.totalEvents = res.total; this.totalEvents = res.total;
@ -115,7 +223,7 @@
this.isLoading = false; this.isLoading = false;
}); });
} else { } else {
this.fetchCollectionEvents({'page': this.page, 'eventsPerPage': this.eventsPerPage, 'collectionId': this.$route.params.collectionId}) this.fetchCollectionEvents({'page': this.eventsPage, 'eventsPerPage': this.eventsPerPage, 'collectionId': this.$route.params.collectionId})
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
this.totalEvents = res.total; this.totalEvents = res.total;
@ -125,9 +233,25 @@
}); });
} }
}, },
loadProcesses() {
this.isLoading = true;
this.fetchProcesses({ 'page': this.processesPage, 'processesPerPage': this.processesPerPage })
.then((res) => {
this.isLoading = false;
this.total = res.total;
})
.catch(() => {
this.isLoading = false;
});
},
getLastEventNumber() { getLastEventNumber() {
let last = (Number(this.eventsPerPage * (this.page - 1)) + Number(this.eventsPerPage)); let last = (Number(this.eventsPerPage * (this.eventPage - 1)) + Number(this.eventsPerPage));
return last > this.totalEvents ? this.totalEvents : last; return last > this.totalEvents ? this.totalEvents : last;
},
getLastProcessesNumber() {
let last = (Number(this.processesPerPage * (this.processesPage - 1)) + Number(this.processesPerPage));
return last > this.total ? this.total : last;
} }
}, },
computed: { computed: {
@ -140,6 +264,9 @@
moment(event['log_date'], 'YYYY-MM-DD h:mm:ss').format('DD/MM/YYYY, hh:mm:ss'); moment(event['log_date'], 'YYYY-MM-DD h:mm:ss').format('DD/MM/YYYY, hh:mm:ss');
return eventsList; return eventsList;
},
processes(){
return this.getProcesses();
} }
}, },
created() { created() {

View File

@ -265,7 +265,8 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_queued_on' => __( 'Queued on:', 'tainacan' ), 'label_queued_on' => __( 'Queued on:', 'tainacan' ),
'label_last_processed_on' => __( 'Last processed on:', 'tainacan' ), 'label_last_processed_on' => __( 'Last processed on:', 'tainacan' ),
'label_progress' => __( 'Progress', 'tainacan' ), 'label_progress' => __( 'Progress', 'tainacan' ),
'label_process_conpleted' => __( 'Process completed', 'tainacan' ), 'label_process_completed' => __( 'Process completed', 'tainacan' ),
'label_unamed_process' => __( 'Unamed process', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders // Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),

View File

@ -114,13 +114,13 @@ class REST_Background_Processes_Controller extends REST_Controller {
public function get_items( $request ) { public function get_items( $request ) {
global $wpdb; global $wpdb;
$body = json_decode($request->get_body(), true); //$body = json_decode($request->get_body(), true);
$perpage = isset($body['perpage']) && is_numeric($body['perpage']) ? $body['perpage'] : 10; $perpage = isset($request['perpage']) && is_numeric($request['perpage']) ? $request['perpage'] : 10;
if ($perpage < 1) { if ($perpage < 1) {
$perpage = 1; $perpage = 1;
} }
$paged = isset($body['paged']) && is_numeric($body['paged']) ? $body['paged'] : 1; $paged = isset($request['paged']) && is_numeric($request['paged']) ? $request['paged'] : 1;
if ($paged < 1) { if ($paged < 1) {
$paged = 1; $paged = 1;
} }
@ -133,8 +133,8 @@ class REST_Background_Processes_Controller extends REST_Controller {
$status_q = ""; $status_q = "";
if (current_user_can('edit_users')) { if (current_user_can('edit_users')) {
if (isset($body['user_id'])) { if (isset($request['user_id'])) {
$user_q = $wpdb->prepare("AND user_id = %d", $body['user_id']); $user_q = $wpdb->prepare("AND user_id = %d", $request['user_id']);
} }
if ( isset($user_q['all_users']) && $user_q['all_users'] ) { if ( isset($user_q['all_users']) && $user_q['all_users'] ) {

View File

@ -1,13 +1,13 @@
import axios from '../../../axios/axios'; import axios from '../../../axios/axios';
// Actions related to background processes // Actions related to background processes
export const fetchProcesses = ({ commit }) => { export const fetchProcesses = ({ commit }, {page, processesPerPage}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.get(`/bg-processes/`) axios.tainacan.get('/bg-processes?paged=' + page + '&perpage=' + processesPerPage)
.then( res => { .then( res => {
let processes = res.data; let processes = res.data;
commit('setProcesses', processes); commit('setProcesses', processes);
resolve(processes) resolve({ 'processes': processes, 'total': res.headers['x-wp-total'] });
}) })
.catch( error => { .catch( error => {
reject(error); reject(error);