summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/commit/pipelines/pipelines_service.js.es6
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-01-28 18:39:01 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-02-03 09:43:54 +0000
commit7ad626e348faaea6f186759dada36079d531f6fd (patch)
treedf00ab0450ca635b260c33025dd9867760267ca3 /app/assets/javascripts/commit/pipelines/pipelines_service.js.es6
parent9972f59f94ab017d27d9278dd1c9dd89da489e64 (diff)
downloadgitlab-ce-7ad626e348faaea6f186759dada36079d531f6fd.tar.gz
Use same folder structure in spec for vue shared resources
Diffstat (limited to 'app/assets/javascripts/commit/pipelines/pipelines_service.js.es6')
-rw-r--r--app/assets/javascripts/commit/pipelines/pipelines_service.js.es677
1 files changed, 77 insertions, 0 deletions
diff --git a/app/assets/javascripts/commit/pipelines/pipelines_service.js.es6 b/app/assets/javascripts/commit/pipelines/pipelines_service.js.es6
new file mode 100644
index 00000000000..7d773e0d361
--- /dev/null
+++ b/app/assets/javascripts/commit/pipelines/pipelines_service.js.es6
@@ -0,0 +1,77 @@
+/* globals Vue */
+/* eslint-disable no-unused-vars, no-param-reassign */
+
+/**
+ * Pipelines service.
+ *
+ * Used to fetch the data used to render the pipelines table.
+ * Used Vue.Resource
+ */
+
+window.gl = window.gl || {};
+gl.pipelines = gl.pipelines || {};
+
+class PipelinesService {
+ constructor(root) {
+ Vue.http.options.root = root;
+
+ this.pipelines = Vue.resource(root);
+
+ Vue.http.interceptors.push((request, next) => {
+ // needed in order to not break the tests.
+ if ($.rails) {
+ request.headers['X-CSRF-Token'] = $.rails.csrfToken();
+ }
+ next();
+ });
+ }
+
+ /**
+ * Given the root param provided when the class is initialized, will
+ * make a GET request.
+ *
+ * @return {Promise}
+ */
+ all() {
+ return this.pipelines.get();
+ }
+}
+
+gl.pipelines.PipelinesService = PipelinesService;
+
+// const pageValues = (headers) => {
+// const normalized = gl.utils.normalizeHeaders(headers);
+//
+// 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;
+// };
+
+// gl.PipelineStore = class {
+// fetchDataLoop(Vue, pageNum, url, apiScope) {
+// const goFetch = () =>
+// this.$http.get(`${url}?scope=${apiScope}&page=${pageNum}`)
+// .then((response) => {
+// const pageInfo = pageValues(response.headers);
+// this.pageInfo = Object.assign({}, this.pageInfo, pageInfo);
+//
+// const res = JSON.parse(response.body);
+// this.count = Object.assign({}, this.count, res.count);
+// this.pipelines = Object.assign([], this.pipelines, res);
+//
+// this.pageRequest = false;
+// }, () => {
+// this.pageRequest = false;
+// return new Flash('Something went wrong on our end.');
+// });
+//
+// goFetch();
+// }
+// };