+ APISchedule

This commit is contained in:
tmshv committed 2016-02-25 03:31:26 +03:00
1 parent c33944866e
commit c855aa9b5f
3 files changed
+25 -9

No files matched your search

+2
View File
@@ -2,6 +2,7 @@ import APIFeed from './APIFeed';
import APIGallery from './APIGallery'; import APIGallery from './APIGallery';
import APIDocument from './APIDocument'; import APIDocument from './APIDocument';
import APICollective from './APICollective'; import APICollective from './APICollective';
import APISchedule from './APISchedule';
export default class API { export default class API {
constructor(request) { constructor(request) {
@@ -9,5 +10,6 @@ export default class API {
this.gallery = new APIGallery(request); this.gallery = new APIGallery(request);
this.document = new APIDocument(request); this.document = new APIDocument(request);
this.collective = new APICollective(request); this.collective = new APICollective(request);
this.schedule = new APISchedule(request);
} }
} }
+17
View File
@@ -0,0 +1,17 @@
import EndPoint from './EndPoint';
export default class APISchedule extends EndPoint {
get(period, semester, doPopulate=true) {
let url = `/schedule/${period}/${semester}?populate=${doPopulate}`;
return this.request.get(url, {cache: true});
}
buildScheduleUrl(period, semester) {
return `/schedule/${period}/${semester}`;
}
list() {
let url = '/schedule/list';
return this.request.get(url, {cache: true});
}
}
+6 -9
View File
@@ -10,19 +10,20 @@ function isRequested(period, semester) {
} }
export default function (app) { export default function (app) {
app.controller('ScheduleController', ($scope, $http, $location, $routeParams, scheduleData, team, menu) => { app.controller('ScheduleController', ($scope, $http, $location, $routeParams, api, menu) => {
menu.activate('/schedule'); menu.activate('/schedule');
let current_period = $routeParams.period; let current_period = $routeParams.period;
let current_semester = $routeParams.semester; let current_semester = $routeParams.semester;
let isScheduleRequested = current_period && current_semester; let isScheduleRequested = current_period && current_semester;
$scope.schedules = [];
let getScheduleByID = (id) => choise( let getScheduleByID = (id) => choise(
$scope.schedules, $scope.schedules,
select(i => i._id === id) select(i => i._id === id)
); );
$http.get('/schedules', {cache: true}) api.schedule.list()
.success(schedules => { .success(schedules => {
// By url params or last element // By url params or last element
let selector = isScheduleRequested ? isRequested(current_period, current_semester) : indexEquals(schedules.length - 1); let selector = isScheduleRequested ? isRequested(current_period, current_semester) : indexEquals(schedules.length - 1);
@@ -56,15 +57,11 @@ export default function (app) {
let sem = schedule_item.semester; let sem = schedule_item.semester;
let period = schedule_item.period; let period = schedule_item.period;
let url = `/schedule/${period}/${sem}`; api.schedule.get(period, sem, true)
$http.get(url, {cache: true})
.success(scheduleRecord => { .success(scheduleRecord => {
$scope.schedule = scheduleData.populate(scheduleRecord.schedule, [ $scope.schedule = scheduleRecord.schedule;
populate(team.short, 'teacher'),
populate(getCourseNameByID, 'lesson')
]);
if (doUpdateURL) $location.url(url); if (doUpdateURL) $location.url(api.schedule.buildScheduleUrl(period, sem));
}); });
} }
}; };