{"size": 1688, "ext": "js", "max_stars_repo_path": "app/users/users.controller.js", "max_stars_repo_name": "jamesdblakely/photo-exercise", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/users/users.controller.js", "max_issues_repo_name": "jamesdblakely/photo-exercise", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/users/users.controller.js", "max_forks_repo_name": "jamesdblakely/photo-exercise", "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": 29.1034482759, "max_line_length": 80, "alphanum_fraction": 0.4881516588}
(function() {
    "use strict";


    angular.module("photoTry")
        .controller("UsersCtrl", UserController);

    UserController.$inject = ["UsersService", "AlbumsService", "PhotosService"];
    function UserController(UsersService, AlbumsService, PhotosService) {
        var vm = this;
        vm.appUsers = {};
        vm.userAlbums = {};
        vm.albumToggle = false;
        vm.openAlbums = _openAlbums;

        (function populateUsers() {

            UsersService.getUsers()
                .then(function(response) {
                    vm.appUsers = response.data.filter(function(user) {
                        if (user.id < 3) {
                            return user;
                        }
                    });

                }).catch(function (response) {
                    console.log(response.data);
            });
        })();

        function _openAlbums(userId) {
            _populateAlbums(userId);
        }

        function _populateAlbums(userId) {

            AlbumsService.getAlbums(userId)
                .then(function (response) {
                    _applyPhotosToAlbums(response.data);

                }).catch(function (response) {
                console.log(response.data);
            });
        }

        function _applyPhotosToAlbums(userAlbums) {
            var _userAlbumsWithPhotos = {};
            PhotosService.getAlbumPhotos(userAlbums)
                .then(function (datas) {
                    _userAlbumsWithPhotos = datas.map(function (album) {
                        return album;
                    });
                    vm.userAlbums = _userAlbumsWithPhotos;
                });
        }

    }
})();