BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
51f03780
Commit
51f03780
authored
Feb 16, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create util to handle pagination transformation
parent
ba53ee78
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
18 deletions
+41
-18
environments_store.js.es6
...javascripts/environments/stores/environments_store.js.es6
+1
-8
common_utils.js.es6
app/assets/javascripts/lib/utils/common_utils.js.es6
+15
-0
store.js.es6
app/assets/javascripts/vue_pipelines_index/store.js.es6
+1
-10
common_utils_spec.js.es6
spec/javascripts/lib/utils/common_utils_spec.js.es6
+24
-0
No files found.
app/assets/javascripts/environments/stores/environments_store.js.es6
View file @
51f03780
...
@@ -58,14 +58,7 @@ class EnvironmentsStore {
...
@@ -58,14 +58,7 @@ class EnvironmentsStore {
setPagination(pagination = {}) {
setPagination(pagination = {}) {
const normalizedHeaders = gl.utils.normalizeHeaders(pagination);
const normalizedHeaders = gl.utils.normalizeHeaders(pagination);
const paginationInformation = {
const paginationInformation = gl.utils.parseIntPagination(normalizedHeaders);
perPage: parseInt(normalizedHeaders['X-PER-PAGE'], 10),
page: parseInt(normalizedHeaders['X-PAGE'], 10),
total: parseInt(normalizedHeaders['X-TOTAL'], 10),
totalPages: parseInt(normalizedHeaders['X-TOTAL-PAGES'], 10),
nextPage: parseInt(normalizedHeaders['X-NEXT-PAGE'], 10),
previousPage: parseInt(normalizedHeaders['X-PREV-PAGE'], 10),
};
this.state.paginationInformation = paginationInformation;
this.state.paginationInformation = paginationInformation;
return paginationInformation;
return paginationInformation;
...
...
app/assets/javascripts/lib/utils/common_utils.js.es6
View file @
51f03780
...
@@ -232,6 +232,21 @@
...
@@ -232,6 +232,21 @@
};
};
/**
/**
* Parses pagination object string values into numbers.
*
* @param {Object} paginationInformation
* @returns {Object}
*/
w.gl.utils.parseIntPagination = paginationInformation => ({
perPage: parseInt(paginationInformation['X-PER-PAGE'], 10),
page: parseInt(paginationInformation['X-PAGE'], 10),
total: parseInt(paginationInformation['X-TOTAL'], 10),
totalPages: parseInt(paginationInformation['X-TOTAL-PAGES'], 10),
nextPage: parseInt(paginationInformation['X-NEXT-PAGE'], 10),
previousPage: parseInt(paginationInformation['X-PREV-PAGE'], 10),
});
/**
* Transforms a DOMStringMap into a plain object.
* Transforms a DOMStringMap into a plain object.
*
*
* @param {DOMStringMap} DOMStringMapObject
* @param {DOMStringMap} DOMStringMapObject
...
...
app/assets/javascripts/vue_pipelines_index/store.js.es6
View file @
51f03780
...
@@ -5,16 +5,7 @@ require('../vue_realtime_listener');
...
@@ -5,16 +5,7 @@ require('../vue_realtime_listener');
((gl) => {
((gl) => {
const pageValues = (headers) => {
const pageValues = (headers) => {
const normalized = gl.utils.normalizeHeaders(headers);
const normalized = gl.utils.normalizeHeaders(headers);
const paginationInfo = gl.utils.normalizeHeaders(normalized);
const paginationInfo = {
perPage: +normalized['X-PER-PAGE'],
page: +normalized['X-PAGE'],
total: +normalized['X-TOTAL'],
totalPages: +normalized['X-TOTAL-PAGES'],
nextPage: +normalized['X-NEXT-PAGE'],
previousPage: +normalized['X-PREV-PAGE'],
};
return paginationInfo;
return paginationInfo;
};
};
...
...
spec/javascripts/lib/utils/common_utils_spec.js.es6
View file @
51f03780
...
@@ -108,6 +108,30 @@ require('~/lib/utils/common_utils');
...
@@ -108,6 +108,30 @@ require('~/lib/utils/common_utils');
});
});
});
});
describe('gl.utils.parseIntPagination', () => {
it('should parse to integers all string values and return pagination object', () => {
const pagination = {
'X-PER-PAGE': 10,
'X-PAGE': 2,
'X-TOTAL': 30,
'X-TOTAL-PAGES': 3,
'X-NEXT-PAGE': 3,
'X-PREV-PAGE': 1,
};
const expectedPagination = {
perPage: 10,
page: 2,
total: 30,
totalPages: 3,
nextPage: 3,
previousPage: 1,
};
expect(gl.utils.parseIntPagination(pagination)).toEqual(expectedPagination);
});
});
describe('gl.utils.isMetaClick', () => {
describe('gl.utils.isMetaClick', () => {
it('should identify meta click on Windows/Linux', () => {
it('should identify meta click on Windows/Linux', () => {
const e = {
const e = {
...
...
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