Merge branch 'design_team' of github.com:Rulingcom/orbit into design_team

This commit is contained in:
Christophe Vilayphiou 2012-05-08 21:47:03 +08:00
commit a186ae08d8
27 changed files with 334 additions and 32 deletions

View File

@ -19,6 +19,9 @@ gem "mongo_session_store-rails3"
gem 'nokogiri' gem 'nokogiri'
gem 'radius' gem 'radius'
gem 'rake' gem 'rake'
gem 'resque' # background jobs
gem 'resque-scheduler' # job scheduling
gem 'resque-restriction'
gem 'ruby-debug19' gem 'ruby-debug19'
gem 'rubyzip' gem 'rubyzip'
gem 'sinatra' gem 'sinatra'

View File

@ -153,6 +153,20 @@ GEM
rake (0.9.2.2) rake (0.9.2.2)
rdoc (3.12) rdoc (3.12)
json (~> 1.4) json (~> 1.4)
redis (2.2.2)
redis-namespace (1.0.3)
redis (< 3.0.0)
resque (1.20.0)
multi_json (~> 1.0)
redis-namespace (~> 1.0.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque-restriction (0.3.0)
resque (>= 1.7.0)
resque-scheduler (1.9.9)
redis (>= 2.0.1)
resque (>= 1.8.0)
rufus-scheduler
rspec (2.8.0) rspec (2.8.0)
rspec-core (~> 2.8.0) rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0) rspec-expectations (~> 2.8.0)
@ -182,6 +196,8 @@ GEM
ruby_parser (2.3.1) ruby_parser (2.3.1)
sexp_processor (~> 3.0) sexp_processor (~> 3.0)
rubyzip (0.9.6.1) rubyzip (0.9.6.1)
rufus-scheduler (2.0.16)
tzinfo (>= 0.3.23)
ruport (1.6.3) ruport (1.6.3)
fastercsv fastercsv
pdf-writer (= 1.1.8) pdf-writer (= 1.1.8)
@ -222,6 +238,8 @@ GEM
uglifier (1.2.3) uglifier (1.2.3)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
vegas (0.1.11)
rack (>= 1.0.0)
warden (1.1.1) warden (1.1.1)
rack (>= 1.0) rack (>= 1.0)
watchr (0.7) watchr (0.7)
@ -259,6 +277,9 @@ DEPENDENCIES
radius radius
rails (>= 3.1.0, < 3.2.0) rails (>= 3.1.0, < 3.2.0)
rake rake
resque
resque-restriction
resque-scheduler
rspec (~> 2.0) rspec (~> 2.0)
rspec-rails (~> 2.0) rspec-rails (~> 2.0)
ruby-debug19 ruby-debug19

View File

@ -1,7 +1,9 @@
# /usr/bin/ruby -Ku
# Add your own tasks in files placed in lib/tasks ending in .rake, # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__) require File.expand_path('../config/application', __FILE__)
require 'resque/tasks'
require 'rake/dsl_definition' require 'rake/dsl_definition'
require 'rake' require 'rake'

15
app/jobs/fetch_time.rb Normal file
View File

@ -0,0 +1,15 @@
# require 'open-uri'
# require 'nokogiri'
class FetchTime < Resque::Plugins::RestrictionJob
restrict :per_300 => 10
@queue = :low
def self.perform()
# sleep 10
doc = Nokogiri::HTML(open('http://www.timeanddate.com/worldclock/city.html?n=241'))
CronMail.time_check(doc.at('#ct').children.first.text).deliver
puts "Mail Sent"
true
end
end

12
app/jobs/nccu_calendar.rb Normal file
View File

@ -0,0 +1,12 @@
class NccuCalendar
require 'open-uri'
@queue = :high
def self.perform()
File.open(File.join(Rails.root, 'public/static', 'nccu_calendar.rss'),'w') do |file|
file << open('http://events.nccu.edu.tw/Feed').read
CronMail.time_check("NCCU Calendar synced").deliver
end
puts "NccuCalendar Synced"
end
end

15
app/jobs/sync_db.rb Normal file
View File

@ -0,0 +1,15 @@
class SyncDb
@queue = :high
def self.perform()
self.start_sync
end
def self.start_sync
task = 'mid_site:sync'
args = []
%x[rake #{task} --trace >> #{Rails.root}/log/rake.log]
puts "SyncDb Synced"
end
end

8
app/mailer/cron_mail.rb Normal file
View File

@ -0,0 +1,8 @@
class CronMail < ActionMailer::Base
default :from => "orbit_test@rulingcom.com"
def time_check(msg)
#attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => "Matt <matt@rulingcom.com>", :subject => msg)
end
end

View File

@ -0,0 +1,12 @@
<%= content_tag :li, :class => active_for_controllers('sites') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('sites')) do -%>
<%= content_tag :li, link_to(t('admin.site_info'), admin_site_site_info_path(@site)), :class => active_for_action('sites', 'site_info') %>
<%= content_tag :li, link_to(t('admin.system_info'), admin_site_system_info_path(@site)), :class => active_for_action('sites', 'system_info') %>
<%= content_tag :li, link_to(t('admin.language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %>
<%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %>
<%= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %>
<% end -%>
<% end -%>

View File

@ -1 +1,5 @@
<% content_for :side_bar do %>
<%= render 'side_bar' %>
<% end %>
language.html.erb language.html.erb

View File

@ -1 +1,5 @@
<% content_for :side_bar do %>
<%= render 'side_bar' %>
<% end %>
mail_setting.html.erb mail_setting.html.erb

View File

@ -1,3 +1,7 @@
<% content_for :side_bar do %>
<%= render 'side_bar' %>
<% end %>
<div id="poststuff"> <div id="poststuff">
<%= form_for @site, :url => admin_site_path(@site), :html => {:class => "clear"} do |f| %> <%= form_for @site, :url => admin_site_path(@site), :html => {:class => "clear"} do |f| %>
<div id="post-body"> <div id="post-body">

View File

@ -1 +1,5 @@
<% content_for :side_bar do %>
<%= render 'side_bar' %>
<% end %>
system_info.html.erb system_info.html.erb

View File

@ -1 +1,5 @@
<% content_for :side_bar do %>
<%= render 'side_bar' %>
<% end %>
ui_theme.html.erb ui_theme.html.erb

View File

@ -10,6 +10,7 @@
<li><%#= link_to content_tag(:i, nil, :class => 'icons-asset') + t('admin.asset'), admin_assets_path %></li> <li><%#= link_to content_tag(:i, nil, :class => 'icons-asset') + t('admin.asset'), admin_assets_path %></li>
<li class="divider"></li> <li class="divider"></li>
<li><%= link_to content_tag(:i, nil, :class => 'icons-structure') + t('admin.structure'), admin_items_path %></li> <li><%= link_to content_tag(:i, nil, :class => 'icons-structure') + t('admin.structure'), admin_items_path %></li>
<li><%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %></li>
<li><%#= link_to content_tag(:i, nil, :class => 'icons-plus-cube') + t('admin.add_item') %></li> <li><%#= link_to content_tag(:i, nil, :class => 'icons-plus-cube') + t('admin.add_item') %></li>
</ul> </ul>
</div> </div>

View File

@ -67,14 +67,3 @@
<%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> <%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %>
<% end -%> <% end -%>
<% end -%> <% end -%>
<%= content_tag :li, :class => active_for_controllers('sites') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('sites')) do -%>
<%= content_tag :li, link_to(t('admin.site_info'), admin_site_site_info_path(@site)), :class => active_for_action('sites', 'site_info') %>
<%= content_tag :li, link_to(t('admin.system_info'), admin_site_system_info_path(@site)), :class => active_for_action('sites', 'system_info') %>
<%= content_tag :li, link_to(t('admin.language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %>
<%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %>
<%= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %>
<% end -%>
<% end -%>

View File

@ -26,7 +26,11 @@
<div class="viewport"> <div class="viewport">
<div class="overview"> <div class="overview">
<ul class="nav nav-list"> <ul class="nav nav-list">
<% if !(yield :side_bar).blank? %>
<%= yield :side_bar %>
<% else %>
<%= render 'layouts/side_bar' %> <%= render 'layouts/side_bar' %>
<% end %>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -62,6 +62,8 @@ module Orbit
# Enable the asset pipeline # Enable the asset pipeline
config.assets.enabled = true config.assets.enabled = true
#config.time_zone = 'Taipei'
ENV['TZ'] = 'Asia/Taipei'
end end
end end
Orbit_Apps = [] Orbit_Apps = []

View File

@ -29,16 +29,16 @@ Orbit::Application.configure do
# :sender_address => %{"notifier" <redmine@rulingcom.com>}, # :sender_address => %{"notifier" <redmine@rulingcom.com>},
# :exception_recipients => %w{chris@rulingcom.com} # :exception_recipients => %w{chris@rulingcom.com}
# config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
# config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
# :tls => true, :tls => true,
# :enable_starttls_auto => true, :enable_starttls_auto => true,
# :address => "smtp.gmail.com", :address => "smtp.gmail.com",
# :port => '587', :port => '587',
# :domain => "smtp.gmail.com", :domain => "smtp.gmail.com",
# :authentication => "plain", :authentication => "plain",
# :user_name => "redmine@rulingcom.com", :user_name => "redmine@rulingcom.com",
# :password => "rulingredmine" } :password => "rulingredmine" }
end end

View File

@ -0,0 +1,20 @@
require 'resque_scheduler'
# require 'resque_scheduler/server'
# require 'yaml'
Resque.redis = 'localhost:6379'
#Resque.redis.namespace = "resque:SchedulerExample"
# If you want to be able to dynamically change the schedule,
# uncomment this line. A dynamic schedule can be updated via the
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
# When dynamic is set to true, the scheduler process looks for
# schedule changes and applies them on the fly.
# Note: This feature is only available in >=2.0.0.
#Resque::Scheduler.dynamic = true
Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }
# The schedule doesn't need to be stored in a YAML, it just needs to
# be a hash. YAML is usually the easiest.
Resque.schedule = YAML.load_file(Rails.root.join('config', 'resque_schedule.yml'))

55
config/resque.god Normal file
View File

@ -0,0 +1,55 @@
rails_env = 'development' #ENV['RAILS_ENV'] || "production"
rails_root = ENV['RAILS_ROOT'] || "/Users/kaito/Documents/MyWorkspeace/orbit/orbit"
num_workers = rails_env == 'production' ? 5 : 2
num_workers.times do |num|
God.watch do |w|
w.dir = "#{rails_root}"
w.name = "resque-#{num}"
w.group = 'resque'
w.interval = 30.seconds
p "/usr/bin/rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}"
# w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env}
w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}"
w.uid = 'kaito'
w.gid = 'staff'
# restart if memory gets too high
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 350.megabytes
c.times = 2
end
end
# determine the state on startup
w.transition(:init, { true => :up, false => :start }) do |on|
on.condition(:process_running) do |c|
c.running = true
end
end
# determine when process has finished starting
w.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.running = true
c.interval = 5.seconds
end
# failsafe
on.condition(:tries) do |c|
c.times = 5
c.transition = :start
c.interval = 5.seconds
end
end
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_running) do |c|
c.running = false
end
end
end
end

View File

@ -0,0 +1,17 @@
# do_mail_matt:
# every: 10s
# class: FetchTime
# args:
# description: Runs the perform method in FetchTime
nccu_daily_ldap_sync:
cron: * * [0,12] * * *
class: SyncDb
args:
description: Sync NCCU middle site with Orbit for LDAP data
nccu_claender_sync:
cron: * * [0,12] * * *
class: NccuCalendar
args:
description: Sync NCCU calendar RSS Feeds

View File

@ -1,5 +1,5 @@
Orbit::Application.routes.draw do Orbit::Application.routes.draw do
mount Resque::Server, :at => "/admin/resque"
devise_for :users devise_for :users
# routes for sinatra app # routes for sinatra app
@ -12,6 +12,7 @@ Orbit::Application.routes.draw do
# routes for admin # routes for admin
namespace :admin do namespace :admin do
mount Resque::Server.new, :at => "/resque"
resources :assets resources :assets
resources :app_auths resources :app_auths
resources :object_auths do resources :object_auths do

BIN
dump.rdb Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
module ParserCommon module ParserCommon
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
def menu_level(page, current, menu, edit = false) def menu_level(page, current_page_id, current, menu, edit = false)
res = '' res = ''
if page.ordered_and_visible_children.size > 0 if page.ordered_and_visible_children.size > 0
res << "<ul class='" res << "<ul class='"
@ -10,10 +10,10 @@ module ParserCommon
i = nil i = nil
i = 1 if menu.values["li_incremental_#{current}"] i = 1 if menu.values["li_incremental_#{current}"]
if menu.values['home'] && current == 1 if menu.values['home'] && current == 1
res << menu_li(page, current, menu, i, edit) res << menu_li(page, current_page_id, current, menu, i, edit)
end end
page.ordered_and_visible_children.each do |child| page.ordered_and_visible_children.each do |child|
res << menu_li(child, current, menu, i, edit) res << menu_li(child, current_page_id, current, menu, i, edit)
i += 1 if i i += 1 if i
end end
res << "</ul>" res << "</ul>"
@ -21,15 +21,16 @@ module ParserCommon
res res
end end
def menu_li(page, current, menu, i, edit) def menu_li(page, current_page_id, current, menu, i, edit)
res = "<li class=" res = "<li class='"
res << menu.values["li_class_#{current}"] rescue nil res << menu.values["li_class_#{current}"] rescue nil
res << "_#{i}" if i res << "_#{i}" if i
res << ">" res << " active" if page.id.eql?(current_page_id)
res << "'>"
res << "<a href='#{edit ? admin_page_path(page.id) : page.full_name}'><span>#{page.i18n_variable[I18n.locale]}</span></a>" res << "<a href='#{edit ? admin_page_path(page.id) : page.full_name}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
if page.ordered_and_visible_children.size > 0 && current <= menu.levels if page.ordered_and_visible_children.size > 0 && current <= menu.levels
res << "<span class='dot'></span>" res << "<span class='dot'></span>"
res << menu_level(page, current + 1, menu, edit) res << menu_level(page, current_page_id, current + 1, menu, edit)
end unless (page.is_home? rescue nil) end unless (page.is_home? rescue nil)
res << "</li>" res << "</li>"
end end
@ -103,7 +104,7 @@ module ParserCommon
page_menu = body.css('.page_menu').first page_menu = body.css('.page_menu').first
home = get_homepage home = get_homepage
menu = page.design.layout.menu menu = page.design.layout.menu
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 1, menu, edit)) fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page.id, 1, menu, edit))
page_menu.swap(fragment) page_menu.swap(fragment)
end end

View File

@ -1,3 +1,4 @@
require 'resque_scheduler/tasks'
# encoding: utf-8 # encoding: utf-8
namespace :anc do namespace :anc do

39
lib/tasks/resque.rake Normal file
View File

@ -0,0 +1,39 @@
# require "resque/tasks"
# require 'resque/scheduler'
# require 'resque/scheduler'
#
# task "resque:setup" => :environment
# Resque tasks
require 'resque/tasks'
require 'resque_scheduler/tasks'
namespace :resque do
task :setup => :environment do
require 'resque'
require 'resque_scheduler'
require 'resque/scheduler'
# you probably already have this somewhere
Resque.redis = 'localhost:6379'
# If you want to be able to dynamically change the schedule,
# uncomment this line. A dynamic schedule can be updated via the
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
# When dynamic is set to true, the scheduler process looks for
# schedule changes and applies them on the fly.
# Note: This feature is only available in >=2.0.0.
#Resque::Scheduler.dynamic = true
# The schedule doesn't need to be stored in a YAML, it just needs to
# be a hash. YAML is usually the easiest.
Resque.schedule = YAML.load_file('config/resque_schedule.yml')
# If your schedule already has +queue+ set for each job, you don't
# need to require your jobs. This can be an advantage since it's
# less code that resque-scheduler needs to know about. But in a small
# project, it's usually easier to just include you job classes here.
# So, someting like this:
#require 'jobs'
end
end

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>國立政治大學校園活動行事曆</title>
<link rel="alternate" href="http://events.nccu.edu.tw/" />
<subtitle>本日最新活動</subtitle>
<dc:language>zh-tw</dc:language>
<entry>
<title>2012年世界狂歡節-「框」住瞬間「框」住世界</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2901&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/05/01-101/05/08 00:00-23:59</summary>
</entry>
<entry>
<title>2012年世界狂歡節-環友世界</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2902&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/05/01-101/05/10 00:00-23:59</summary>
</entry>
<entry>
<title>2012年世界狂歡節-從政大看台灣</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2903&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/05/01-101/05/10 08:00-22:00</summary>
</entry>
<entry>
<title>2012年世界狂歡節-美食嘉年華</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2905&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/05/08-101/05/10 12:00-14:00</summary>
</entry>
<entry>
<title>2012年世界狂歡節-「原,夜」晚會</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2906&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/05/08 19:00-21:00</summary>
</entry>
<entry>
<title>2012年世界狂歡節-開幕式</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2907&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/05/08 12:10-13:30</summary>
</entry>
<entry>
<title>職場講座「數位文本實務課程」</title>
<link rel="alternate" href="http://events.nccu.edu.tw/more.do?key=2874&amp;key2=20120508" />
<author>
<name />
</author>
<summary type="text">101/04/24-101/05/15 12:20-13:50</summary>
</entry>
</feed>