12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- (function()
- {
- angular.module('appSdk')
- .factory('WeeksBusiness', ['WeeksDataAccess', '$q', function (WeeksDataAccess, $q) {
-
- function isDateInCourse(course, date)
- {
- return course.BeginDate < date && course.EndDate > date;
- }
-
- var Business = {};
-
- Business.formatWeek = function(data)
- {
- data.DayList.forEach(function(day) {
- day.DateTime = new Date(day.DateTime);
- day.CourseList.forEach(function (course) {
-
- course.BeginDate = new Date(course.BeginDate);
- var dt = new Date(course.BeginDate);
- var secs = dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours());
- course.BeginPercent = secs / (60 * 60 * 24) * 100;
- course.BeginSeconds = secs;
-
- course.EndDate = new Date(course.EndDate);
- dt = new Date(course.EndDate);
- secs = dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours());
- course.EndPercent = secs / (60 * 60 * 24) * 100;
- course.EndSeconds = secs;
- });
- });
- data.DayList.forEach(function(day) {
- day.CourseList.forEach(function (course) {
- course.ParallelCoursesCount = 1;
- course.ParallelCoursesPosition = 0;
- day.CourseList.forEach(function (course2) {
- if (course.Id == course2.Id) {
- return;
- }
- var beginBeforeEndIn = (course2.BeginDate <= course.BeginDate && isDateInCourse(course, course2.EndDate));
- var beginInEndAfter = (course2.EndDate >= course.EndDate && isDateInCourse(course, course2.BeginDate));
- var beginBeforeEndAfter = (course2.BeginDate <= course.BeginDate && course2.EndDate >= course.EndDate);
- var beginInEndIn = (isDateInCourse(course, course2.EndDate) && isDateInCourse(course, course2.BeginDate));
- if (beginBeforeEndIn || beginInEndAfter || beginBeforeEndAfter || beginInEndIn) {
- ++course.ParallelCoursesCount;
- course2.ParallelCoursesPosition = Math.max(course.ParallelCoursesPosition, course2.ParallelCoursesPosition) + 1
- }
- });
- });
- });
- };
-
- Business.getWeek = function(data, promise)
- {
- var defer = $q.defer();
- WeeksDataAccess.getWeek(data, promise)
- .then(function(data)
- {
- Business.formatWeek(data);
- defer.resolve(data);
- }, defer.reject);
- return defer.promise;
- };
-
- Business.getCurrentWeek = function(data, promise)
- {
- var defer = $q.defer();
- WeeksDataAccess.getCurrentWeek(data, promise)
- .then(function(data)
- {
- Business.formatWeek(data);
- defer.resolve(data);
- }, defer.reject);
- return defer.promise;
- };
-
- return Business;
- }]);
- })();
|