Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

home.controller.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.getCourseListByDay = function(date)
  40. {
  41. if ($scope.courses == null || date == null) {
  42. return null;
  43. }
  44. return $scope.courses.DayList.find(function(day)
  45. {
  46. var d = new Date(day.DateTime);
  47. return d.getTime() == date.getTime();
  48. });
  49. };
  50. $scope.getCoursesByDate = function(date)
  51. {
  52. var courses = $scope.getCourseListByDay(date);
  53. if (courses == null) {
  54. return [];
  55. }
  56. return ["42", "24"];
  57. };
  58. $scope.$watch(function(){return DataShareBusiness.CurrentGroups}, function()
  59. {
  60. var group = DataShareBusiness.getCurrentGroup();
  61. if (group != null && $scope.getSheetCount() < 5) {
  62. var promiseLoadCourses = {
  63. id: "promiseLoadCourses",
  64. groups: ["coursesView"]
  65. };
  66. WeeksBusiness.getCurrentWeek({group_id: group.Id, type_id: group.Type}, promiseLoadCourses)
  67. .then(function(data)
  68. {
  69. $scope.courses = data;
  70. $scope.setDates($scope.getMonday(new Date()));
  71. });
  72. }
  73. else {
  74. $scope.courses = null;
  75. }
  76. });
  77. }]);