Compare commits

..

15 Commits
master ... fgu

Author SHA1 Message Date
manson 3ac4aa551b Fix announcement preview for IE 2014-06-25 11:54:06 +08:00
spen 10d3031509 Fix IE use CKeditor can not upload 2014-06-18 15:53:59 +08:00
spen cfeeb92263 announcement image upload limit 2014-06-17 10:35:02 +08:00
manson 9f01a4099c Upgrade CKeditor to 4.4.1, support IE 8,9,10,11 2014-06-17 10:30:49 +08:00
manson b7807bf612 Fix show page not displaying content 2014-06-17 10:30:35 +08:00
manson 55d43dff8f Fix announcement search page 2014-06-17 10:30:06 +08:00
spen 77663feb84 Merge branch 'fgu' of gitlab.tp.rulingcom.com:saurabh/orbit-4-2 into fgu 2014-06-16 10:15:52 +08:00
rulingcom 17dcbe95f1 fix login 2014-06-11 16:01:30 +08:00
rulingcom 97738b0e63 fgu 2014-06-11 16:01:30 +08:00
manson 1d17228c98 Fix resque-scheduler version, 3.0.0 is not compatible 2014-05-28 14:21:38 +08:00
spen 13fd8d03e4 fix reset password 2014-05-28 11:35:47 +08:00
manson 420f64776d Ignore compressed log files 2014-05-28 11:35:36 +08:00
manson 251f539de5 Fix mobile page 500 error when there's no adbanner named "Home" 2014-05-28 11:35:27 +08:00
rulingcom 748813aae2 fix login 2014-04-16 17:08:59 +08:00
rulingcom fd4e8fd9b9 fgu 2014-04-16 17:08:59 +08:00
24 changed files with 382 additions and 67 deletions

View File

@ -109,7 +109,7 @@ group :test, :development do
gem "spork"
gem "capybara"
#gem 'rack-mini-profiler'
gem "better_errors", "1.1.0"
gem "better_errors"
# gem 'yard'
# gem "bluecloth"
end

View File

@ -19,8 +19,8 @@ $(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
maxFileSize: 50000000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx|csv|txt|zip|rar|tar|gz|odt|tiff|key|page)$/i,
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx)$/i,
dropZone: $('#dropzone'),
headers:{
'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content")

View File

@ -28,8 +28,6 @@ CKEDITOR.editorConfig = function( config ) {
{ name: 'about' }
];
config.allowedContent = true;
config.skin = 'moono';
config.filebrowserBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path(:module_app_id=>ModuleApp.where(:key=>'asset').first.id) %>";
@ -37,10 +35,6 @@ CKEDITOR.editorConfig = function( config ) {
//Font Config
config.font_names = 'Arial;Comic Sans MS;Courier New;Georgia;Helvetica;Lucida Sans Unicode;Tahoma;Times New Roman;Trebuchet MS;Verdana;微軟正黑體';
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;
config.pasteFromWordPromptCleanup = true;
};
CKEDITOR.on('instanceReady',function(){

View File

@ -32,6 +32,7 @@ function preview() {
var resize = 500/bannerW
bannerW = Math.floor(bannerW*resize);
bannerH = Math.floor(bannerH*resize);
console.log(bannerW)
};
if(bannerH > 300) {
var resize = 300/bannerH

View File

@ -7,12 +7,7 @@ $(function() {
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
var formData;
if(typeof(FormData) == "function"){
formData = new FormData( $('form.previewable')[0] );
}else{
formData = $('form.previewable').serialize()
}
var formData = new FormData( $('form.previewable')[0] );
$.ajax({
type: "post",

View File

@ -4,7 +4,7 @@ class Admin::AdBannersController < OrbitBackendController
open_for_sub_manager
def index
@ad_banners = get_sorted_and_filtered("ad_banner")
@ad_banners = AdBanner.all.page(params[:page]).per(10)
end
def show

View File

@ -11,7 +11,7 @@ class Admin::AdImagesController < Admin::AdBannersController
end
def index
@ad_images = get_sorted_and_filtered("ad_image")
@ad_images = AdImage.all.page(params[:page]).per(10)
end
def edit

View File

@ -11,7 +11,7 @@ class Admin::DashboardsController < OrbitBackendController
check_backend_openness
@module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link')
@recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link')
@most_visited = get_most_visited('bulletin', 'page_context')
@most_visited = get_most_visited('bulletin', 'page_context','page')
end
def reload_all_content
@ -22,7 +22,7 @@ class Admin::DashboardsController < OrbitBackendController
end
def reload_most_visited
@most_visited = get_most_visited('bulletin', 'page_context')
@most_visited = get_most_visited('bulletin', 'page_context','page')
respond_to do |format|
format.js { render 'reload', locals: {div_id: 'most_visited'} }
end
@ -46,7 +46,8 @@ class Admin::DashboardsController < OrbitBackendController
end
def get_disk_usage
render :json => `df -m /home`.scan(/\d+%/).first.gsub('%','') rescue '0'
@usw = Usagewatch
render :json => @usw.uw_diskused_perc.to_s
end
def get_month_traffic

View File

@ -0,0 +1,10 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def doorkeeper
oauth_data = request.env["omniauth.auth"]
@user = User.find_or_create_for_doorkeeper_oauth(oauth_data)
@user.update_doorkeeper_credentials(oauth_data)
@user.save
sign_in_and_redirect @user
end
end

View File

@ -321,8 +321,6 @@ class ApplicationController < ActionController::Base
sorted_objects.flatten!
sorted_objects.uniq!
objects = get_with_nil(objects, option, sorted_objects)
elsif option.eql?('size')
objects = objects.order_by([ [:width, params[:direction]], [:height, params[:direction]] ])
end
end
end
@ -363,12 +361,7 @@ class ApplicationController < ActionController::Base
end
if pagination
filtered_objects = filter_authorized_objects(objects)
if filtered_objects.is_a?(Array)
Kaminari.paginate_array(filtered_objects).page(params[:page]).per(10)
else
filter_authorized_objects(objects).page(params[:page]).per(10)
end
Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10)
else
filter_authorized_objects(objects)
end

View File

@ -0,0 +1,66 @@
# encoding: utf-8
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
require 'net/http'
require 'uri'
def create
@user_id = params[:user][:user_id]
@user_password = params[:user][:password]
if @user_id == 'rulingcom'
resource = User.first(conditions:{user_id: @user_id})
if !resource.blank? and resource.valid_password?(@user_password)
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
redirect_to after_sign_in_path_for(resource)
elsif !resource.valid_password?(@user_password)
flash[:error] = "密碼錯誤<br />password Local fail"
redirect_to :root
else
flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員<br />Sorry, you don't have the account or authority to login. Please contact the website administrator."
redirect_to :root
end
else
uri = URI('http://www.fgu.edu.tw/cgi-bin/check_intrant.pl')
response = Net::HTTP.post_form(uri, 'username' => @user_id, 'password' => params[:user][:password])
@response = response.body
if @response.include?("username=#{@user_id}")
resource = User.first(conditions:{user_id: @user_id})
if !resource.blank?
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
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
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
end
end

View File

@ -190,10 +190,8 @@ module ApplicationHelper
end
def page_stylesheets(page, edit=nil)
orbit_bar_bootstrap = asset_path 'orbit_bar_bootstrap'
orbit_bar_bootstrap = orbit_bar_bootstrap.include?('css') ? orbit_bar_bootstrap : orbit_bar_bootstrap+'.css'
stylesheets = ''
stylesheets << "<link href='#{orbit_bar_bootstrap}' rel='stylesheet' type='text/css' />\n"
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"
@ -248,24 +246,15 @@ module ApplicationHelper
end
def get_month_traffic
site = Site.first
if site.month_traffic_cache.blank? or (site.month_traffic_cache['updated_at'] < (Time.now-1.day) rescue true)
site.month_traffic_cache = {}
site.month_traffic_cache['result'] = []
(1..30).each do |i|
visits = Impression.where( created_at: {
'$gte' => Time.now.beginning_of_day-i.days,
'$lte' => Time.now.end_of_day-i.days}
).count
site.month_traffic_cache['result'].push([ Time.now.beginning_of_day-i.days, visits])
end
site.month_traffic_cache['updated_at'] = Time.now
site.save
result = []
(0..30).each do |i|
visits = Impression.where( created_at: {
'$gte' => Time.now.beginning_of_day-i.days,
'$lte' => Time.now.end_of_day-i.days}
).count
result.push([ Time.now.beginning_of_day-i.days, visits])
end
[:name=> t(:visitors_count),:data=>site.month_traffic_cache['result']]
[:name=> t(:visitors_count),:data=>result]
end
# def get_today_traffic

View File

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

View File

@ -63,6 +63,7 @@ class MailCronMailer < ActionMailer::Base
end
end
@mail_cron_log = {
:mail_subject => @data.mail_subject,
:mail_to => group_mail,
@ -73,16 +74,10 @@ class MailCronMailer < ActionMailer::Base
@mail_cron_log = MailCronLog.new(@mail_cron_log)
@mail_cron_log.save
@mail_to_count = @data.mail_to.split(',') - group_mail.split(',')
if @mail_to_count.count == 0
@data.destroy
else
@data.mail_to = @mail_to_count.join(',')
@data.save
end
@data.destroy
end

View File

@ -38,7 +38,7 @@ class MailCron
if !email_user_id.blank?
@user = User.find(email_user_id) rescue nil
@user = User.find(email_user_id)
@group_mail << @user.email if !@user.blank?

View File

@ -49,9 +49,6 @@ class Site
field :site_token
field :mobile_on, :type => Boolean, :default => false
field :store_confirmation, :type => Boolean, :default => false
field :meta_viewport, :type => Boolean, :default => false
field :month_traffic_cache
belongs_to :design
has_many :site_metas, :autosave => true, :dependent => :destroy

View File

@ -4,8 +4,6 @@
<link rel="shortcut icon" href="<%= asset_path 'favicon.ico' %>">
<% end %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<% if @site.meta_viewport %>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<% end %>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

View File

@ -1,6 +1,6 @@
#built-in-modules
gem 'archive', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-archive.git'
gem 'announcement', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-announcement.git'
gem 'announcement', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-announcement.git', :branch => 'fgu'
gem 'gallery', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-gallery.git'
gem 'member', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-member.git'
gem 'member_staff', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-memberstaff.git'

View File

@ -56,7 +56,6 @@ module Orbit
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', 'modules', '*.{rb,yml}').to_s]
config.i18n.enforce_available_locales = false
config.i18n.default_locale = :zh_tw
# JavaScript files you want as :defaults (application.js is always included).

View File

@ -1,5 +1,5 @@
update_tag_cloud:
cron: 0 0 0,12 * * *
cron: 0 0 [0,12] * * *
class: UpdateTagCloud
args:
description: UpdateTagCloud
@ -11,7 +11,13 @@ generate_system_summary:
description: Generate the system status such as disk free space,package version list for showing at site tab
email_cron:
cron: 0 0 10,14,17,20 * * *
cron: 0 0 [10,14,17,20] * * *
class: EmailCron
args:
description: EmailCron
get_remote_announcement:
cron: 0 * * * * *
class: GetRemoteAnnouncement
args:
description: GetRemoteAnnouncement

View File

@ -4,7 +4,7 @@ Orbit::Application.routes.draw do
# get "robots.txt" => 'robots#index'
devise_for :users, :controllers => { :registrations => "registrations", :passwords => 'passwords', :confirmations => 'confirmations' } do
devise_for :users, :controllers => { :sessions => 'sessions', :registrations => "registrations", :passwords => 'passwords', :confirmations => 'confirmations' } do
resources :passwords, :except => [:index, :show, :destroy]
match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put
end

57
config/solr.god Normal file
View File

@ -0,0 +1,57 @@
rails_env = ENV['RAILS_ENV'] || "production"
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/..'
user_home = ENV['HOME'] || File.dirname(__FILE__) + '/../..'
development_uid = ''
development_gid = ''
God.watch do |w|
w.dir = rails_root
w.name = "sunspot-solr"
w.group = 'rulingcom'
w.interval = 30.seconds
w.env = {"RAILS_ENV"=>rails_env}
w.start = "HOME=#{user_home} QUEUE=* RAILS_ENV=#{rails_env} rake -f #{rails_root}/Rakefile sunspot:solr:start"
w.keepalive
w.uid = (rails_env == 'production' )? "root" : development_uid
w.gid = (rails_env == 'production' )? "root" : development_gid
w.pid_file = "#{rails_root}/solr/pids/production/sunspot-solr-production.pid"
w.log = (rails_env == 'production' )? "/var/log/#{w.group}/#{w.name}.log":"#{rails_root}/log/dev-#{w.name}.log"
# 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

View File

@ -0,0 +1,26 @@
module OmniAuth
module Strategies
class Doorkeeper < OmniAuth::Strategies::OAuth2
option :name, :doorkeeper
option :client_options, {
:site => "http://localhost:8000",
:authorize_path => "/oauth/authorize"
}
uid do
raw_info["id"]
end
info do
{
:email => raw_info["email"]
}
end
def raw_info
@raw_info ||= access_token.get('/api/v1/me.json').parsed
end
end
end
end

181
lib/remote_announcement.rb Normal file
View File

@ -0,0 +1,181 @@
require 'mongo'
require 'open-uri'
require 'json'
require 'date'
@db = Mongo::Connection.new("localhost", 27017).db("fgu_new")
@coll_bulletin = @db["bulletins"]
@bulletin_links = @db["bulletin_links"]
@coll_cat = @db["categories"]
@updated_bulletins = Array.new
bulletin_module_id = @db["module_apps"].find(key: "announcement").first
coll_bulletin = @db["bulletins"]
@coll_buffer_cat = @db["buffer_categories"]
coll_cat = @db["categories"]
coll_bulletin_cat = @db["categories"].find(module_app_id: bulletin_module_id["_id"])
@categories = coll_bulletin_cat.find().to_a.inject({}) do |categories, category|
categories[category['key']] = category['_id']
categories
end
# @categories = @coll_cat.find().to_a.inject({}) do |categories, category|
# categories[category['key']] = category['_id']
# categories
# end
def save_bulletin_links bulletin_id, title, url, c_time
title = "Link" if title == ''
bulletin_link = {
title: {"zh_tw" => title, "en" => title },
url: url,
bulletin_id: bulletin_id,
created_at: c_time,
updated_at: c_time
}
@bulletin_links.save(bulletin_link)
end
def get_remote_bulletins_json(url)
data = ""
open(url){|f| f.each_line {|line| data << line} }
bulletins = JSON.parse data
bulletins.each do |b|
lang = b[1]=='zh-tw' ? "zh_tw".to_sym : "en".to_sym
next if b[2]==""
next if @categories["#{b[7]}"].nil?
if b[5]=="" and b[4]!=""
b[5]=b[4]
b[4]=""
end
bulletin = { _type: "Bulletin",
postdate: Time.parse(b[8]),
created_at: Time.parse(b[8]),
updated_at: Time.parse(b[8]),
is_checked: true,
is_pending: false,
is_rejected: false,
category_id: @categories["#{b[7]}"],
title: {lang => b[2]},
subtitle: {lang => b[4]},
text: {lang => b[5]},
available_for_zh_tw: true,
available_for_en: true,
create_user_id: "",
public: true,
sn: b[0],
site: b[9],
site_id: b[10],
is_top: false,
is_hot: false,
is_hidden: false }
this_bulletin = @coll_bulletin.find_one(:$and => [{ :sn => bulletin[:sn]},{ :site => bulletin[:site]}])
@updated_bulletins.push({:sn => bulletin[:sn],:site => bulletin[:site] })
# p bulletin
unless this_bulletin
bs = @coll_bulletin.save(bulletin)
buffer_cat = { _type: "BufferCategory",
category_id: @categories["#{b[7]}"],
categorizable_type: "Bulletin",
categorizable_id: bs }
@coll_buffer_cat.save(buffer_cat)
#files
(10..14).each do |i|
ta = i + 5
save_bulletin_links( bulletin[:_id], b[ta], b[i], bulletin[:created_at] ) if b[i] != ''
end
#url
save_bulletin_links( bulletin[:_id], '', b[20], bulletin[:created_at] ) if b[20] != ''
# puts "Inserted "+lang.to_s+" "+bulletin[:title][lang]
# p bulletin
else
@coll_bulletin.update(
{"_id"=>this_bulletin["_id"]},
{
:_type => "Bulletin",
:postdate => bulletin[:postdate],
:created_at => bulletin[:created_at],
:updated_at => bulletin[:updated_at],
:is_checked => this_bulletin["is_checked"],
:is_pending => this_bulletin["is_pending"],
:is_rejected => this_bulletin["is_rejected"],
:category_id => bulletin[:category_id],
:title => bulletin[:title],
:subtitle => bulletin[:subtitle],
:text => bulletin[:text],
:available_for_zh_tw => this_bulletin["available_for_zh_tw"],
:available_for_en => this_bulletin["available_for_en"],
:create_user_id => "",
:public => this_bulletin["public"],
:sn => bulletin[:sn],
:site => bulletin[:site],
:site_id => bulletin[:site_id],
:is_top => this_bulletin["is_top"],
:is_hot => this_bulletin["is_hot"],
:is_hidden => this_bulletin["is_hidden"]
})
@coll_buffer_cat.remove(categorizable_id: BSON::ObjectId(this_bulletin["_id"].to_s) )
buffer_cat = { _type: "BufferCategory",
category_id: bulletin[:category_id],
categorizable_type: "Bulletin",
categorizable_id: this_bulletin["_id"] }
@coll_buffer_cat.save(buffer_cat)
@bulletin_links.remove(bulletin_id: BSON::ObjectId(this_bulletin["_id"].to_s) )
#files
(10..14).each do |i|
ta = i + 5
save_bulletin_links( this_bulletin["_id"], b[ta], b[i], this_bulletin["created_at"] ) if b[i] != ''
end
#url
save_bulletin_links( this_bulletin["_id"], '', b[20], bulletin[:created_at] ) if b[20] != ''
# puts "Updated "+lang.to_s+" "+bulletin[:title][lang]
# p this_bulletin["_id"]
end
end
end
get_remote_bulletins_json("http://president.fgu.edu.tw/remote_annoucement/get_news2.php")
get_remote_bulletins_json("http://car.fgu.edu.tw/remote_annoucement/get_news2.php")
# Delete bulletins that had been removed form remote sites
# Find all remote bulletins on server
local_bulletins = @coll_bulletin.find({ site: { :$exists => true } })
# Check if each remote bulletins on server exist in the updated bulletins
local_bulletins.each do |local_bulletin|
result = @updated_bulletins.select {|remote_bulletin| remote_bulletin[:sn] == local_bulletin["sn"] and remote_bulletin[:site] == local_bulletin["site"]}
if result.length == 0
@coll_bulletin.remove(:$and => [{ :sn => local_bulletin["sn"]},{ :site => local_bulletin["site"]}])
p "Delete: "+local_bulletin["site"]+"-"+local_bulletin["sn"]
end
end