Schedule ES6 update
This commit is contained in:
1 parent
b9526ad1a6
commit
9025044ae5
19 files changed
+249
-223
No files matched your search
+12
-6
@@ -12,6 +12,11 @@ import Timeline from './components/Timeline';
|
||||
import TimelineRecord from './components/TimelineRecord';
|
||||
import TimelineRecordPost from './components/TimelineRecordPost';
|
||||
import TimelineRecordInstagram from './components/TimelineRecordInstagram';
|
||||
import Schedule from './components/Schedule';
|
||||
import ScheduleTable from './components/ScheduleTable';
|
||||
import ScheduleSlider from './components/ScheduleSlider';
|
||||
import ScheduleSlide from './components/ScheduleSlide';
|
||||
import ScheduleRecord from './components/ScheduleRecord';
|
||||
import AppController from './controllers/AppController';
|
||||
import HomeController from './controllers/HomeController';
|
||||
import ScheduleController from './controllers/ScheduleController';
|
||||
@@ -29,17 +34,13 @@ import IOService from './services/io';
|
||||
import MenuService from './services/menu';
|
||||
import api from './api/api';
|
||||
|
||||
let deps = [
|
||||
require('./modules/schedule')
|
||||
].map(m => m.name);
|
||||
|
||||
let app = angular.module('hudozka', deps.concat([
|
||||
let app = angular.module('hudozka', [
|
||||
'hudozhka.data',
|
||||
'ngRoute',
|
||||
'angulartics',
|
||||
'angulartics.google.analytics',
|
||||
'angularSpinner'
|
||||
]));
|
||||
]);
|
||||
|
||||
app.config(($locationProvider, $routeProvider) => {
|
||||
$locationProvider.hashPrefix('!');
|
||||
@@ -129,6 +130,11 @@ app.run(($location, $rootScope, $http) => {
|
||||
DocumentsController,
|
||||
CopyrightController,
|
||||
ContactsController,
|
||||
Schedule,
|
||||
ScheduleTable,
|
||||
ScheduleSlider,
|
||||
ScheduleSlide,
|
||||
ScheduleRecord,
|
||||
function (app) {
|
||||
app.controller('HomePageController', ($scope) => {
|
||||
$scope.pageClass = 'page-home';
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import template from '../../templates/components/schedule.html';
|
||||
|
||||
export default function(app) {
|
||||
app.component('schedule', {
|
||||
bindings: {
|
||||
schedule: '<'
|
||||
},
|
||||
template: template,
|
||||
controller: function () {
|
||||
this.type = 'table';
|
||||
|
||||
try {
|
||||
if (window.matchMedia('(max-device-width: 30em)').matches) {
|
||||
this.type = 'slider';
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import template from '../../templates/components/schedule-record.html';
|
||||
|
||||
export default function(app) {
|
||||
app.component('scheduleRecord', {
|
||||
bindings: {
|
||||
record: '<',
|
||||
i: '<'
|
||||
},
|
||||
template: template
|
||||
})
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import template from '../../templates/components/schedule-slide.html';
|
||||
|
||||
export default function(app) {
|
||||
app.component('scheduleSlide', {
|
||||
bindings: {
|
||||
day: '<'
|
||||
},
|
||||
template: template
|
||||
})
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
import template from '../../templates/components/schedule-slider.html';
|
||||
import {getDates} from '../../utils/date';
|
||||
|
||||
function week(schedule) {
|
||||
let now = new Date();
|
||||
let dates = getDates(now);
|
||||
|
||||
return ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота']
|
||||
.map((day, i) => {
|
||||
return {
|
||||
current: i === now.getDay() - 1,
|
||||
day: day,
|
||||
date: dates[i],
|
||||
groups: schedule.map(group => {
|
||||
return {
|
||||
name: group.name,
|
||||
time: group.time,
|
||||
content: group.days[i]
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default function(app) {
|
||||
app.directive('scheduleSlider', ($compile) => {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: template,
|
||||
scope:{
|
||||
schedule: '='
|
||||
},
|
||||
link: function (scope, element) {
|
||||
let $slick = element.find('.schedule-slick');
|
||||
|
||||
scope.$watch('schedule', value => {
|
||||
try {
|
||||
$slick.slick('unslick');
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
if (value) {
|
||||
let days = week(value);
|
||||
scope.days = days;
|
||||
|
||||
$slick.html(
|
||||
days.map((day, i) => {
|
||||
return `<schedule-slide day="days[${i}]"></schedule-slide>`
|
||||
}).join('')
|
||||
).show();
|
||||
$compile($slick.contents())(scope);
|
||||
|
||||
$slick.slick({
|
||||
mobileFirst: true,
|
||||
infinite: false,
|
||||
dots: false,
|
||||
arrows: false,
|
||||
touchThreshold: 20,
|
||||
speed: 250,
|
||||
slidesToShow: 1,
|
||||
centerMode: false
|
||||
});
|
||||
|
||||
let now = new Date();
|
||||
let currentWeekIndex = now.getDay() - 1;
|
||||
$slick.slick('slickGoTo', currentWeekIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
import template from '../../templates/components/schedule-table.html';
|
||||
import {getDates} from '../../utils/date';
|
||||
|
||||
export default function(app) {
|
||||
app.component('scheduleTable', {
|
||||
bindings: {
|
||||
schedule: '<'
|
||||
},
|
||||
template: template,
|
||||
controller: function () {
|
||||
const now = new Date();
|
||||
const dates = getDates(now);
|
||||
|
||||
this.isToday = weekDayIndex => (now.getDay() - 1) === weekDayIndex;
|
||||
this.weekDay = weekDayIndex => dates[weekDayIndex];
|
||||
|
||||
//var $tbody = element.find('table tbody');
|
||||
//var $thead = element.find('table thead');
|
||||
|
||||
//let setHeadWidth = () => {
|
||||
// var $td_list = element.find('table tbody tr:first-child td');
|
||||
// $td_list.each(function (i) {
|
||||
// var w = this.offsetWidth;
|
||||
// $thead.find('th')[i].style.width = `${w}px`;
|
||||
// });
|
||||
//};
|
||||
|
||||
//let resetHeadWidth = () => {
|
||||
// var $td_list = element.find('table tbody tr:first-child td');
|
||||
// $td_list.each(function (i) {
|
||||
// var w = this.offsetWidth;
|
||||
// $thead.find('th')[i].style.width = null;
|
||||
// });
|
||||
//};
|
||||
|
||||
//var min;
|
||||
//var max;
|
||||
//$(window).scroll(function () {
|
||||
// const scrollOffset = 150;
|
||||
// if(!min) min = element.find('table tbody tr:first-child')[0].offsetTop + scrollOffset;
|
||||
// if(!max) max = element.find('table tbody tr:last-child')[0].offsetTop + scrollOffset;
|
||||
//
|
||||
// var scroll = $(this).scrollTop();
|
||||
// if (scroll >= min && scroll <= max) {
|
||||
// setHeadWidth();
|
||||
// $thead.addClass('fix animated fadeInDown');
|
||||
// $tbody.addClass('fix');
|
||||
// } else {
|
||||
// resetHeadWidth();
|
||||
// $thead.removeClass('fix animated fadeInDown');
|
||||
// $tbody.removeClass('fix');
|
||||
// }
|
||||
//});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -48,7 +48,7 @@ export default function (app) {
|
||||
$scope.loadSchedule($scope.currentSchedule, isScheduleRequested);
|
||||
});
|
||||
|
||||
$scope.loadSchedule = (s, updateURL) => {
|
||||
$scope.loadSchedule = (s, doUpdateURL) => {
|
||||
let id = s._id;
|
||||
let schedule_item = getScheduleByID(id);
|
||||
|
||||
@@ -59,12 +59,12 @@ export default function (app) {
|
||||
let url = `/schedule/${period}/${sem}`;
|
||||
$http.get(url, {cache: true})
|
||||
.success(scheduleRecord => {
|
||||
$scope.groups = scheduleData.populate(scheduleRecord.schedule, [
|
||||
$scope.schedule = scheduleData.populate(scheduleRecord.schedule, [
|
||||
populate(team.short, 'teacher'),
|
||||
populate(getCourseNameByID, 'lesson')
|
||||
]);
|
||||
|
||||
if (updateURL) $location.url(url);
|
||||
if (doUpdateURL) $location.url(url);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
import {getDates} from '../../utils/date';
|
||||
|
||||
module.exports = angular.module('hudozka.schedule', [])
|
||||
.directive('schedule', function ($compile) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
groups: '='
|
||||
},
|
||||
link: function (scope, element) {
|
||||
var template = `<schedule-table groups="${scope.groups}"></schedule-table>`;
|
||||
|
||||
try {
|
||||
if (window.matchMedia('(max-device-width: 30em)').matches) {
|
||||
template = `<schedule-slider groups="${scope.groups}"></schedule-slider>`
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
element.html(template).show();
|
||||
$compile(element.contents())(scope);
|
||||
}
|
||||
};
|
||||
})
|
||||
.directive('scheduleTable', function () {
|
||||
return {
|
||||
templateUrl: '/views/schedule/table.html',
|
||||
link: function (scope, element) {
|
||||
//var this_element = element[0];
|
||||
|
||||
var now = new Date();
|
||||
var dates = getDates(now);
|
||||
|
||||
scope.isToday = function (weekDayIndex) {
|
||||
return (now.getDay() - 1) === weekDayIndex;
|
||||
};
|
||||
|
||||
scope.weekDay = function (weekDayIndex) {
|
||||
return dates[weekDayIndex];
|
||||
};
|
||||
|
||||
var $tbody = element.find('table tbody');
|
||||
var $thead = element.find('table thead');
|
||||
|
||||
let setHeadWidth = () => {
|
||||
var $td_list = element.find('table tbody tr:first-child td');
|
||||
$td_list.each(function (i) {
|
||||
var w = this.offsetWidth;
|
||||
$thead.find('th')[i].style.width = `${w}px`;
|
||||
});
|
||||
};
|
||||
|
||||
let resetHeadWidth = () => {
|
||||
var $td_list = element.find('table tbody tr:first-child td');
|
||||
$td_list.each(function (i) {
|
||||
var w = this.offsetWidth;
|
||||
$thead.find('th')[i].style.width = null;
|
||||
});
|
||||
};
|
||||
|
||||
var min;
|
||||
var max;
|
||||
$(window).scroll(function () {
|
||||
const scrollOffset = 150;
|
||||
if(!min) min = element.find('table tbody tr:first-child')[0].offsetTop + scrollOffset;
|
||||
if(!max) max = element.find('table tbody tr:last-child')[0].offsetTop + scrollOffset;
|
||||
|
||||
var scroll = $(this).scrollTop();
|
||||
if (scroll >= min && scroll <= max) {
|
||||
setHeadWidth();
|
||||
$thead.addClass('fix animated fadeInDown');
|
||||
$tbody.addClass('fix');
|
||||
} else {
|
||||
resetHeadWidth();
|
||||
$thead.removeClass('fix animated fadeInDown');
|
||||
$tbody.removeClass('fix');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.directive('scheduleSlider', function ($compile) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: '<div class="schedule-slick"></div>',
|
||||
|
||||
link: function (scope, element) {
|
||||
var $slick = element.find('.schedule-slick');
|
||||
|
||||
scope.$watch('groups', function (value) {
|
||||
try {
|
||||
$slick.slick('unslick');
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
if (value) {
|
||||
var days = week(value);
|
||||
scope.days = days;
|
||||
|
||||
$slick.html(
|
||||
days.map(function (day, i) {
|
||||
return `<schedule-slide day="days[${i}]"></schedule-slide>`
|
||||
}).join('')
|
||||
).show();
|
||||
$compile($slick.contents())(scope);
|
||||
|
||||
$slick.slick({
|
||||
mobileFirst: true,
|
||||
infinite: false,
|
||||
dots: false,
|
||||
arrows: false,
|
||||
touchThreshold: 20,
|
||||
speed: 250,
|
||||
slidesToShow: 1,
|
||||
centerMode: false
|
||||
});
|
||||
|
||||
var now = new Date();
|
||||
var currentWeekIndex = now.getDay() - 1;
|
||||
$slick.slick('slickGoTo', currentWeekIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.directive('scheduleSlide', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: "/views/schedule/slide.html",
|
||||
scope: {
|
||||
day: '='
|
||||
}
|
||||
}
|
||||
})
|
||||
.directive('scheduleRecord', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: "/views/schedule/record.html",
|
||||
scope: {
|
||||
record: '=',
|
||||
i: '='
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function week(schedule) {
|
||||
var now = new Date();
|
||||
var dates = getDates(now);
|
||||
|
||||
return ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота']
|
||||
.map(function (day, i) {
|
||||
return {
|
||||
current: i === now.getDay() - 1,
|
||||
day: day,
|
||||
date: dates[i],
|
||||
groups: schedule.map(function (group) {
|
||||
return {
|
||||
name: group.name,
|
||||
time: group.time,
|
||||
content: group.days[i]
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user