Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
64b66c9a
Commit
64b66c9a
authored
Dec 07, 2016
by
Regis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use API values for pagination
parent
c9b63924
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
21 deletions
+39
-21
app/assets/javascripts/vue_pagination/index.js.es6
app/assets/javascripts/vue_pagination/index.js.es6
+16
-15
app/assets/javascripts/vue_pipelines_index/pipelines.js.es6
app/assets/javascripts/vue_pipelines_index/pipelines.js.es6
+8
-6
app/assets/javascripts/vue_pipelines_index/store.js.es6
app/assets/javascripts/vue_pipelines_index/store.js.es6
+15
-0
No files found.
app/assets/javascripts/vue_pagination/index.js.es6
View file @
64b66c9a
...
...
@@ -2,7 +2,6 @@
/* eslint-disable no-param-reassign, no-plusplus */
((gl) => {
const PAGINATION_SIZE = 30;
const PAGINATION_UI_BUTTON_LIMIT = 4;
const SPREAD = '...';
const PREV = 'Prev';
...
...
@@ -13,24 +12,26 @@
gl.VueGlPagination = Vue.extend({
props: [
'changepage',
'count',
'pagenum',
'pageInfo',
],
computed: {
last() {
return Math.ceil(+this.count / PAGINATION_SIZE);
prev() {
return this.pageInfo.previousPage;
},
next() {
return this.pageInfo.nextPage;
},
getItems() {
const total =
+this.last
;
const page =
+this.pagenum
;
const total =
this.pageInfo.totalPages
;
const page =
this.pageInfo.page
;
const items = [];
if (page > 1) items.push({ title: FIRST
, where: 1
});
if (page > 1) items.push({ title: FIRST });
if (page > 1) {
items.push({ title: PREV
, where: page - 1
});
items.push({ title: PREV });
} else {
items.push({ title: PREV,
where: page - 1,
disabled: true });
items.push({ title: PREV, disabled: true });
}
if (page > 6) items.push({ title: SPREAD, separator: true });
...
...
@@ -40,7 +41,7 @@
for (let i = start; i <= end; i++) {
const isActive = i === page;
items.push({ title: i, active: isActive
, where: i
});
items.push({ title: i, active: isActive });
}
if (total - page > PAGINATION_UI_BUTTON_LIMIT) {
...
...
@@ -48,12 +49,12 @@
}
if (page === total) {
items.push({ title: NEXT,
where: page + 1,
disabled: true });
items.push({ title: NEXT, disabled: true });
} else if (total - page >= 1) {
items.push({ title: NEXT
, where: page + 1
});
items.push({ title: NEXT });
}
if (total - page >= 1) items.push({ title: LAST
, where: total
});
if (total - page >= 1) items.push({ title: LAST });
return items;
},
...
...
@@ -69,7 +70,7 @@
}'
>
<span
@click="changepage($event
, item.where
)"
@click="changepage($event)"
>
{{item.title}}
</span>
...
...
app/assets/javascripts/vue_pipelines_index/pipelines.js.es6
View file @
64b66c9a
...
...
@@ -35,8 +35,8 @@
pipelines: [],
timeLoopInterval: '',
intervalId: '',
pagenum: 1,
apiScope: 'all',
pageInfo: {},
count: {
all: 0,
running_or_pending: 0,
...
...
@@ -64,13 +64,14 @@
);
},
methods: {
changepage(e
, last
) {
changepage(e) {
const text = e.target.innerText;
const { totalPages, nextPage, previousPage } = this.pageInfo;
if (text === SPREAD) return;
if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text;
if (text === LAST) this.pagenum =
last
;
if (text === NEXT) this.pagenum =
+this.pagenum + 1
;
if (text === PREV) this.pagenum =
+this.pagenum - 1
;
if (text === LAST) this.pagenum =
totalPages
;
if (text === NEXT) this.pagenum =
nextPage
;
if (text === PREV) this.pagenum =
previousPage
;
if (text === FIRST) this.pagenum = 1;
window.history.pushState({}, null, `?p=${this.pagenum}`);
...
...
@@ -141,10 +142,11 @@
<i class="fa fa-spinner fa-spin"></i>
</div>
<gl-pagination
v-if='
count.al
l > 30'
v-if='
pageInfo.tota
l > 30'
:pagenum='pagenum'
:changepage='changepage'
:count='count.all'
:pageInfo='pageInfo'
>
</gl-pagination>
</div>
...
...
app/assets/javascripts/vue_pipelines_index/store.js.es6
View file @
64b66c9a
...
...
@@ -2,6 +2,17 @@
/* eslint-disable no-param-reassign, no-underscore-dangle */
((gl) => {
const pageValues = (headers) => {
const values = {};
values.perPage = +headers['X-Per-Page'];
values.page = +headers['X-Page'];
values.total = +headers['X-Total'];
values.totalPages = +headers['X-Total-Pages'];
values.nextPage = +headers['X-Next-Page'];
values.previousPage = +headers['X-Prev-Page'];
return values;
};
gl.PipelineStore = class {
fetchDataLoop(Vue, pageNum, url, apiScope) {
const updatePipelineNums = (count) => {
...
...
@@ -14,9 +25,13 @@
const goFetch = () =>
this.$http.get(`${url}?scope=${apiScope}&page=${pageNum}`)
.then((response) => {
const pageInfo = pageValues(response.headers);
Vue.set(this, 'pageInfo', pageInfo);
const res = JSON.parse(response.body);
Vue.set(this, 'pipelines', res.pipelines);
Vue.set(this, 'count', res.count);
updatePipelineNums(this.count);
this.pageRequest = false;
}, () => new Flash(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment