{"size": 1859, "ext": "js", "max_stars_repo_path": "app/js/controllers/issue-page-controller.js", "max_stars_repo_name": "CharlieScarver/IssueTrackingSystem-AngularJS", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/js/controllers/issue-page-controller.js", "max_issues_repo_name": "CharlieScarver/IssueTrackingSystem-AngularJS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/js/controllers/issue-page-controller.js", "max_forks_repo_name": "CharlieScarver/IssueTrackingSystem-AngularJS", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.5571428571, "max_line_length": 74, "alphanum_fraction": 0.6385153308}
'use strict';

angular.module('issueTrackingSystem.issues.issuePage', [
		'issueTrackingSystem.users.identity',
		'issueTrackingSystem.issues.getIssue',
		'issueTrackingSystem.projects.getProject',
		'issueTrackingSystem.issues.changeIssueStatus'
	])
	.config(['$routeProvider', function ($routeProvider) {
		var routeChecks = {
			authenticated: ['$q', 'authentication', function ($q, authentication) {
				if (authentication.isAuthenticated()) {
					return $q.when(true);
				}

				return $q.reject('Unauthorized Access');
			}]
		};

		$routeProvider.when('/issues/:id', {
			templateUrl: 'views/issue-page.html',
			controller: 'IssuePageController',
			resolve: routeChecks.authenticated
		})
	}])	
	.controller('IssuePageController', [
		'$scope',
		'$route',
		'identity',
		'getIssue',
		'getProject',
		'changeIssueStatus',
		function IssuePageController($scope, $route, 
			identity, getIssue, getProject, changeIssueStatus) {

			var issueId = $route.current.pathParams['id'];

			$scope.changeIssueStatus = function(statusId, statusName) {
				changeIssueStatus.changeStatus(issueId, statusId)
					.then(function (newStatusesArr) {
						$scope.issue.AvailableStatuses = newStatusesArr;
						$scope.issue.Status = {
							Id: statusId,
							Name: statusName
						};
					});
			};
			
			getIssue.getIssueById(issueId)
				.then(function (issueData) {
					$scope.issue = issueData;

					getProject.getProjectById(issueData.Project.Id)
						.then(function (projectData) {							

							identity.getCurrentUser()
								.then(function (user) {
									$scope.currentUser = user;
									if (user.Id === projectData.Lead.Id || user.isAdmin) {
										$scope.isProjectLeader = true;
									}

									if (user.Id === issueData.Assignee.Id) {
										$scope.isAssignee = true;
									}
								});
						});					
				});

		}]);