|
@@ -6,11 +6,18 @@ angular.module('app')
|
6
|
6
|
$scope.dateFormat = "dd MMM yyyy";
|
7
|
7
|
$scope.hourFormat = "HH:mm";
|
8
|
8
|
$scope.courses = null;
|
|
9
|
+ $scope.weekId = {
|
|
10
|
+ id: null,
|
|
11
|
+ date: null
|
|
12
|
+ };
|
9
|
13
|
$scope.days = [{day:"Monday", date: null}, {day:"Tuesday", date: null}, {day:"Wednesday", date: null},
|
10
|
14
|
{day:"Thursday", date: null}, {day:"Friday", date: null}, {day:"Saturday", date: null},
|
11
|
15
|
{day:"Sunday", date: null}];
|
12
|
16
|
$scope.hours = [];
|
13
|
17
|
|
|
18
|
+ $scope.selectedDate = new Date();
|
|
19
|
+ $scope.selectedDate.setHours(0, 0, 0, 0);
|
|
20
|
+
|
14
|
21
|
for (var i = 0; i < 48; ++i) {
|
15
|
22
|
var d = new Date();
|
16
|
23
|
d.setHours(i / 2, 30 * (i % 2), 0, 0);
|
|
@@ -84,7 +91,17 @@ angular.module('app')
|
84
|
91
|
);
|
85
|
92
|
};
|
86
|
93
|
|
87
|
|
- $scope.$watch(function(){return DataShareBusiness.CurrentGroups}, function()
|
|
94
|
+ $scope.onWeekReceived = function(data)
|
|
95
|
+ {
|
|
96
|
+ $scope.courses = data;
|
|
97
|
+ if ($scope.weekId.id == null) {
|
|
98
|
+ $scope.weekId.date = $scope.getMonday(new Date());
|
|
99
|
+ $scope.weekId.id = $scope.courses.Id;
|
|
100
|
+ }
|
|
101
|
+ $scope.setDates($scope.getMonday($scope.selectedDate));
|
|
102
|
+ };
|
|
103
|
+
|
|
104
|
+ $scope.loadWeeks = function()
|
88
|
105
|
{
|
89
|
106
|
var group = DataShareBusiness.getCurrentGroup();
|
90
|
107
|
if (group != null && $scope.getSheetCount() < 5) {
|
|
@@ -92,15 +109,40 @@ angular.module('app')
|
92
|
109
|
id: "promiseLoadCourses",
|
93
|
110
|
groups: ["coursesView"]
|
94
|
111
|
};
|
95
|
|
- WeeksBusiness.getCurrentWeek({group_id: group.Id, type_id: group.Type}, promiseLoadCourses)
|
96
|
|
- .then(function(data)
|
97
|
|
- {
|
98
|
|
- $scope.courses = data;
|
99
|
|
- $scope.setDates($scope.getMonday(new Date()));
|
100
|
|
- });
|
|
112
|
+ if ($scope.weekId.id == null) {
|
|
113
|
+ WeeksBusiness.getCurrentWeek({group_id: group.Id, type_id: group.Type}, promiseLoadCourses)
|
|
114
|
+ .then($scope.onWeekReceived);
|
|
115
|
+ }
|
|
116
|
+ else {
|
|
117
|
+ var diff = Math.round(($scope.getMonday($scope.selectedDate) - $scope.weekId.date) / 604800000);
|
|
118
|
+ var weekId = $scope.weekId.id + diff;
|
|
119
|
+ WeeksBusiness.getWeek({
|
|
120
|
+ group_id: group.Id,
|
|
121
|
+ type_id: group.Type,
|
|
122
|
+ week_id: weekId
|
|
123
|
+ }, promiseLoadCourses).then($scope.onWeekReceived);
|
|
124
|
+ }
|
101
|
125
|
}
|
102
|
126
|
else {
|
103
|
127
|
$scope.courses = null;
|
104
|
128
|
}
|
|
129
|
+ };
|
|
130
|
+
|
|
131
|
+ $scope.weekDiff = function(date1, date2)
|
|
132
|
+ {
|
|
133
|
+ return Math.round(($scope.getMonday(date1) - $scope.getMonday(date2)) / 604800000)
|
|
134
|
+ };
|
|
135
|
+
|
|
136
|
+ $scope.$watch(function(){return DataShareBusiness.CurrentGroups}, $scope.loadWeeks);
|
|
137
|
+
|
|
138
|
+ $scope.$watch(function(){return $scope.selectedDate}, function(newValue, oldValue)
|
|
139
|
+ {
|
|
140
|
+ if (oldValue == null || newValue == oldValue) {
|
|
141
|
+ return;
|
|
142
|
+ }
|
|
143
|
+ var diff = $scope.weekDiff($scope.selectedDate, oldValue);
|
|
144
|
+ if (diff != 0) {
|
|
145
|
+ $scope.loadWeeks();
|
|
146
|
+ }
|
105
|
147
|
});
|
106
|
148
|
}]);
|