{"size": 5931, "ext": "js", "max_stars_repo_path": "app/scripts/app/controllers/admin/controller.profile.js", "max_stars_repo_name": "pfitzpaddy/ngm-reportHub", "max_stars_repo_stars_event_min_datetime": "2019-01-17T15:37:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T21:06:39.000Z", "max_issues_repo_path": "app/scripts/app/controllers/admin/controller.profile.js", "max_issues_repo_name": "pfitzpaddy/ngm-reportHub", "max_issues_repo_issues_event_min_datetime": "2017-06-06T19:44:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-31T11:23:37.000Z", "max_forks_repo_path": "app/scripts/app/controllers/admin/controller.profile.js", "max_forks_repo_name": "pfitzpaddy/ngm-reportHub", "max_forks_repo_forks_event_min_datetime": "2017-09-20T05:34:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-02T17:50:46.000Z"}
{"max_stars_count": 2, "max_issues_count": 418, "max_forks_count": 10, "avg_line_length": 30.7305699482, "max_line_length": 197, "alphanum_fraction": 0.5392008093}
/**
 * @ngdoc function
 * @name ngmReportHubApp.controller:DashboardProfileCtrl
 * @description
 * # LoginCtrl
 * Controller of the ngmReportHub
 */
angular.module('ngmReportHub')
	.controller('DashboardProfileCtrl', ['$scope', '$route', 'ngmData', 'ngmAuth', '$translate', '$filter', '$rootScope', function ($scope, $route, ngmData, ngmAuth, $translate, $filter, $rootScope) {
		this.awesomeThings = [
			'HTML5 Boilerplate',
			'AngularJS',
			'Karma'
		];

		// assign to ngm app scope
		$scope.model = $scope.$parent.ngm.dashboard.model;
		
		// login object
		$scope.dashboard = {

			// parent
			ngm: $scope.$parent.ngm,

			// current ReportHub user
			user: $scope.$parent.ngm.getUser(),

			// profile username to load
			username: $route.current.params.username,

			// the header navigation settings
			getHeaderHtml: function(){
				var url ='#/team';
				if ($rootScope.teamPreviouseUrl){
					url = $rootScope.teamPreviouseUrl;
				}
				var html = '<div class="row hide-on-small-only">'
										+'<div class="col s12 m12 l12">'
											+'<div>'
												+'<a class="btn-flat waves-effect waves-teal" href="'+url+'">'
													+'<i class="material-icons mirror left">keyboard_return</i>'+$filter('translate')('back_to_team')
												+'</a>'
												+'<span class="right" style="padding-top:8px;">'+$filter('translate')('last_updated')+ ' ' + moment( $scope.dashboard.user.updatedAt ).format( 'DD MMMM, YYYY @ h:mm:ss a' ) +'</span>'
											+'</div>'
										+'</div>'
									+'</div>';

				return html;
			},

			// load dashboard
			init: function( user ){
				
				// add padding to style?
				$scope.dashboard.ngm.style.paddingHeight = 20;		

				// dews dashboard model
				var model = {
					name: 'dashboard_profile',
					header: {
						div: {
							'class': 'col s12 m12 l12 report-header',
							style: 'border-bottom: 3px ' + $scope.dashboard.ngm.style.defaultPrimaryColor + ' solid;'
						},
						title: {
							'class': 'col s12 m12 l12 report-title report-title',
							style: 'color: ' + $scope.dashboard.ngm.style.defaultPrimaryColor,
							title: $filter('translate')('profile')+' | ' + user.username

						},
						subtitle: {
							'class': 'col s12 m12 l12 report-subtitle',
							html: true,
							title: user.admin0name.toUpperCase().substring(0, 3) + ' | ' + user.cluster.toUpperCase() + ' | ' + user.organization + ' | ' + user.username,
						}
					},
					rows: [{
						columns: [{
							styleClass: 's12 m12 l12',
							widgets: [{
								type: 'html',
								card: 'white grey-text text-darken-2',
								style: 'padding: 20px;',
								config: {
									html: $scope.dashboard.getHeaderHtml()
								}
							}]
						}]
					},{
						columns: [{
							styleClass: 's12',
							widgets: [{
								type: 'form.authentication',
								config: {
									style: $scope.dashboard.ngm.style,
									user: user,
						      formDisabled: (function() {
						        var disabled = true;
										if ( user.status === 'active' &&
						        			( $scope.dashboard.username === $scope.dashboard.user.username ||
											( ngmAuth.canDo( 'EDIT_USER', { adminRpcode: user.adminRpcode, 
																			  admin0pcode: user.admin0pcode, 
																			  cluster_id: user.cluster_id, 
																			  organization_tag: user.organization_tag } ) ) ) ) {
						          disabled = false;
						        }
						        return disabled;
						      })(),
						      activateUpdateVisible: (function() {
						        var visible = false;
						        if ( $scope.dashboard.user.username !== $scope.dashboard.username && 
											( ngmAuth.canDo( 'EDIT_USER', { adminRpcode: user.adminRpcode, 
																			  admin0pcode: user.admin0pcode, 
																			  cluster_id: user.cluster_id, 
																			  organization_tag: user.organization_tag } ) ) ) {
						          visible = true;
						        }
						        return visible;
									})(),
									updateOrgUser: (function () {
										var clusterDisabled = true;
										if ((ngmAuth.canDo('EDIT_USER_ORG', {
																admin0pcode: user.admin0pcode
											}))) {
											clusterDisabled = false;
										}
										return clusterDisabled;
									})(),
									updateClusterUser:(function(){
										var clusterDisabled = true;
										if ($scope.dashboard.user.username === $scope.dashboard.username ||
											(ngmAuth.canDo('EDIT_USER_CLUSTER', {
												
											}))) {
											clusterDisabled = false;
										}
										return clusterDisabled;
									})(),
									templateUrl: '/scripts/app/views/authentication/profile.html',
									showProfile:(function(){
										var show = false;
										if(!user.anonymous){
											show = true;
											return show
										}
										if (user.anonymous &&
											($scope.dashboard.username === $scope.dashboard.user.username ||
												(ngmAuth.canDo('EDIT_USER', {
													adminRpcode: user.adminRpcode,
													admin0pcode: user.admin0pcode,
													cluster_id: user.cluster_id,
													organization_tag: user.organization_tag
												})))) {
											show = true;
										}
										return show;

									})()
								}
							}]
						}]
					}]
				}

				// assign model to scope
				$scope.model = model;

				// assign to ngm app scope
				$scope.dashboard.ngm.dashboard = $scope.model;
			}

		}

		// if not current user 
		if ( $scope.dashboard.username && 
					( $scope.dashboard.username !== $scope.dashboard.user.username ) ) {

			// get use
			ngmData
				.get( { method: 'GET', url: ngmAuth.LOCATION + '/api/getUserByUsername?username=' + $scope.dashboard.username } )
				.then( function( user ){
					// load with user profile
					$scope.dashboard.init( user );
			});

		} else {
			// load with current user profile
			$scope.dashboard.init( $scope.dashboard.user );

		}
		
	}]);
