Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

WeeksBusiness.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. (function()
  2. {
  3. angular.module('appSdk')
  4. .factory('WeeksBusiness', ['WeeksDataAccess', '$q', function (WeeksDataAccess, $q) {
  5. function isDateInCourse(course, date)
  6. {
  7. return course.BeginDate < date && course.EndDate > date;
  8. }
  9. var Business = {};
  10. Business.formatWeek = function(data)
  11. {
  12. data.DayList.forEach(function(day) {
  13. day.DateTime = new Date(day.DateTime);
  14. day.CourseList.forEach(function (course) {
  15. course.BeginDate = new Date(course.BeginDate);
  16. var dt = new Date(course.BeginDate);
  17. var secs = dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours());
  18. course.BeginPercent = secs / (60 * 60 * 24) * 100;
  19. course.BeginSeconds = secs;
  20. course.EndDate = new Date(course.EndDate);
  21. dt = new Date(course.EndDate);
  22. secs = dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours());
  23. course.EndPercent = secs / (60 * 60 * 24) * 100;
  24. course.EndSeconds = secs;
  25. });
  26. });
  27. data.DayList.forEach(function(day) {
  28. day.CourseList.forEach(function (course) {
  29. course.ParallelCoursesCount = 1;
  30. course.ParallelCoursesPosition = 0;
  31. day.CourseList.forEach(function (course2) {
  32. if (course.Id == course2.Id) {
  33. return;
  34. }
  35. var beginBeforeEndIn = (course2.BeginDate <= course.BeginDate && isDateInCourse(course, course2.EndDate));
  36. var beginInEndAfter = (course2.EndDate >= course.EndDate && isDateInCourse(course, course2.BeginDate));
  37. var beginBeforeEndAfter = (course2.BeginDate <= course.BeginDate && course2.EndDate >= course.EndDate);
  38. var beginInEndIn = (isDateInCourse(course, course2.EndDate) && isDateInCourse(course, course2.BeginDate));
  39. if (beginBeforeEndIn || beginInEndAfter || beginBeforeEndAfter || beginInEndIn) {
  40. ++course.ParallelCoursesCount;
  41. course2.ParallelCoursesPosition = Math.max(course.ParallelCoursesPosition, course2.ParallelCoursesPosition) + 1
  42. }
  43. });
  44. });
  45. });
  46. };
  47. Business.getWeek = function(data, promise)
  48. {
  49. var defer = $q.defer();
  50. WeeksDataAccess.getWeek(data, promise)
  51. .then(function(data)
  52. {
  53. Business.formatWeek(data);
  54. defer.resolve(data);
  55. }, defer.reject);
  56. return defer.promise;
  57. };
  58. Business.getCurrentWeek = function(data, promise)
  59. {
  60. var defer = $q.defer();
  61. WeeksDataAccess.getCurrentWeek(data, promise)
  62. .then(function(data)
  63. {
  64. Business.formatWeek(data);
  65. defer.resolve(data);
  66. }, defer.reject);
  67. return defer.promise;
  68. };
  69. return Business;
  70. }]);
  71. })();