You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

home.controller.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. angular.module('app')
  2. .controller('HomeController', ['$scope', '$state', 'DataShareBusiness', 'WeeksBusiness',
  3. function($scope, $state, DataShareBusiness, WeeksBusiness) {
  4. $scope.DataShareBusiness = DataShareBusiness;
  5. $scope.dateFormat = "dd MMM yyyy";
  6. $scope.courses = null;
  7. $scope.days = [{day:"Monday", date: null}, {day:"Tuesday", date: null}, {day:"Wednesday", date: null},
  8. {day:"Thursday", date: null}, {day:"Friday", date: null}, {day:"Saturday", date: null},
  9. {day:"Sunday", date: null}];
  10. $scope.getSheetCount = function()
  11. {
  12. var sheetCount = function(group)
  13. {
  14. var c = (group.Groups == null || group.Groups.length == 0) ? 1 : 0;
  15. if (group.Groups != null) {
  16. group.Groups.forEach(function (group) {
  17. c += sheetCount(group);
  18. });
  19. }
  20. return c;
  21. };
  22. return sheetCount(DataShareBusiness.getCurrentGroupOrRoot())
  23. };
  24. $scope.getMonday = function(d)
  25. {
  26. d = new Date(d);
  27. var day = d.getDay(), diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
  28. d = new Date(d.setDate(diff));
  29. d.setHours(0, 0, 0, 0);
  30. return d;
  31. };
  32. $scope.setDates = function(monday)
  33. {
  34. $scope.days[0].date = new Date(monday);
  35. for (var i = 1; i < $scope.days.length; ++i) {
  36. $scope.days[i].date = new Date(monday.setDate(monday.getDate() + 1));
  37. }
  38. };
  39. $scope.getDayListByDay = function(date)
  40. {
  41. if ($scope.courses == null || date == null) {
  42. return null;
  43. }
  44. return $scope.courses.DayList.find(function(day)
  45. {
  46. return day.DateTime.getTime() == date.getTime();
  47. });
  48. };
  49. $scope.getCoursesByDate = function(date)
  50. {
  51. var courses = $scope.getDayListByDay(date);
  52. if (courses == null) {
  53. return [];
  54. }
  55. return courses.CourseList;
  56. };
  57. $scope.$watch(function(){return DataShareBusiness.CurrentGroups}, function()
  58. {
  59. var group = DataShareBusiness.getCurrentGroup();
  60. if (group != null && $scope.getSheetCount() < 5) {
  61. var promiseLoadCourses = {
  62. id: "promiseLoadCourses",
  63. groups: ["coursesView"]
  64. };
  65. WeeksBusiness.getCurrentWeek({group_id: group.Id, type_id: group.Type}, promiseLoadCourses)
  66. .then(function(data)
  67. {
  68. $scope.courses = data;
  69. $scope.setDates($scope.getMonday(new Date()));
  70. });
  71. }
  72. else {
  73. $scope.courses = null;
  74. }
  75. });
  76. }]);