angulared
This commit is contained in:
1 parent
7391872813
commit
efd77a62e3
36 files changed
+1149
-547
No files matched your search
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Created by tmshv on 04/11/14.
|
||||
*/
|
||||
|
||||
var app = angular.module("hudozhka", ["ngRoute", "data.hudozhka"]);
|
||||
|
||||
app.config(function ($locationProvider, $routeProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
|
||||
var routes = [
|
||||
{
|
||||
name: "/",
|
||||
templateUrl: "/views/home.html",
|
||||
controller: "HomePageController"
|
||||
},
|
||||
{
|
||||
name: "/schedule",
|
||||
templateUrl: "/views/schedule.html",
|
||||
controller: "SchedulePageController"
|
||||
},
|
||||
{
|
||||
name: "/team",
|
||||
templateUrl: "/views/team.html",
|
||||
controller: "TeamPageController"
|
||||
},
|
||||
{
|
||||
name: "/docs",
|
||||
templateUrl: "/views/docs.html",
|
||||
controller: "DocsPageController"
|
||||
}
|
||||
];
|
||||
|
||||
routes.forEach(function (route) {
|
||||
$routeProvider.when(route.name, route);
|
||||
});
|
||||
|
||||
$routeProvider.otherwise({
|
||||
redirectTo: "/"
|
||||
});
|
||||
});
|
||||
|
||||
require("./ui/menu")(app);
|
||||
require("./filters/uppercase-first")(app);
|
||||
require("./pages/schedule")(app);
|
||||
require("./pages/team")(app);
|
||||
require("./pages/docs")(app);
|
||||
|
||||
app.controller("HomePageController", function ($scope) {
|
||||
$scope.pageClass = "page-home";
|
||||
});
|
||||
|
||||
app.controller("SchedulePageController", function ($scope) {
|
||||
$scope.pageClass = "page-schedule";
|
||||
});
|
||||
|
||||
app.controller("TeamPageController", function ($scope) {
|
||||
$scope.pageClass = "page-team";
|
||||
});
|
||||
|
||||
app.controller("DocsPageController", function ($scope) {
|
||||
$scope.pageClass = "page-docs";
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Created by tmshv on 06/11/14.
|
||||
*/
|
||||
|
||||
angular.module("data.hudozhka", [])
|
||||
.service("team", function () {
|
||||
return require("../models/team");
|
||||
})
|
||||
.service("schedule", function () {
|
||||
return require("../models/schedule");
|
||||
})
|
||||
.service("docs", function () {
|
||||
return require("../models/document");
|
||||
});
|
||||
+148
-128
@@ -1,132 +1,152 @@
|
||||
var Doc = (function(){
|
||||
var Document = function(baseURL){
|
||||
this.pages = [];
|
||||
this.baseURL = baseURL;
|
||||
}
|
||||
|
||||
Document.prototype.hasPage = function(index){
|
||||
return index >= 0 && index < this.pages.length;
|
||||
}
|
||||
|
||||
Document.prototype.getPageURL = function(pageNumber){
|
||||
var s = pageNumber <2 ? "" : "/" + pageNumber;
|
||||
return this.baseURL + s;
|
||||
}
|
||||
|
||||
Document.prototype.page = function(index){
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
return Document;
|
||||
})();
|
||||
var app = angular.module("document.hudozhka", ["ngRoute", "data.hudozhka"]);
|
||||
|
||||
(function(){
|
||||
const PAGES = [];
|
||||
var currentPageIndex = 0;
|
||||
var doc = new Doc(location.pathname.replace(/\/\d+$/, ""));
|
||||
$(document).ready(function(){
|
||||
try{
|
||||
var hrefPage = /\/(\d+)$/.exec(location.href)[1];
|
||||
currentPageIndex = parseInt(hrefPage) - 1;
|
||||
}catch(error){
|
||||
app.config(function ($locationProvider, $routeProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
//$routeProvider
|
||||
// .when("/document/:doc", {
|
||||
// controller: "DocumentPageController"
|
||||
// })
|
||||
// .otherwise({
|
||||
// redirectTo: "/"
|
||||
// });
|
||||
});
|
||||
|
||||
}
|
||||
app.controller("DocumentPageController", function ($scope, $location, docs) {
|
||||
$scope.pageClass = "page-document";
|
||||
|
||||
$("#buttonNext").click(function(event){
|
||||
loadNext();
|
||||
});
|
||||
var doc = $location.$$path.replace("/document/", "");
|
||||
$scope.doc = docs.doc(doc);
|
||||
});
|
||||
|
||||
$("#buttonPrev").click(function(event){
|
||||
loadPrevious();
|
||||
});
|
||||
|
||||
$("#page-container .pf").each(function(index, elem){
|
||||
var url = $(elem).data("page-url");
|
||||
doc.pages.push(url);
|
||||
});
|
||||
|
||||
$("#currentPage").attr("max", doc.pages.length);
|
||||
$("#totalPages").text(doc.pages.length);
|
||||
$("#currentPage").change(function(){
|
||||
var i = parseInt($(this).val()) - 1;
|
||||
if(i && doc.hasPage(i)){
|
||||
loadPage(i);
|
||||
}
|
||||
});
|
||||
|
||||
$("#page-container").html("");
|
||||
loadPage(currentPageIndex);
|
||||
|
||||
window.addEventListener("popstate", function(event){
|
||||
console.log("pops");
|
||||
console.log(event);
|
||||
var i = event.state;
|
||||
loadPage(i);
|
||||
});
|
||||
});
|
||||
|
||||
function loadNext(){
|
||||
var i = currentPageIndex + 1;
|
||||
if(doc.hasPage(i)){
|
||||
loadPage(i);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function loadPrevious(){
|
||||
var i = currentPageIndex - 1;
|
||||
if(doc.hasPage(i)){
|
||||
loadPage(i);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function loadPage(index){
|
||||
if(doc.hasPage(index)){
|
||||
var url = doc.pages[index];
|
||||
// $.ajax(
|
||||
// url,
|
||||
|
||||
// {
|
||||
// xhrFields: {
|
||||
// crossDomain: true,
|
||||
// withCredentials: true
|
||||
// },
|
||||
|
||||
// success: function(data, status){
|
||||
// currentPageIndex = index;
|
||||
// $("#currentPage").val(doc.page(currentPageIndex));
|
||||
// $("#page-container").html(data);
|
||||
|
||||
// var p = doc.page(currentPageIndex);
|
||||
// console.log("look at page ", p);
|
||||
// window.history.pushState(
|
||||
// currentPageIndex,
|
||||
// "State 2013 — " + p,
|
||||
// doc.getPageURL(p)
|
||||
// );
|
||||
// },
|
||||
|
||||
// error: function(xhr, aaa, error){
|
||||
// console.log(error);
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
$.get(url, function(data){
|
||||
currentPageIndex = index;
|
||||
$("#currentPage").val(doc.page(currentPageIndex));
|
||||
$("#page-container").html(data);
|
||||
|
||||
var p = doc.page(currentPageIndex);
|
||||
console.log("look at page ", p);
|
||||
window.history.pushState(
|
||||
currentPageIndex,
|
||||
"State 2013 — " + p,
|
||||
doc.getPageURL(p)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
//var Doc = (function(){
|
||||
// var Document = function(baseURL){
|
||||
// this.pages = [];
|
||||
// this.baseURL = baseURL;
|
||||
// }
|
||||
//
|
||||
// Document.prototype.hasPage = function(index){
|
||||
// return index >= 0 && index < this.pages.length;
|
||||
// }
|
||||
//
|
||||
// Document.prototype.getPageURL = function(pageNumber){
|
||||
// var s = pageNumber <2 ? "" : "/" + pageNumber;
|
||||
// return this.baseURL + s;
|
||||
// }
|
||||
//
|
||||
// Document.prototype.page = function(index){
|
||||
// return index + 1;
|
||||
// }
|
||||
//
|
||||
// return Document;
|
||||
//})();
|
||||
//
|
||||
//(function(){
|
||||
// const PAGES = [];
|
||||
// var currentPageIndex = 0;
|
||||
// var doc = new Doc(location.pathname.replace(/\/\d+$/, ""));
|
||||
// $(document).ready(function(){
|
||||
// try{
|
||||
// var hrefPage = /\/(\d+)$/.exec(location.href)[1];
|
||||
// currentPageIndex = parseInt(hrefPage) - 1;
|
||||
// }catch(error){
|
||||
//
|
||||
// }
|
||||
//
|
||||
// $("#buttonNext").click(function(event){
|
||||
// loadNext();
|
||||
// });
|
||||
//
|
||||
// $("#buttonPrev").click(function(event){
|
||||
// loadPrevious();
|
||||
// });
|
||||
//
|
||||
// $("#page-container .pf").each(function(index, elem){
|
||||
// var url = $(elem).data("page-url");
|
||||
// doc.pages.push(url);
|
||||
// });
|
||||
//
|
||||
// $("#currentPage").attr("max", doc.pages.length);
|
||||
// $("#totalPages").text(doc.pages.length);
|
||||
// $("#currentPage").change(function(){
|
||||
// var i = parseInt($(this).val()) - 1;
|
||||
// if(i && doc.hasPage(i)){
|
||||
// loadPage(i);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// $("#page-container").html("");
|
||||
// loadPage(currentPageIndex);
|
||||
//
|
||||
// window.addEventListener("popstate", function(event){
|
||||
// console.log("pops");
|
||||
// console.log(event);
|
||||
// var i = event.state;
|
||||
// loadPage(i);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// function loadNext(){
|
||||
// var i = currentPageIndex + 1;
|
||||
// if(doc.hasPage(i)){
|
||||
// loadPage(i);
|
||||
// }else{
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// function loadPrevious(){
|
||||
// var i = currentPageIndex - 1;
|
||||
// if(doc.hasPage(i)){
|
||||
// loadPage(i);
|
||||
// }else{
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// function loadPage(index){
|
||||
// if(doc.hasPage(index)){
|
||||
// var url = doc.pages[index];
|
||||
// // $.ajax(
|
||||
// // url,
|
||||
//
|
||||
// // {
|
||||
// // xhrFields: {
|
||||
// // crossDomain: true,
|
||||
// // withCredentials: true
|
||||
// // },
|
||||
//
|
||||
// // success: function(data, status){
|
||||
// // currentPageIndex = index;
|
||||
// // $("#currentPage").val(doc.page(currentPageIndex));
|
||||
// // $("#page-container").html(data);
|
||||
//
|
||||
// // var p = doc.page(currentPageIndex);
|
||||
// // console.log("look at page ", p);
|
||||
// // window.history.pushState(
|
||||
// // currentPageIndex,
|
||||
// // "State 2013 — " + p,
|
||||
// // doc.getPageURL(p)
|
||||
// // );
|
||||
// // },
|
||||
//
|
||||
// // error: function(xhr, aaa, error){
|
||||
// // console.log(error);
|
||||
// // }
|
||||
// // }
|
||||
// // );
|
||||
// $.get(url, function(data){
|
||||
// currentPageIndex = index;
|
||||
// $("#currentPage").val(doc.page(currentPageIndex));
|
||||
// $("#page-container").html(data);
|
||||
//
|
||||
// var p = doc.page(currentPageIndex);
|
||||
// console.log("look at page ", p);
|
||||
// window.history.pushState(
|
||||
// currentPageIndex,
|
||||
// "State 2013 — " + p,
|
||||
// doc.getPageURL(p)
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//})();
|
||||
@@ -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);
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
var populate = require("../../utils/populate").populate;
|
||||
const course = require("../../models/course");
|
||||
|
||||
module.exports = function (app) {
|
||||
app.controller("ScheduleController", function ($scope, schedule, team) {
|
||||
var now = new Date();
|
||||
var day = now.getDay();
|
||||
var dates = getDates(day);
|
||||
|
||||
var sem = "late";
|
||||
$scope.sem = [["early", "весеннего"], ["late", "осеннего"]].reduce(function (s, word) {
|
||||
if (word[0] === sem) return word[1];
|
||||
});
|
||||
$scope.year = 2014;
|
||||
|
||||
$scope.schedule = schedule($scope.year, sem, [
|
||||
populate(team.short, "teacher"),
|
||||
populate(course.name, "lesson")
|
||||
]);
|
||||
|
||||
$scope.isToday = function (weekDayIndex) {
|
||||
return (now.getDay() - 1) === weekDayIndex;
|
||||
};
|
||||
|
||||
$scope.weekDay = function (weekDayIndex) {
|
||||
return dates[weekDayIndex];
|
||||
};
|
||||
|
||||
$(window).scroll(function () {
|
||||
if ($(this).scrollTop() >= 220) {
|
||||
$(".schedule table thead").addClass("fix animated fadeInDown");
|
||||
$(".schedule table tbody").addClass("fix");
|
||||
} else {
|
||||
$(".schedule table thead").removeClass("fix animated fadeInDown");
|
||||
$(".schedule table tbody").removeClass("fix");
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
var populate = require("../../utils/populate").populate;
|
||||
const course = require("../../models/course");
|
||||
|
||||
module.exports = function (app) {
|
||||
app.controller("TeamController", function ($scope, team) {
|
||||
$scope.team = team.team.map(function (person) {
|
||||
person.names = team.splitName(person.name);
|
||||
return person;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
$(document).ready(function(){
|
||||
$(window).scroll(function(){
|
||||
if ($(window).scrollTop() >= 220) {
|
||||
$(".schedule table thead").addClass("fix animated fadeInDown");
|
||||
$(".schedule table tbody").addClass("fix");
|
||||
}else{
|
||||
$(".schedule table thead").removeClass("fix animated fadeInDown");
|
||||
$(".schedule table tbody").removeClass("fix");
|
||||
}
|
||||
});
|
||||
|
||||
var now = new Date();
|
||||
var day = now.getDay();
|
||||
// day = 3;
|
||||
if(day == 0) deselectDays();
|
||||
else selectDay(day);
|
||||
|
||||
var dates = getDates(day);
|
||||
$(".schedule thead .date").each(function(index, elem){
|
||||
$(elem).text(dates[index]);
|
||||
});
|
||||
|
||||
function selectDay(day){
|
||||
deselectDays();
|
||||
// day = Math.min(1, day);
|
||||
// day = Math.max(6, day);
|
||||
|
||||
$($(".schedule thead th")[day]).addClass("current first");
|
||||
$(".schedule tbody tr").each(function(index, elem){
|
||||
$($(elem).find("td")[day]).addClass("current");
|
||||
});
|
||||
$($(".schedule tbody tr").last().find("td")[day]).addClass("last");
|
||||
}
|
||||
|
||||
function deselectDays(){
|
||||
$(".schedule thead th").removeClass("current first");
|
||||
$(".schedule tbody td").removeClass("current last");
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 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));
|
||||
console.log("day mask", dayMask);
|
||||
dayMask.forEach(function(m){
|
||||
var time = Date.now() + (1000 * 60 * 60 * 24) * m;
|
||||
var date = new Date(time);
|
||||
console.log(date);
|
||||
dates.push(date.getDate());
|
||||
});
|
||||
return dates;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Created by tmshv on 05/11/14.
|
||||
*/
|
||||
|
||||
var menu = require("../../models/menu.json");
|
||||
|
||||
module.exports = function(app) {
|
||||
app.service("menu", function ($route) {
|
||||
menu.isActive = function (path) {
|
||||
if ($route.current && $route.current.regexp) {
|
||||
return $route.current.regexp.test(path);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return menu;
|
||||
});
|
||||
|
||||
app.controller("MenuController", function ($scope, menu) {
|
||||
$scope.vkgroup = menu.vkgroup;
|
||||
$scope.menu = menu.menu;
|
||||
|
||||
$scope.isCurrent = function(item) {
|
||||
return menu.isActive(item.url);
|
||||
};
|
||||
|
||||
$scope.isValid = function(item) {
|
||||
return Boolean(item.url);
|
||||
};
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user