From 7e30f7f2789f266e14d647253dc18fc9d13d067f Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 4 Nov 2014 21:50:09 +0300 Subject: [PATCH] upadate --- assets/style/document.scss | 152 +++++++++--- assets/style/pdf.scss | 179 ++++++++++++++ assets/style/schedule.scss | 17 +- client/document.js | 132 ++++++++++ client/schedule.js | 47 ++-- config.js | 83 +------ gulpfile.js | 2 +- main.js | 6 +- models/document.js | 68 +++++ models/documents.json | 69 +++--- models/schedule-2014-2015.json | 438 +++++++++++++++++++++++++++++++++ models/schedule.js | 61 +++++ package.json | 3 +- pages/document/document.jade | 59 ++++- pages/schedule/schedule.jade | 23 +- routers/docs.js | 46 ++++ routers/route.js | 33 --- routers/schedule.js | 15 ++ server.js | 7 +- utils/populate.js | 38 +++ 20 files changed, 1250 insertions(+), 228 deletions(-) create mode 100644 assets/style/pdf.scss create mode 100644 client/document.js create mode 100644 models/document.js create mode 100644 models/schedule-2014-2015.json create mode 100644 models/schedule.js create mode 100644 routers/docs.js create mode 100644 routers/schedule.js create mode 100644 utils/populate.js diff --git a/assets/style/document.scss b/assets/style/document.scss index a59cc243..b1316d54 100644 --- a/assets/style/document.scss +++ b/assets/style/document.scss @@ -1,57 +1,127 @@ * { - // position: absolute; - // width: 100%; - height: 100%; + margin: 0; + padding: 0; } -.norm{ - font-weight: normal; +body { + font-family: "PT Sans"; } -.bold{ - font-weight: bold; +.norm { + font-weight: 400; } -.menu{ - width: 100%; - height: 45px; - background-color: white; - - &.opac{ - position:fixed; - opacity: 0.9; - box-shadow: 0 0 10px rgba(0,0,0,0.5); - } - - h1{ - padding:10px 0 0 25px; - font-size: 14pt; - color: black; - } +.bold { + font-weight: 700; } -iframe{ - // display: absolute; - width: 100%; - height: 100%; - border:none; +#page-container > div { + /* box-shadow: 1px 1px 3px 1px #333;*/ } -.doclist{ - // width: 100%; - padding-top: 70px; +.menu { + position: fixed; + width: 100%; + height: 45px; + background-color: #fff; + z-index: 100; + box-shadow: 0 1px 5px 0px rgba(0, 0, 0, 0.5); + &.opac { + opacity: .97; + } + .panel { + width: auto; + display: inline-block; + margin: 10px 25px 0; + &.right { + float: right; + } + } + h1 { + font-size: 14pt; + } +} - img{ - max-width: 90%; - height: auto; +.controls { + display: inline-block; + margin-top: -4px; + /* vertical-align: middle;*/ + .block { + display: inline-block; + /* height: 100%;*/ + margin: 0px 5px; + vertical-align: middle; + } + input { + width: 30px; + height: 30px; + margin: 0 2px; + text-align: center; + font-size: .9em; + } + button { + display: inline-block; + height: 30px; + padding: 0 10px; + border-radius: 6px; + border: 2px solid #bbb; + color: #555; + background-color: white; + font-size: 1.3em; + text-align: center; + outline: none; + &:hover { + /* border: 1px solid #666;*/ + /* background-color: #eee;*/ + border: 2px solid #4d62d9; + color: #4d62d9; + } + &:active { + border: 2px solid #3d4fb2; + color: #3d4fb2; + background-color: rgba(61, 79, 178, 0.3); + } + } + a.download { + width: 22px; + height: 22px; + padding: 5px 8px; + display: inline-block; + background: #f3f3f3 url(download-icon.png) no-repeat; + background-position: 50%; + border-radius: 3px; + border: 1px solid #e0e0e0; + } +} - margin-left: auto; - margin-right: auto; +#page-container { + background-color: #c3bfa3; + transition: left 500ms; +} - display: block; - margin-bottom: 50px; +.pf { + margin: 60px auto 20px; + /* box-shadow: 1px 1px 3px 1px #333;*/ + box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.9); + border-collapse: separate; +} - // border: 1px solid #999; - box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.2); - } +iframe { + width: 100%; + height: 100%; + border: 0; +} + +.doclist { + padding-top: 70px; + img { + max-width: 90%; + height: auto; + margin-left: auto; + margin-right: auto; + display: block; + margin-bottom: 50px; + -webkit-box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.2); + box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.2); + } } \ No newline at end of file diff --git a/assets/style/pdf.scss b/assets/style/pdf.scss new file mode 100644 index 00000000..2c74b295 --- /dev/null +++ b/assets/style/pdf.scss @@ -0,0 +1,179 @@ +#page-container { + position: absolute; + top: 0; + left: 0; + margin: 0; + padding: 0; + border: 0; +} + +@media screen { + #page-container { + bottom: 0; + right: 0; + overflow: auto; + } + .loading-indicator { + display: none; + &.active { + display: block; + position: absolute; + width: 64px; + height: 64px; + top: 50%; + left: 50%; + margin-top: -32px; + margin-left: -32px; + } + img { + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + } + } +} + +@media print { + @page { + margin: 0; + } + + html { + margin: 0; + } + body { + margin: 0; + -webkit-print-color-adjust: exact; + } + #page-container { + width: auto; + height: auto; + overflow: visible; + background-color: transparent; + } + .d { + display: none; + } +} + +.pf { + position: relative; + background-color: white; + overflow: hidden; + margin: 0; + border: 0; +} + +.pc { + position: absolute; + border: 0; + padding: 0; + margin: 0; + top: 0; + left: 0; + width: 100%; + height: 100%; + overflow: hidden; + display: block; + transform-origin: 0 0; + -ms-transform-origin: 0 0; + -webkit-transform-origin: 0 0; + &.opened { + display: block; + } +} + +.bf { + position: absolute; + border: 0; + margin: 0; + top: 0; + bottom: 0; + width: 100%; + height: 100%; + -ms-user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + user-select: none; +} + +.bi { + position: absolute; + border: 0; + margin: 0; + -ms-user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + user-select: none; +} + +@media print { + .pf { + margin: 0; + box-shadow: none; + page-break-after: always; + page-break-inside: avoid; + } + @-moz-document url-prefix() { + .pf { + overflow: visible; + border: 1px solid #fff; + } + .pc { + overflow: visible; + } + } +} + +.c { + position: absolute; + border: 0; + padding: 0; + margin: 0; + overflow: hidden; + display: block; +} + +.t { + position: absolute; + white-space: pre; + font-size: 1px; + transform-origin: 0 100%; + -ms-transform-origin: 0 100%; + -webkit-transform-origin: 0 100%; + unicode-bidi: bidi-override; + -moz-font-feature-settings: "liga" 0; +} + +._ { + color: transparent; + z-index: -1; +} + +::selection { + background: rgba(127, 255, 255, 0.4); +} + +::-moz-selection { + background: rgba(127, 255, 255, 0.4); +} + +.pi { + display: none; +} + +.d { + position: absolute; + transform-origin: 0 100%; + -ms-transform-origin: 0 100%; + -webkit-transform-origin: 0 100%; +} + +// .@CSS_LINK_CN span { +// position: relative; +// vertical-align: baseline; +// display: inline-block; +// unicode-bidi: bidi-override; +// } \ No newline at end of file diff --git a/assets/style/schedule.scss b/assets/style/schedule.scss index 71676161..9f69ff98 100644 --- a/assets/style/schedule.scss +++ b/assets/style/schedule.scss @@ -1,10 +1,11 @@ .schedule{ position: relative; margin: 30px auto 0 auto; + text-align: center; table{ position: relative; - margin: 0 auto 0 auto; + margin: 30px auto 0 auto; border-spacing: 0px; text-align: center; @@ -28,25 +29,21 @@ position: relative; vertical-align:baseline; - p{ + p.name{ // position: absolute; width:30px; height: 30px; left: 0; right: 0; - margin: 7px auto 0 auto; + margin: 7px auto 10px auto; padding: 7px; border: 1px solid #e8e8e8; - background-color: white; + // background-color: white; border-radius: 50%; font-size: 1.4em; } } } - - tr:nth-child(even) td.group p{ - background-color: #f9f9fd; - } } thead{ @@ -72,8 +69,8 @@ } } - tbody tr:nth-child(odd){ - background-color: #f9f9fd; + tbody tr:nth-child(even){ + background-color: #f3f3fd; } .lesson{ diff --git a/client/document.js b/client/document.js new file mode 100644 index 00000000..b0687d2c --- /dev/null +++ b/client/document.js @@ -0,0 +1,132 @@ +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) + ); + }); + } + } +})(); \ No newline at end of file diff --git a/client/schedule.js b/client/schedule.js index f3a4d765..8c66858b 100644 --- a/client/schedule.js +++ b/client/schedule.js @@ -11,11 +11,11 @@ $(document).ready(function(){ var now = new Date(); var day = now.getDay(); - if(day < 7) selectDay(day); - else deselectDays(); + // day = 3; + if(day == 0) deselectDays(); + else selectDay(day); - var dates = getDates(day); - // var dates = [45, 53, 53, 23, 53, 64]; + var dates = getDates(day); $(".schedule thead .date").each(function(index, elem){ $(elem).text(dates[index]); }); @@ -38,21 +38,40 @@ $(document).ready(function(){ } }); +/** + * 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 1 + .controls + p.block + span Страница + input#currentPage(pattern='[0-9]{,3}') + | из + span#totalPages + + p.block + button#buttonPrev ← + button#buttonNext → + + if doc.download + p.block + a.download(href='#{doc.download}') + if doc.viewer == "default" + div(id='page-container') + for url in doc.url + //- p #{url} + .pf(data-page-url='#{url}') + //- img(src='#{url}') + //- //- for url in doc.url + //- //- .pf + //- //- //- + + if doc.viewer == "img-sheet" + .doclist + for url in doc.url + img(src='#{url}') \ No newline at end of file diff --git a/pages/schedule/schedule.jade b/pages/schedule/schedule.jade index 6c425c7c..758942d8 100644 --- a/pages/schedule/schedule.jade +++ b/pages/schedule/schedule.jade @@ -3,20 +3,22 @@ extends ../layout block custom_head link(rel='stylesheet', href='/s/animate.min.css') link(rel='stylesheet', href='/s/schedule.css') - script(src='http://code.jquery.com/jquery-2.1.0.min.js') + //- script(src='http://code.jquery.com/jquery-2.1.0.min.js') + script(src='/c/jquery-2.1.0.js') script(src='/c/schedule.js') block content include ../menu .schedule - ul - li - a(href='') 2012, осень - li - a(href='') 2013, весна - li - a(href='') 2013, осень - li.current 2014, весна + p Расписание весеннего семестра 2014 года + //- ul + //- li + //- a(href='') 2012, осень + //- li + //- a(href='') 2013, весна + //- li + //- a(href='') 2013, осень + //- li.current 2014, весна table thead - var days = ["Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"]; @@ -31,7 +33,8 @@ block content for group in groups tr td.group - p #{group.name} + p.name #{group.name} + p.time #{group.time} for day in group.days td if day diff --git a/routers/docs.js b/routers/docs.js new file mode 100644 index 00000000..82649e57 --- /dev/null +++ b/routers/docs.js @@ -0,0 +1,46 @@ +var Router = require("express").Router; +var route = require("./route"); +var document = require("../models/document"); + +var router = new Router(); +module.exports = router.middleware; + +router.get("/docs", function(req, res){ + var url = "/docs"; + + res.render("docs/docs", { + menu: route.menu(url), + blocks: [ + { + type: "documents", + name: "Лицензии, свидетельства и уставы", + items: document.cap( + document.doc( + ["statue-2013", "edu-license", "gov-certificate", "VAT", "EGRYL1", "EGRYL2"] + ) + ) + } + ] + }); +}); + +router.get("/document/:doc/:page?", function(req, res){ + var name = req.param("doc"); + var doc = document.doc(name); + // doc = document.extra(doc, { + // "style": [ + // "/s/pdf.css" + // ], + // "script": [ + // "http://code.jquery.com/jquery-2.1.0.min.js", + // "/c/document.js" + // ] + // }); + + if(doc){ + doc.startPage = req.param("page"); + res.render("document/document", {doc: doc}); + }else{ + res.error(404); + } +}); \ No newline at end of file diff --git a/routers/route.js b/routers/route.js index a5c52167..a0ed50ef 100644 --- a/routers/route.js +++ b/routers/route.js @@ -1,41 +1,9 @@ const config = require("../config") -const DOCUMENTS = config.data.documents; function getMenu(){ return clone(config.data.menu); } -function getDoc(name, capitalFirstLetter){ - if(name && typeof name == "string"){ - for(var i=0; i