diff --git a/ployst/celery.py b/ployst/celery.py index b760b90..58f9af8 100644 --- a/ployst/celery.py +++ b/ployst/celery.py @@ -7,7 +7,7 @@ # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ployst.settings.dev') -from django.conf import settings +from django.conf import settings # noqa app = Celery('ployst') diff --git a/ployst/core/accounts/serializers.py b/ployst/core/accounts/serializers.py index f32088f..b52d98a 100644 --- a/ployst/core/accounts/serializers.py +++ b/ployst/core/accounts/serializers.py @@ -27,7 +27,8 @@ class Meta: class ProjectSerializer(serializers.ModelSerializer): - users = ProjectUserSerializer(source='projectuser_set', many=True) + users = ProjectUserSerializer(source='projectuser_set', many=True, + read_only=True) am_manager = serializers.SerializerMethodField('managed_by_me') extra_data = serializers.ReadOnlyField() diff --git a/ployst/github/github_client.py b/ployst/github/github_client.py index 6b42d56..8bfaba8 100644 --- a/ployst/github/github_client.py +++ b/ployst/github/github_client.py @@ -49,6 +49,13 @@ def org_repos(self, org): """ return list(org.iter_repos()) + def repo_issues(self, org, repo): + """ + Return all repos from the given organisation. + + """ + return list(self.gh.iter_repo_issues(org, repo)) + def create_hook(self, org, repo, url): """ Create a hook for the given org and repo. diff --git a/ployst/github/static/github/github-app.js b/ployst/github/static/github/github-app.js index df73b9d..90fa58d 100644 --- a/ployst/github/static/github/github-app.js +++ b/ployst/github/static/github/github-app.js @@ -23,6 +23,17 @@ angular.module('ployst.github', [ ); } ]) + .factory('github.RepoIssues', [ + '$resource', + function($resource) { + return $resource( + '/github/repo-issues/:org/:repo', { + org: '@org', + repo: '@repo' + } + ); + } + ]) .factory('github.Token', [ '$resource', function($resource) { @@ -153,4 +164,86 @@ angular.module('ployst.github', [ } }; } + ]) + .controller('GithubIssuesController', [ + '$scope', 'github.Token', 'Repos', 'github.RepoIssues', + + function($scope, GHToken, Repos, GHRepoIssues) + { + $scope.hasToken = null; + $scope.repos = null; + $scope.allIssues = []; + $scope.issues = []; + $scope.count = 0; + $scope.groupings = {}; + $scope.groupBy = null; + + var buildGroupings = function(repoIssues) { + angular.forEach(repoIssues, function(issue) { + angular.forEach(issue['labels'], function(label) { + if(label.name.indexOf(':') !== -1) { + var keyval = label.name.split(':'), + key = keyval[0], + val = keyval[1]; + if($scope.groupings[key] === undefined) { + $scope.groupings[key] = {}; + } + if($scope.groupings[key][val] === undefined) { + $scope.groupings[key][val] = []; + } + $scope.groupings[key][val].push(issue); + } + }); + }); + }; + + var loadData = function() { + $scope.issues = []; + Repos.query({project: $scope.project.id}, function(projectRepos) { + $scope.repos = projectRepos; + angular.forEach(projectRepos, function(repo) { + GHRepoIssues.query( + {org: repo.owner, repo: repo.name}, + function(repoIssues) { + $scope.issues = $scope.issues.concat(repoIssues); + buildGroupings(repoIssues); + $scope.allIssues = $scope.issues; + } + ); + }); + }); + }; + + $scope.setGroupBy = function(key) { + $scope.groupBy = key; + if(key === null) { + $scope.issues = $scope.allIssues; + } else { + $scope.issues = $scope.groupings[key]; + } + }; + + GHToken.query(function(token) { + if (token.length > 0) { + loadData(); + $scope.hasToken = true; + } else { + $scope.hasToken = false; + } + }); + } + ]) + .directive('githubIssues', [ + 'Django', + + function(Django) { + return { + controller: 'GithubIssuesController', + restrict: 'E', + templateUrl: Django.URL.STATIC + 'github/github-issues.html', + scope: { + project: '=' + } + }; + } ]); diff --git a/ployst/github/static/github/github-issues.html b/ployst/github/static/github/github-issues.html new file mode 100644 index 0000000..643d307 --- /dev/null +++ b/ployst/github/static/github/github-issues.html @@ -0,0 +1,65 @@ +
+ Loading... +
+ +You still haven't authorised ployst to access your Github account.
+ Assimilate Github account +Filter: + +
+Group by: + + + {{ key }} + + + + (no groups) + +
+