diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/deployment.xml b/.idea/deployment.xml deleted file mode 100644 index c0f20cd..0000000 --- a/.idea/deployment.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gitlab.iml b/.idea/gitlab.iml deleted file mode 100644 index d57918d..0000000 --- a/.idea/gitlab.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index 0a82b8d..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 31184f5..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index e334ee9..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 7f39ebd..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,714 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - project - - - - - - - - - - - - - - - - - - - - - - - - 1465198523267 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/config.js b/config.js index f244f4b..77b9ed6 100644 --- a/config.js +++ b/config.js @@ -2,7 +2,7 @@ * Created by benedikt.ringlein on 06.06.2016. */ birdsEyeConfig = { - gitLabAddress: "http://127.0.0.1", - privateToken: "", + gitLabAddress: "https://git.cobraops.de", + privateToken: "j6_6bBdoQ4mT_zgMaQpz", branches: ["develop", "release", "master"] -}; \ No newline at end of file +}; diff --git a/index.html b/index.html index d817c38..a625127 100644 --- a/index.html +++ b/index.html @@ -65,12 +65,16 @@ + - + + src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.3/angular-animate.min.js"> @@ -78,4 +82,4 @@ - \ No newline at end of file + diff --git a/js/app.js b/js/app.js index 5461cc8..8dfbdc9 100644 --- a/js/app.js +++ b/js/app.js @@ -137,28 +137,30 @@ this.updateOpenMergeRequests(); }; - app.controller("birdsEyeController", function ($http, $uibModal) { + app.controller("birdsEyeController", function ($http, $q, $uibModal) { var ctrl = this; - this.gitLabApi = new GitLabApi($http, birdsEyeConfig.gitLabAddress, birdsEyeConfig.privateToken); + this.gitLabApi = new GitLabApi($http, $q, birdsEyeConfig.gitLabAddress, birdsEyeConfig.privateToken); this.finishedLoadingProjectsCount = 0; this.visibleProjects = 0; this.branchConfigError = birdsEyeConfig.branches.length != 3; this.filterMergableProjects = true; - if(!this.branchConfigError){ - this.gitLabApi.getProjects(function (response) { + if (!this.branchConfigError) { + this.gitLabApi.getProjects(function (projects) { ctrl.projects = []; - ctrl.projectsCount = response.data.length; + ctrl.projectsCount = projects.length; // create a project object for each project in the response - for (var i in response.data) { - var responseData = response.data[i]; - var p = new Project(responseData, ctrl.gitLabApi, birdsEyeConfig.branches, function (project) { - ctrl.finishedLoadingProjectsCount += 1; - if (project.differences > 0) { - ctrl.visibleProjects += 1; - } + + projects + .forEach(function (project) { + var p = new Project(project, ctrl.gitLabApi, birdsEyeConfig.branches, function (fetchedProject) { + ctrl.finishedLoadingProjectsCount += 1; + if (fetchedProject.differences > 0) { + ctrl.visibleProjects += 1; + } + }); + ctrl.projects.push(p); }); - ctrl.projects.push(p); - } + }, function (response) { if (response.status == 401) { // unauthorized, private token is missing or wrong @@ -173,9 +175,9 @@ templateUrl: 'html/help.html' }); }; - this.toggleFilterMergableProjects = function(){ + this.toggleFilterMergableProjects = function () { this.filterMergableProjects = !this.filterMergableProjects; } }); -})(); \ No newline at end of file +})(); diff --git a/js/gitLabApi.js b/js/gitLabApi.js index 40221d4..1361f03 100644 --- a/js/gitLabApi.js +++ b/js/gitLabApi.js @@ -1,8 +1,10 @@ /** * Created by benedikt.ringlein on 06.06.2016. */ -function GitLabApi($http, gitLabAddress, privateToken) { +function GitLabApi($http, $q, gitLabAddress, privateToken) { this.$http = $http; + this.queue = $q; + this.gitLabAddress = gitLabAddress; this.privateToken = privateToken; @@ -13,7 +15,7 @@ function GitLabApi($http, gitLabAddress, privateToken) { * @returns {string} A ready-to-use url for an API call */ this.getRequestUrl = function (request, parameters) { - var url = this.gitLabAddress + '/api/v3/' + request + '?private_token=' + this.privateToken + '&per_page=100'; + var url = this.gitLabAddress + '/api/v4/' + request + '?private_token=' + this.privateToken; if (parameters != null) { url += '&' + parameters; } @@ -26,10 +28,56 @@ function GitLabApi($http, gitLabAddress, privateToken) { * @param errorCallback callback for errors */ this.getProjects = function (callback, errorCallback) { - this.$http({ - method: 'GET', - url: this.getRequestUrl('projects', null) - }).then(callback, errorCallback); + // Do Preflight call (maybe keep response) + + var self = this; + + this + .$http + .get(this.getRequestUrl('projects', null)) + .then(function (gitlabApiResponse) { + + + if (!gitlabApiResponse.headers || (typeof gitlabApiResponse.headers) !== 'function') { + throw new Error('Invalid PreFlightResponse'); + } + + var headerData = gitlabApiResponse.headers(); + + if (!headerData['x-total-pages']) { + throw new Error('Missing mandatory header params (paging and limitation)'); + } + + var queueItems = []; + + for (var pageIndex = 1; pageIndex <= headerData['x-total-pages']; pageIndex += 1) { + queueItems.push(self.$http.get(self.getRequestUrl('projects', 'page=' + pageIndex))); + } + + + return self.queue.all(queueItems); + }) + .then(function (gitlabRepositoriesResponsesRaw) { + var gitlabRepositoriesResponsesDataRaw = []; + + gitlabRepositoriesResponsesRaw.forEach(function (gitlabRepositoriesResponseRaw) { + gitlabRepositoriesResponsesDataRaw.push(gitlabRepositoriesResponseRaw.data); + }); + + + var gitlabRepositoriesResponsesProcessed = [].concat.apply([], gitlabRepositoriesResponsesDataRaw); + + + callback(gitlabRepositoriesResponsesProcessed); + + }) + .catch(errorCallback) + // Calculate necessary amount of calls + // Paralyze requests and fill promises into a queue + + // Make manu smile + + }; /** @@ -68,11 +116,11 @@ function GitLabApi($http, gitLabAddress, privateToken) { * @param id The project id * @param callback A callback for a successful response */ - this.getOpenMergeRequests = function(id, callback){ + this.getOpenMergeRequests = function (id, callback) { this.$http({ method: 'GET', url: this.getRequestUrl('projects/' + id + '/merge_requests', 'state=opened') }).then(callback); }; -} \ No newline at end of file +}