Commit d0a5428a authored by Regis's avatar Regis

constant variable hardcoding

parent 758cdf54
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
/* eslint-disable no-param-reassign, no-plusplus */ /* eslint-disable no-param-reassign, no-plusplus */
((gl) => { ((gl) => {
const PAGINATION_SIZE = 30;
const PAGINATION_UI_BUTTON_LIMIT = 4;
const SPREAD = '...';
const PREV = 'Prev';
const NEXT = 'Next';
const FIRST = '<< First';
const LAST = 'Last >>';
gl.VueGlPagination = Vue.extend({ gl.VueGlPagination = Vue.extend({
props: [ props: [
'changepage', 'changepage',
...@@ -10,40 +18,42 @@ ...@@ -10,40 +18,42 @@
], ],
computed: { computed: {
last() { last() {
return Math.ceil(+this.count / 30); return Math.ceil(+this.count / PAGINATION_SIZE);
}, },
getItems() { getItems() {
const total = +this.last; const total = +this.last;
const page = +this.pagenum; const page = +this.pagenum;
const items = []; const items = [];
if (page > 1) items.push({ title: '<< First', where: 1 }); if (page > 1) items.push({ title: FIRST, where: 1 });
if (page > 1) { if (page > 1) {
items.push({ title: 'Prev', where: page - 1 }); items.push({ title: PREV, where: page - 1 });
} else { } else {
items.push({ title: 'Prev', where: page - 1, disabled: true }); items.push({ title: PREV, where: page - 1, disabled: true });
} }
if (page > 6) items.push({ title: '...', separator: true }); if (page > 6) items.push({ title: SPREAD, separator: true });
const start = Math.max(page - 4, 1); const start = Math.max(page - PAGINATION_UI_BUTTON_LIMIT, 1);
const end = Math.min(page + 4, total); const end = Math.min(page + PAGINATION_UI_BUTTON_LIMIT, total);
for (let i = start; i <= end; i++) { for (let i = start; i <= end; i++) {
const isActive = i === page; const isActive = i === page;
items.push({ title: i, active: isActive, where: i }); items.push({ title: i, active: isActive, where: i });
} }
if (total - page > 4) items.push({ title: '...', separator: true }); if (total - page > PAGINATION_UI_BUTTON_LIMIT) {
items.push({ title: SPREAD, separator: true });
}
if (page === total) { if (page === total) {
items.push({ title: 'Next', where: page + 1, disabled: true }); items.push({ title: NEXT, where: page + 1, disabled: true });
} else if (total - page >= 1) { } else if (total - page >= 1) {
items.push({ title: 'Next', where: page + 1 }); items.push({ title: NEXT, where: page + 1 });
} }
if (total - page >= 1) items.push({ title: 'Last >>', where: total }); if (total - page >= 1) items.push({ title: LAST, where: total });
return items; return items;
}, },
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
store: new gl.PipelineStore(), store: new gl.PipelineStore(),
}, },
components: { components: {
'vue-pipelines': gl.VuePipeLines, 'vue-pipelines': gl.VuePipelines,
}, },
template: ` template: `
<div> <div>
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
/* eslint-disable no-param-reassign, no-bitwise*/ /* eslint-disable no-param-reassign, no-bitwise*/
((gl) => { ((gl) => {
gl.VuePipeLines = Vue.extend({ const SPREAD = '...';
const PREV = 'Prev';
const NEXT = 'Next';
const FIRST = '<< First';
const LAST = 'Last >>';
gl.VuePipelines = Vue.extend({
components: { components: {
runningPipeline: gl.VueRunningPipeline, runningPipeline: gl.VueRunningPipeline,
pipelineActions: gl.VuePipelineActions, pipelineActions: gl.VuePipelineActions,
...@@ -41,12 +47,12 @@ ...@@ -41,12 +47,12 @@
methods: { methods: {
changepage(e, last) { changepage(e, last) {
const text = e.target.innerText; const text = e.target.innerText;
if (text === '...') return; if (text === SPREAD) return;
if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text; if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text;
if (text === 'Last >>') this.pagenum = last; if (text === LAST) this.pagenum = last;
if (text === 'Next') this.pagenum = +this.pagenum + 1; if (text === NEXT) this.pagenum = +this.pagenum + 1;
if (text === 'Prev') this.pagenum = +this.pagenum - 1; if (text === PREV) this.pagenum = +this.pagenum - 1;
if (text === '<< First') this.pagenum = 1; if (text === FIRST) this.pagenum = 1;
window.history.pushState({}, null, `?p=${this.pagenum}`); window.history.pushState({}, null, `?p=${this.pagenum}`);
clearInterval(this.intervalId); clearInterval(this.intervalId);
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((gl) => { ((gl) => {
const PAGINATION_LIMIT = 31;
const SLICE_LIMIT = 29;
class PipelineUpdater { class PipelineUpdater {
constructor(pipelines) { constructor(pipelines) {
this.pipelines = pipelines; this.pipelines = pipelines;
...@@ -11,8 +14,8 @@ ...@@ -11,8 +14,8 @@
}); });
}; };
this.currentPageSlicer = (update) => { this.currentPageSlicer = (update) => {
if (update.length <= 30) return update; if (update.length < PAGINATION_LIMIT) return update;
return update.slice(0, 29); return update.slice(0, SLICE_LIMIT);
}; };
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment