From c855aa9b5f710a1aa3a1a869b1c3130be44516b3 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Thu, 25 Feb 2016 03:31:26 +0300 Subject: [PATCH] + APISchedule --- src/client/api/API.js | 2 ++ src/client/api/APISchedule.js | 17 +++++++++++++++++ src/client/controllers/ScheduleController.js | 15 ++++++--------- 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/client/api/APISchedule.js diff --git a/src/client/api/API.js b/src/client/api/API.js index b2cc07af..59b6767f 100644 --- a/src/client/api/API.js +++ b/src/client/api/API.js @@ -2,6 +2,7 @@ import APIFeed from './APIFeed'; import APIGallery from './APIGallery'; import APIDocument from './APIDocument'; import APICollective from './APICollective'; +import APISchedule from './APISchedule'; export default class API { constructor(request) { @@ -9,5 +10,6 @@ export default class API { this.gallery = new APIGallery(request); this.document = new APIDocument(request); this.collective = new APICollective(request); + this.schedule = new APISchedule(request); } } \ No newline at end of file diff --git a/src/client/api/APISchedule.js b/src/client/api/APISchedule.js new file mode 100644 index 00000000..5a8b3e56 --- /dev/null +++ b/src/client/api/APISchedule.js @@ -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}); + } +} \ No newline at end of file diff --git a/src/client/controllers/ScheduleController.js b/src/client/controllers/ScheduleController.js index bd1f02be..f67def41 100644 --- a/src/client/controllers/ScheduleController.js +++ b/src/client/controllers/ScheduleController.js @@ -10,19 +10,20 @@ function isRequested(period, semester) { } 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'); let current_period = $routeParams.period; let current_semester = $routeParams.semester; let isScheduleRequested = current_period && current_semester; + $scope.schedules = []; let getScheduleByID = (id) => choise( $scope.schedules, select(i => i._id === id) ); - $http.get('/schedules', {cache: true}) + api.schedule.list() .success(schedules => { // By url params or last element 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 period = schedule_item.period; - let url = `/schedule/${period}/${sem}`; - $http.get(url, {cache: true}) + api.schedule.get(period, sem, true) .success(scheduleRecord => { - $scope.schedule = scheduleData.populate(scheduleRecord.schedule, [ - populate(team.short, 'teacher'), - populate(getCourseNameByID, 'lesson') - ]); + $scope.schedule = scheduleRecord.schedule; - if (doUpdateURL) $location.url(url); + if (doUpdateURL) $location.url(api.schedule.buildScheduleUrl(period, sem)); }); } };