From 2695e0ff67a0daf96c8436d7cecf515197d4857c Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Mon, 30 Sep 2019 08:35:34 +0800 Subject: [PATCH] add confirm box and recover file feature --- .../admin/patchfiles_controller.rb | 10 +- app/models/filefield.rb | 270 +++++++++++------- .../admin/patchfiles/editckeditor.html.erb | 103 +++++-- app/views/admin/patchfiles/index.html.erb | 109 ++++++- 4 files changed, 363 insertions(+), 129 deletions(-) diff --git a/app/controllers/admin/patchfiles_controller.rb b/app/controllers/admin/patchfiles_controller.rb index 2c2eb95..1830a91 100644 --- a/app/controllers/admin/patchfiles_controller.rb +++ b/app/controllers/admin/patchfiles_controller.rb @@ -24,8 +24,14 @@ class Admin::PatchfilesController < OrbitAdminController @key = @file_to_show.file_show.keys[index] @file_to_show.file_show[@key] = value.to_i end - @file_to_show.update - redirect_to admin_patchfiles_path + if params["filefield"]["recovery_btn"] == "true" + @file_to_show.recovery = "true" + @file_to_show.update + redirect_to admin_patchfiles_path and return + else + @file_to_show.update + redirect_to admin_patchfiles_path and return + end end def showckeditor end diff --git a/app/models/filefield.rb b/app/models/filefield.rb index 3a5f7be..dd7fb09 100644 --- a/app/models/filefield.rb +++ b/app/models/filefield.rb @@ -33,111 +33,175 @@ class Filefield return dir_str end def updatefile - self.file_show.each do |key,value| - if value == 1 - @model_path = Rails.root.to_s + '/app/models/' - @helper_path = Rails.root.to_s + '/app/helpers/' - @views_path = Rails.root.to_s + '/app/views/' - @controller_path = Rails.root.to_s + '/app/controllers/' - if key == "ckeditor" - @app_path = File.expand_path(__dir__) - @app_path = lastpath(@app_path) - @app_path = lastpath(@app_path) - @ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/' - puts 'copying CKEDITOR' - begin - Dir.chdir(@ckeditor_path) - File.rename('config.js.erb','config.js.erb_back') - rescue - puts Dir.pwd - end - FileUtils.cd(@app_path+'/updatefiles/') - begin - FileUtils.cp('config.js.erb' , @ckeditor_path) - puts @ckeditor_path - rescue - puts Dir.pwd - puts 'error copy' - end - elsif key == "site-preference(two-site-logo)" - @app_path = File.expand_path(__dir__) - @app_path = lastpath(@app_path) - @app_path = lastpath(@app_path) - puts @app_path - puts 'copying site' - begin - Dir.chdir(@model_path) - File.rename('site.rb','site.rb_back') - Dir.chdir(@helper_path) - File.rename('application_helper.rb','application_helper.rb_back') - Dir.chdir(@views_path+'admin/sites/') - File.rename('preference.html.erb','preference.html.erb_back') - rescue - puts Dir.pwd - end - FileUtils.cd(@app_path+'/updatefiles/') - begin - FileUtils.cp('site.rb' , @model_path) - FileUtils.cp('application_helper.rb' , @helper_path) - FileUtils.cd('admin/') - FileUtils.cp('preference.html.erb',@views_path+'admin/sites/') - rescue - puts Dir.pwd - Dir.chdir(Rails.root.to_s) - puts 'error copy' - end - elsif key == "member" - @app_path = File.expand_path(__dir__) - @app_path = lastpath(@app_path) - @app_path = lastpath(@app_path) - begin - Dir.chdir(@model_path) - File.rename('member_profile.rb','member_profile.rb_back') - Dir.chdir(@controller_path+'admin/') - File.rename('members_controller.rb','members_controller.rb_back') - Dir.chdir(@views_path+'admin/members/') - File.rename('_user_basic_passwd.html.erb','_user_basic_passwd.html.erb_back') - rescue - puts Dir.pwd - end - FileUtils.cd(@app_path+'/updatefiles/') - puts 'copying member' - begin - FileUtils.cp('member_profile.rb' , @model_path) - FileUtils.cd('admin/') - FileUtils.cp('members_controller.rb' , @controller_path+'admin/') - FileUtils.cp('_user_basic_passwd.html.erb' , @views_path+'admin/members/') - rescue - puts Dir.pwd - Dir.chdir(Rails.root.to_s) - puts 'error copy' - end - elsif key == "accessibility" - @app_path = File.expand_path(__dir__) - @app_path = lastpath(@app_path) - @app_path = lastpath(@app_path) - begin - Dir.chdir(@views_path+'layouts/') - File.rename('back_end.html.erb','back_end.html.erb_back') - Dir.chdir(@views_path+'page_parts/') - File.rename('_form.html.erb','_form.html.erb_back') - rescue - puts Dir.pwd - end - FileUtils.cd(@app_path+'/updatefiles/accessibility/') - puts 'copying accessibility' - begin - FileUtils.cp('back_end.html.erb' , @views_path+'layouts/') - FileUtils.cp('_form.html.erb' , @views_path+'page_parts/') - FileUtils.cp_r('jquery-ui-1.12.1/' , ENV['PWD'] + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/') - rescue - puts Dir.pwd - Dir.chdir(Rails.root.to_s) - puts 'error copy' + if self.recovery == "true" + self.file_show.each do |key,value| + if value == 1 + @model_path = Rails.root.to_s + '/app/models/' + @helper_path = Rails.root.to_s + '/app/helpers/' + @views_path = Rails.root.to_s + '/app/views/' + @controller_path = Rails.root.to_s + '/app/controllers/' + if key == "ckeditor" + @ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/' + puts 'recovery CKEDITOR' + begin + FileUtils.cd(@ckeditor_path) + FileUtils.cp('config.js.erb_back' , 'config.js.erb') + rescue + puts Dir.pwd + puts 'error recovery' + end + elsif key == "site-preference(two-site-logo)" + puts 'recovery site' + begin + FileUtils.cd(@model_path) + FileUtils.cp('site.rb_back' , 'site.rb') + FileUtils.cd(@helper_path) + FileUtils.cp('application_helper.rb_back' , 'application_helper.rb') + FileUtils.cd(@views_path+'admin/sites/') + FileUtils.cp('preference.html.erb_back','preference.html.erb') + rescue + puts Dir.pwd + Dir.chdir(Rails.root.to_s) + puts 'error recovery' + end + elsif key == "member" + puts 'recovery member' + begin + FileUtils.cd(@model_path) + FileUtils.cp('member_profile.rb_back' , 'member_profile.rb') + FileUtils.cd(@controller_path+'admin/') + FileUtils.cp('members_controller.rb_back' , 'members_controller.rb') + FileUtils.cd(@views_path+'admin/members/') + FileUtils.cp('_user_basic_passwd.html.erb_back' , '_user_basic_passwd.html.erb') + rescue + puts Dir.pwd + Dir.chdir(Rails.root.to_s) + puts 'error recovery' + end + elsif key == "accessibility" + puts 'recovery accessibility' + begin + FileUtils.cd(@views_path+'layouts/') + FileUtils.cp('back_end.html.erb_back' , 'back_end.html.erb') + FileUtils.cd(@views_path+'page_parts/') + FileUtils.cp('_form.html.erb_back' , '_form.html.erb') + rescue + puts Dir.pwd + Dir.chdir(Rails.root.to_s) + puts 'error recovery' + end end + Dir.chdir(Rails.root.to_s) + FileUtils.cd(Rails.root.to_s) + end + end + else + self.file_show.each do |key,value| + if value == 1 + @model_path = Rails.root.to_s + '/app/models/' + @helper_path = Rails.root.to_s + '/app/helpers/' + @views_path = Rails.root.to_s + '/app/views/' + @controller_path = Rails.root.to_s + '/app/controllers/' + if key == "ckeditor" + @app_path = File.expand_path(__dir__) + @app_path = lastpath(@app_path) + @app_path = lastpath(@app_path) + @ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/' + puts 'copying CKEDITOR' + begin + Dir.chdir(@ckeditor_path) + File.rename('config.js.erb','config.js.erb_back') + rescue + puts Dir.pwd + end + FileUtils.cd(@app_path+'/updatefiles/') + begin + FileUtils.cp('config.js.erb' , @ckeditor_path) + puts @ckeditor_path + rescue + puts Dir.pwd + puts 'error copy' + end + elsif key == "site-preference(two-site-logo)" + @app_path = File.expand_path(__dir__) + @app_path = lastpath(@app_path) + @app_path = lastpath(@app_path) + puts @app_path + puts 'copying site' + begin + Dir.chdir(@model_path) + File.rename('site.rb','site.rb_back') + Dir.chdir(@helper_path) + File.rename('application_helper.rb','application_helper.rb_back') + Dir.chdir(@views_path+'admin/sites/') + File.rename('preference.html.erb','preference.html.erb_back') + rescue + puts Dir.pwd + end + FileUtils.cd(@app_path+'/updatefiles/') + begin + FileUtils.cp('site.rb' , @model_path) + FileUtils.cp('application_helper.rb' , @helper_path) + FileUtils.cd('admin/') + FileUtils.cp('preference.html.erb',@views_path+'admin/sites/') + rescue + puts Dir.pwd + Dir.chdir(Rails.root.to_s) + puts 'error copy' + end + elsif key == "member" + @app_path = File.expand_path(__dir__) + @app_path = lastpath(@app_path) + @app_path = lastpath(@app_path) + begin + Dir.chdir(@model_path) + File.rename('member_profile.rb','member_profile.rb_back') + Dir.chdir(@controller_path+'admin/') + File.rename('members_controller.rb','members_controller.rb_back') + Dir.chdir(@views_path+'admin/members/') + File.rename('_user_basic_passwd.html.erb','_user_basic_passwd.html.erb_back') + rescue + puts Dir.pwd + end + FileUtils.cd(@app_path+'/updatefiles/') + puts 'copying member' + begin + FileUtils.cp('member_profile.rb' , @model_path) + FileUtils.cd('admin/') + FileUtils.cp('members_controller.rb' , @controller_path+'admin/') + FileUtils.cp('_user_basic_passwd.html.erb' , @views_path+'admin/members/') + rescue + puts Dir.pwd + Dir.chdir(Rails.root.to_s) + puts 'error copy' + end + elsif key == "accessibility" + @app_path = File.expand_path(__dir__) + @app_path = lastpath(@app_path) + @app_path = lastpath(@app_path) + begin + Dir.chdir(@views_path+'layouts/') + File.rename('back_end.html.erb','back_end.html.erb_back') + Dir.chdir(@views_path+'page_parts/') + File.rename('_form.html.erb','_form.html.erb_back') + rescue + puts Dir.pwd + end + FileUtils.cd(@app_path+'/updatefiles/accessibility/') + puts 'copying accessibility' + begin + FileUtils.cp('back_end.html.erb' , @views_path+'layouts/') + FileUtils.cp('_form.html.erb' , @views_path+'page_parts/') + FileUtils.cp_r('jquery-ui-1.12.1/' ,Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/') + rescue + puts Dir.pwd + Dir.chdir(Rails.root.to_s) + puts 'error copy' + end + end + Dir.chdir(Rails.root.to_s) + FileUtils.cd(Rails.root.to_s) end - Dir.chdir(Rails.root.to_s) - FileUtils.cd(Rails.root.to_s) end end end diff --git a/app/views/admin/patchfiles/editckeditor.html.erb b/app/views/admin/patchfiles/editckeditor.html.erb index 5a377ba..97f88af 100644 --- a/app/views/admin/patchfiles/editckeditor.html.erb +++ b/app/views/admin/patchfiles/editckeditor.html.erb @@ -9,11 +9,11 @@ <% for @i in @arr %>
<% if @field.font_array[@i.to_s] == true%> - <%=fontfield.check_box @i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %> + <%=fontfield.check_box @i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;",:class=>"checkbox"} %> <% else %> - <%=fontfield.check_box @i.to_s,{:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %> + <%=fontfield.check_box @i.to_s,{:id=>"checkbox"+@i.to_s,:style=>"float:left;",:class=>"checkbox"} %> <% end %> - <%=fontfield.label @i.to_s ,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%> + <%=fontfield.label @i.to_s ,{:for=>"checkbox"+@i.to_s,:style=>"float:right;",:class=>"checklabel"}%>
<%end%> <%end%> @@ -21,9 +21,9 @@
<%=f.text_field :new_add_font,{:id=>"newfont",:placeholder=>t(:newfont)}%>
<%=f.submit "#{t(:updatefont)}",{:id=>"submitbtn"}%> - + <%=f.text_field :initial_btn, {:id=>"hidden-initial",:type => "hidden",:value=>"false"} %> - + <%=f.text_field :delete_btn, {:id=>"hidden-delete",:type => "hidden",:value=>"false"} %> <%end%>
  • @@ -51,24 +51,89 @@ } \ No newline at end of file