diff --git a/app/controllers/personal_certificates_controller.rb b/app/controllers/personal_certificates_controller.rb new file mode 100644 index 0000000..9c8de60 --- /dev/null +++ b/app/controllers/personal_certificates_controller.rb @@ -0,0 +1,81 @@ +class PersonalCertificatesController < ApplicationController + def index + params = OrbitHelper.params + certificates = Certificate.where(:is_hidden=>false).order_by(:created_at=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] + + if fields_to_show.blank? + fields_to_show = [ + "title", + "issued_by", + "authors" + ] + end + certificates_list = [] + certificates.each do |certificate| + t = [] + fields_to_show.each do |fs| + case fs + when "title" + t << {"value" => "" + (certificate.send(fs) rescue "") + ""} + when "authors" + t << {"value" => (certificate.send(:member_profile).name rescue "")} + else + t << {"value" => (certificate.send(fs) rescue "")} + end + end + certificates_list << {"personal_certificates" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "title" + header = fs == "authors" ? t("users.name") : t("personal_certificate.#{fs}") + headers << { + "head-title" => header, + "col" => col + } + end + { + "certificates" => certificates_list, + "headers" => headers, + "extras" => {"widget-title" => t("module_name.personal_certificate")}, + "total_pages" => certificates.total_pages + } + end + + def show + params = OrbitHelper.params + plugin = Certificate.where(:is_hidden=>false).find_by(uid: params[:uid]) + fields_to_show = [ + "title", + "issued_by" + ] + + {"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 = [ + "title", + "issued_by", + "authors" + ] + @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_certificate.#{fs}")), fs]} + @default_fields_to_show = [ + "title", + "issued_by", + "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 \ No newline at end of file diff --git a/app/controllers/psesonal_certificates_controller.rb b/app/controllers/psesonal_certificates_controller.rb deleted file mode 100644 index 53f2ee2..0000000 --- a/app/controllers/psesonal_certificates_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -class PersonalCertificatesController < ApplicationController - def index - certificates = Certificate.where(:is_hidden=>false).order_by(:created_at=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - certificates_list = certificates.collect do |certificate| - { - "title" => certificate.title, - "issued_by" => certificate.issued_by, - "link_to_show" => OrbitHelper.url_to_show(certificate.to_param) - } - end - { - "courses" => certificates_list, - "extras" => { - "widget-title" => t("module_name.personal_certificate"), - "th_title" => t('personal_certificate.title'), - "th_issued_by" => t("personal_certificate.issued_by") - }, - "total_pages" => certificates.total_pages - } - end - - def show - params = OrbitHelper.params - plugin = Certificate.where(:is_hidden=>false).find_by(uid: params[:uid]) - fields_to_show = [ - "title", - "issued_by" - ] - - {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} - end -end \ No newline at end of file diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 4fa717f..ab8d6da 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -12,11 +12,16 @@ class Certificate scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:created_at =>'desc') } def self.get_plugin_datas_to_member(datas) + page = Page.where(:module => "personal_certificate").first rescue nil - fields_to_show = [ - "title", - "issued_by", - ] + if !page.nil? && !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = [ + "title", + "issued_by" + ] + end fields_to_remove = [] diff --git a/app/views/personal_certificates/get_fields_for_index.html.erb b/app/views/personal_certificates/get_fields_for_index.html.erb new file mode 100644 index 0000000..a18b1cf --- /dev/null +++ b/app/views/personal_certificates/get_fields_for_index.html.erb @@ -0,0 +1,48 @@ +<% if !@page.nil? %> +
+
+ +
+ +
+ +
+ +
+ <%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %> +
+
+ Add Field + + +
+
+ +<% else %> +

Page not found.

+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index fc89b87..65a418b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,5 +21,7 @@ Rails.application.routes.draw do end end end + get "/xhr/personal_certificate/get_fields_for_index" => "personal_certificates#get_fields_for_index" + post "/xhr/personal_certificate/save_index_fields" => "personal_certificates#save_index_fields" end end diff --git a/lib/personal_certificate/engine.rb b/lib/personal_certificate/engine.rb index 798c419..b21cc30 100644 --- a/lib/personal_certificate/engine.rb +++ b/lib/personal_certificate/engine.rb @@ -4,7 +4,7 @@ module PersonalCertificate OrbitApp.registration "PersonalCertificate",:type=> 'ModuleApp' do module_label 'module_name.certificates' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '35', :app_name=>"Certificate", :intro_app_name=>"CertificateIntro",:path=>"/plugin/personal_certificate/profile",:front_path=>"/profile",:admin_path=>"/admin/certificates/",:i18n=>'module_name.certificates', :module_app_name=>'Certificate' + personal_plugin :enable => true, :sort_number => '35', :app_name=>"Certificate", :intro_app_name=>"CertificateIntro",:path=>"/plugin/personal_certificate/profile",:front_path=>"/profile",:admin_path=>"/admin/certificates/",:i18n=>'module_name.certificates', :module_app_name=>'Certificate', :field_modifiable => true version "0.1" desktop_enabled true