1
0
Fork 0

More stable, I hope...

This commit is contained in:
magnolia-fan 2011-11-27 13:56:10 +04:00
parent 8cf69faf32
commit 453e809646
12 changed files with 107 additions and 61 deletions

View File

@ -3,6 +3,14 @@ class window.Ajax
referer: false
previous_page: null
showSpinner: ->
$('#artist-load-spinner').show()
false
hideSpinner: ->
$('#artist-load-spinner').hide()
false
load404Page: ->
$.get '/404.html', (data) ->
$('.data-container .inner').html data
@ -43,19 +51,22 @@ class window.Ajax
detectPage: () ->
return false if @previous_page == _ajax.getAnchor()
@previous_page = _ajax.getAnchor()
path = _ajax.getAnchor()
if path == "/"
path = "/greetings/"
log "Ajax controller is detecting page ..."
log "Ajax controller is detecting page for #{path} ..."
if m = _ajax.getAnchor().match /\/artist\/(.+)\//
if m = path.match /\/artist\/(.+)\//
_search.loadArtistData m[1]
else if _ajax.getAnchor().match /\/settings\//
else if path.match /\/settings\//
_settings.loadSettingsPage()
else if _ajax.getAnchor().match /\/about\//
_ajax.loadAboutPage()
else if _ajax.getAnchor().match /\/stat\//
_ajax.loadStatPage()
else
_ajax.loadIndexPage();
this.showSpinner()
_session.query path, {}, (response) ->
_page.render response
_ajax.hideSpinner()
false
false
$(window).bind 'hashchange', ->

View File

@ -15,6 +15,9 @@ jQuery ->
l.href = 'http://beathaven.org/'+ l.hash
window.log = (str) ->
_beathaven.logs.push
timestamp: Date()
info: str
console.log(str) if console?
$.ajaxSetup
@ -28,9 +31,10 @@ class window.BeatHaven
last_height: false
lang: 'ru'
logs: []
init: ->
log "Initiatin BeatHaven ..."
log "Initiating BeatHaven ..."
window._vkontakte = new Vkontakte(2335068)
window._vkontakte.init()

View File

@ -1,5 +1,22 @@
class window.Page
@data: {}
@html: ""
@status: ""
render: (params) ->
@data = params.data
@html = params.html
@title = params.title
@status = params.status
log "Rendering page titled \"#{@title}\" of type \"#{params.renderer}\" ..."
$('#content').html(@html)
# yaCounter7596904.hit _ajax.getAnchor(), @title, _ajax.referer
_ajax.setTitle @title
false
print: (html) ->
$('#content').html(html)
false

View File

@ -12,7 +12,9 @@ class window.Session
@vk_params = _params
setUser: (user) ->
log "Setting user ..."
@user = user
log "Hello, #{if user.name? then user.name else "%username%"}!"
false
getUser: ->

View File

@ -8,11 +8,10 @@ class window.Vkontakte
@api_id
init: ->
log "Initiatin Vkontakte API ..."
log "Initiating Vkontakte API ..."
window.vkAsyncInit = ->
VK.init apiId: _vkontakte.getApiId()
VK.Auth.getLoginStatus (response) ->
_vkontakte.authInfo(response)
_vkontakte.auth()
setTimeout ->
$('#vk_api_transport').append($('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js">'))
@ -50,10 +49,13 @@ class window.Vkontakte
$('.fullscreen').hide();
if response.session.expire?
expire_in = response.session.expire * 1000 - new Date().getTime()
log "Session will expire in #{Math.round(expire_in / 1000)} seconds"
setTimeout ->
log "Session expired"
_vkontakte.auth()
false
, response.session.expire * 1000 - new Date().getTime() + 1000
, expire_in + 1000
else
_session = new Session({})
_session.setUser {}
@ -63,6 +65,7 @@ class window.Vkontakte
$('.fullscreen').hide();
auth: ->
log "Requesting new Vkontakte session ..."
VK.Auth.getLoginStatus (response) ->
_vkontakte.authInfo(response)
false

View File

@ -10,11 +10,13 @@ class ApplicationController < ActionController::Base
end
def compile_page params
@data = params[:data]
@data = params[:data] unless params[:data].nil?
render json: {
status: (params[:status] unless params[:status].nil?),
renderer: "unified",
data: @data,
html: render_compact_partial(params[:partial])
html: render_compact_partial(params[:partial]),
title: params[:title],
status: (params[:status] unless params[:status].nil?)
}, include: (params[:include] unless params[:include].nil?)
end

View File

@ -4,18 +4,20 @@ class PageController < ApplicationController
end
def greetings
render partial: 'greetings'
compile_page(partial: "page/greetings", title: t("title.greetings"))
end
def about
render partial: 'about'
compile_page(partial: "page/about", title: t("title.about"))
end
def stat
@artists = Artist.count
@albums = Album.count
@tracks = Track.count
@users = User.count
render partial: 'stat'
data = {
artists: Artist.count,
albums: Album.count,
tracks: Track.count,
users: User.count
}
compile_page(data: data, partial: "page/stat", title: t("title.stat"))
end
end

View File

@ -1,19 +0,0 @@
%h2 BeatHaven statistics
%table.zebra-striped.stats
%tr
%td
%strong Artists
%td= @artists
%tr
%td
%strong Albums
%td= @albums
%tr
%td
%strong Tracks
%td= @tracks
%tr
%td
%strong Users
%td= @users

View File

@ -0,0 +1,19 @@
%h2= t('stat.title')
%table.zebra-striped.stats
%tr
%td
%strong= t('stat.artists')
%td= @data[:artists]
%tr
%td
%strong= t('stat.albums')
%td= @data[:albums]
%tr
%td
%strong= t('stat.tracks')
%td= @data[:tracks]
%tr
%td
%strong= t('stat.users')
%td= @data[:users]

View File

@ -1,19 +0,0 @@
%h2 Статистика BeatHaven
%table.zebra-striped.stats
%tr
%td
%strong Исполнителей
%td= @artists
%tr
%td
%strong Альбомов
%td= @albums
%tr
%td
%strong Треков
%td= @tracks
%tr
%td
%strong Пользователей
%td= @users

View File

@ -12,11 +12,23 @@ en:
settings: "Settings"
your_ad_here: "Your ad couldn't<br/>be here"
title:
greetings: Greetings
about: About
stat: Stats
search:
fail: "Something very bad happened while we tried out to load some info about this artist. How about some other one?"
loading: "Artist info is loading for the first time now. Usually it takes less than a minute, please wait a bit."
typo: "Misspelled?"
stat:
title: BeatHaven stats
artists: Artists
albums: Albums
tracks: Tracks
users: Users
settings:
title: "Settings"
tab:

View File

@ -12,11 +12,23 @@ ru:
settings: "Настройки"
your_ad_here: "Здесь не могла бы<br/>быть Ваша реклама"
title:
greetings: Привет
about: О проекте
stat: Статистика
search:
fail: "Что-то ужасное произошло пока мы собирали информацию об этом исполнителе. Может пока поищем другого?"
loading: "Прямо сейчас мы собираем всю возможною информацию об этом исполнителе в первый раз. Обычно это занимает меньше минуты."
typo: "Опечатались?"
stat:
title: Статистика BeatHaven
artists: Исполнителей
albums: Альбомов
tracks: Треков
users: Пользователей
settings:
title: "Настройки"
tab: