source files -> src/ folder

This commit is contained in:
tmshv committed 2016-01-09 17:26:44 +03:00
1 parent f006207112
commit d25f4439fa
144 files changed

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
/**
* Created by tmshv on 22/11/14.
*/
var APINews = require("./news");
var APIGallery = require("./gallery");
module.exports = function(app) {
var minute = 1000 * 60;
app.factory("api", function ($http) {
var api = {};
api.news = new APINews($http);
api.gallery = new APIGallery($http, minute);
return api;
});
};
+22
View File
@@ -0,0 +1,22 @@
/**
* Created by tmshv on 22/11/14.
*/
function APIGallery(http){
this.request = http;
}
APIGallery.prototype.year = function(year) {
return this.request.get("/gallery/" + year, {cache: true});
};
APIGallery.prototype.album = function(year, course, album) {
var url = '/gallery/{year}/{course}/{album}'
.replace('{year}', year)
.replace('{course}', course)
.replace('{album}', album);
return this.request.get(url, {cache: true});
};
module.exports = APIGallery;
+15
View File
@@ -0,0 +1,15 @@
/**
* Created by tmshv on 22/11/14.
*/
var query = require("../../utils/net").query;
function APIFeed(http){
this.request = http;
}
APIFeed.prototype.feed = function(count, portion) {
return this.request.get("/news?"+query([["count", count], ["portion", portion]]));
};
module.exports = APIFeed;
+111
View File
@@ -0,0 +1,111 @@
/**
* Created by tmshv on 04/11/14.
*/
var deps = [
require('./modules/schedule')
]
.map(function(m){
return m.name;
});
var app = angular.module("hudozhka", deps.concat([
"hudozhka.data",
"ngRoute",
"angulartics",
"angulartics.google.analytics",
"angularSpinner"
]));
app.config(function ($locationProvider, $routeProvider) {
$locationProvider.hashPrefix("!");
$locationProvider.html5Mode(true);
var routes = [
{
name: "/",
templateUrl: "/views/home.html",
controller: "HomePageController",
title: "ДХШ Шлиссельбурга"
},
{
name: "/schedule/:period?/:semester?",
templateUrl: "/views/schedule.html",
controller: "SchedulePageController",
title: "Расписание"
},
{
name: "/team",
templateUrl: "/views/team.html",
controller: "TeamPageController",
title: "Преподаватели"
},
{
name: "/gallery",
templateUrl: "/views/gallery.html",
controller: "GalleryPageController",
title: "Работы учащихся"
},
{
name: "/gallery/:year/:course/:album",
templateUrl: "/views/gallery-album.html",
controller: "AlbumPageController"
},
{
name: "/docs",
templateUrl: "/views/docs.html",
controller: "DocsPageController",
title: "Документы"
}
];
routes.forEach(function (route) {
if (typeof route === 'function') route = route();
$routeProvider.when(route.name, route);
});
$routeProvider.otherwise({
templateUrl: "/404.html"
});
});
app.run(function ($location, $rootScope, $http) {
$rootScope.$on("$routeChangeSuccess", function (event, current) {
var title = current["$$route"].title;
if (title) $rootScope.title = title;
});
$http.defaults.headers.common["Accept"] = "application/json";
});
require("./api/api")(app);
require("./services/io")(app);
require("./directives/mainMenu")(app);
require("./directives/teamMemberProfile")(app);
require("./directives/backgroundPicture")(app);
require("./ui/menu")(app);
require("./ui/breadcrumbs")(app);
require("./ui/timeline")(app);
require("./filters/strip")(app);
require("./filters/remove-hashtags")(app);
require("./filters/removeNewline")(app);
require("./filters/uppercase-first")(app);
require("./pages/home")(app);
require("./pages/schedule")(app);
require("./pages/team")(app);
require("./pages/gallery")(app);
require("./pages/docs")(app);
require("./controllers/ContactsController")(app);
require("./controllers/CopyrightController")(app);
app.controller("SchedulePageController", function ($scope) {
$scope.pageClass = "page-schedule";
});
app.controller("DocsPageController", function ($scope) {
$scope.pageClass = "page-docs";
});
app.controller("AppController", function ($scope, menu) {
$scope.menuProvider = menu.items;
});
@@ -0,0 +1,7 @@
module.exports = function (app) {
app.controller('ContactsController', function ($scope, config) {
$scope.address = config.address;
$scope.telephone = config.telephone;
$scope.email = config.email;
});
};
@@ -0,0 +1,17 @@
module.exports = function (app) {
app.controller('CopyrightController', function ($scope, $rootScope) {
$scope.developer = true;
$scope.now = new Date().getFullYear();
$rootScope.$on('$routeChangeSuccess', function (event, current) {
var originalPath;
try{
originalPath = current['$$route'].originalPath;
}catch(e){
originalPath = null;
}
$scope.developer = originalPath == '/';
});
});
};
+24
View File
@@ -0,0 +1,24 @@
/**
* Created by tmshv on 06/11/14.
*/
angular.module("hudozhka.data", [])
.service("team", function () {
return require("../models/team");
})
.service("scheduleData", function () {
return require("../models/schedule");
})
.service("docs", function () {
return require("../models/document");
})
.service("config", function(){
return {
telephone: "+7 (81362) 76-312",
email: "hudozka@gmail.com",
address: ["г. Шлиссельбург", "ул. 18 января", "д. 3"]
.reduce(function(address, item){
return address + (address == '' ? '' : ' ') + item.replace(' ', String.fromCharCode(0xA0));
}, '')
};
});
@@ -0,0 +1,26 @@
module.exports = function (app) {
app.directive('backgroundPicture', function () {
return {
restrict: 'E',
template: '<div class="background-picture" />',
scope: {
src: '='
},
link: function($scope, $element){
var element = $element.find('.background-picture').get(0);
element.style.backgroundImage = `url('${$scope.src}')`;
setTimeout(function () {
var w = element.offsetWidth;
var h = element.offsetHeight;
if (w > h) {
element.classList.add('horizontal');
} else {
element.classList.add('vertical');
}
}, 100);
}
}
});
};
+24
View File
@@ -0,0 +1,24 @@
module.exports = function (app) {
app.directive('mainMenu', function (menu) {
return {
restrict: 'E',
templateUrl: '/views/menu.html',
scope: {
menu: '=items'
},
link: function(scope, element){
scope.isActive = function (item) {
if (menu.current) {
return item.url == menu.current.url;
} else {
return false;
}
};
scope.isValid = function (item) {
return 'url' in item;
};
}
}
});
};
@@ -0,0 +1,13 @@
module.exports = function (app) {
app.directive('teamMemberProfile', function (menu) {
return {
restrict: 'E',
templateUrl: '/views/team/profile.html',
scope: {
person: '=profile'
},
link: function(scope, element){
}
}
});
};
+30
View File
@@ -0,0 +1,30 @@
var app = angular.module("hudozhka.document", [
"hudozhka.data",
"angulartics",
"angulartics.google.analytics"
]);
app.factory("docname", function ($location) {
return function(){
var abs = $location.absUrl();
var doc_uri = /\/([\w-]+)$/.exec(abs);
if(doc_uri.length >= 2) {
return doc_uri[1];
}else{
return null;
}
}
});
app.controller("DocumentController", function ($rootScope, $scope, docs, docname) {
$scope.pageClass = "page-document";
var n = docname();
if(n) {
var d = docs.doc(n);
$scope.document = d;
$rootScope.title = d.title;
}
});
require("./filters/uppercase-first")(app);
+11
View File
@@ -0,0 +1,11 @@
/**
* Created by tmshv on 21/11/14.
*/
module.exports = function(app) {
app.filter("removeHashtags", function () {
return function(string) {
return string.replace(/(#[^\s]+)/g, '');
};
});
};
+11
View File
@@ -0,0 +1,11 @@
/**
* Created by tmshv on 21/11/14.
*/
module.exports = function(app) {
app.filter("removeNewline", function () {
return function(string) {
return string.replace(/(\n)/g, ' ');
};
});
};
+13
View File
@@ -0,0 +1,13 @@
/**
* Created by tmshv on 21/11/14.
*/
module.exports = function(app) {
app.filter("strip", function () {
return function(string) {
return string
.replace(/^\s+/, '')
.replace(/\s+$/, '');
};
});
};
+11
View File
@@ -0,0 +1,11 @@
/**
* Created by tmshv on 21/11/14.
*/
module.exports = function(app) {
app.filter("uppercaseFirst", function () {
return function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
};
});
};
+28
View File
@@ -0,0 +1,28 @@
/**
* Created by tmshv on 06/11/14.
*/
angular.module("hudozhka.instagram", [])
.controller("InstagramController", function($scope, $http, $window){
//$scope.auth = function() {
// $http.get("/instagram/auth/url")
// .success(function (data) {
// $window.location.href = data.url;
// });
//};
$http.get("/instagram/user")
.error(function() {
})
.success(function (user) {
$scope.user = user;
});
$scope.invite = function() {
$http.get("/instagram/invite")
.success(function (data) {
$scope.inviteCode = data.code;
});
};
});
+155
View File
@@ -0,0 +1,155 @@
var getDates = require('../../utils/date').getDates;
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');
var $td_list = [];
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;
if(!$td_list.length) $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`;
});
var scroll = $(this).scrollTop();
if (scroll >= min && scroll <= max) {
$thead.addClass('fix animated fadeInDown');
$tbody.addClass('fix');
} else {
$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]
}
})
}
});
}
+48
View File
@@ -0,0 +1,48 @@
module.exports = function (app) {
app.controller("DocumentsController", function ($scope, docs) {
$scope.documents = docs.docs;
});
};
/**
* Generates list of numbers
* @param {Number} start starting value
* @param {Number} num amount of numbers in list
* @param {Number} step difference value
* @return {Array} list of numbers
*/
function range(start, num, step) {
var list = [];
var val = start;
for (var i = 0; i < num; i++) {
list.push(val);
val += step;
}
return list;
}
///**
// * Monday date of current week
// * @param {[type]} d [description]
// * @return {[type]} [description]
// */
//function getMonday(d) {
// d = new Date(d);
// var day = d.getDay();
// var diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
// return new Date(d.setDate(diff));
//}
function getDates(day) {
var dates = [];
var prev = day == 0 ? 0 : day - 1;
var next = 6 - prev;
var dayMask = range(-1, prev, -1).concat([0]).concat(range(1, next, 1));
dayMask.forEach(function (m) {
var time = Date.now() + (1000 * 60 * 60 * 24) * m;
var date = new Date(time);
dates.push(date.getDate());
});
return dates;
}
+114
View File
@@ -0,0 +1,114 @@
module.exports = function (app) {
app.directive("gFotorama", function () {
return {
restrict: "A",
link: function (scope, element, attrs) {
element.addClass('fotorama');
var $fotorama = $(element.fotorama());
var fotorama = $fotorama.data('fotorama');
fotorama.setOptions({
width: "100%",
maxheight: 500,
loop: true,
nav: "thumbs"
});
//$fotorama.on('fotorama:show', function (e, fotorama, extra) {
$fotorama.on('fotorama:error', function (e, fotorama, extra) {
console.log('## ' + e.type);
console.log('active frame', fotorama.activeFrame);
console.log('additional data', extra);
});
scope.$watch(attrs.gFotorama, function (value) {
console.log(value);
fotorama.load(value);
});
}
}
});
app.controller("GalleryPageController", function ($scope, api) {
$scope.years = [];
var years = [2015, 2014, 2013, 2012, 2011, 2010];
years.forEach(function (year, year_index) {
api.gallery.year(year)
.success(function (albums) {
if (albums.length) {
$scope.years[year_index] = {
year: year,
albums: albums.map(function (album) {
var preview = album.content[0];
album.preview_url = preview.content.medium.url;
//album.fotorama = album.content.map(productToFotorama);
return album;
})
};
}
})
});
}
);
app.controller("AlbumPageController", function ($scope, $rootScope, $http, $routeParams, team, api, menu) {
menu.activate('/gallery');
var year_uri = $routeParams.year;
var course_uri = $routeParams.course;
var album_uri = $routeParams.album;
api.gallery.album(
year_uri,
course_uri,
album_uri
)
.success(function (album) {
//var preview = album.content[0];
//album.preview_url = preview.content.medium.url;
//album.fotorama = album.content.map(productToFotorama);
album.teacherName = team.name(album['teacher']);
$scope.album = album;
$scope.crumbs = [
{
url: '/gallery',
name: 'Галерея'
},
{
//url: '/gallery/{year}'.replace('{year}', year_uri),
name: year_uri
},
{
//url: '/gallery/{year}/{course}'
// .replace('{year}', year_uri)
// .replace('{course}', course_uri),
name: album.course
},
{
name: album.title
}
];
$rootScope.title = album.title;
});
});
};
function productToFotorama(product) {
//var tpl = '<div class="album-item"><div><p>' + product.author + '</p><p>' + product.authorAge + ' лет</p></div></div>';
var $e = $('<div class="album-item"><div></div></div>');
var $c = $e.find('.album-item div');
$('<p></p>').text(product.author).appendTo($c);
if (product['authorAge']) {
$('<p></p>').text(product['authorAge'] + ' лет').appendTo($c);
}
return {
img: product.content["big"].url,
thumb: product.content["small"].url,
full: product.content["original"].url,
//html: $.parseHTML(tpl)[0]
html: $e
};
}
+38
View File
@@ -0,0 +1,38 @@
/**
* Created by tmshv on 22/11/14.
*/
module.exports = function (app) {
app.controller('HomePageController', function ($scope, config) {
var fotorama;
$scope.pageClass = 'page-home';
var $tape = $('.tape-block');
var $fotorama = $tape.find('.tape-block__content');
$tape.addClass('simplified');
$fotorama.on('fotorama:ready', function () {
$tape.removeClass('simplified');
fotorama.setOptions({
nav: 'dots',
transition: 'crossfade',
autoplay: '6000',
arrows: 'false',
width: '100%',
fit: 'cover',
loop: 'true'
});
});
fotorama = $fotorama.fotorama().data('fotorama');
setTimeout(function(){
fotorama.load([
{img: 'https://static.shburg.org/art/img/cat1.jpg'},
{img: 'https://static.shburg.org/art/img/cat2.jpg'},
{img: 'https://static.shburg.org/art/img/cat3.jpg'}
]);
}, 100);
});
};
+81
View File
@@ -0,0 +1,81 @@
var populate = require('../../utils/populate').populate;
const course = require('../../models/course');
function indexEquals(i) {
return function (_, index) {
return i === index;
}
}
function isRequested(period, semester) {
return function (schedule) {
return schedule.period === period && schedule.semester === semester;
}
}
module.exports = function (app) {
app.controller('ScheduleController', function ($scope, $http, $location, $routeParams, scheduleData, team, menu) {
menu.activate('/schedule');
var current_period = $routeParams.period;
var current_semester = $routeParams.semester;
var isScheduleRequested = current_period && current_semester;
$http.get("/schedules", {cache: true})
.success(function (schedules) {
// By url params or last element
var select_fn = isScheduleRequested ? isRequested(current_period, current_semester) : indexEquals(schedules.length - 1);
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} ${schedule.period} года`;
return schedule;
});
schedules.forEach(function (schedule, i) {
if (select_fn(schedule, i)) {
$scope.currentSchedule = schedules[i];
}
});
$scope.schedules = schedules;
$scope.loadSchedule($scope.currentSchedule, isScheduleRequested);
});
$scope.loadSchedule = function (s, updateURL) {
var id = s._id;
var schedule_item = getScheduleByID(id);
if (schedule_item) {
var sem = schedule_item.semester;
var period = schedule_item.period;
var url = `/schedule/${period}/${sem}`;
$http.get(url, {cache: true})
.success(function (scheduleRecord) {
$scope.groups = scheduleData.populate(scheduleRecord.schedule, [
populate(team.short, 'teacher'),
populate(course.name, 'lesson')
]);
if (updateURL) {
$location.url(url);
}
});
}
};
function getScheduleByID(id) {
var schedules = $scope.schedules;
for (var i = 0, l = schedules.length; i < l; i++) {
var s = schedules[i];
if (id === s._id) return s;
}
return null;
}
});
};
+13
View File
@@ -0,0 +1,13 @@
var populate = require('../../utils/populate').populate;
const course = require('../../models/course');
module.exports = function (app) {
app.controller('TeamPageController', function ($scope, team) {
$scope.pageClass = 'page-team';
$scope.teamMembers = team.team.map(function (person) {
person.names = team.splitName(person.name);
return person;
});
});
};
+15
View File
@@ -0,0 +1,15 @@
/**
* Created by tmshv on 15/03/15.
*/
module.exports = function (app) {
var socket;
function init(){
socket = io();
}
app.service("io", function () {
if (!socket) init();
return socket;
});
};
+11
View File
@@ -0,0 +1,11 @@
module.exports = function(app) {
app.directive('breadcrumbs', function () {
return {
restrict: 'E',
templateUrl: '/views/breadcrumbs.html',
scope: {
crumbs: '='
}
};
});
};
+34
View File
@@ -0,0 +1,34 @@
/**
* Created by tmshv on 05/11/14.
*/
module.exports = function (app) {
app.factory("menu", function ($route, $rootScope) {
function Menu() {
this.items = require("../../models/menu.json");
this.current = null;
}
Menu.prototype.activate = function (path) {
var f = this.items.filter(function (i) {
return i.url === path;
});
if(f.length) {
this.current = f[0];
}
};
var menu = new Menu();
$rootScope.$on('$routeChangeSuccess', function (event, current) {
try{
var path = current['$$route'].originalPath;
menu.activate(path);
}catch(e){
}
});
return menu;
});
};
+147
View File
@@ -0,0 +1,147 @@
/**
* Created by tmshv on 23/11/14.
*/
function personByInstagram(list, instagram){
list = list.filter(function (member) {
try {
return member.contacts.instagram === instagram;
} catch (error) {
return false;
}
});
if(list.length){
return list[0].id;
}else{
return null;
}
}
function postText(post){
try{
return post.data.caption.text.replace(/#[\w_]+/, "")
}catch(error){
return "";
}
}
module.exports = function(app) {
app.directive("timeline", function (team) {
function toInstagram(post){
var author_id = personByInstagram(team.team, post.data.author);
var name = author_id ? team.short(author_id) : post.data.author;
return {
date: post.date,
image: post.data.image.standard_resolution.url,
url: post.data.url,
username: name,
userpic: 'https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/11357496_464997000344800_2124591831_a.jpg',
text: post.body,
//text: postText(post),
type: post.type
};
}
return {
templateUrl: "/views/timeline.html",
scope: {
},
link: function(scope, element, attrs){
scope.isEven = function(index){
return index % 2 === 1;
}
},
controller: function($scope, $timeout, usSpinnerService, io, api){
var portion = 0;
var count = 10;
$scope.feed = [];
$scope.timelineUpdating = false;
usSpinnerService.stop("timelineMore");
//usSpinnerService.spin("timelineMore");
$scope.recordClass = function (i) {
return i['type'];
};
$scope.showFooter = function () {
var canLoadMore = true;
return $scope.feed && $scope.feed.length && canLoadMore;
};
$scope.loadNext = function () {
$scope.timelineUpdating = true;
usSpinnerService.spin("timelineMore");
api.news.feed(count, portion)
.error(function(error) {
console.log(error);
})
.success(function (list) {
$scope.timelineUpdating = false;
usSpinnerService.stop("timelineMore");
var feed = list.map(function (post) {
if(post.type == "instagram") return toInstagram(post);
else return post;
});
portion++;
$scope.feed = $scope.feed.concat(feed);
});
};
$scope.loadNext();
io.on("post", function (params) {
var posts = params instanceof Array ? params : [params];
var feed = posts.map(function (post) {
if(post.type == "instagram") return toInstagram(post);
else return post;
});
$scope.$apply(function () {
$scope.feed = feed.concat($scope.feed);
});
});
}
};
});
app.directive("timelineRecord", function ($compile, $http, $sce, team) {
var templates = {
"post": ["/views/timeline-post.html", linkPost],
"instagram": ["/views/timeline-gram.html", linkGram]
};
function linkPost(scope, element, attrs) {
scope.message = $sce.trustAsHtml(scope.post.body);
}
function linkGram(scope, element, attrs) {
}
return {
restrict: "E",
scope: {
post:"=content"
},
link: function(scope, element, attrs){
var type = scope.post.type;
if(type in templates) {
$http.get(templates[type][0])
.success(function (tpl) {
element.html(tpl).show();
$compile(element.contents())(scope);
templates[type][1](scope, element, attrs);
});
}
}
};
});
};