forked from twitter/opensource-website
-
Notifications
You must be signed in to change notification settings - Fork 5
/
issuesLoader.js
1 lines (1 loc) · 1.23 KB
/
issuesLoader.js
1
angular.module("issuesLoader",[]).factory("issuesLoader",function($http,commentsHandler,arrayUtill){var issuesLoader=function(){function getIssuesURL(repoURL){var startOfRepoName=repoURL.lastIndexOf("/")+1,repoName=repoURL.substring(startOfRepoName,repoURL.length);if(-1===repoURL.indexOf("hasadna")){var userName=repoURL.substring(0,startOfRepoName-1);return userName=userName.substring(userName.lastIndexOf("/")+1,userName.length),"https://api.github.com/repos/"+userName+"/"+repoName+"/issues"}return"https://api.github.com/repos/hasadna/"+repoName+"/issues"}function processIssues(data,cb){var labels=new Array;commentsHandler.treatComments(data);for(var i=0;i<data.length;i++){data[i].textLimit=30;for(var j=0;j<data[i].labels.length;j++)labels.push(data[i].labels[j])}labels=arrayUtill.clusterNcount(labels,"name"),cb(data,labels)}this.load=function(reposArr,cb){function loadIssues(i){if(-1===i)return void processIssues(issues_list,cb);var comment_request=$http({method:"GET",url:getIssuesURL(reposArr[i].url)});comment_request.success(function(comment){issues_list=issues_list.concat(comment),i--,loadIssues(i)}),comment_request.error(function(){i--,loadIssues(i)})}var issues_list=new Array;loadIssues(reposArr.length-1)}};return new issuesLoader});