From 8cc5c59563938b03aa347557e05b6e789e4d82fd Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 22 Feb 2016 04:45:38 +0300 Subject: [PATCH] ScheduleController update --- src/client/controllers/ScheduleController.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/client/controllers/ScheduleController.js b/src/client/controllers/ScheduleController.js index 3a435303..29190e35 100644 --- a/src/client/controllers/ScheduleController.js +++ b/src/client/controllers/ScheduleController.js @@ -1,7 +1,7 @@ import {populate} from '../../utils/populate'; import {getCourseNameByID} from '../../models/course'; import {indexEquals} from '../../utils/common'; -import {select} from '../../utils/common'; +import {select, choise} from '../../utils/common'; function isRequested(period, semester) { return function (schedule) { @@ -17,6 +17,11 @@ export default function (app) { let current_semester = $routeParams.semester; let isScheduleRequested = current_period && current_semester; + let getScheduleByID = (id) => choise( + $scope.schedules, + select(i => i._id === id) + ); + $http.get('/schedules', {cache: true}) .success(schedules => { // By url params or last element @@ -63,14 +68,5 @@ export default function (app) { }); } }; - - function getScheduleByID(id) { - let schedules = $scope.schedules; - for (let i = 0, l = schedules.length; i < l; i++) { - let s = schedules[i]; - if (id === s._id) return s; - } - return null; - } }); };