From b65696fea6a3d7502d4a8d84d4e70ff2a25573c6 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Thu, 6 Feb 2020 14:40:35 +0800 Subject: [PATCH] update --- updatefiles/admin/preference.html.erb | 50 +++++- updatefiles/members_controller.rb | 236 ++++++++++++-------------- updatefiles/page_set.rb | 6 + updatefiles/site.rb | 38 ++++- 4 files changed, 200 insertions(+), 130 deletions(-) create mode 100644 updatefiles/page_set.rb diff --git a/updatefiles/admin/preference.html.erb b/updatefiles/admin/preference.html.erb index e3bd47c..884f823 100644 --- a/updatefiles/admin/preference.html.erb +++ b/updatefiles/admin/preference.html.erb @@ -22,6 +22,9 @@ <%= t('preferences.sidebar_nav') %> <% end %> +
  • + <%= t('preferences.page_set') %> +
  • <%= t('preferences.system_email') %>
  • @@ -58,7 +61,12 @@ <% end %> - + +
    + <%= f.fields_for :page_sets do |page_set| %> + <%= page_set.check_box :auto_convert_flag %> <%= t('preferences.auto_convert_flag') %> + <% end %> +
    <%= f.fields_for :site_settings, @site['site_settings'] do |f| %> @@ -274,6 +282,46 @@ +
    + +
    + <%= f.text_field :orbit_bar_background_color, :class=>'set_color',:type=>'color',:value=>@site.orbit_bar_background_color%> +
    +
    +
    + +
    + <%= f.text_field :orbit_bar_text_color, :class=>'set_color',:type=>'color',:value=>@site.orbit_bar_text_color%> +
    +
    +
    + +
    + <%= f.text_field :orbit_bar_submenu_background_color, :class=>'set_color',:type=>'color',:value=>@site.orbit_bar_submenu_background_color%> +
    +
    +
    + +
    + <%= f.text_field :orbit_bar_submenu_text_color, :class=>'set_color',:type=>'color',:value=>@site.orbit_bar_submenu_text_color%> +
    +
    +
    + +
    + <%if @site.is_hidden_orbit_bar%> + <%= f.check_box :is_hidden_orbit_bar ,:checked=>'checked'%> + <%else%> + <%= f.check_box :is_hidden_orbit_bar ,:checked=>false%> + <%end%> +
    +
    +
    + +
    + <%= f.text_field :orbit_bar_animation_time ,:value=>@site.orbit_bar_animation_time %> +
    +
    diff --git a/updatefiles/members_controller.rb b/updatefiles/members_controller.rb index 14b752b..02721c1 100644 --- a/updatefiles/members_controller.rb +++ b/updatefiles/members_controller.rb @@ -1,5 +1,6 @@ class MembersController < ApplicationController helper_method :current_user + include AttributeValuesHelper def index page_roles = OrbitHelper.page_categories page_role_status = OrbitHelper.page_role_status @@ -15,22 +16,8 @@ class MembersController < ApplicationController member_sort_position = OrbitHelper.member_sort_position sort = nil if !member_sort_position - # sort = "data['list_order']" - # else - # sort = fields_to_show - # .collect.with_index{|field,idx| {'sort_order'=>field['sort_order'], 'index'=>idx}} - # .select{|field|!field['sort_order'].blank?} - # .sort_by{|field|field['sort_order']} - # .collect.with_index{|field| "data['profile_data'][#{field['index']}]['sort_value'] rescue 0"} - # # sort = "[(data['first_name'][0])]" - - # sort = '[('+sort.join('),(')+')]' - fields_to_show.each_with_index do |field, idx| - if field["key"] == "name" - # sort = "[(data['profile_data'][idx]['sort_value'] rescue 0)]" - sort = idx - end - end + sort_select = fields_to_show.to_enum.with_index.select{|v| v[0]['key']=='name'} + sort = sort_select.blank? ? nil : sort_select[0][1] end if page_roles.include?("all") roles = Role.all.asc(:key).collect do |role| @@ -38,7 +25,7 @@ class MembersController < ApplicationController end else page_role_status.each do |status_id| - page_roles << RoleStatus.find(status_id).role.id.to_s + page_roles << (RoleStatus.find(status_id).role.id.to_s rescue '') end roles = Role.where(:id.in => page_roles.uniq).asc(:key).collect do |role| { "title" => role.title, "id" => role.id, "status" => RoleStatus.where(:role_id=>role, :_id.in=>page_role_status).asc(:key).to_a } @@ -134,14 +121,14 @@ class MembersController < ApplicationController def get_member_data(member, fields_to_show) image = member.avatar.present? ? member.avatar.thumb.url : ActionController::Base.helpers.asset_path('member-pic.png') member_data_return = member_data(member, fields_to_show) - if !member_data_return.nil? && (!member_data_return.empty? rescue false) - { - 'profile_data'=> member_data_return, - 'list_order' => member.position, - 'name' => member.name, - 'image'=>image, - "link_to_show" => OrbitHelper.url_to_show(member.to_param) - } + if !member_data_return.blank? + { + 'profile_data'=> member_data_return, + 'list_order' => member.position, + 'name' => member.name, + 'image'=>image, + "link_to_show" => OrbitHelper.url_to_show(member.to_param) + } else nil end @@ -149,7 +136,7 @@ class MembersController < ApplicationController def show params = OrbitHelper.params - member = MemberProfile.find_by(uid: params[:uid]) + member = MemberProfile.find_by(uid: params[:uid]) rescue nil page = Page.where(:page_id => params[:page_id]).first rescue nil profile_data = [] @@ -162,8 +149,10 @@ class MembersController < ApplicationController role_status = member.role_statuses.where(role_id: role.id).map{|t|t.title.to_s}.join(',') rescue '' profile_data = profile_data.push({"key"=>"role_status", "title"=>"", "value"=> role_status, "title_class"=>"member-data-title-role-status", "value_class"=>"member-data-value-role-status"}) if !role_status.blank? if fields_to_show.blank? - attribute_field = role.attribute_fields.where(:key => 'job_title').first - profile_data = profile_data + member_data(member, [{"id"=> attribute_field.id.to_s, "key"=> attribute_field.key, "type"=>"role"}]) if !attribute_field.blank? and !attribute_field.to_show.blank? + attribute_field = role.attribute_fields.first + if !attribute_field.blank? && !attribute_field.to_show.blank? + profile_data = profile_data + member_data(member, [{"id"=> attribute_field.id.to_s, "key"=> attribute_field.key.to_s, "type"=>"role"}]) + end end end if fields_to_show.blank? @@ -190,7 +179,7 @@ class MembersController < ApplicationController role_fields_to_show = [] member.roles.where(:disabled => false).asc("_id").collect do |role| role.attribute_fields.where(:key.ne => 'job_title').asc("_id").each do |attribute_field| - role_fields_to_show << {"id"=> attribute_field.id.to_s, "key"=> attribute_field.key, "type"=>"role"} if !attribute_field.to_show.blank? + role_fields_to_show << {"id"=> attribute_field.id.to_s,"key"=> attribute_field.key.to_s, "type"=>"role"} if !attribute_field.to_show.blank? end end profile_data = profile_data + member_data(member, role_fields_to_show) @@ -337,120 +326,113 @@ class MembersController < ApplicationController def member_data(member, fields_to_show) profile_data = [] fields_to_show.each do |field| - privacy_approved_status = true - if field['type'] != 'role' - field_key = field["key"] - else - field_key = field["id"] - end - privacy_approved_status = false if member.get_privacy_type_for_field(field_key) != "public" - if !OrbitHelper.current_user.nil? - if(member.get_privacy_type_for_field(field_key) == "logged_in") - privacy_approved_status = true - elsif(member.get_privacy_type_for_field(field_key) == "locked") - if member.user.id == OrbitHelper.current_user.id || OrbitHelper.current_user.is_admin? - privacy_approved_status = true - end - end - end - if member.get_privacy_type_for_field(field_key) == "default" - if field['type'] != 'role' - privacy_approved_status = true #Todo: set not role field's default privacy_approved_status - else - case AttributeField.find(field["id"]).privacy_default - when 'public' - privacy_approved_status = true - when 'logged_in' - privacy_approved_status = true if !OrbitHelper.current_user.nil? - when 'locked' - if !OrbitHelper.current_user.nil? - privacy_approved_status = true if member.user.id == OrbitHelper.current_user.id || OrbitHelper.current_user.is_admin? - end - end - end - end - case field['type'] - when 'profile' - next if !privacy_approved_status - field_data = member.get_attribute_data(field) rescue {} - when 'custom' - if !field['id'].blank? - next if !privacy_approved_status - field_data = member.member_profile_field_values.find_by(:member_profile_field_id=>field['id'],:key=>field['key']).get_field_value rescue {"value" => " "} - else - field_data = member.member_profile_field_values.find_by(:key=>field['key']).get_field_value rescue {"value" => " "} + privacy_approved_status = true + if field['type'] != 'role' + field_key = field["key"] + else + field_key = field["id"] + end + privacy_approved_status = false if member.get_privacy_type_for_field(field_key) != "public" + if !OrbitHelper.current_user.nil? + if(member.get_privacy_type_for_field(field_key) == "logged_in") + privacy_approved_status = true + elsif(member.get_privacy_type_for_field(field_key) == "locked") + if member.user.id == OrbitHelper.current_user.id || OrbitHelper.current_user.is_admin? + privacy_approved_status = true end - when 'role' - if !field['id'].blank? - next if !privacy_approved_status - av = member.attribute_values.find_by(:attribute_field_id=>field['id'],:key=>field['key']) rescue nil - av = member.attribute_values.find_by(:attribute_field_id=>field['id']) rescue nil if av.nil? #some role's key has been changed to sort number,so it doesn't work when searching field from using its key - field_data = {"value" => " "} + end + end + if member.get_privacy_type_for_field(field_key) == "default" + if field['type'] != 'role' + privacy_approved_status = true #Todo: set not role field's default privacy_approved_status + else + case (AttributeField.find(field["id"]).privacy_default rescue nil) + when 'public' + privacy_approved_status = true + when 'logged_in' + privacy_approved_status = true if !OrbitHelper.current_user.nil? + when 'locked' + if !OrbitHelper.current_user.nil? + privacy_approved_status = true if member.user.id == OrbitHelper.current_user.id || OrbitHelper.current_user.is_admin? + end + end + end + end + case field['type'] + when 'profile' + next if !privacy_approved_status + field_data = member.get_attribute_data(field) rescue {} + when 'custom' + if !field['id'].blank? + next if !privacy_approved_status + field_data = member.member_profile_field_values.find_by(:member_profile_field_id=>field['id'],:key=>field['key']).get_field_value rescue {"value" => " "} + else + field_data = member.member_profile_field_values.find_by(:key=>field['key']).get_field_value rescue {"value" => " "} + end + when 'role' + av = member.attribute_values.find_by(:attribute_field_id=>field['id']) rescue nil #some role's key has been changed to sort number,so it doesn't work when searching field from using its key + field_data = {"value" => " "} + if !av.nil? + next if !privacy_approved_status + r = av.attribute_field.role rescue nil + if !r.nil? + if member.roles.include?(r) + field_data = av.get_field_value(member) rescue {"value" => " "} + end + end + else + avs = member.attribute_values.find_by(:key=>field['key']) rescue [] + avs.each do |av| if !av.nil? r = av.attribute_field.role rescue nil - if !r.nil? - if member.roles.include?(r) - field_data = av.get_field_value rescue {"value" => " "} - else - field_data = {"value" => " "} - end - else - field_data = {"value" => " "} + if !r.nil? && member.roles.include?(r) + field_data = av.get_field_value(member) rescue {"value" => " "} + break end - else - field_data = {"value" => " "} end - else - avs = member.attribute_values.where(:key=>field['key']) rescue nil - field_data = {"value" => " "} - avs.each do |av| - if !av.nil? - r = av.attribute_field.role rescue nil - if !r.nil? - if member.roles.include?(r) - field_data = av.get_field_value rescue {"value" => " "} - break - else - field_data = {"value" => " "} - end - else - field_data = {"value" => " "} - end - else - field_data = {"value" => " "} + end + if avs.blank? && !field['id'].nil? + attr_field = AttributeField.find(field['id']) rescue nil + if !attr_field.blank? && attr_field.markup.eql?("member_relationship") + field_data = { + "key" => attr_field.key, + "title" => attr_field.title, + "value" => get_member_show(attr_field.get_member_relationship(member.id.to_s)) + } + if field_data['value'].blank? + field_data['value'] = ' ' end end end end - next if field_data.blank? or field_data['value'].blank? or (OrbitHelper.params[:target_action] == "show" && field_data['value'] == " ") + end + next if field_data.blank? || field_data['value'].blank? || (OrbitHelper.params[:target_action] == "show" && field_data['value'] == " ") if field['sort_order'] field_data['sort_value'] = field_data['val'].blank? ? field_data['value'] : field_data['val'] if !field_data['sort_value'].is_a?(Hash) if field_data['sort_value'].is_a?(Integer) || (field_data['sort_value'].is_i? rescue false) field_data['sort_value'] = field_data['sort_value'].to_i rescue field_data['sort_value'] - else - if I18n.locale == :zh_tw - field_data['sort_value'] = field_data['sort_value'].strip.encode("Big5") rescue "簡".encode("Big5") - end + elsif I18n.locale == :zh_tw + field_data['sort_value'] = field_data['sort_value'].strip.encode("Big5") rescue "簡".encode("Big5") end end end - @current_field_value = field_data['value'] - if (@current_field_value.gsub(' ','').strip rescue nil) == "" - @locale = I18n.locale - @site_in_use_locales = current_site.in_use_locales - @new_field_data = Hash.new - @site_in_use_locales.each_with_index do |locale,i| - I18n.locale = locale - @new_field_data = member.get_attribute_data(field) rescue {} - break if @new_field_data['value'].to_s.gsub(' ','').strip !="" - end - field_data['value'] = @new_field_data['value'].nil? ? " " : @new_field_data['value'] - I18n.locale = @locale - end + @current_field_value = field_data['value'] + if (@current_field_value.gsub(' ','').strip rescue nil) == "" + @locale = I18n.locale + @site_in_use_locales = current_site.in_use_locales + @new_field_data = Hash.new + @site_in_use_locales.each_with_index do |locale,i| + I18n.locale = locale + @new_field_data = member.get_attribute_data(field) rescue {} + break if @new_field_data['value'].to_s.gsub(' ','').strip !="" + end + field_data['value'] = @new_field_data['value'].nil? ? " " : @new_field_data['value'] + I18n.locale = @locale + end if field['link_to_show'] - if field_data['value'] == ' ' #空白欄位 + if field_data['value'] == ' ' #空白欄位 field_data['value'] = "" #若無網站連結,刪除實驗室網站字樣 field_data['title'] = "" #無網站連結,則不顯示 elsif field_data['value'].include? 'href=' @@ -465,9 +447,9 @@ class MembersController < ApplicationController field_data['value'] = (field_data['value'].length > field['max_length']) ? field_data['value'][0..field['max_length']]+'...' : field_data['value'] end - field_data['title_class'] = "member-data-title-"+field['key'].underscore.gsub('_','-') - field_data['value_class'] = "member-data-value-"+field['key'].underscore.gsub('_','-') - if !field_data['title'].blank? && !field_data['value'].blank? + field_data['title_class'] = "member-data-title-"+field['key'].to_s.underscore.gsub('_','-') + field_data['value_class'] = "member-data-value-"+field['key'].to_s.underscore.gsub('_','-') + if !field_data['title'].blank? && !field_data['value'].blank? profile_data.push(field_data) end end diff --git a/updatefiles/page_set.rb b/updatefiles/page_set.rb new file mode 100644 index 0000000..4b3de87 --- /dev/null +++ b/updatefiles/page_set.rb @@ -0,0 +1,6 @@ +class PageSet + include Mongoid::Document + include Mongoid::Timestamps + belongs_to :site + field :auto_convert_flag, type: Boolean, :default => false +end \ No newline at end of file diff --git a/updatefiles/site.rb b/updatefiles/site.rb index 514315e..a842953 100644 --- a/updatefiles/site.rb +++ b/updatefiles/site.rb @@ -4,7 +4,8 @@ class Site include Slug DEBUG = false - + has_many :page_sets, :autosave => true, :dependent => :destroy + accepts_nested_attributes_for :page_sets, :allow_destroy => true field :title, as: :slug_title, type: String, localize: true field :school, type: String field :department, type: String @@ -59,12 +60,45 @@ class Site field :home_link_1, :type => String, :default=>"/" field :site_title, :type => Hash, :default=>{:zh_tw=>"主頁",:en=>"home_page"} field :site_title_1, :type => Hash, :default=>{:zh_tw=>"主頁",:en=>"home_page"} + field :is_hidden_orbit_bar , type: Boolean, :default => false + field :orbit_bar_background_color , type: String, :default => "" + field :orbit_bar_text_color , type: String, :default => "" + field :orbit_bar_submenu_background_color , type: String, :default => "" + field :orbit_bar_submenu_text_color , type: String, :default => "" + field :orbit_bar_animation_time , type: String, :default => "0.3s" mount_uploader :default_image, ImageUploader mount_uploader :site_logo, ImageUploader mount_uploader :site_logo_1, ImageUploader mount_uploader :favicon, ImageUploader mount_uploader :mobile_icon, ImageUploader - + after_initialize do + if !self.new_record? + if self.is_hidden_orbit_bar.nil? + self.is_hidden_orbit_bar = false + self.save + end + if self.orbit_bar_background_color.nil? + self.orbit_bar_background_color = "" + self.save + end + if self.orbit_bar_text_color.nil? + self.orbit_bar_text_color = "" + self.save + end + if self.orbit_bar_submenu_background_color.nil? + self.orbit_bar_submenu_background_color = "" + self.save + end + if self.orbit_bar_submenu_text_color.nil? + self.orbit_bar_submenu_text_color = "" + self.save + end + if self.orbit_bar_animation_time.nil? + self.orbit_bar_animation_time = "0.3s" + self.save + end + end + end def register_site(url,university,department,email,country) api_key = STORE_CONFIG[:store_settings]["api_key"] self.generate_site_token