{"size": 1130, "ext": "js", "max_stars_repo_path": "src/app/users/js/users.factory.js", "max_stars_repo_name": "Vindexus/angularfire-todo-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/app/users/js/users.factory.js", "max_issues_repo_name": "Vindexus/angularfire-todo-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app/users/js/users.factory.js", "max_forks_repo_name": "Vindexus/angularfire-todo-app", "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.2790697674, "max_line_length": 82, "alphanum_fraction": 0.5619469027}
const todoLib = require('angularfire-todo-lib');
const usersUtil = todoLib.usersUtil;

/* @ngInject */
function usersFactory ($firebaseArray, $timeout) {
  function Factory () {
    this.$users = $firebaseArray(usersUtil.usersRef);

    this.getStatusOptions = usersUtil.getStatusOptions;

    this.addUser = (user) => {
      console.log('You cannot add users without using CLI.');
    };

    this.saveUser = (user) => {
        console.log('user', user);
      return this.$users.$save(user).then((u) => {
        console.log('u',u);
      });
    }

    this.scopeWatcher = (scope) => {
      const updateScope = () => {
        scope.userOptions = [{id: null, label: '[no user]'}];
        for(var i = 0; i < this.$users.length; i++) {
          let u = this.$users[i];
          let label = u.username ? u.username : '';
          scope.userOptions.push({id: u.$id, label: label + ' [' + u.email + ']'})
        }
        $timeout(function () {});
      }

      scope.users = this.$users;
      this.$users.$watch(updateScope)
    }
  }

  return function () {
    return new Factory();
  }
}

module.exports = usersFactory