From 5aa0bd0cad8963834326f642de8ffb47287e43c7 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Wed, 20 May 2026 17:50:28 +0800 Subject: [PATCH] Initial commit: personal_competition gem --- .gitignore | 8 + Gemfile | 14 + Gemfile.lock | 104 ++++++++ MIT-LICENSE | 20 ++ README.rdoc | 3 + Rakefile | 32 +++ app/assets/images/personal_conference/.keep | 0 .../javascripts/personal_conference/.keep | 0 .../stylesheets/personal_conference/.keep | 0 app/controllers/.keep | 0 .../admin/competition_types_controller.rb | 52 ++++ .../admin/competitions_controller.rb | 208 +++++++++++++++ .../desktop/personal_honors_controller.bak | 23 ++ .../personal_competitions_controller.rb | 136 ++++++++++ app/helpers/.keep | 0 .../admin/personal_competitions_helper.rb | 119 +++++++++ app/mailers/.keep | 0 app/models/.keep | 0 app/models/competition.rb | 146 +++++++++++ app/models/competition_intro.rb | 4 + app/models/competition_type.rb | 28 ++ app/views/.keep | 0 .../admin/competition_types/_form.html.erb | 24 ++ .../admin/competition_types/_list.js.erb | 2 + app/views/admin/competition_types/edit.js.erb | 1 + app/views/admin/competition_types/new.js.erb | 1 + .../admin/competitions/_competition.html.erb | 17 ++ app/views/admin/competitions/_form.html.erb | 242 ++++++++++++++++++ .../_list_competition_type.html.erb | 8 + app/views/admin/competitions/destroy.js.erb | 1 + app/views/admin/competitions/edit.html.erb | 5 + .../competitions/frontend_setting.html.erb | 94 +++++++ app/views/admin/competitions/index.html.erb | 44 ++++ app/views/admin/competitions/new.html.erb | 5 + app/views/admin/competitions/setting.html.erb | 70 +++++ .../get_fields_for_index.html.erb | 48 ++++ .../personal_competitions/index.html.erb | 1 + app/views/personal_competitions/show.html.erb | 1 + .../personal_competition/_profile.html.erb | 88 +++++++ bin/rails | 16 ++ config/locales/en.yml | 68 +++++ config/locales/zh_tw.yml | 64 +++++ config/routes.rb | 37 +++ lib/personal_competition.rb | 4 + lib/personal_competition/engine.rb | 22 ++ lib/personal_competition/version.rb | 3 + lib/tasks/personal_honor_tasks.rake | 4 + personal_competition.gemspec | 19 ++ 48 files changed, 1786 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 MIT-LICENSE create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 app/assets/images/personal_conference/.keep create mode 100644 app/assets/javascripts/personal_conference/.keep create mode 100644 app/assets/stylesheets/personal_conference/.keep create mode 100644 app/controllers/.keep create mode 100644 app/controllers/admin/competition_types_controller.rb create mode 100644 app/controllers/admin/competitions_controller.rb create mode 100644 app/controllers/desktop/personal_honors_controller.bak create mode 100644 app/controllers/personal_competitions_controller.rb create mode 100644 app/helpers/.keep create mode 100644 app/helpers/admin/personal_competitions_helper.rb create mode 100644 app/mailers/.keep create mode 100644 app/models/.keep create mode 100644 app/models/competition.rb create mode 100644 app/models/competition_intro.rb create mode 100644 app/models/competition_type.rb create mode 100644 app/views/.keep create mode 100644 app/views/admin/competition_types/_form.html.erb create mode 100644 app/views/admin/competition_types/_list.js.erb create mode 100644 app/views/admin/competition_types/edit.js.erb create mode 100644 app/views/admin/competition_types/new.js.erb create mode 100644 app/views/admin/competitions/_competition.html.erb create mode 100644 app/views/admin/competitions/_form.html.erb create mode 100644 app/views/admin/competitions/_list_competition_type.html.erb create mode 100644 app/views/admin/competitions/destroy.js.erb create mode 100644 app/views/admin/competitions/edit.html.erb create mode 100644 app/views/admin/competitions/frontend_setting.html.erb create mode 100644 app/views/admin/competitions/index.html.erb create mode 100644 app/views/admin/competitions/new.html.erb create mode 100644 app/views/admin/competitions/setting.html.erb create mode 100644 app/views/personal_competitions/get_fields_for_index.html.erb create mode 100644 app/views/personal_competitions/index.html.erb create mode 100644 app/views/personal_competitions/show.html.erb create mode 100644 app/views/plugin/personal_competition/_profile.html.erb create mode 100644 bin/rails create mode 100644 config/locales/en.yml create mode 100644 config/locales/zh_tw.yml create mode 100644 config/routes.rb create mode 100644 lib/personal_competition.rb create mode 100644 lib/personal_competition/engine.rb create mode 100644 lib/personal_competition/version.rb create mode 100644 lib/tasks/personal_honor_tasks.rake create mode 100644 personal_competition.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b09db87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.bundle/ +log/*.log +pkg/ +test/dummy/db/*.sqlite3 +test/dummy/db/*.sqlite3-journal +test/dummy/log/*.log +test/dummy/tmp/ +test/dummy/.sass-cache diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..67ecc09 --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +# Declare your gem's dependencies in personal_honor.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use debugger +# gem 'debugger' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..76cff72 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,104 @@ +PATH + remote: . + specs: + personal_honor (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_honor! diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..03d3c85 --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2014 YOURNAME + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..b356386 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += PersonalHonor + +This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a4f9763 --- /dev/null +++ b/Rakefile @@ -0,0 +1,32 @@ +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end + +require 'rdoc/task' + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'PersonalHonor' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + + + + +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + + +task default: :test diff --git a/app/assets/images/personal_conference/.keep b/app/assets/images/personal_conference/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/personal_conference/.keep b/app/assets/javascripts/personal_conference/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/personal_conference/.keep b/app/assets/stylesheets/personal_conference/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/.keep b/app/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/admin/competition_types_controller.rb b/app/controllers/admin/competition_types_controller.rb new file mode 100644 index 0000000..c7f3e78 --- /dev/null +++ b/app/controllers/admin/competition_types_controller.rb @@ -0,0 +1,52 @@ +class Admin::CompetitionTypesController < OrbitMemberController + before_action :allow_admin_only + + def new + @competition_type = CompetitionType.new + @url = admin_competition_types_path(@competition_type) + render :layout=>false + end + + def create + @competition_type = CompetitionType.new(competition_type_params) + @competition_type.save + @competition_types = CompetitionType.all + render :partial=>'list', :layout=>false + end + + def update_order + orders = params["order"] + CompetitionType.each do |ct| + ct.sort_position = orders["#{ct.id}"] + ct.save + end + render :json => {"success" => true}.to_json + end + + def edit + @competition_type = CompetitionType.find(params[:id]) + @url = admin_competition_type_path(@competition_type) + render :layout=>false + end + + def update + @competition_type = CompetitionType.find(params[:id]) + @competition_type.update_attributes(competition_type_params) + @competition_type.save + @competition_types = CompetitionType.all + render :partial=>'list', :layout=>false + end + + def destroy + competition_type = CompetitionType.find(params[:id]) + competition_type.destroy + @competition_types = CompetitionType.all + render :partial=>'list', :layout=>false + end + + private + + def competition_type_params + params.require(:competition_type).permit! rescue nil + end +end diff --git a/app/controllers/admin/competitions_controller.rb b/app/controllers/admin/competitions_controller.rb new file mode 100644 index 0000000..c4b3b66 --- /dev/null +++ b/app/controllers/admin/competitions_controller.rb @@ -0,0 +1,208 @@ +class Admin::CompetitionsController < OrbitMemberController + layout "member_plugin" + include Admin::PersonalCompetitionsHelper + + before_action :set_competition, 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] + + def index + @competitions = Competition.sort_year_date.page(params[:page]).per(10) + end + + def new + @member = MemberProfile.find_by(:uid=>params['uid'].to_s) rescue nil + @competition = Competition.new + + if params[:desktop] + render :layout => false + end + end + + def analysis_report + role = params[:role_id] + year_start = params[:year_start].to_i + year_end = params[:year_end].to_i + graph_by = params[:graph_by] + + @data = get_chart_data(year_start,year_end,role,params[:graph_by]) + + render :layout => false + end + + def download_excel + year_start = params[:year_start].to_i + year_end = params[:year_end].to_i + @data = get_data_for_excel(year_start,year_end) + respond_to do |format| + format.xlsx { + response.headers['Content-Disposition'] = 'attachment; filename="competitions.xlsx"' + } + end + end + + def create + + if !competition_params['member_profile_id'].blank? + + @member = MemberProfile.find(competition_params['member_profile_id']) rescue nil + @competition = Competition.new(competition_params) + @competition.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? + + params[:author_members].each do |author_member| + + competition_params['member_profile_id'] = author_member + @competition = Competition.new(competition_params) + @competition.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + + redirect_to params['referer_url'] + + else + + competition_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @competition = Competition.new(competition_params) + @competition.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + redirect_to params['referer_url'] + + end + + end + + def edit + @member = @competition.member_profile rescue nil + if params[:desktop] + render :layout => false + end + end + + def update + @member = @competition.member_profile rescue nil + @competition.update_attributes(competition_params) + @competition.save + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end + end + + def destroy + @competition.destroy + respond_to do |format| + format.html { redirect_to(admin_competition_url) } + # format.xml { head :ok } + format.js + format.json {render json: {"success" => true}} + end + end + + def toggle_hide + if params[:ids] + @competitions = Competition.any_in(_id: params[:ids]) + + @competitions.each do |competition| + competition.is_hidden = params[:disable] + competition.save + end + end + + render json: {"success"=>true} + end + + def excel_format + respond_to do |format| + format.xlsx { + response.headers['Content-Disposition'] = 'attachment; filename="competition_format.xlsx"' + } + end + end + + def import_from_excel + workbook = RubyXL::Parser.parse(params["import_file"].tempfile) + sheet = workbook[0] + if sheet.count <= 503 + sheet.each_with_index do |row, i| + next if i < 3 + user = User.where(:user_name => row.cells[0].value).first rescue nil + if !user.nil? + mp = user.member_profile + import_this_competition(row,mp) + end + end + redirect_to admin_competitions_url + else + redirect_to admin_competitions_url(:error => "1") + end + end + + def setting + end + + def frontend_setting + @member = MemberProfile.find_by(:uid=>params['uid'].to_s) rescue nil + @intro = CompetitionIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? CompetitionIntro.new({:member_profile_id=>@member.id}) : @intro + end + + def update_frontend_setting + @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil + @intro = CompetitionIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? CompetitionIntro.new({:member_profile_id=>@member.id}) : @intro + @intro.update_attributes(intro_params) + @intro.save + redirect_to URI.encode('/admin/members/'+@member.to_param+'/Competition') + end + + def get_settings + @competition_types = CompetitionType.all + end + + def set_plugin + @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Competition'}.first + end + + private + + def set_competition + path = request.path.split('/') + if path.last.include? '-' + uid = path[-1].split("-").last + uid = uid.split("?").first + else + uid = path[-2].split("-").last + uid = uid.split("?").first + end + @competition = Competition.find_by(:uid => uid) rescue Competition.find(params[:id]) + end + + def competition_params + params.require(:competition).permit! rescue nil + end + + def intro_params + params.require(:competition_intro).permit! rescue nil + end +end diff --git a/app/controllers/desktop/personal_honors_controller.bak b/app/controllers/desktop/personal_honors_controller.bak new file mode 100644 index 0000000..64c6537 --- /dev/null +++ b/app/controllers/desktop/personal_honors_controller.bak @@ -0,0 +1,23 @@ +class Desktop::PersonalHonorsController < DesktopAdminController + include Admin::PersonalHonorsHelper + + def menu + user = OrbitHelper.current_user + [ + { + "title" => "List", + "layout" => "list" + }, + { + "title" => "Add/Edit", + "layout" => "form", + "new_path" => "/admin/members/#{user.member_profile.to_param}/honors/new" + } + ] + end + + def list + get_paper_list + end + +end \ No newline at end of file diff --git a/app/controllers/personal_competitions_controller.rb b/app/controllers/personal_competitions_controller.rb new file mode 100644 index 0000000..30afeab --- /dev/null +++ b/app/controllers/personal_competitions_controller.rb @@ -0,0 +1,136 @@ +class PersonalCompetitionsController < ApplicationController + def index + params = OrbitHelper.params + filter_value = params[:competitions_filter_value] + competitions = nil + + if filter_value.nil? || filter_value == t("personal_competition.competition_types_all") || filter_value.empty? + competitions = Competition.where(:competition_name.nin => [nil, ""]).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + else + competition_type_id = CompetitionType.any_of({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id + competitions = Competition.where(competition_type_id: competition_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + end + + fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] + + if fields_to_show.blank? + fields_to_show = [ + "year", + "award_name", + "awarding_unit", + "work_name", + "student_name", + "authors" + ] + end + + competition_list = [] + competitions.each do |competition| + t = [] + fields_to_show.each do |fs| + case fs + when "competition_name" + t << {"value" => "" + (competition.send(fs) rescue "") + ""} + when "competition_type" + t << {"value" => (competition.send("competition_type").title rescue "")} + when "authors" + member_profile = competition.send(:member_profile) + role_status_id = member_profile.role_status_ids.first.to_s + path = OrbitHelper.url_to_plugin_show(member_profile.to_param, 'member') rescue '#' + t << {"value" => "" + (member_profile.name rescue "") + "" } + when "competition_date" + t << {"value" => (competition.send(fs).strftime("%Y/%m") rescue "")} + else + t << {"value" => (competition.send(fs) rescue "")} + end + end + competition_list << {"personal_competitions" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "award_name" + header = fs == "authors" ? t("users.name") : t("personal_competition.#{fs}") + headers << { + "head-title" => header, + "col" => col + } + end + + current_locale = I18n.locale + competition_types = CompetitionType.all.pluck(:title).map { |title| { 'competition_type' => title.to_h[current_locale] } } + competition_types.unshift({ 'competition_type' => t("personal_competition.competition_types_all") }) + + { + "competitions" => competition_list, + "competition_types" => competition_types, + "extras" => { "widget-title" => t("module_name.personal_competition"), + "url" => '/' + current_locale.to_s + params[:url] }, + "headers" => headers, + "total_pages" => competitions.total_pages + } + end + + def show + params = OrbitHelper.params + plugin = Competition.where(:is_hidden=>false).find_by(uid: params[:uid].to_s) + fields_to_show = [ + "year", + "competition_type", + "competition_name", + "work_name", + "student_name", + "instructor_name", + "award_place", + "competition_date", + "country", + "honoree", + "awarding_unit", + "keywords", + "url", + "note" + ] + + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} + end + + def get_fields_for_index + @page = Page.find(params[:page_id]) rescue nil + @fields_to_show = [ + "year", + "competition_name", + "award_name", + "work_name", + "student_name", + "instructor_name", + "award_place", + "awarding_unit", + "competition_type", + "competition_date", + "country", + "keywords", + "url", + "note", + "authors", + "award_winner" + ] + @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_competition.#{fs}")), fs]} + @default_fields_to_show = [ + "year", + "award_name", + "awarding_unit", + "work_name", + "student_name", + "authors" + ] + render :layout => false + end + + def save_index_fields + page = Page.find(params[:page_id]) rescue nil + page.custom_array_field = params[:keys] + page.save + render :json => {"success" => true}.to_json + end +end diff --git a/app/helpers/.keep b/app/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/helpers/admin/personal_competitions_helper.rb b/app/helpers/admin/personal_competitions_helper.rb new file mode 100644 index 0000000..b85eb64 --- /dev/null +++ b/app/helpers/admin/personal_competitions_helper.rb @@ -0,0 +1,119 @@ +module Admin::PersonalCompetitionsHelper + + def get_paper_list + user = current_user.nil? ? OrbitHelper.current_user : current_user + user_profile = user.member_profile + competitions = Competition.where(:member_profile_id => user_profile.id) + competitions = competitions.collect do |c| + { + "id" => c.id.to_s, + "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/competitions/#{c.to_param}/edit", + "delete_url" => "/#{I18n.locale.to_s}/admin/competitions/#{c.id.to_s}", + "paper_title" => c.competition_name, + "keywords" => c.keywords, + "files" => [] + } + end + competitions + end + + def import_this_competition(row,mp) + value = nil + competition = Competition.new + row.cells.each_with_index do |cell,index| + next if index < 2 + next if cell.nil? + val = cell.value + next if val.nil? || val == "" + case index + when 2 + value = {"en" => val} + when 3 + begin + value["zh_tw"] = val + rescue + value = {"zh_tw" => val} + end + competition.competition_name_translations = value + when 4 + value = {"en" => val} + when 5 + begin + value["zh_tw"] = val + rescue + value = {"zh_tw" => val} + end + competition.awarding_unit_translations = value + when 6 + competition.year = val + when 7 + competition.language = val + when 8 + cts = CompetitionType.asc(:created_at).all.to_a + competition.competition_type = cts[val.to_i] if val.to_s.is_i? && val.to_i < cts.count + when 9 + competition.url = val + when 10 + competition.keywords = val + when 11 + competition.note = val + end + end + competition.member_profile = mp + competition.save + end + + def get_data_for_excel(year_start,year_end) + data = [] + roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key) + roles.each do |role| + d = {} + d["name"] = role.title + mps = role.member_profile_ids + # d1 = DateTime.new(year_start,1,1,0,0) + # d2 = DateTime.new(year_end,12,31,23,59) + d["data"] = Competition.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue [] + data << d + end + return data + end + + def get_chart_data(year_start,year_end,role,type) + case type + when "category" + jls = CompetitionType.all + end + + finaldata = [] + role = Role.find(role) rescue nil + mps = [] + if !role.nil? + mps = role.member_profile_ids + end + jls.each do |jl| + data = {} + data["name"] = jl.title + data["data"] = {} + (year_start..year_end).each do |year| + # d1 = DateTime.new(year,1,1,0,0) + # d2 = DateTime.new(year,12,31,23,59) + t = jl.competitions.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0 + data["data"][year.to_s] = t + end + finaldata << data + end + data = {"name" => "N/A", "data" => {}} + (year_start..year_end).each do |year| + # d1 = DateTime.new(year,1,1,0,0) + # d2 = DateTime.new(year,12,31,23,59) + case type + when "category" + t = Competition.where(:year => year, :member_profile_id.in => mps, :competition_type_id => nil).count rescue 0 + end + + data["data"][year.to_s] = t + end + finaldata << data + finaldata + end +end diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/competition.rb b/app/models/competition.rb new file mode 100644 index 0000000..303f71f --- /dev/null +++ b/app/models/competition.rb @@ -0,0 +1,146 @@ +class Competition + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include Slug + + belongs_to :competition_type + belongs_to :member_profile + + field :year, type: Integer + field :award_name, localize: true + field :awarding_unit, localize: true + field :competition_name, localize: true + field :work_name, localize: true + field :student_name, localize: true + field :instructor_name, localize: true + field :award_place, localize: true + field :competition_date, type: DateTime + field :language + field :keywords + field :url + field :note + field :rss2_id + field :country, localize: true + field :create_user_id, :type => BSON::ObjectId + field :update_user_id, :type => BSON::ObjectId + + # paginates_per 10 + + before_validation :add_http + + index({year: -1, :competition_date => -1, _id: -1}, { unique: false, background: false }) + scope :sort_year_date, ->{ order_by(:year => "desc",:competition_date => "desc", :id => "desc") } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc",:competition_date => "desc", :id => "desc") } + + def slug_title + self.award_name+' '+self.awarding_unit rescue "" + end + + def get_plugin_data(fields_to_show) + plugin_datas = [] + fields_to_show.each do |field| + plugin_data = self.get_plugin_field_data(field) rescue nil + next if plugin_data.blank? or plugin_data['value'].blank? + plugin_datas << plugin_data + end + plugin_datas + end + + def self.get_plugin_datas_to_member(datas) + page = Page.where(:module => "personal_competition").first rescue nil + + if !page.nil? && !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = [ + "competition_type", + "year", + "competition_name", + "work_name", + "student_name", + "instructor_name", + "award_place" + ] + end + + fields_to_remove = [] + + pd_title = [] + + fields_to_show.each do |t| + if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" 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_competition.#{t}") + } if !fields_to_remove.include?(t) + end + + fields_to_show = fields_to_show - fields_to_remove + + plugin_datas = datas.sort_for_frontend.collect.with_index do |p,idx| + pd_data = [] + fields_to_show.collect do |t| + if t == "competition_name" + link = OrbitHelper.url_to_plugin_show(p.to_param,'personal_competition') + url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank) + tmp_title = p.competition_name + pd_data << { "data_title" => (url_to_plugin_show_blank ? tmp_title : "#{tmp_title}") } + elsif t == "competition_type" + pd_data << {"data_title" => (p.competition_type.title rescue "")} + elsif t == "competition_date" + pd_data << {"data_title" => (p.send(t).strftime("%Y/%m/%d") rescue "")} + else + pd_data << { "data_title" => p.send(t) } + end + end + { + "pd_datas" => pd_data, + "type-sort" => (p.competition_type.sort_position.to_i rescue 1000), + "sort-index" => idx + } + + end + plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]} + return [pd_title,plugin_datas] + + end + + def get_plugin_field_data(field) + case field + when "honoree" + path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#' + value = "" + self.member_profile.name + "" + when "language" + value = I18n.t(self.language) rescue "" + when "competition_type" + value = self.competition_type.title rescue "" + when "competition_date" + value = self.competition_date.strftime("%Y/%m/%d") rescue "" + else + value = self.send(field) rescue "" + end + + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value + + { + "key"=>field, + "title_class"=>"competition-#{field.gsub('_','-')}-field", + "value_class"=>"competition-#{field.gsub('_','-')}-value", + "title"=>I18n.t('personal_competition.'+field), + "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/competition_intro.rb b/app/models/competition_intro.rb new file mode 100644 index 0000000..7e01e79 --- /dev/null +++ b/app/models/competition_intro.rb @@ -0,0 +1,4 @@ +class CompetitionIntro < PersonalPluginIntro + + +end diff --git a/app/models/competition_type.rb b/app/models/competition_type.rb new file mode 100644 index 0000000..9c9574b --- /dev/null +++ b/app/models/competition_type.rb @@ -0,0 +1,28 @@ +class CompetitionType + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include Slug + + field :title, localize: true + field :sort_position, type: Integer, default: 1 + field :rss2_id + + has_many :competitions, :dependent => :destroy + + before_create :add_to_index + before_destroy :remove_from_index + + scope :sort_position, ->{ order_by(:sort_position=>'asc') } + + def add_to_index + if self.is_hidden == false + Rss2.create(:data => self, :title => self.title) + end + end + + def remove_from_index + Rss2.nt_list.delete(@rss2_id) if !@rss2_id.blank? + end + +end diff --git a/app/views/.keep b/app/views/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/admin/competition_types/_form.html.erb b/app/views/admin/competition_types/_form.html.erb new file mode 100644 index 0000000..04d104b --- /dev/null +++ b/app/views/admin/competition_types/_form.html.erb @@ -0,0 +1,24 @@ +<%= form_for(@competition_type, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %> + + + + + +<% end %> diff --git a/app/views/admin/competition_types/_list.js.erb b/app/views/admin/competition_types/_list.js.erb new file mode 100644 index 0000000..91cf1dc --- /dev/null +++ b/app/views/admin/competition_types/_list.js.erb @@ -0,0 +1,2 @@ +$('#competition_types tbody').html("<%= j render :partial => '/admin/competitions/list_competition_type', :collection => @competition_types %>"); +$('#competition_type_modal').modal('hide'); diff --git a/app/views/admin/competition_types/edit.js.erb b/app/views/admin/competition_types/edit.js.erb new file mode 100644 index 0000000..3f4e4f0 --- /dev/null +++ b/app/views/admin/competition_types/edit.js.erb @@ -0,0 +1 @@ +$('#competition_type_modal').html("<%= j render 'form' %>"); diff --git a/app/views/admin/competition_types/new.js.erb b/app/views/admin/competition_types/new.js.erb new file mode 100644 index 0000000..3f4e4f0 --- /dev/null +++ b/app/views/admin/competition_types/new.js.erb @@ -0,0 +1 @@ +$('#competition_type_modal').html("<%= j render 'form' %>"); diff --git a/app/views/admin/competitions/_competition.html.erb b/app/views/admin/competitions/_competition.html.erb new file mode 100644 index 0000000..27c56df --- /dev/null +++ b/app/views/admin/competitions/_competition.html.erb @@ -0,0 +1,17 @@ +<% @competitions.each do |competition| %> + "> + <%= competition.year %> + + <%= link_to competition.competition_name, OrbitHelper.url_to_plugin_show(competition.to_param,'personal_competition'), target: "blank"%> +
+ +
+ + <%= competition.awarding_unit %> + <%= competition.work_name %> + <%= competition.student_name %> + +<% end %> diff --git a/app/views/admin/competitions/_form.html.erb b/app/views/admin/competitions/_form.html.erb new file mode 100644 index 0000000..c82686d --- /dev/null +++ b/app/views/admin/competitions/_form.html.erb @@ -0,0 +1,242 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + + +
+ + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+ <%= f.fields_for :competition_name_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.competition_name"), value: (@competition.competition_name_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :work_name_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.work_name"), value: (@competition.work_name_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :student_name_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.student_name"), value: (@competition.student_name_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :instructor_name_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.instructor_name"), value: (@competition.instructor_name_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :award_place_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.award_place"), value: (@competition.award_place_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :award_name_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.award_name"), value: (@competition.award_name_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :awarding_unit_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.awarding_unit"), value: (@competition.awarding_unit_translations[locale] rescue nil) %> + <% end %> +
+
+ +
+ +
+ <%= f.fields_for :country_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_competition.country"), value: (@competition.country_translations[locale] rescue nil) %> + <% end %> +
+
+ +
+ + <% end %> + +
+ + + + + + +
+ + +
+ + <% if !@member.nil? %> + +
+ +
+ <%= @member.name rescue ''%> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
+
+ + <% else %> + +
+ +
+ <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %> +
+
+ + <% end %> + + +
+ +
+ <%= select_year(@competition.year, {:start_year => (DateTime.now.year+5), :end_year => 1930, :prompt => "Choose year"}, {:name => 'competition[year]', :class => "span1"} ) %> +
+
+ + +
+ +
+ <%= f.datetime_picker :competition_date, :no_label => true, :format=>"yyyy/MM/dd", :placeholder=>"YYYY/MM/DD", :value => @competition.competition_date, :new_record => @competition.new_record? %> +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ <%= f.select :competition_type_id, @competition_types.collect {|t| [ t.title, t.id ]} %> +
+
+ + +
+ +
+ <%= f.text_field :url , :class => "span6" %> +
+
+ + +
+ +
+ <%= f.text_field :keywords %> +
+
+ + +
+ +
+ <%= f.text_area :note, rows: 2, class: "input-block-level" %> +
+
+ +
+ + +
+
+ +
+ +
+
+
+ +
+ +
+ + +
+ <%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %> + + <%= f.submit t('submit'), class: 'btn btn-primary' %> + <%= link_to t('cancel'), get_go_back, :class=>"btn" %> +
diff --git a/app/views/admin/competitions/_list_competition_type.html.erb b/app/views/admin/competitions/_list_competition_type.html.erb new file mode 100644 index 0000000..fc0dff4 --- /dev/null +++ b/app/views/admin/competitions/_list_competition_type.html.erb @@ -0,0 +1,8 @@ + + <%= list_competition_type.title %> + + + <%= t(:edit) %> + <%= link_to t(:delete_), admin_competition_type_path(list_competition_type), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %> + + diff --git a/app/views/admin/competitions/destroy.js.erb b/app/views/admin/competitions/destroy.js.erb new file mode 100644 index 0000000..13cc776 --- /dev/null +++ b/app/views/admin/competitions/destroy.js.erb @@ -0,0 +1 @@ +$('#competition_<%= @competition.id.to_s%>').remove(); diff --git a/app/views/admin/competitions/edit.html.erb b/app/views/admin/competitions/edit.html.erb new file mode 100644 index 0000000..c381088 --- /dev/null +++ b/app/views/admin/competitions/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @competition, url: admin_competition_path(@competition), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/competitions/frontend_setting.html.erb b/app/views/admin/competitions/frontend_setting.html.erb new file mode 100644 index 0000000..a73033a --- /dev/null +++ b/app/views/admin/competitions/frontend_setting.html.erb @@ -0,0 +1,94 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> + +<%= form_for(:competition_intro, :url => update_frontend_setting_admin_competitions_path, :method => "post", html: {class: "form-horizontal main-forms previewable"} ) do |f| %> +
+ +
+ + + + + + +
+ +
+ <% if !@member.blank? %> +
+ +
+ <%= @member.name rescue ''%> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
+
+ <% end %> + +
+ +
+ <%= f.check_box :brief_intro, :checked => @intro.brief_intro %> <%= t("personal_plugins.brief_intro") %> + <%= f.check_box :complete_list, :checked => @intro.complete_list %> <%= t("personal_plugins.complete_list") %> +
+
+
+
+ + + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+
+ <%= f.fields_for :text_translations do |f| %> + <%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@intro.text_translations[locale] rescue nil) %> + <% end %> +
+
+
+ + +
+ + <% end %> + + + +
+ + + +
+ + +
+ <%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %> + <%= hidden_field_tag :member_profile_id, @member.id.to_s %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + <%= link_to t('cancel'), get_go_back, :class=>"btn" %> +
+
+<% end %> diff --git a/app/views/admin/competitions/index.html.erb b/app/views/admin/competitions/index.html.erb new file mode 100644 index 0000000..0c88744 --- /dev/null +++ b/app/views/admin/competitions/index.html.erb @@ -0,0 +1,44 @@ + + + + + + + + + + + + <%= render 'competition' %> + +
<%= t('personal_competition.year') %><%= t('personal_competition.competition_name') %><%= t('personal_competition.awarding_unit') %><%= t('personal_competition.work_name') %><%= t('personal_competition.student_name') %>
+ +
+
+
+ + +
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_competition_path, :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_competition_setting_path, :class => 'btn btn-primary pull-right' %> +
+ +
+<% if params[:error] == "1" %> + +<% end %> diff --git a/app/views/admin/competitions/new.html.erb b/app/views/admin/competitions/new.html.erb new file mode 100644 index 0000000..8be923a --- /dev/null +++ b/app/views/admin/competitions/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @competition, url: admin_competitions_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/competitions/setting.html.erb b/app/views/admin/competitions/setting.html.erb new file mode 100644 index 0000000..2b8b825 --- /dev/null +++ b/app/views/admin/competitions/setting.html.erb @@ -0,0 +1,70 @@ +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/jquery-ui-sortable.min" %> +<% end %> + + +
+
+
+

+ <%= t('add')%> + <%= t("personal_competition.competition_category") %> +

+
+
+
+
+
+
+
+
+
+
+ + + <%= render :partial => 'list_competition_type', :collection => @competition_types.asc(:sort_position) %> + +
+
+
+
+
+
+
+ +
+ +
+ diff --git a/app/views/personal_competitions/get_fields_for_index.html.erb b/app/views/personal_competitions/get_fields_for_index.html.erb new file mode 100644 index 0000000..5c29acc --- /dev/null +++ b/app/views/personal_competitions/get_fields_for_index.html.erb @@ -0,0 +1,48 @@ +<% if !@page.nil? %> +
+
+
    + <% if @page.custom_array_field.blank? %> + <% @default_fields_to_show.each do |fs| %> +
  • <%= fs == "authors" ? t("users.name") : t("personal_competition.#{fs}") %>
  • + <% end %> + <% else %> + <% @page.custom_array_field.each do |fs| %> +
  • <%= fs == "authors" ? t("users.name") : t("personal_competition.#{fs}") %>
  • + <% end %> + <% end %> +
+
+ +
+ +
+ +
+ <%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %> +
+
+ Add Field + + +
+
+ +<% else %> +

Page not found.

+<% end %> diff --git a/app/views/personal_competitions/index.html.erb b/app/views/personal_competitions/index.html.erb new file mode 100644 index 0000000..9f04326 --- /dev/null +++ b/app/views/personal_competitions/index.html.erb @@ -0,0 +1 @@ +<%= render_view %> diff --git a/app/views/personal_competitions/show.html.erb b/app/views/personal_competitions/show.html.erb new file mode 100644 index 0000000..9f04326 --- /dev/null +++ b/app/views/personal_competitions/show.html.erb @@ -0,0 +1 @@ +<%= render_view %> diff --git a/app/views/plugin/personal_competition/_profile.html.erb b/app/views/plugin/personal_competition/_profile.html.erb new file mode 100644 index 0000000..5018230 --- /dev/null +++ b/app/views/plugin/personal_competition/_profile.html.erb @@ -0,0 +1,88 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/list-check" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/list-check" %> +<% end %> + +<% + if has_access? + @competitions = Competition.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) + else + @competitions = Competition.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) + end +%> + +<% if has_access? %> +
+
+ <%= link_to('Hide', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-hide", :rel => toggle_hide_admin_competitions_path(member_profile_id: @member.id.to_s, disable: 'true') ) %> + <%= link_to('Show', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-show", :rel => toggle_hide_admin_competitions_path(member_profile_id: @member.id.to_s, disable: 'false') ) %> +
+
+<% end -%> + + + + + <% if has_access? %> + + <% end -%> + + + + + + + + <% @competitions.each do |competition| %> + "> + <% if has_access? %> + + <% end %> + + + + + + <% end %> + +
<%= t('personal_competition.year') %><%= t('personal_competition.competition_name') %><%= t('personal_competition.awarding_unit') %><%= t('personal_competition.award_winner') %>
+ <%= check_box_tag 'to_change[]', competition.id.to_s, false, :class => "list-check" %> + <%= competition.year %> + <% link = OrbitHelper.url_to_plugin_show(competition.to_param,'personal_competition') %> + <%= (link = (link == "#") ? competition.competition_name : link_to(competition.competition_name, link, target: "blank"))%> +
+ +
+
<%= competition.awarding_unit %><%= competition.member_profile.name %>
+ + +
+ <% if has_access? %> +
+ <%= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),'/admin/members/'+@member.to_param+'/competitions/frontend_setting', :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'), + '/admin/members/'+@member.to_param+'/competitions/new', :class => 'btn btn-primary' %> +
+ <% end %> + +
+ + diff --git a/bin/rails b/bin/rails new file mode 100644 index 0000000..90e9edb --- /dev/null +++ b/bin/rails @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. + +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/personal_honor/engine', __FILE__) + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) + +require "action_controller/railtie" +require "action_mailer/railtie" +require "sprockets/railtie" +require "rails/test_unit/railtie" +require "mongoid" +require 'rails/engine/commands' \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..1056e6d --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,68 @@ +en: + module_name: + personal_competition: Competition + personal_competition: + competition_name : "Competition Name" + work_name : "Work Name" + student_name : "Student Name" + instructor_name : "Instructor Name" + award_place : "Award Place" + award_winner : "Award winner" + paper_title : "Paper Title" + book_title : "Book Title" + award_name : "Award Name" + awarding_unit : "Awarding Unit" + competition_category : "Competition Category" + competition_type: "Competition Category" + competition_types_all: "All Competition Types" + extracted_chapters : "Extracted Chapters" + publishers : "Publishers" + honoree: "Honoree" + authors : "Authors" + tags : "Tags" + year : "Year" + language : "Language" + isbn : "ISSN(ISBN)" + vol_no : "Vol.No" + issue_no : "Issue.No" + form_to_start : "From" + form_to_end : "To" + country: "Country" + competition_date: "Competition Date" + total_pages : "Total Pages" + keywords : "Keywords" + abstract : "Abstract" + publication_date : "Date of Publication" + url : "Reference URL" + note : "Note" + level_type : "Level Type" + author_type : "Author Type" + from : "From" + to : "To" + file : "File" + file_name : "File name" + description : "File Description" + pages : "Pages" + book_paper_type : "Book Paper Type" + graph_by : "Graph By" + frontend: + competitions: "Competition 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…" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml new file mode 100644 index 0000000..5a899a3 --- /dev/null +++ b/config/locales/zh_tw.yml @@ -0,0 +1,64 @@ +zh_tw: + module_name: + personal_competition: 競賽 + personal_competition: + competition_name : "競賽名稱" + work_name : "作品名稱" + student_name : "參賽學生姓名" + instructor_name : "共同指導老師" + award_place : "獲獎名次" + award_winner : "得獎人" + paper_title : "論文名稱" + book_title : "期刊名稱" + award_name : "獎項名稱" + awarding_unit : "頒獎單位" + competition_category : "類別" + competition_type: "類別" + competition_types_all: "所有競賽項目" + honoree: "受獎人" + authors : "作者" + tags : "領域" + year : "年度" + language : "語言" + isbn : "ISSN(ISBN)" + vol_no : "卷數" + issue_no : "期數" + form_to_start : "起" + form_to_end : "迄" + total_pages : "總頁數" + keywords : "關鍵字" + abstract : "摘要" + publication_date : "發表日期" + competition_date: "比賽日期" + country: "國別" + url : "參考連結" + note : "記事" + level_type : "期刊類別" + author_type : "作者類別" + from : "起" + to : "迄" + file : "檔案" + file_name : "檔案名稱" + description : "描述" + graph_by : "Graph By" + frontend: + competitions: "競賽前台" + + create_success : "新增完成!!" + update_success : "更新完成!!" + delete_success : "刪除成功!!" + add: "新增" + back: "返回" + delete: "刪除" + edit: "編輯" + nothing: "無" + show: "顯示" + sure?: "您肯定嗎?" + update: "更新" + yes_: "是" + no_: "否" + cancel : "取消" + save: "儲存" + hintText: "請輸入搜尋關鍵字" + noResultsText: "沒有相關的比對結果" + searchingText: "搜尋中…" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..f273ce6 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,37 @@ +Rails.application.routes.draw do + locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales + scope "(:locale)", locale: Regexp.new(locales.join("|")) do + namespace :admin do + get 'competition_setting' => "competitions#setting" + get 'competitions/download_excel_format' => 'competitions#excel_format' + post 'competitions/import_from_excel' => 'competitions#import_from_excel' + + resources :competitions do + collection do + get 'toggle_hide' => 'competitions#toggle_hide' + get 'analysis' + get 'analysis_report' + get "download_excel" + end + end + + resources :members do + collection do + scope '(:name-:uid)' do + resources :competitions do + collection do + get 'frontend_setting' => 'competitions#frontend_setting' + post 'update_frontend_setting' => 'competitions#update_frontend_setting' + end + end + end + end + end + + resources :competition_types + post "competition_types/update_order" => "competition_types#update_order" + end + get "/xhr/personal_competition/get_fields_for_index" => "personal_competitions#get_fields_for_index" + post "/xhr/personal_competition/save_index_fields" => "personal_competitions#save_index_fields" + end +end diff --git a/lib/personal_competition.rb b/lib/personal_competition.rb new file mode 100644 index 0000000..2bc1872 --- /dev/null +++ b/lib/personal_competition.rb @@ -0,0 +1,4 @@ +require "personal_competition/engine" + +module PersonalCompetition +end diff --git a/lib/personal_competition/engine.rb b/lib/personal_competition/engine.rb new file mode 100644 index 0000000..099fe95 --- /dev/null +++ b/lib/personal_competition/engine.rb @@ -0,0 +1,22 @@ +module PersonalCompetition + class Engine < ::Rails::Engine + initializer "personal_competition" do + OrbitApp.registration "PersonalCompetition",:type=> 'ModuleApp' do + module_label 'module_name.personal_competition' + base_url File.expand_path File.dirname(__FILE__) + personal_plugin :enable => true, :sort_number => '50', :app_name=>"Competition", :intro_app_name=>"PersonalCompetitionIntro",:path=>"/plugin/personal_competition/profile",:front_path=>"/profile",:admin_path=>"/admin/competitions",:i18n=>'module_name.personal_competition', :module_app_name=>'PersonalCompetition', :field_modifiable => true, :analysis => true, :analysis_path => "/admin/competitions/analysis" + + version "0.1" + desktop_enabled true + organization "Rulingcom" + author "RD dep" + intro "I am intro" + update_info 'some update_info' + + frontend_enabled + icon_class_no_sidebar "icons-user" + data_count 1..10 + end + end + end +end diff --git a/lib/personal_competition/version.rb b/lib/personal_competition/version.rb new file mode 100644 index 0000000..498a958 --- /dev/null +++ b/lib/personal_competition/version.rb @@ -0,0 +1,3 @@ +module PersonalCompetition + VERSION = "0.0.1" +end diff --git a/lib/tasks/personal_honor_tasks.rake b/lib/tasks/personal_honor_tasks.rake new file mode 100644 index 0000000..94f4e40 --- /dev/null +++ b/lib/tasks/personal_honor_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :personal_honor do +# # Task goes here +# end diff --git a/personal_competition.gemspec b/personal_competition.gemspec new file mode 100644 index 0000000..a18d780 --- /dev/null +++ b/personal_competition.gemspec @@ -0,0 +1,19 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "personal_competition/version" + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "personal_competition" + s.version = PersonalCompetition::VERSION + s.authors = ["Ruling Digital Inc."] + s.email = ["orbit@rulingcom.com"] + s.homepage = "http://www.rulingcom.com" + s.summary = "Summary of Personal Competition." + s.description = "Description of Personal Competition." + s.license = "MIT" + + s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] + s.test_files = Dir["test/**/*"] +end