2019-09-28 11:48:59 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'rubyXL'
|
|
|
|
class Admin::PatchfilesController < OrbitAdminController
|
|
|
|
include Admin::PatchfilesHelper
|
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
|
|
|
before_action :getfont , :create_first_field
|
|
|
|
#before_action :load_access_levels
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "patchfile"
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
|
|
|
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def edit
|
|
|
|
params["filefield"]["file_show"].each_with_index do |(key,value),index|
|
|
|
|
@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
|
|
|
|
end
|
|
|
|
def showckeditor
|
|
|
|
end
|
|
|
|
def editckeditor
|
|
|
|
end
|
|
|
|
def editfontfile
|
|
|
|
end
|
|
|
|
def update
|
|
|
|
if params[:id] == "editfontfile"
|
|
|
|
@field_name
|
|
|
|
params["fontfile"]["font_file"] = "" if params["fontfile"]["font_file"].nil? == true
|
|
|
|
params["fontfile"].each do |update_key,update_value|
|
|
|
|
if update_key != "font_file"
|
|
|
|
@font_settings["old_"+update_key] = @font_settings[update_key] rescue nil
|
|
|
|
@font_settings[update_key] = update_value
|
|
|
|
else
|
|
|
|
@file = params["fontfile"]["font_file"] if params["fontfile"]["font_file"] != ""
|
|
|
|
@file_path = Rails.root.to_s + '/app/assets/fonts'
|
|
|
|
|
|
|
|
if @file.nil? != true
|
|
|
|
@file_name = @file.original_filename
|
|
|
|
@file_content = @file.read
|
|
|
|
@file_content.force_encoding('UTF-8')
|
|
|
|
Dir.chdir(@file_path)
|
|
|
|
@filetowrite
|
|
|
|
if !File.file?(@file_name)
|
|
|
|
@filetowrite = File.new(@file_name,"w")
|
|
|
|
else
|
|
|
|
@filetowrite = File.open(@file_name,"w")
|
|
|
|
end
|
|
|
|
@filetowrite.write(@file_content)
|
|
|
|
@filetowrite.close
|
|
|
|
Dir.chdir(Rails.root.to_s)
|
|
|
|
else
|
|
|
|
@file_name = @font_settings.font_file_name
|
|
|
|
end
|
|
|
|
@field_name = {"font_file_name" => @file_name,"font_dir" => @file_path}
|
|
|
|
@field_name.each do |name,value|
|
|
|
|
@font_settings["old_" + name.to_s] = @font_settings[name.to_s]
|
|
|
|
@font_settings[name.to_s] = value.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@font_settings.update
|
|
|
|
end
|
|
|
|
redirect_to admin_patchfiles_showckeditor_path
|
|
|
|
end
|
|
|
|
def newfont
|
2019-09-28 15:38:15 +00:00
|
|
|
if params["patchfilefield"]["initial_btn"] == "true"
|
|
|
|
#render :html => @field.id and return
|
2019-09-29 04:18:19 +00:00
|
|
|
@field_to_copy = Patchfilefield.where("title"=>(@app_title + "_back")).take_while{true}.last
|
|
|
|
@field_to_copy.attributes.each do |copy_field,value|
|
|
|
|
if copy_field != "_id" || copy_field != "title"
|
|
|
|
@field[copy_field] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@field.update
|
|
|
|
@field = Patchfilefield.where("title"=>@app_title).first
|
2019-09-28 15:38:15 +00:00
|
|
|
@field.update
|
2019-09-29 04:18:19 +00:00
|
|
|
@field = Patchfilefield.where("title"=>@app_title).first
|
|
|
|
@font_arr = []
|
|
|
|
@field.font_array.each do |font,istrue|
|
|
|
|
@font_arr.push font
|
|
|
|
end
|
|
|
|
@font_arr.each do |font,istrue|
|
|
|
|
if (@field_to_copy.font_array.keys.include? font) == false
|
|
|
|
@field.font_array.delete(font)
|
|
|
|
@field.delete_font = font
|
|
|
|
@field.update
|
|
|
|
@field = Patchfilefield.where("title"=>@app_title).first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to admin_patchfiles_editckeditor_path and return
|
|
|
|
elsif params["patchfilefield"]["delete_btn"] == "true"
|
|
|
|
params["patchfilefield"]["font_array"] = {} if params["patchfilefield"]["font_array"].nil? == true
|
|
|
|
params["patchfilefield"]["font_array"].each do |font,istrue|
|
|
|
|
if istrue =="1"
|
|
|
|
@field.font_array.delete(font)
|
|
|
|
@field.delete_font = font
|
|
|
|
@field.update
|
|
|
|
@field = Patchfilefield.where("title"=>@app_title).first
|
|
|
|
end
|
|
|
|
end
|
2019-09-28 15:38:15 +00:00
|
|
|
redirect_to admin_patchfiles_editckeditor_path and return
|
|
|
|
else
|
2019-09-29 06:58:58 +00:00
|
|
|
params["patchfilefield"]["new_add_font"] = params["patchfilefield"]["new_add_font"].gsub('\"','').gsub("\'",'').gsub(";",'').gsub('\\','')
|
2019-09-28 15:38:15 +00:00
|
|
|
@field.new_add_font = params["patchfilefield"]["new_add_font"] rescue (redirect_to admin_patchfiles_showckeditor_path and return)
|
|
|
|
@key_arr = @field.font_array.keys
|
2019-09-29 04:18:19 +00:00
|
|
|
params["patchfilefield"]["font_array"] = {} if params["patchfilefield"]["font_array"].nil? == true
|
|
|
|
params["patchfilefield"]["font_array"].each do |font,istrue|
|
2019-09-28 15:38:15 +00:00
|
|
|
if istrue =="0"
|
2019-09-29 04:18:19 +00:00
|
|
|
@field.font_array[font] = false
|
2019-09-28 15:38:15 +00:00
|
|
|
elsif istrue =="1"
|
2019-09-29 04:18:19 +00:00
|
|
|
@field.font_array[font] = true
|
2019-09-28 15:38:15 +00:00
|
|
|
end
|
2019-09-28 11:48:59 +00:00
|
|
|
end
|
2019-09-28 15:38:15 +00:00
|
|
|
@field.update
|
|
|
|
redirect_to admin_patchfiles_showckeditor_path and return
|
2019-09-28 11:48:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def getfont
|
2019-09-29 08:13:18 +00:00
|
|
|
@font_array = []
|
2019-09-28 11:48:59 +00:00
|
|
|
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
2019-09-29 08:13:18 +00:00
|
|
|
@filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return
|
2019-09-28 11:48:59 +00:00
|
|
|
@name_to_search ="config.font_names"
|
|
|
|
@index_of_font = @filedata.index(@name_to_search)
|
|
|
|
@font_str = ""
|
|
|
|
@end_character
|
|
|
|
@str_start
|
|
|
|
@str_end
|
|
|
|
if @index_of_font != nil
|
|
|
|
@inex_start_to_search = @index_of_font + @name_to_search.length
|
|
|
|
@str_start = @inex_start_to_search
|
|
|
|
if (@filedata[@inex_start_to_search] != "\'" && @filedata[@inex_start_to_search] != "\"")
|
|
|
|
for @str_start in @inex_start_to_search..@filedata.length
|
|
|
|
break if (@filedata[@str_start] == "\'" || @filedata[@str_start] == "\"")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@end_character = @filedata[@str_start]
|
|
|
|
@str_end = @str_start+1
|
|
|
|
if @str_start+1 < @filedata.length
|
|
|
|
@str_end = @str_start+1
|
|
|
|
for @str_end in @str_start+1..@filedata.length
|
|
|
|
break if @filedata[@str_end] == @end_character || @str_end == @str_start
|
|
|
|
if @filedata[@str_end] == "="
|
|
|
|
@str_end = @str_start
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if @str_end != @str_start
|
|
|
|
@font_str = @filedata[@str_start+1...@str_end]
|
|
|
|
else
|
|
|
|
@font_str = ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@font_array = @font_str.split("\;")
|
|
|
|
@font_array.map!{|i| i.strip}
|
|
|
|
@font_array.delete("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def create_first_field
|
2019-09-29 04:18:19 +00:00
|
|
|
if Patchfilefield.where("title"=>(@app_title + "_back")).take_while{true}.count == 0
|
2019-09-28 15:38:15 +00:00
|
|
|
@field = Patchfilefield.new()
|
2019-09-29 04:18:19 +00:00
|
|
|
@field.title = @app_title +"_back"
|
2019-09-28 15:38:15 +00:00
|
|
|
@field.save
|
|
|
|
end
|
2019-09-28 11:48:59 +00:00
|
|
|
@field
|
|
|
|
if Patchfilefield.where("title"=>@app_title).take_while{true}.count == 0
|
|
|
|
@field = Patchfilefield.new()
|
|
|
|
@field.title=@app_title
|
|
|
|
@field.save
|
|
|
|
@field = Patchfilefield.where("title"=>@app_title).first
|
|
|
|
else
|
|
|
|
@field = Patchfilefield.where("title"=>@app_title).first
|
|
|
|
end
|
|
|
|
if params[:font] != nil
|
|
|
|
if Fontfile.where("title"=>params[:font]).first.nil? == true
|
|
|
|
@font_settings = Fontfile.new
|
|
|
|
@font_settings.title = params[:font]
|
|
|
|
@font_settings.save
|
|
|
|
end
|
|
|
|
@font_settings = Fontfile.where("title"=>params[:font]).first
|
|
|
|
end
|
|
|
|
if Filefield.where("title"=>@app_title).take_while{true}.count == 0
|
|
|
|
@file_to_show = Filefield.new()
|
|
|
|
@file_to_show.title=@app_title
|
|
|
|
@file_to_show.save
|
|
|
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
|
|
|
else
|
2019-09-29 09:44:49 +00:00
|
|
|
@default_field = Filefield.new()
|
2019-09-28 11:48:59 +00:00
|
|
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
2019-09-29 09:44:49 +00:00
|
|
|
@default_field.file_show.each do |check,istrue|
|
|
|
|
if @file_to_show.file_show[check] == nil
|
|
|
|
@file_to_show.file_show[check] = istrue
|
|
|
|
@file_to_show.save
|
|
|
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
|
|
|
end
|
|
|
|
end
|
2019-09-28 11:48:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|