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
bff8e5ba
Commit
bff8e5ba
authored
Dec 08, 2016
by
Regis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add change page logic to pagination component - add first test for pagination
parent
b5cd430a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
21 deletions
+74
-21
index.js.es6
app/assets/javascripts/vue_pagination/index.js.es6
+31
-1
pipelines.js.es6
app/assets/javascripts/vue_pipelines_index/pipelines.js.es6
+4
-20
pagination_spec.js.es6
spec/javascripts/vue_pagination/pagination_spec.js.es6
+39
-0
No files found.
app/assets/javascripts/vue_pagination/index.js.es6
View file @
bff8e5ba
...
@@ -9,11 +9,41 @@
...
@@ -9,11 +9,41 @@
const FIRST = '<< First';
const FIRST = '<< First';
const LAST = 'Last >>';
const LAST = 'Last >>';
const getParameterByName = (name) => {
const url = window.location.href;
name = name.replace(/[[\]]/g, '\\$&');
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
const results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
};
gl.VueGlPagination = Vue.extend({
gl.VueGlPagination = Vue.extend({
props: [
props: [
'change
page
',
'change',
'pageInfo',
'pageInfo',
],
],
methods: {
changepage(e) {
let pagenum = this.pageInfo.page;
let apiScope = getParameterByName('scope');
if (!apiScope) apiScope = 'all';
const text = e.target.innerText;
const { totalPages, nextPage, previousPage } = this.pageInfo;
if (text === SPREAD) return;
if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) pagenum = +text;
if (text === LAST) pagenum = totalPages;
if (text === NEXT) pagenum = nextPage;
if (text === PREV) pagenum = previousPage;
if (text === FIRST) pagenum = 1;
this.change(pagenum, apiScope);
},
},
computed: {
computed: {
prev() {
prev() {
return this.pageInfo.previousPage;
return this.pageInfo.previousPage;
...
...
app/assets/javascripts/vue_pipelines_index/pipelines.js.es6
View file @
bff8e5ba
...
@@ -2,12 +2,6 @@
...
@@ -2,12 +2,6 @@
/* eslint-disable no-param-reassign, no-bitwise*/
/* eslint-disable no-param-reassign, no-bitwise*/
((gl) => {
((gl) => {
const SPREAD = '...';
const PREV = 'Prev';
const NEXT = 'Next';
const FIRST = '<< First';
const LAST = 'Last >>';
const getParameterByName = (name) => {
const getParameterByName = (name) => {
const url = window.location.href;
const url = window.location.href;
name = name.replace(/[[\]]/g, '\\$&');
name = name.replace(/[[\]]/g, '\\$&');
...
@@ -51,21 +45,11 @@
...
@@ -51,21 +45,11 @@
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope, this.apiScope);
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope, this.apiScope);
},
},
methods: {
methods: {
changepage(e) {
change(pagenum, apiScope) {
const scope = getParameterByName('scope');
window.history.pushState({}, null, `?scope=${apiScope}&p=${pagenum}`);
if (scope) this.apiScope = scope;
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 = totalPages;
if (text === NEXT) this.pagenum = nextPage;
if (text === PREV) this.pagenum = previousPage;
if (text === FIRST) this.pagenum = 1;
window.history.pushState({}, null, `?scope=${this.apiScope}&p=${this.pagenum}`);
clearInterval(this.timeLoopInterval);
clearInterval(this.timeLoopInterval);
this.pageRequest = true;
this.pageRequest = true;
this.store.fetchDataLoop.call(this, Vue,
this.pagenum, this.scope, this.
apiScope);
this.store.fetchDataLoop.call(this, Vue,
pagenum, this.scope,
apiScope);
},
},
author(pipeline) {
author(pipeline) {
if (!pipeline.commit) return ({ avatar_url: '', web_url: '', username: '' });
if (!pipeline.commit) return ({ avatar_url: '', web_url: '', username: '' });
...
@@ -129,7 +113,7 @@
...
@@ -129,7 +113,7 @@
<gl-pagination
<gl-pagination
v-if='pageInfo.total > pageInfo.perPage'
v-if='pageInfo.total > pageInfo.perPage'
:pagenum='pagenum'
:pagenum='pagenum'
:change
page='changepa
ge'
:change
='chan
ge'
:count='count.all'
:count='count.all'
:pageInfo='pageInfo'
:pageInfo='pageInfo'
>
>
...
...
spec/javascripts/vue_pagination/pagination_spec.js.es6
0 → 100644
View file @
bff8e5ba
//= require vue
//= require vue_pagination/index
describe('Pagination component', () => {
let component;
const changeChanges = {
one: '',
two: '',
};
const change = (one, two) => {
changeChanges.one = one;
changeChanges.two = two;
};
it('should render', () => {
fixture.set('<div class="test-pagination-container"></div>');
component = new window.gl.VueGlPagination({
el: document.querySelector('.test-pagination-container'),
propsData: {
pageInfo: {
totalPages: 10,
nextPage: 2,
previousPage: '',
},
change,
},
});
expect(component.$el.classList).toContain('gl-pagination');
component.changepage({ target: { innerText: '1' } });
expect(changeChanges.one).toEqual(1);
expect(changeChanges.two).toEqual('all');
});
});
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