diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..41c7197 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,104 @@ +PATH + remote: . + specs: + personal_activity (0.0.1) + mongoid (= 4.0.0.beta2) + rails (= 4.1.0.rc2) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.0.rc2) + actionpack (= 4.1.0.rc2) + actionview (= 4.1.0.rc2) + mail (~> 2.5.4) + actionpack (4.1.0.rc2) + actionview (= 4.1.0.rc2) + activesupport (= 4.1.0.rc2) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.0.rc2) + activesupport (= 4.1.0.rc2) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.0.rc2) + activesupport (= 4.1.0.rc2) + builder (~> 3.1) + activerecord (4.1.0.rc2) + activemodel (= 4.1.0.rc2) + activesupport (= 4.1.0.rc2) + arel (~> 5.0.0) + activesupport (4.1.0.rc2) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) + bson (2.3.0) + builder (3.2.2) + connection_pool (2.0.0) + erubis (2.7.0) + hike (1.2.3) + i18n (0.6.9) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (5.3.4) + mongoid (4.0.0.beta2) + activemodel (>= 4.0.0) + moped (~> 2.0.beta6) + origin (~> 2.1) + tzinfo (>= 0.3.37) + moped (2.0.0.rc1) + bson (~> 2.2) + connection_pool (~> 2.0) + optionable (~> 0.2.0) + multi_json (1.10.1) + optionable (0.2.0) + origin (2.1.1) + polyglot (0.3.5) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.1.0.rc2) + actionmailer (= 4.1.0.rc2) + actionpack (= 4.1.0.rc2) + actionview (= 4.1.0.rc2) + activemodel (= 4.1.0.rc2) + activerecord (= 4.1.0.rc2) + activesupport (= 4.1.0.rc2) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.0.rc2) + sprockets-rails (~> 2.0.0) + railties (4.1.0.rc2) + actionpack (= 4.1.0.rc2) + activesupport (= 4.1.0.rc2) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.3.2) + sprockets (2.12.1) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + thor (0.19.1) + thread_safe (0.3.4) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + tzinfo (1.2.1) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + personal_activity! diff --git a/app/controllers/admin/activities_controller.rb b/app/controllers/admin/activities_controller.rb index d391a34..2bc59ea 100644 --- a/app/controllers/admin/activities_controller.rb +++ b/app/controllers/admin/activities_controller.rb @@ -2,44 +2,82 @@ class Admin::ActivitiesController < OrbitMemberController layout "member_plugin" include Admin::PersonalActivitiesHelper - before_action :set_activity, only: [:edit, :update, :destroy] - #before_action :set_plugin + before_action :set_activity, only: [:show, :edit, :update, :destroy] + before_action :set_plugin + before_action :get_settings,:only => [:new, :edit, :setting] - #before_action :need_access_right - #before_action :allow_admin_only, :only => [:index, :setting] + before_action :need_access_right + before_action :allow_admin_only, :only => [:index, :setting] def index @activities = Activity.order_by(:year => 'desc').page(params[:page]).per(10) - respond_to do |format| - format.html - format.xml { render :xml => @activities } - end + #respond_to do |format| + #format.html + #format.xml { render :xml => @activities } + #end end def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @activity = Activity.new + if params[:desktop] + render :layout => false + end end def create if !activity_params['member_profile_id'].blank? @member = MemberProfile.find(activity_params['member_profile_id']) rescue nil + @activity = Activity.new(activity_params) + @activity.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end + elsif !params[:author_members].blank? - activity_params['member_profile_id'] = params[:author_members] + + params[:author_members].each do |author_member| + activity_params['member_profile_id'] = author_member + @activity = Activity.new(activity_params) + @activity.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + end + redirect_to params['referer_url'] else - activity_params['member_profile_id'] = current_user.member_profile_id + activity_params['member_profile_id'] = User.find(current_user.id).member_profile_id + @activity = Activity.new(activity_params) + @activity.save + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + redirect_to params['referer_url'] end - @activity = Activity.new(activity_params) - @activity.save - redirect_to params['referer_url'] + end + def edit + @member = @activity.member_profile rescue nil + if params[:desktop] + render :layout => false + end end def update + @member = @activity.member_profile rescue nil @activity.update_attributes(activity_params) - redirect_to params['referer_url'] + @activity.save + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end end def destroy @@ -51,6 +89,7 @@ class Admin::ActivitiesController < OrbitMemberController end end + def analysis end @@ -102,6 +141,45 @@ class Admin::ActivitiesController < OrbitMemberController end end + def toggle_hide + if params[:ids] + @activities = Activity.any_in(_id: params[:ids]) + @activities.each do |activity| + activity.is_hidden = params[:disable] + activity.save + end + end + render json: {"success"=>true} + end + + def setting + end + + def frontend_setting + @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @intro = ActivityIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? ActivityIntro.new({:member_profile_id=>@member.id}) : @intro + end + + def update_frontend_setting + @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil + @intro = ActivityIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? ActivityIntro.new({:member_profile_id=>@member.id}) : @intro + @intro.update_attributes(intro_params) + @intro.save + redirect_to URI.encode('/admin/members/'+@member.to_param+'/activity') + end + + def get_settings + end + + def set_plugin + @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Activity'}.first + @module_app = ModuleApp.where(:key=>'personal_activity').first + @module_app = ModuleApp.create(:key=>'personal_activity',:title=>'PersonalActivity','frontend_enable'=>true) if @module_app.nil? + @categories = @module_app.categories + end + private def set_activity @@ -119,4 +197,8 @@ class Admin::ActivitiesController < OrbitMemberController def activity_params params.require(:activity).permit! rescue nil end + + def intro_params + params.require(:activity_intro).permit! rescue nil + end end diff --git a/app/controllers/personal_activities_controller.rb b/app/controllers/personal_activities_controller.rb index 252047a..378c0ec 100644 --- a/app/controllers/personal_activities_controller.rb +++ b/app/controllers/personal_activities_controller.rb @@ -34,7 +34,8 @@ class PersonalActivitiesController < ApplicationController 'activity_end_date' => t('personal_activity.activity_end_date'), 'year' => t('personal_activity.year'), 'note' => t('personal_activity.note') - } + }, + "total_pages" => activities.total_pages } end diff --git a/app/models/activity.rb b/app/models/activity.rb index 0f106c5..225182d 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -4,8 +4,10 @@ class Activity #include Mongoid::Attributes::Dynamic #include Admin::PersonalActivitiesHelper include OrbitModel::Status - include MemberHelper + #include MemberHelper include Slug + include OrbitCategory::Categorizable + belongs_to :member_profile # Language field :activity_name, as: :slug_title, type: String, localize: true @@ -17,8 +19,16 @@ class Activity field :activity_start_date, type: DateTime field :activity_end_date, type: DateTime field :note, type: String - - belongs_to :member_profile + field :url + field :rss2_id + # paginates_per 10 + + has_many :activity_files, :autosave => true, :dependent => :destroy + #belongs_to :activity_category + + accepts_nested_attributes_for :activity_files, :allow_destroy => true + before_validation :add_http + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc") } def get_plugin_data(fields_to_show) plugin_datas = [] @@ -30,8 +40,55 @@ class Activity plugin_datas end + def self.get_plugin_datas_to_member(datas) + fields_to_show = [ + "attendee", + "activity_name", + "activity_organizer", + "activity_area", + "activity_start_date", + "activity_end_date" + ] + fields_to_remove = [] + + pd_title = [] + + fields_to_show.each do |t| + if (self.fields[t].type.to_s == "String" rescue false) + fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false) + else + fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) + end + pd_title << { + "plugin_data_title" => I18n.t("personal_activity.#{t}") + } if !fields_to_remove.include?(t) + end + + fields_to_show = fields_to_show - fields_to_remove + + plugin_datas = datas.sort_for_frontend.collect do |p| + + pd_data = [] + fields_to_show.collect do |t| + if t == "activity_title" + pd_data << { "data_title" => "#{p.send(t)}" } + elsif t.include?("date") + pd_data << { "data_title" => (p.send(t).strftime('%Y-%m-%d') rescue p.send(t)) } + else + pd_data << { "data_title" => p.send(t) } + end + end + { + "pd_datas" => pd_data + } + end + return [pd_title,plugin_datas] + end + def get_plugin_field_data(field) case field + when "language" + value = self.language.nil? ? "" : I18n.t(self.language) rescue "" when 'attendee' path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#' value = "#{self.member_profile.name}" @@ -42,17 +99,27 @@ class Activity when 'activity_area' value = self.activity_area rescue '' when 'activity_start_date' - value = self.activity_start_date rescue '' + value = self.activity_start_date.strftime('%Y-%m-%d') rescue '' when 'activity_end_date' - value = self.activity_end_date rescue '' + value = self.activity_end_date.strftime('%Y-%m-%d') rescue '' when 'year' value = self.year rescue '' when 'note' value = self.note rescue '' + when "file" + files = [] + self.research_files.each do |research_file| + url = research_file.file.url + title = (research_file.title.blank? ? File.basename(research_file.file.path) : research_file.title) + files << "
  • #{title}
  • " + end + value = files.join("") else value = self.send(field) rescue '' end + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value + { 'key' => field, 'title_class' => "activity-#{field.gsub('_','-')}-field", @@ -61,4 +128,12 @@ class Activity 'value' => value } end + + protected + def add_http + unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//] + self.url = 'http://' + self.url + end + end + end diff --git a/app/models/activity_file.rb b/app/models/activity_file.rb new file mode 100644 index 0000000..1c827aa --- /dev/null +++ b/app/models/activity_file.rb @@ -0,0 +1,10 @@ +class ActivityFile + include Mongoid::Document + include Mongoid::Timestamps + mount_uploader :file, AssetUploader + field :description, localize: true + field :should_destroy, :type => Boolean + field :title, localize: true + + belongs_to :activity + end \ No newline at end of file diff --git a/app/models/activity_intro.rb b/app/models/activity_intro.rb new file mode 100644 index 0000000..32e4d80 --- /dev/null +++ b/app/models/activity_intro.rb @@ -0,0 +1,2 @@ +class ActivityIntro < PersonalPluginIntro +end \ No newline at end of file diff --git a/app/views/admin/activities/index.html.erb b/app/views/admin/activities/index.html.erb index b2dae40..1ee9b57 100644 --- a/app/views/admin/activities/index.html.erb +++ b/app/views/admin/activities/index.html.erb @@ -4,8 +4,8 @@ <%= t("personal_activity.participant") %> <%= t("personal_activity.year") %> - <%= t("personal_plugins.activity_name") %> - <%= t("personal_plugins.activity_organizer") %> + <%= t("personal_activity.activity_name") %> + <%= t("personal_activity.activity_organizer") %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 95b837c..7a8150b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,3 +13,28 @@ en: activity_end_date: "End Date" note: "Note" graph_by: "Graphy By" + file : "File" + file_name : "File name" + upload: "upload" + description : "File Description" + frontend: + researchs: "Activity Front-end" + + create_success : "Successfully Create" + update_success : "Successfully Update" + delete_success : "Successfully Delete" + add: "Add" + back: "Back" + delete: "Delete" + edit: "Edit" + nothing: "Nothing" + show: "Show" + sure?: "Are you sure?" + update: "Update" + yes_: "Yes" + no_: "No" + cancel : "Cancel" + save: "save" + hintText: "Type in a search term" + noResultsText: "No results" + searchingText: "Searching…" \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 3a2807d..a31fc1c 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,3 +2,39 @@ zh_tw: module_name: activity: "教師參與展演活動" personal_activity: "教師參與展演活動" + personal_activity: + attendee: "主辦人" + participant: "參與人" + year: "年度" + activity_name: "活動名稱" + activity_organizer: "活動組織" + activity_area: "地點" + activity_start_date: "開始時間" + activity_end_date: "結束時間" + note: "備註" + graph_by: "Graphy By" + file : "檔案" + file_name : "檔案名稱" + description : "描述" + upload: "上傳" + frontend: + activities: "活動前台" + + create_success : "新增完成!!" + update_success : "更新完成!!" + delete_success : "刪除成功!!" + add: "新增" + back: "返回" + delete: "刪除" + edit: "編輯" + nothing: "無" + show: "顯示" + sure?: "您肯定嗎?" + update: "更新" + yes_: "是" + no_: "否" + cancel : "取消" + save: "儲存" + hintText: "請輸入搜尋關鍵字" + noResultsText: "沒有相關的比對結果" + searchingText: "搜尋中…" diff --git a/lib/personal_activity/engine.rb b/lib/personal_activity/engine.rb index d185e3b..ef28981 100644 --- a/lib/personal_activity/engine.rb +++ b/lib/personal_activity/engine.rb @@ -4,7 +4,7 @@ module PersonalActivity OrbitApp.registration "PersonalActivity",:type=> 'ModuleApp' do module_label 'module_name.personal_activity' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '6', :app_name=>"Activity", :intro_app_name=>"PersonalActivityIntro",:path=>"/plugin/personal_activity/profile",:front_path=>"/profile",:admin_path=>"/admin/activities",:i18n=>'module_name.personal_activity', :module_app_name=>'PersonalActivity', :one_line_title => true, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/activities/analysis" + personal_plugin :enable => true, :sort_number => '20', :app_name=>"Activity", :intro_app_name=>"PersonalActivityIntro",:path=>"/plugin/personal_activity/profile",:front_path=>"/profile",:admin_path=>"/admin/activities",:i18n=>'module_name.personal_activity', :module_app_name=>'PersonalActivity', :one_line_title => true, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/activities/analysis" version "0.1" desktop_enabled true @@ -14,7 +14,7 @@ module PersonalActivity update_info 'some update_info' frontend_enabled - data_count 1..10 + data_count 1..30 icon_class_no_sidebar "icons-user" end end diff --git a/modules/personal_activity/index.html.erb b/modules/personal_activity/index.html.erb new file mode 100644 index 0000000..6f6d760 --- /dev/null +++ b/modules/personal_activity/index.html.erb @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + +

    {{widget-title}}

    {{year}}{{activity_name}}{{activity_organizer}}{{activity_area}}{{activity_start_date}}{{activity_end_date}}{{note}}
    {{year}}{{activity_name}}{{activity_organizer}}{{activity_area}}{{activity_start_date}}{{activity_end_date}}{{note}}
    +{{pagination_goes_here}} + + diff --git a/modules/personal_activity/index_search1.html.erb b/modules/personal_activity/index_search1.html.erb new file mode 100644 index 0000000..f51c040 --- /dev/null +++ b/modules/personal_activity/index_search1.html.erb @@ -0,0 +1,62 @@ + + +
    +

    {{widget-title}}

    +
    + + + + + + Clear +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +

    {{widget-title}}

    {{year}}{{activity_name}}{{activity_organizer}}{{activity_area}}{{activity_start_date}}{{activity_end_date}}{{note}}
    {{year}}{{activity_name}}{{activity_organizer}}{{activity_area}}{{activity_start_date}}{{activity_end_date}}{{note}}
    +{{pagination_goes_here}} + + + diff --git a/modules/personal_activity/info.json b/modules/personal_activity/info.json new file mode 100644 index 0000000..cda3d13 --- /dev/null +++ b/modules/personal_activity/info.json @@ -0,0 +1,12 @@ +{ + "frontend": [ + { + "filename" : "index", + "name" : { + "zh_tw" : "1. 列表", + "en" : "1. List" + }, + "thumbnail" : "thumb.png" + } + ] +} \ No newline at end of file diff --git a/modules/personal_activity/show.html.erb b/modules/personal_activity/show.html.erb new file mode 100644 index 0000000..b183818 --- /dev/null +++ b/modules/personal_activity/show.html.erb @@ -0,0 +1,8 @@ + + + + + + + +
    {{title}}{{value}}
    diff --git a/modules/personal_activity/thumbs/thumb.png b/modules/personal_activity/thumbs/thumb.png new file mode 100644 index 0000000..266af56 Binary files /dev/null and b/modules/personal_activity/thumbs/thumb.png differ