From f747ce17f31b8cc819d75eb7e48e1de958d12387 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Wed, 5 Aug 2015 00:53:25 +0300 Subject: [PATCH] schedule page update: multiple schedules, prettify, other changes --- assets/style/schedule.scss | 8 ++--- client/pages/schedule.js | 60 ++++++++++++++++++++++++++++------- templates/views/schedule.html | 13 +++++--- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/assets/style/schedule.scss b/assets/style/schedule.scss index b6783d52..2f25e578 100644 --- a/assets/style/schedule.scss +++ b/assets/style/schedule.scss @@ -15,6 +15,10 @@ padding-bottom: 50px; text-align: center; + & > p{ + text-align: right; + } + .schedule-block{ overflow-x: scroll; } @@ -90,10 +94,6 @@ font-style: italic; } - p{ - margin-bottom: 10px; - } - a{ color: black; diff --git a/client/pages/schedule.js b/client/pages/schedule.js index 18899047..9987d3e4 100644 --- a/client/pages/schedule.js +++ b/client/pages/schedule.js @@ -6,20 +6,58 @@ module.exports = function (app) { var now = new Date(); var dates = getDates(now); - var sem = "autumn"; - $scope.sem = [["spring", "весеннего"], ["autumn", "осеннего"]].reduce(function (s, word) { - if (word[0] === sem) return word[1]; - }); - $scope.year = "2014-2015"; + $http.get("/schedules") + .success(function (schedules) { + //return ; + var last = schedules.length - 1; - $http.get("/schedule/2014-2015/spring") - .success(function (s) { - $scope.schedule = schedule.populate(s.schedule, [ - populate(team.short, "teacher"), - populate(course.name, "lesson") - ]); + $scope.schedules = schedules.map(function (schedule) { + var sem = [["spring", "весеннего"], ["autumn", "осеннего"]].reduce(function (s, word) { + if (word[0] === schedule.semester) return word[1]; + else return s[1]; + }); + + schedule.text = 'Расписание {{sem}} семестра {{period}} года' + .replace('{{sem}}', sem) + .replace('{{period}}', schedule.period); + + return schedule; + }); + $scope.schedules[last].selected = true; + $scope.currentSchedule = $scope.schedules[last]._id; + $scope.loadSchedule(); }); + $scope.$watch('currentSchedule', function (newValue) { + + }); + + $scope.loadSchedule = function (id) { + var schedule_item = getScheduleByID(id || $scope.currentSchedule); + + if(schedule_item) { + var sem = schedule_item.semester; + var period = schedule_item.period; + + $http.get("/schedule/" + period + "/" + sem) + .success(function (scheduleRecord) { + $scope.groups = schedule.populate(scheduleRecord.schedule, [ + populate(team.short, "teacher"), + populate(course.name, "lesson") + ]); + }); + } + }; + + function getScheduleByID(id) { + var schedules = $scope.schedules; + for (var i in schedules) { + var s = schedules[i]; + if (id === s._id) return s; + } + return null; + } + $scope.isToday = function (weekDayIndex) { return (now.getDay() - 1) === weekDayIndex; }; diff --git a/templates/views/schedule.html b/templates/views/schedule.html index fe1eb49d..ea44d982 100644 --- a/templates/views/schedule.html +++ b/templates/views/schedule.html @@ -1,6 +1,11 @@
-

Расписание {{sem}} семестра {{year}} года

-
+

+ +

+ +
@@ -37,8 +42,8 @@ - - + +

{{group.name}}