'use strict';

class PersonCtrl {

    constructor($rootScope, $routeParams, appService, userService, countryService, authService) {
        this.$rootScope = $rootScope;
        this.$routeParams = $routeParams;
        this.appService = appService;
        this.countryService = countryService;
        this.authService = authService;


        this.countries = [];

        this.userId = this.$rootScope.user._id;
        this.tests = [];
        this.testResults = [];
        this.app = {};
        this.$rootScope.editorEnabled = false;
        this.releaseBtn = false;
        this.editBtn = false;

        /* TODO: remove hardcoded id's */
        if ((this.$rootScope.currentUser._id =='54e83de7b752bfa10e47d8bf') || (this.$rootScope.currentUser._id =='5502409dd4ac39257ca71f86') || (this.$rootScope.currentUser._id =='54feefcccf4100975819aeeb')){
            this.canDoAdmin = true;
        }else {
          this.canDoAdmin = false;
        }

        this.init();
    }

    init() {
        this.countryService.getCountries().then(() => {
            this.countries = this.countryService.countries;
        });
    }

    /**
     * Edit profile
     */

    enableEditor() {
        this.$rootScope.editorEnabled = true;
        this.editUser = this.user;
    }

    disableEditor() {
        this.$rootScope.editorEnabled = false;
    }

    save() {
        this.user = this.editUser;
        this.userService.updateUser(this.editUser).then(
            () => {
                if (this.$rootScope.currentUser._id === this.userService.user._id) {
                    this.$rootScope.currentUser = this.userService.user;
                }
            }
        );

        this.disableEditor();
    }

    sendConfirmEmail() {
        this.authService.register(this.user);
    }

}

angular.module('feedID.profile').controller('PersonCtrl', PersonCtrl);

@@ -122,16 +122,29 @@
 hService
+, testService
 ) %7B%0A    
@@ -343,16 +343,55 @@
 ervice;%0A
+        this.testService = testService;
 %0A%0A      
@@ -435,10 +435,8 @@
 user
-Id
  = t
@@ -454,20 +454,16 @@
 ope.user
-._id
 ;%0A      
@@ -951,32 +951,34 @@
 lse %7B%0A          
+  
 this.canDoAdmin 
@@ -1165,16 +1165,972 @@
      %7D);
+%0A%0A        /**%0A         * These charts are filled with testresults for this test.%0A         * The testresults are unique for a specific user.%0A         */%0A         this.testService.getTests(this.user._id).then(%0A             (tests) =%3E %7B%0A                this.tests = tests;%0A                this.selectedTest = tests%5B0%5D;%0A%0A                 /**%0A                  * Get all testresults from a specific user.%0A                  */%0A                this.testService.getResults(this.user._id, %7B'_id': this.$rootScope.currentUser._id%7D).then(%0A                    (testResults) =%3E %7B%0A                        for (let result of _.compact(testResults)) %7B%0A                            if (result === null)%7B%0A                                this.tests = %5B%5D;%0A                            %7D else%7B%0A                                this.testResults = testResults;%0A                            %7D%0A                        %7D%0A                    %7D%0A                );%0A            %7D%0A        );
 %0A    %7D%0A%0A

Add tests