From 76c68d1a185009b831bab014446829158ced2f17 Mon Sep 17 00:00:00 2001 From: Regis Date: Mon, 9 Jan 2017 09:19:55 -0700 Subject: namespace getParametersByName to gl.utils instead of just gl --- app/assets/javascripts/lib/utils/param_helper.js.es6 | 7 +++++-- app/assets/javascripts/vue_pagination/index.js.es6 | 2 +- app/assets/javascripts/vue_pipelines_index/pipelines.js.es6 | 6 +++--- spec/javascripts/vue_pagination/pagination_spec.js.es6 | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/lib/utils/param_helper.js.es6 b/app/assets/javascripts/lib/utils/param_helper.js.es6 index 2b150c415c8..01b3a2ee07f 100644 --- a/app/assets/javascripts/lib/utils/param_helper.js.es6 +++ b/app/assets/javascripts/lib/utils/param_helper.js.es6 @@ -1,12 +1,15 @@ /* eslint-disable no-param-reassign */ -((w) => { +((gl) => { + gl.utils = gl.utils || (gl.utils = {}); + /** this will take in the `name` of the param you want to parse in the url if the name does not exist this function will return `null` otherwise it will return the value of the param key provided */ - w.getParameterByName = (name) => { + + gl.utils.getParameterByName = (name) => { const url = window.location.href; name = name.replace(/[[\]]/g, '\\$&'); const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`); diff --git a/app/assets/javascripts/vue_pagination/index.js.es6 b/app/assets/javascripts/vue_pagination/index.js.es6 index b69062e0849..b9678d8a97f 100644 --- a/app/assets/javascripts/vue_pagination/index.js.es6 +++ b/app/assets/javascripts/vue_pagination/index.js.es6 @@ -58,7 +58,7 @@ }, methods: { changePage(e) { - let apiScope = gl.getParameterByName('scope'); + let apiScope = gl.utils.getParameterByName('scope'); if (!apiScope) apiScope = 'all'; diff --git a/app/assets/javascripts/vue_pipelines_index/pipelines.js.es6 b/app/assets/javascripts/vue_pipelines_index/pipelines.js.es6 index d4166be4a34..eb9035146ba 100644 --- a/app/assets/javascripts/vue_pipelines_index/pipelines.js.es6 +++ b/app/assets/javascripts/vue_pipelines_index/pipelines.js.es6 @@ -28,8 +28,8 @@ }, props: ['scope', 'store', 'svgs'], created() { - const pagenum = gl.getParameterByName('p'); - const scope = gl.getParameterByName('scope'); + const pagenum = gl.utils.getParameterByName('p'); + const scope = gl.utils.getParameterByName('scope'); if (pagenum) this.pagenum = pagenum; if (scope) this.apiScope = scope; this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope, this.apiScope); @@ -42,7 +42,7 @@ this.store.fetchDataLoop.call(this, Vue, pagenum, this.scope, apiScope); }, author(pipeline) { - if (!pipeline.commit) return ({ avatar_url: '', web_url: '', username: '' }); + if (!pipeline.commit) return { avatar_url: '', web_url: '', username: '' }; if (pipeline.commit.author) return pipeline.commit.author; return { avatar_url: pipeline.commit.author_gravatar_url, diff --git a/spec/javascripts/vue_pagination/pagination_spec.js.es6 b/spec/javascripts/vue_pagination/pagination_spec.js.es6 index 3a57f69676f..c5f70ba5bfb 100644 --- a/spec/javascripts/vue_pagination/pagination_spec.js.es6 +++ b/spec/javascripts/vue_pagination/pagination_spec.js.es6 @@ -147,8 +147,8 @@ describe('paramHelper', () => { it('can parse url parameters correctly', () => { window.history.pushState({}, null, '?scope=all&p=2'); - const scope = gl.getParameterByName('scope'); - const p = gl.getParameterByName('p'); + const scope = gl.utils.getParameterByName('scope'); + const p = gl.utils.getParameterByName('p'); expect(scope).toEqual('all'); expect(p).toEqual('2'); @@ -157,8 +157,8 @@ describe('paramHelper', () => { it('returns null if param not in url', () => { window.history.pushState({}, null, '?p=2'); - const scope = gl.getParameterByName('scope'); - const p = gl.getParameterByName('p'); + const scope = gl.utils.getParameterByName('scope'); + const p = gl.utils.getParameterByName('p'); expect(scope).toEqual(null); expect(p).toEqual('2'); -- cgit v1.2.1