Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. angular.module('appointmentsCalendar', []);
  4. angular.module('appointmentsCalendar')
  5.     .component('appointmentsCalendar', {
  6.         templateUrl:'/app/appointments-calendar/appointments-calendar.html',
  7.         controller: function($scope, $http, $routeParams, $location, appointmentsService) {
  8.             console.log("Incializando appointments calendar")
  9.             moment.locale("es");
  10.            
  11.             var currentMonth = moment().startOf('month');
  12.             if($routeParams.month) {
  13.                 currentMonth = moment($routeParams.month, "YYYYMM");
  14.             }
  15.             $scope.currentMonth = currentMonth.toDate();
  16.             $scope.prevMonth = moment(currentMonth).add(-1,'M').toDate();
  17.             $scope.nextMonth = moment(currentMonth).add(1,'M').toDate();
  18.  
  19.             $scope.cells = []
  20.  
  21.             var firstWeekDay = currentMonth.weekday();
  22.             for(var i = 0; i < firstWeekDay; i++) {
  23.                 $scope.cells.push({date: "---"});
  24.             }
  25.  
  26.             appointmentsService.getMonthAppointmentsByDate(currentMonth).then(function(response){
  27.                 $scope.appointmentsByDate = response;
  28.                 for (var m = moment(currentMonth); m.isBefore($scope.nextMonth); m.add(1, 'days')) {
  29.                     var currentDate = m.format('YYYYMMDD');
  30.                     $scope.cells.push({
  31.                         date: m.toDate(),
  32.                         appointments: $scope.appointmentsByDate[currentDate],
  33.                         appointmentsCount: $scope.appointmentsByDate[currentDate] ? Object.keys($scope.appointmentsByDate[currentDate]).length : 0,
  34.                     });
  35.                 }
  36.             });
  37.            
  38.             $scope.openDayAppointments = (date) => {
  39.                 $location.path("/appointments-day-list/" + moment(date).format('YYYYMMDD'))
  40.             };
  41.         }
  42.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement