Compare commits

...

7 Commits

Author SHA1 Message Date
Bernie Chiu a85d87fc1f Add uncategorized category 2014-02-18 14:36:28 +08:00
thomaschen 5c8f822993 fix duplicated announcement when rss feed 2014-02-18 13:57:57 +08:00
Manson Wang b9f62c6382 Fix Resque "Internal Server Error" issue in pushion passenger forked environment 2014-02-13 17:37:19 +08:00
thomaschen a247b1042a add sceduler job for rss feed 2014-02-12 14:51:26 +08:00
Manson Wang 5ce584a75a ntu_ga_subscription 2014-02-12 13:21:50 +08:00
Manson Wang 72d3fa428d Added missing Gem 2014-02-12 13:15:39 +08:00
Manson Wang 4c8c7b19ff ntu_ga 2014-02-12 13:15:38 +08:00
25 changed files with 661 additions and 12 deletions

View File

@ -41,6 +41,7 @@ gem 'fb_graph'
gem 'rack-gridfs'
gem 'radius'
gem 'rake'
gem 'roo'
# gem 'remotipart'
gem 'resque', :require => 'resque/server' # background jobs
gem 'resque-scheduler' # job scheduling

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@ -0,0 +1,33 @@
window.SocialShareButton =
openUrl : (url) ->
window.open(url)
false
share : (el) ->
site = $(el).data('site')
title = encodeURIComponent($(el).parent().data('title'))
img = encodeURIComponent($(el).parent().data("img"))
fb_url = encodeURIComponent($(el).parent().data("fb_url"))
url = encodeURIComponent(location.href)
switch site
when "weibo"
SocialShareButton.openUrl("http://v.t.sina.com.cn/share/share.php?url=#{url}&pic=#{img}&title=#{title}&content=utf-8")
when "twitter"
SocialShareButton.openUrl("https://twitter.com/home?status=#{title}: #{url}")
when "douban"
SocialShareButton.openUrl("http://www.douban.com/recommend/?url=#{url}&title=#{title}&image=#{img}")
when "facebook"
SocialShareButton.openUrl("http://www.facebook.com/sharer.php?t=#{title}&u=#{fb_url}")
when "qq"
SocialShareButton.openUrl("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=#{url}&title=#{title}&pics=#{img}")
when "tqq"
SocialShareButton.openUrl("http://share.v.t.qq.com/index.php?c=share&a=index&url=#{url}&title=#{title}&pic=#{img}")
when "baidu"
SocialShareButton.openUrl("http://apps.hi.baidu.com/share/?url=#{url}&title=#{title}&content=")
when "kaixin001"
SocialShareButton.openUrl("http://www.kaixin001.com/rest/records.php?url=#{url}&content=#{title}&style=11&pic=#{img}")
when "renren"
SocialShareButton.openUrl("http://widget.renren.com/dialog/share?resourceUrl=#{url}&title=#{title}&description=")
when "google_plus"
SocialShareButton.openUrl("https://plus.google.com/share?url=#{url}&t=#{title}")
false

View File

@ -10,7 +10,7 @@ $(document).ready(function() {
type: 'GET',
url: $(this).attr("rel"),
dataType: 'script',
data: {ids: ids},
data: {field: $(this).attr("field"), ids: ids},
success: function (msg) {
$("#member-filter").modal('show'); },
error: function(){
@ -20,6 +20,11 @@ $(document).ready(function() {
});
return false;
});
$(document).on('click', ".remove_user", function(){
$(this).parent().remove();
});
$("#remove_users").on('click', function(){
var ids = [];
var users = $('.selected_user input[type="checkbox"]:checked');

View File

@ -0,0 +1,10 @@
$(document).ajaxStop(function() {
$('.nav').find('.dropdown').on({
mouseleave: function() {
$(this).removeClass("open");
},
mouseenter: function() {
$(this).addClass("open")
}
});
});

View File

@ -0,0 +1,230 @@
/* Member Filter */
#select_user #select_user_modal.modal {
width: 80%;
margin-left: -40%;
}
#select_user #select_user_modal .modal-body {
max-height: 425px;
}
#select_user #select_user_modal .modal-body form {
margin-bottom: 0px;
}
#select_user #select_user_modal .modal-body form fieldset {
min-height: 360px;
}
#select_user #select_user_modal .modal-body .radio.inline,
#select_user #select_user_modal .modal-body .checkbox.inline {
display: inline-block;
padding-top: 5px;
margin-bottom: 0;
vertical-align: middle;
min-width: 100px;
margin-left: 0;
}
#select_user #select_user_modal .modal-body .form-actions {
margin: 20px 0 0;
padding: 10px 0 0;
background-color: transparent;
text-align: right;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano {
width: 160px;
min-height: 425px;
float: left;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano .pane {
right: 6px;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs {
width: 140px;
float: left;
margin-bottom: 0;
margin-right: 0;
border-right: 1px solid #ddd;
border-bottom: none;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li {
float: none;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li > a {
min-width: 74px;
margin-right: 0;
margin-bottom: 3px;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li > a {
margin-right: -1px;
-webkit-border-radius: 4px 0 0 4px;
-moz-border-radius: 4px 0 0 4px;
border-radius: 4px 0 0 4px;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li > a:hover {
border-color: #eeeeee #dddddd #eeeeee #eeeeee;
}
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs .active > a,
#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs .active > a:hover {
border-color: #ddd transparent #ddd #ddd;
*border-right-color: #ffffff;
}
#select_user #select_user_modal .member-filter-options {
float: left;
display: inline-block;
width: 175px;
min-height: 425px;
margin-right: 10px;
padding: 0 10px 0 0;
}
#select_user #select_user_modal .member-filter-options select {
width: 165px;
}
#select_user #select_user_modal .member-filter-options .btn {
display: block;
}
#select_user #select_user_modal .member-filter-result {
padding-left: 15px;
min-height: 360px;
width: auto;
}
/* Check Box Card */
.checkbox-card {
margin: 0;
}
.checkbox-card li {
position: relative;
list-style: none;
color: #FFFFFF;
width: 180px;
height: 40px;
margin: 0 10px 10px 0;
float: left;
display: inline-block;
background-color: #cccccc;
overflow: hidden;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
transition: all .2s linear;
}
.checkbox-card li.mark {
width: 0;
height: 0;
padding: 0;
margin: 0;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
visibility: hidden;
}
.checkbox-card li:hover {
background-color: #0088cc;
}
.checkbox-card li:after {
content: "";
display: block;
clear: both;
height: 0;
visibility: hidden;
}
.checkbox-card li.active:before {
-webkit-text-size-adjust : none;
font-family: FontAwesome;
font-weight: normal;
font-style: normal;
color: #FFF;
text-decoration: inherit;
content: "\f00c";
position: absolute;
right: 0px;
top: 0px;
line-height: 14px;
text-indent: 10px;
font-size: 10px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 22px 22px 0;
border-color: transparent #51a351 transparent transparent;
}
.checkbox-card li.active label {
}
.checkbox-card li label {
margin-bottom: 0px;
overflow: hidden;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.checkbox-card li input {
opacity: 0;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
margin: 0;
z-index: 10;
}
.checkbox-card li label span {
-webkit-text-size-adjust : none;
font-size: 10px;
display: block;
width: 130px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #666666;
margin-top: -3px;
}
.checkbox-card li:hover label span,
.checkbox-card li:hover label span.user-name {
color: #FFFFFF;
}
.checkbox-card li label span.user-name {
font-size: 12px;
color: #363636;
padding: 2px 0 0;
margin-top: 0;
}
.checkbox-card li .user-pic {
float: left;
margin-right: 5px;
width: 40px;
height: 40px;
}
#selected_users .selected_user {
display: block;
margin-bottom: 5px;
}
#selected_users .selected_user .remove_user {
font-size: 15px;
}
/*
.promoter {
border-color: #CCCCCC;
border-style: solid;
border-width: 0 1px;
padding: 0 10px 5px 10px;
}
.promoter > div {
border-bottom: 1px solid #CCCCCC;
}
.promoter > div:after {
content: "";
clear: both;
display: block;
visibility: hidden;
}
.promoter > div > span {
display: block;
margin-left: 70px;
padding-bottom: 5px;
}
.promoter p {
width: 70px;
float: left;
text-align:right;
}*/

View File

@ -0,0 +1,90 @@
.social-share-button-baidu {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") 0px 0px no-repeat;
}
.social-share-button-delicious {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -16px 0px no-repeat;
}
.social-share-button-douban {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") 0px -16px no-repeat;
}
.social-share-button-email {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -16px -16px no-repeat;
}
.social-share-button-facebook {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -32px 0px no-repeat;
}
.social-share-button-flickr {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -32px -16px no-repeat;
}
.social-share-button-google {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") 0px -32px no-repeat;
}
.social-share-button-google_plus {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -16px -32px no-repeat;
}
.social-share-button-kaixin001 {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -32px -32px no-repeat;
}
.social-share-button-qq {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -48px 0px no-repeat;
}
.social-share-button-renren {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -48px -16px no-repeat;
}
.social-share-button-tqq {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -48px -32px no-repeat;
}
.social-share-button-twitter {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") 0px -48px no-repeat;
}
.social-share-button-weibo {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -16px -48px no-repeat;
}
.social-share-button-rss {
display:inline-block;
width:16px;
height:16px;
background:url("/assets/social-share-button.png") -32px -48px no-repeat;
}

View File

@ -0,0 +1,40 @@
# encoding: utf-8
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
def create
@site = Site.first
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
wresult = private_key.private_decrypt(request.params['wresult'])
@ids = wresult.split("@")
login_uid = @ids[0]
resource = User.first(conditions:{user_id: login_uid})
if !resource.blank?
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
session[:user_id_type] = "myntu"
redirect_to after_sign_in_path_for(resource)
else
flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員<br />Sorry, you don't have the account or authority to login. Please contact the website administrator."
redirect_to :root
end
end
def destroy
@user_id_type = session[:user_id_type]
sign_out
if @user_id_type == "myntu"
redirect_to "https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignout1.0&wreply=https://galogin.ntu.edu.tw"
else
redirect_to root_path
end
end
end

View File

@ -194,7 +194,8 @@ module ApplicationHelper
stylesheets << "<link href='#{asset_path 'orbit_bar_bootstrap'}' rel='stylesheet' type='text/css' />\n"
stylesheets << "<link href='#{page.design.css_reset.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.css_reset
# stylesheets << "<link href='#{asset_path 'banner_nav.css'}' rel='stylesheet' type='text/css' />\n"
# stylesheets << "<link href='#{asset_path 'default_widget.css'}' rel='stylesheet' type='text/css' />\n"
# stylesheets << "<link href='#{asset_path 'default_widget.css'}' rel='stylesheet' type='text/css' />\n"
stylesheets << "<link href='/assets/social-share-button.css' rel='stylesheet' type='text/css' />\n"
stylesheets << "<link href='#{page.design.css_default.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.css_default
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
stylesheets << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />\n" if theme
@ -203,8 +204,12 @@ module ApplicationHelper
def page_javascripts(page, edit=nil)
javascripts = ''
unless edit
javascripts << "<script type='text/javascript' src='/assets/orbit-bar-search.js'></script>\n"
end
# javascripts << "<script type='text/javascript' src='/assets/lib/jquery.preload-min.js'></script>\n"
# javascripts << "<script type='text/javascript' src='/assets/jquery.cycle.all.latest.js'></script>\n"
javascripts << "<script type='text/javascript' src='/assets/lib/social-share-button.js'></script>\n"
page.design.javascripts.each do |js|
javascripts << "<script type='text/javascript' src='#{js.file.url}'></script>"
end
@ -301,7 +306,7 @@ module ApplicationHelper
# NTU link
def get_link(site_number)
"http://#{request.host}:2#{site_number}00"
"http://#{site_number}.#{request.domain(3)}"
end
def sortable(column, title = nil, options = {})

View File

@ -355,7 +355,7 @@ module OrbitBackendHelper
if object.is_a?(klass.constantize)
autorized ||= object.user_can_sub_manage?(current_user)
else
autorized ||= object.send(klass.underscore).user_can_sub_manage?(current_user)
autorized ||= object.send(klass.underscore).user_can_sub_manage?(current_user) rescue nil
end
autorized
end

View File

@ -0,0 +1,7 @@
class GetAnnouncementFromRss
@queue = :high
def self.perform()
%x(ruby "#{Rails.root}/lib/rss_ntu_job.rb")
end
end

View File

@ -28,6 +28,7 @@
<div class="form-actions">
<button type="button" class="btn" data-dismiss="modal"><%= t(:cancel) %></button>
<%= submit_tag t(:submit), class: "btn btn-primary" %>
<%= hidden_field_tag field, @field %>
</div>
<% end %>
</div>
@ -53,6 +54,7 @@
<div class="form-actions condition">
<button type="button" class="btn" data-dismiss="modal"><%= t(:cancel) %></button>
<%= submit_tag t(:submit), class: "btn btn-primary" %>
<%= hidden_field_tag field, @field %>
</div>
</fieldset>
<% end %>

View File

@ -0,0 +1,14 @@
<% unless users.blank? %>
<div class="promoter-block">
<p class="promoter-title"><%= t(:promoter) %></p>
<ul>
<% users.each do |user| %>
<li class="promoter">
<p>
<%= link_to user.name, "mailto:#{user.email}", class: "promoter-name" %> / <span class="promoter-phone"><%= user.office_tel %></span>
</p>
</li>
<% end %>
</ul>
</div>
<% end %>

View File

@ -0,0 +1,16 @@
<% content_for :page_specific_javascript do -%>
<%= javascript_include_tag "member-selection" %>
<%= javascript_include_tag "lib/jquery.nanoscroller" %>
<%= javascript_include_tag "lib/checkbox.card" %>
<% end -%>
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "member_select" %>
<% end %>
<div>
<div id="selected_users">
<%= render partial: 'admin/member_selects/user', collection: users, locals: {field: field} %>
<%= hidden_field_tag field %>
</div>
<%= link_to t(:add), '#', class: 'btn btn-primary btn-small select_user_modal', rel: select_members_admin_member_selects_path, field: field %>
</div>

View File

@ -12,10 +12,11 @@
<input name="utf8" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" />
</div>
<!-- <div class="other-sign-in">
<a class="btn btn-primary" type="submit">Other Sign In</a>
<div class="other-sign-in">
<% @request_hosts = request.host_with_port.split(".") %>
<a class="btn btn-primary" type="submit" href="https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignin1.0&wtrealm=https://galogin.ntu.edu.tw/saml_login&wctx=<%= @request_hosts[0] %>">使用計中帳號登入</a>
<p>or</p>
</div> -->
</div>
<div class="form-block">
<div class="form-list clearfix">
<form class="content" accept-charset="UTF-8" action="/users/sign_in" method="post">

View File

@ -13,6 +13,16 @@
</form>
</li>
<!-- ntu sites -->
<li id="orbit-tag" class="dropdown">
<a class="dropdown-toggle orbit-bar-language" data-icons="&#xe02d;" href="#" data-toggle="dropdown"></a>
<ul class="dropdown-menu language-menu">
<% t('ntu.site_names').each do |site| %>
<li><%= link_to site[1], get_link(site[0]) %></li>
<% end %>
</ul>
</li>
<!-- Language -->
<li id="orbit-language" class="dropdown">
<a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"><%= t(:_locale, :locale => I18n.locale) %></a>
@ -36,7 +46,7 @@
<% if @site.desktop_closed %>
<li><%= link_to content_tag(:i, nil, class: 'icons-screen') + ' ' + t(:desktop), desktop_path, tabindex: '-1' %></li>
<% end %>
<li><%= link_to content_tag(:i, nil, class: 'icons-logout') + ' ' + t(:logout), destroy_user_session_path, tabindex: '-1' %></li>
<li><%= link_to content_tag(:i, nil, class: 'icons-logout') + ' ' + t(:logout), user_logout_path, tabindex: '-1' %></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#"><i class="icons-lifebuoy"></i> <%= t(:help) %></a></li>
</ul>
@ -56,6 +66,12 @@
</div>
<div class="modal-body">
<%= form_for :user, url: user_session_path, html: {class: 'container'} do |f| %>
<div class="other-sign-in">
<% @request_hosts = request.host_with_port.split(".") %>
<a class="btn btn-primary" type="submit" href="https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignin1.0&wtrealm=https://galogin.ntu.edu.tw/saml_login&wctx=<%= @request_hosts[0] %>">使用計中帳號登入</a>
<p>or</p>
</div>
<div class="input-prepend">
<span class="add-on">
<i class="icon-user"></i>

View File

@ -1,9 +1,9 @@
#built-in-modules
gem 'announcement', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-announcement.git'
gem 'announcement', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-announcement.git', :branch => 'ntu_ga'
gem 'gallery', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-gallery.git'
gem 'member', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-member.git'
gem 'member_staff', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-memberstaff.git'
gem 'page_content', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-pagecontent.git'
gem 'member_staff', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-memberstaff.git', :branch => 'ntu_ga'
gem 'page_content', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-pagecontent.git', :branch => 'ntu_ga'
gem 'personal_book', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalbook.git'
gem 'personal_conference', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalconference.git'
gem 'personal_diploma', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personaldiploma.git'
@ -15,3 +15,9 @@ gem 'personal_patent', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-
gem 'personal_project', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalproject.git'
gem 'personal_research', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalresearch.git'
gem 'web_resource', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-webresource.git'
gem 'ask', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-ask.git', :branch => 'ntu_ga'
gem 'survey', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-survey.git', :branch => 'ntu_ga'
gem 'archive', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-archive.git', :branch => 'ntu_ga'
gem 'faq', '0.0.1', :git => "git@gitlab.tp.rulingcom.com:root/orbit-faq.git"
gem 'feed', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-feed.git'

View File

@ -0,0 +1,11 @@
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
Resque.redis.client.disconnect
Resque.redis = Redis.new(:host => 'localhost', :port => 6379)
Resque.redis.namespace = Site.first.resque_namespace rescue APP_CONFIG['orbit']
else
# We're in conservative spawning mode. We don't need to do anything.
end
end
end

View File

@ -391,6 +391,7 @@ en:
system_email: System Email
preview: Preview
profile: Profile
promoter: Promoter
publications: Publications
purchase: Purchase
quantity: Quantity

17
config/locales/ntu.en.yml Normal file
View File

@ -0,0 +1,17 @@
en:
ntu:
rss_origin: Back to NTU Announcements
site_names:
"www": "Dean of General Affairs"
"sec": "Office of the Dean and Secretariat"
"doc": "Documentation Division"
"general": "General Service Division"
"property": "Property Management Division"
"construction": "Construction and Maintenance Division"
"cashier": "Cashier Division"
"procurement": "Procurement Division"
"fss": "Facilities Service Division"
"police": "Campus Security"
"social": "General Affairs Division, College of Social Science"
"medicine": "General Service Division, College of Medicine"

View File

@ -0,0 +1,17 @@
zh_tw:
ntu:
rss_origin: 回臺大校園公佈欄
site_names:
"www": "總務處"
"sec": "總務長室暨總務處秘書室"
"doc": "文書組"
"general": "事務組"
"property": "保管組"
"construction": "營繕組"
"cashier": "出納組"
"procurement": "採購組"
"fss": "經營管理組"
"police": "駐警隊"
"social": "社科院總務分處"
"medicine": "醫學院總務分處"

View File

@ -393,6 +393,7 @@ zh_tw:
sidebar_nav: 側欄導引
system_email: 系統信箱
profile: 基本資料
promoter: 承辦人
publications: 著作
purchase: 購買
quantity: 數量

View File

@ -8,4 +8,10 @@ generate_system_summary:
cron: 0 0 12 * * *
class: GenerateSystemSummary
args:
description: Generate the system status such as disk free space,package version list for showing at site tab
description: Generate the system status such as disk free space,package version list for showing at site tab
get_announcement_from_rss:
cron: "30 * * * * *"
class: GetAnnouncementFromRss
args:
description: Loop through the announcement RSS until 24h ago

View File

@ -8,6 +8,11 @@ Orbit::Application.routes.draw do
match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put
end
devise_scope :user do
get 'user_login' => 'sessions#create'
match 'user_logout' => 'sessions#destroy'
end
mount Resque::Server, :at => "/admin/resque"
mount Rack::GridFS::Endpoint.new(:db => Mongoid.database,:lookup=>:path), :at => "gridfs"

115
lib/rss_ntu_job.rb Normal file
View File

@ -0,0 +1,115 @@
# encoding: utf-8
require 'rss'
require 'mongo'
require 'mongoid'
# Change this according to local DB
DB_NAME = "orbit_site_new"
Mongoid.configure do |config|
config.master = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
end
class Bulletin
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
end
class BufferCategory
include Mongoid::Document
include Mongoid::Timestamps
end
# Create a hash rss site list from mongodb
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
SITES = Hash[ db["announcement_feeds"].find(accepted: true).entries.collect {|f| [ f["name"], f["link"] ]} ]
CATEGORIES = Array( db["announcement_feeds"].find().entries.collect {|f| f["categories"]} )
yesterday = Time.now - 86400
two_weeks_ago = Time.new - 60 * 60 * 24 * 14
recent_feed = {}
SITES.each_with_index do |(name, url), i|
open("http://#{url}/panel/announcement/front_end/bulletins.rss?inner=true") do |rss|
# Giving 'false' parameter is for skipping irregular format of the RSS
feed = RSS::Parser.parse(rss, false)
feed.items.each do |item|
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
category = "未分類" if category.blank?
if ( item.pubDate > yesterday ) && ( CATEGORIES[i][0] == "全部" || CATEGORIES[i].include?(category) )
recent_feed[item.title.strip] = { date: item.pubDate, description: item.description.gsub("\r\n", '<br/>').strip,
link: item.link, category: category, source: name }
end
end
end
end
def get_category_id(category, categories, coll_cat)
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
if categories.keys.include? "rss_#{category}"
[categories["rss_#{category}"], categories]
else
cat = {
_type: "Category",
key: "rss_#{category}",
disable: false,
title: {:zh_tw => "rss_#{category}"},
created_at: Time.now,
updated_at: Time.now,
module_app_id: db["module_apps"].find({:key=>"announcement"}).first['_id']
}
categories["rss_#{category}"] = result = coll_cat.save(cat)
[result, categories]
end
end
def get_mongo_and_categories
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
coll_bulletin = db["bulletins"]
coll_cat = db["categories"]
categories = coll_cat.find().to_a.inject({}) do |categories, category|
categories[category['key']] = category['_id']
categories
end
[categories, coll_bulletin, coll_cat]
end
recent_feed.each do |title, bulletin|
categories, coll_bulletin, coll_cat = get_mongo_and_categories
category_id, categories = get_category_id(bulletin[:category], categories, coll_cat)
unless coll_bulletin.find_one(title: {:zh_tw => title, :en => ""})
bulletin = { _type: "Bulletin",
postdate: bulletin[:date],
created_at: bulletin[:date],
updated_at: bulletin[:date],
category_id: category_id,
title: {:zh_tw => title, :en => ""},
text: {:zh_tw => bulletin[:description], :en => ""},
available_for_zh_tw: true,
available_for_en: false,
rss_link: bulletin[:link],
rss_source: bulletin[:source],
is_top: false,
is_hot: false,
is_hidden: false }
# coll_bulletin.save(bulletin)
bulletin = Bulletin.new(bulletin)
bulletin.save!
category = { _type: "BufferCategory",
category_id: category_id,
categorizable_type: "Bulletin",
categorizable_id: bulletin.id }
buffer_category = BufferCategory.new(category)
buffer_category.save!
end
end