<commit_before>angular.module('owner.controllers', ['ng-token-auth', 'ionic-timepicker', 'ui.calendar'])

.config(function($authProvider, $authConfigProvider) {
  var config = $authConfigProvider.$get()('/owner');
  $authProvider.configure(config);
})

.controller('LoginCtrl', function($scope, $auth, $state, $config) {
  $scope.user = {};

  $scope.login = function(provider) {
    $auth.authenticate(provider).then(function(owner) {
      if(owner.profile_id === null) {
        $state.go('owner.profile');
      } else {
        $state.go('owner.calendar');
      }
    });
  };
})

.controller('ProfileCtrl', function($scope, $auth, $state, $config, $filter, $toast, 
  CepService, ProfileService) {
  function createDateObj(hour) {
    var obj = {
      inputEpochTime: parseDate(hour),
      step: 5,
      format: 24,
      setLabel: 'Selecionar',
      closeLabel: 'Fechar',
      callback: function(val) {
        if(val !== undefined) {
          obj.inputEpochTime = val;
        }
      }
    };
    return obj;
  };

  function parseDate(date) {
    var newDate = new Date(date);
    newDate.setYear(1970);
    newDate.setMonth(0);
    newDate.setDate(1);
    var seconds = newDate.getTime() / 1000;
    var day = 24 * 60 * 60;
    if(seconds > day) {
      return seconds - day;
    }
    return seconds;
  }
  
  function formatDate(date) {
    var newDate = new Date(date * 1000);
    newDate.setYear(2000);
    newDate.setMonth(0);
    newDate.setDate(1);
    return newDate;
  }

  $scope.profile = new ProfileService();
  if($auth.user.profile_id === null) {
    $scope.profile.owner = $auth.owner;
  } else {
    $scope.profile.$get({id: $auth.user.profile_id}, function() {
      $scope.timeStart.inputEpochTime = parseDate($scope.profile.owner.start);
      $scope.timeEnd.inputEpochTime = parseDate($scope.profile.owner.end);
      $scope.timeClient.inputEpochTime = parseDate($scope.profile.owner.time_per_client);
    });
  }

  $scope.cep = {value: '', $present: false};

  $scope.timeStart = createDateObj('2010-01-01T09:00:00Z');
  $scope.timeEnd = createDateObj('2010-01-01T20:00:00Z');
  $scope.timeClient = createDateObj('2010-01-01T00:20:00Z');
  
  $scope.$watch('profile.zipcode', function(zipcode) {
    if(zipcode !== undefined && zipcode.length === 8) {
      CepService.get({cep: $scope.profile.zipcode}, function(address) {
        if(!address.erro) {
          $scope.profile.zipcode.$present = true;
          $scope.profile.address = (address.logradouro + ' ' + address.complemento).trim();
          $scope.profile.number = address.number;
          $scope.profile.neighborhood = address.bairro;
          $scope.profile.city = address.localidade;
          $scope.profile.state = address.uf;
          $scope.profile.zipcode = address.cep;
          $scope.profile.zipcode_present = true;
        }
      });
    }
  });

  $scope.registry = function() {
    $scope.profile.owner.start = formatDate($scope.timeStart.inputEpochTime);
    $scope.profile.owner.end = formatDate($scope.timeEnd.inputEpochTime);
    $scope.profile.owner.time_per_client = formatDate($scope.timeClient.inputEpochTime);

    $scope.profile.$save(function(profile) {
      $toast.show('Salvo com sucesso!');
    });
  };
})

.controller('CalendarCtrl', function($scope, $state, $auth, $config, $ionicModal, 
  $ionicScrollDelegate, uiCalendarConfig) {
  
  $ionicModal.fromTemplateUrl('templates/owner/modal.html', {scope: $scope})
    .then(function(modal) {
    $scope.modal = modal;
  });

  $scope.eventSources = [];
  $scope.uiConfig = {
    calendar: {
      defaultView: 'agendaWeek',
      height: 'auto',
      allDaySlot: false,
      selectable: false,
      editable: false,
      droppable: false,
      lang: 'pt-br',
      timezone: 'local',
      minTime: '10:00',
      maxTime: '18:00',
      slotDuration: '00:20',
      hiddenDays: [0],
      header:{
        left: 'title',
        right: 'today agendaDay,agendaWeek,month'
      },
      dayClick: function(date, jsEvent, view) {
        if (view.name === 'agendaDay') {
          $scope.modal.date = date.toDate();
          $scope.modal.show();
        } else {
          $(uiCalendarConfig.calendars.monthly).fullCalendar('gotoDate', date);
          $(uiCalendarConfig.calendars.monthly).fullCalendar('changeView', 'agendaDay');
        }
      },
      eventClick: function(e) {
      }
    }
  };

  $scope.selectClient = function(item) {
    $scope.modal.selected = item;
  };

  $scope.close = function() {
    $scope.modal.hide();
  };

  $scope.uiConfig.calendar.defaultView = 'agendaWeek';
  $scope.uiConfig.calendar.events = [
    {id: 1, foo: 'bar', title: 'All Day Event', start: new Date(2015, 11, 1), end: new Date(2016, 5, 1)},
    {id: 2, title: 'All Day Event', start: new Date(2015, 10, 2)},
    {id: 3, title: 'All Day Event', start: new Date(2015, 11, 3)}
  ];

  $scope.foo = function() {
    console.log('bar')
  }

  $scope.left = function() {
    $(uiCalendarConfig.calendars.monthly).fullCalendar('next');
  };

  $scope.right = function() {
    $(uiCalendarConfig.calendars.monthly).fullCalendar('prev');
  };

  var scrollSize = window.screen.height / 5 * 4;

  $scope.down = function() {
    $scope._scroll(scrollSize * -1);
  };

  $scope.up = function() {
    $scope._scroll(scrollSize);
  };

  $scope._scroll = function(top) {
    var pos = $ionicScrollDelegate.getScrollPosition();
    $ionicScrollDelegate.scrollTo(pos.left, pos.top + top, true); 
  }
})

.controller('AccountCtrl', function($scope, $auth) {

});
<commit_msg>Integrated profile to calendar<commit_after>angular.module('owner.controllers', ['ng-token-auth', 'ionic-timepicker', 'ui.calendar'])

.config(function($authProvider, $authConfigProvider) {
  var config = $authConfigProvider.$get()('/owner');
  $authProvider.configure(config);
})

.controller('LoginCtrl', function($scope, $auth, $state, $config) {
  $scope.user = {};

  $scope.login = function(provider) {
    $auth.authenticate(provider).then(function(owner) {
      if(owner.profile_id === null) {
        $state.go('owner.profile');
      } else {
        $state.go('owner.calendar');
      }
    });
  };
})

.controller('ProfileCtrl', function($scope, $auth, $state, $config, $filter, $toast, 
  CepService, ProfileService) {
  function createDateObj(hour) {
    var obj = {
      inputEpochTime: parseDate(hour),
      step: 5,
      format: 24,
      setLabel: 'Selecionar',
      closeLabel: 'Fechar',
      callback: function(val) {
        if(val !== undefined) {
          obj.inputEpochTime = val;
        }
      }
    };
    return obj;
  };

  function parseDate(date) {
    return $.fullCalendar.moment(new Date(date)).utc().year(1970).month(0).date(1).time() / 1000;
  }
  
  function formatDate(date) {
    return $.fullCalendar.moment(new Date(date * 1000)).utc().year(2000).month(0).date(1).toISOString();
  }

  $scope.profile = new ProfileService();
  if($auth.user.profile_id === null) {
    $scope.profile.owner = $auth.owner;
  } else {
    $scope.profile.$get({id: $auth.user.profile_id}, function() {
      $scope.timeStart.inputEpochTime = parseDate($scope.profile.owner.start);
      $scope.timeEnd.inputEpochTime = parseDate($scope.profile.owner.end);
      $scope.timeClient.inputEpochTime = parseDate($scope.profile.owner.time_per_client);
    });
  }

  $scope.cep = {value: '', $present: false};

  $scope.timeStart = createDateObj('2010-01-01T09:00:00Z');
  $scope.timeEnd = createDateObj('2010-01-01T20:00:00Z');
  $scope.timeClient = createDateObj('2010-01-01T00:20:00Z');
  
  $scope.$watch('profile.zipcode', function(zipcode) {
    if(zipcode !== undefined && zipcode.length === 8) {
      CepService.get({cep: $scope.profile.zipcode}, function(address) {
        if(!address.erro) {
          $scope.profile.zipcode.$present = true;
          $scope.profile.address = (address.logradouro + ' ' + address.complemento).trim();
          $scope.profile.number = address.number;
          $scope.profile.neighborhood = address.bairro;
          $scope.profile.city = address.localidade;
          $scope.profile.state = address.uf;
          $scope.profile.zipcode = address.cep;
          $scope.profile.zipcode_present = true;
        }
      });
    }
  });

  $scope.registry = function() {
    $scope.profile.owner.start = formatDate($scope.timeStart.inputEpochTime);
    $scope.profile.owner.end = formatDate($scope.timeEnd.inputEpochTime);
    $scope.profile.owner.time_per_client = formatDate($scope.timeClient.inputEpochTime);

    $scope.profile.$save(function(profile) {
      $toast.show('Salvo com sucesso!');
    });
  };
})

.controller('CalendarCtrl', function($scope, $state, $auth, $config, $ionicModal, 
  $ionicScrollDelegate, uiCalendarConfig) {
  
  $ionicModal.fromTemplateUrl('templates/owner/modal.html', {scope: $scope})
    .then(function(modal) {
    $scope.modal = modal;
  });

  var start = $.fullCalendar.moment($auth.user.start).utc().format('HH:mm');
  var end = $.fullCalendar.moment($auth.user.end).utc().format('HH:mm');
  var duration = $.fullCalendar.moment($auth.user.time_per_client).utc().format('HH:mm');

  $scope.eventSources = [];
  $scope.uiConfig = {
    calendar: {
      defaultView: 'agendaWeek',
      height: 'auto',
      allDaySlot: false,
      selectable: false,
      editable: false,
      droppable: false,
      lang: 'pt-br',
      timezone: 'local',
      minTime: start,
      maxTime: end,
      slotDuration: duration,
      hiddenDays: [0],
      header:{
        left: 'title',
        right: 'today agendaDay,agendaWeek,month'
      },
      dayClick: function(date, jsEvent, view) {
        if (view.name === 'agendaDay') {
          $scope.modal.date = date.toDate();
          $scope.modal.show();
        } else {
          $(uiCalendarConfig.calendars.monthly).fullCalendar('gotoDate', date);
          $(uiCalendarConfig.calendars.monthly).fullCalendar('changeView', 'agendaDay');
        }
      },
      eventClick: function(e) {
      }
    }
  };

  $scope.selectClient = function(item) {
    $scope.modal.selected = item;
  };

  $scope.close = function() {
    $scope.modal.hide();
  };

  $scope.uiConfig.calendar.defaultView = 'agendaWeek';
  $scope.uiConfig.calendar.events = [
    {id: 1, foo: 'bar', title: 'All Day Event', start: new Date(2015, 11, 1), end: new Date(2016, 5, 1)},
    {id: 2, title: 'All Day Event', start: new Date(2015, 10, 2)},
    {id: 3, title: 'All Day Event', start: new Date(2015, 11, 3)}
  ];

  $scope.foo = function() {
    console.log('bar')
  }

  $scope.left = function() {
    $(uiCalendarConfig.calendars.monthly).fullCalendar('next');
  };

  $scope.right = function() {
    $(uiCalendarConfig.calendars.monthly).fullCalendar('prev');
  };

  var scrollSize = window.screen.height / 5 * 4;

  $scope.down = function() {
    $scope._scroll(scrollSize * -1);
  };

  $scope.up = function() {
    $scope._scroll(scrollSize);
  };

  $scope._scroll = function(top) {
    var pos = $ionicScrollDelegate.getScrollPosition();
    $ionicScrollDelegate.scrollTo(pos.left, pos.top + top, true); 
  }
})

.controller('AccountCtrl', function($scope, $auth) {

});

{'fraction_non_alphanumeric': 0.1712187695889675, 'fraction_numerical': 0.0195218053192442, 'mean_word_length': 3.1149594694178333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '746916', 'n_tokens_mistral': 3895, 'n_tokens_neox': 3677, 'n_words': 597}