commit ed01254efc89c83e4b5a301e7dcf342332e8a6c0 Author: BoHung Chiu Date: Wed Oct 4 21:02:40 2023 +0800 First version. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de5d954 --- /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..d97db1e --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +# Declare your gem's dependencies in personal_course.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/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..1e4beb8 --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2015 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..148e53b --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += ModuleGenerator + +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..78646ad --- /dev/null +++ b/Rakefile @@ -0,0 +1,34 @@ +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 = 'PersonalCourse' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + + + +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/module_generator/.keep b/app/assets/images/module_generator/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/module_generator/application.js b/app/assets/javascripts/module_generator/application.js new file mode 100644 index 0000000..a1873dd --- /dev/null +++ b/app/assets/javascripts/module_generator/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/app/assets/stylesheets/module_generator/application.css b/app/assets/stylesheets/module_generator/application.css new file mode 100644 index 0000000..a443db3 --- /dev/null +++ b/app/assets/stylesheets/module_generator/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/app/controllers/admin/module_generators_controller.rb b/app/controllers/admin/module_generators_controller.rb new file mode 100644 index 0000000..227eee8 --- /dev/null +++ b/app/controllers/admin/module_generators_controller.rb @@ -0,0 +1,961 @@ +class Admin::ModuleGeneratorsController < OrbitAdminController + require 'fileutils' + include Admin::ModuleGeneratorsHelper + before_action :set_module_field, only: [:show, :edit , :update, :destroy, :fields_setting, :update_fields_setting,:generate_module] + + def index + @module_fields = ModuleField.order_by(:created_at=>'desc').page(params[:page]).per(10) + end + + def new + @member = MemberProfile.find_by(:uid=>params['uid'].to_s) rescue nil + @module_field = ModuleField.new + end + def download + zip_path = "tmp/" + FileUtils.mkdir_p(zip_path) if !Dir.exist?(zip_path) + module_field = ModuleField.find(params[:module_generator_id]) rescue nil + if module_field + module_key = File.basename(module_field.module_key) + zip_file_path = zip_path + "#{module_key}.zip" + zip_file= ZipFileGenerator.new(zip_path + module_key ,zip_file_path) + begin + zip_file.write + rescue + File.delete(zip_path + "#{module_key}.zip") + zip_file.write + end + send_file(zip_file_path) + end + end + def copy + @member = MemberProfile.find_by(:uid=>params['uid'].to_s) rescue nil + attributes = ModuleField.find(params[:module_generator_id]).attributes rescue {} + attributes = attributes.except("_id") + copy_attributes = {} + attributes.each do |k,v| + if (ModuleField.fields[k].options[:localize] rescue false) + copy_attributes["#{k}_translations"] = v + else + copy_attributes[k] = v + end + end + #render :html => attributes and return + @module_field = ModuleField.new(copy_attributes) + end + def create + module_field = ModuleField.create(module_field_params) + redirect_to admin_module_fields_path + end + + def edit + end + + def destroy + @module_field.destroy + redirect_to admin_module_fields_path(:page => params[:page]) + end + + def update + @module_field.update_attributes(module_field_params) + @module_field.save + redirect_to admin_module_fields_path + end + def fields_setting + end + def update_fields_setting + field_params = params.require(:module_field).permit! rescue {} + field_params[:fields_order] = field_params[:fields_order].map do |k, v| + [k, v.sort_by{|k,vv| k.to_i}.map{|vv| vv[1].to_i}] + end.to_h + @module_field.update_attributes(field_params) + @module_field.save + redirect_to params[:referer_url] + end + def scan_word_block(word) + words_idx = [] + tmp = [] + is_word = false + word.split('').each_with_index do |w, i| + if w.match(/\w/) + if !is_word + tmp << i + is_word = true + end + elsif is_word + tmp << i - 1 + words_idx << tmp + tmp = [] + is_word = false + end + end + if tmp.count == 1 + tmp << word.length - 1 + words_idx << tmp + tmp = [] + end + last_idx = word.length - 1 + new_res = [] + words_idx_reverse = words_idx.reverse + words_idx_reverse.each_with_index do |v, i| + s = v[0] + e = v[1] + tmp_str = word[s..e] + tmp = word[e+1..last_idx] + need_find_quote = tmp.match(/['"]/) + need_find_quote = need_find_quote ? need_find_quote[0] : nil + tmp_str += tmp + prev_word_range = words_idx_reverse[i + 1] + start_idx = 0 + if prev_word_range + start_idx = prev_word_range[1] + 1 + end + if need_find_quote + tmp = word[start_idx...s].match(/(,\s+|)[,#{need_find_quote}]+\s*$/) + else + tmp = word[start_idx...s].match(/(,\s+|)\s*$/) + end + if tmp + tmp = tmp[0] + tmp_str = tmp + tmp_str + last_idx = s - 1 - tmp.length + else + last_idx = s - 1 + end + new_res << tmp_str + end + new_res.reverse + end + def generate_module + template_dir_path = File.expand_path("../../../../template_generator/", __FILE__) + "/" + cp_template_dir_path = "#{Rails.root}/tmp/#{@module_field.module_key}/" + Bundler.with_clean_env { system("cd #{File.dirname(template_dir_path)} && git checkout -- template_generator") } + FileUtils.rm_rf(cp_template_dir_path) + FileUtils.cp_r(template_dir_path,cp_template_dir_path) + dirs = Dir.glob("#{cp_template_dir_path}*/") + files = Dir.glob("#{cp_template_dir_path}*").select { |fn| File.file?(fn) } + begin + in_use_locales = Site.first.in_use_locales + primary_modal_fields = @module_field.primary_modal_fields.select{|f| (f[:field_name].present? rescue false)} + primary_modal_fields << {:field_name=>"authors", :translation_name=>{"zh_tw"=>"全部作者", "en"=>"Authors"}, :field_type=>"text_editor", :localize=>"1", :slug_title=>"0", :periodic_time=>"0"} if primary_modal_fields.select{|f| f[:field_name] == "authors"}.count == 0 + yml_files = Dir.glob("#{cp_template_dir_path}config/locales/*.yml") + yml_files.each do |yml_file| + locale = yml_file.split("/").last.split(".yml").first + yml_text = File.read(yml_file) + translate_hash = {} + primary_modal_fields.each do |field_value| + if (field_value[:translation_name][locale].present? rescue false) + translate_hash[field_value[:field_name]] = field_value[:translation_name][locale] + end + end + @module_field.related_modal_name.each_with_index do |related_modal_name,i| + field_values = @module_field.related_modal_fields[i].to_a rescue [] + sub_hash = {} + field_values.each do |field_value| + if field_value[:field_name] && (field_value[:translation_name][locale].present? rescue false) + sub_hash[field_value[:field_name]] = field_value[:translation_name][locale] + end + end + if related_modal_name.present? && sub_hash.present? + translate_hash[related_modal_name] = sub_hash + end + #sub_hash["modal_name"] = "關聯欄位翻譯" + end + col_name_translate_yaml = "" + if translate_hash.present? + col_name_translate_yaml = translate_hash.to_yaml.gsub("---\n", '') + end + yml_text = gsub_text_by_key_value(yml_text,"col_name_translate_yaml",col_name_translate_yaml) + yml_text = yml_text.gsub("module_template_translate",@module_field.title_translations[locale]) + File.open(yml_file,'w+') do |f| + f.write(yml_text) + end + end + @blank_text = " " + slug_title = primary_modal_fields.select{|field_value| field_value[:slug_title] == "1" rescue false}.first[:field_name].to_s rescue "" + module_modal_template_related_files = primary_modal_fields.select{|field_value| field_value[:field_type] == "file" rescue false}.map{|v| v[:field_name]} + module_modal_template_related_links = primary_modal_fields.select{|field_value| field_value[:field_type] == "link" rescue false}.map{|v| v[:field_name]} + module_modal_template_related_members = primary_modal_fields.select{|field_value| field_value[:field_type] == "member" rescue false}.map{|v| v[:field_name]} + module_modal_template_related_files_text = module_modal_template_related_files.to_s + module_modal_template_related_links_text = module_modal_template_related_links.to_s + fields = module_modal_template_related_files + module_modal_template_related_links + module_modal_template_related_files_fields = fields.map{|field_name| + "has_many :#{field_name.pluralize}, :dependent => :destroy, :autosave => true\n" + + "accepts_nested_attributes_for :#{field_name.pluralize}, :allow_destroy => true" + }.join("\n") + module_modal_template = @module_field.primary_modal_name + all_fields = primary_modal_fields.map{|f| f[:field_name]} + ["member_profile"] + @module_field.related_modal_name.each_with_index do |k,i| + all_fields += @module_field.related_modal_fields[i].to_a.map{|f| "#{k}.#{f[:field_name]}"} + end + @module_field.frontend_fields.each do |k,v| + @module_field.frontend_fields[k] = v & all_fields + end + @module_field.backend_fields.each do |k,v| + @module_field.backend_fields[k] = v & all_fields + end + date_fields = [] + year_month_fields = [] + date_time_fields = [] + primary_modal_fields.each do |field_value| + if (field_value[:field_type].present? rescue false) + case field_value[:field_type] + when "date" + date_fields << field_value[:field_name] + when "year_month" + year_month_fields << field_value[:field_name] + when "date_time" + date_time_fields << field_value[:field_name] + end + end + end + @module_field.related_modal_name.each_with_index do |k,i| + @module_field.related_modal_fields[i].to_a.each do |field_value| + field_name = "#{k}.#{field_value[:field_name]}" + if (field_value[:field_type].present? rescue false) + case field_value[:field_type] + when "date" + date_fields << field_name + when "year_month" + year_month_fields << field_name + when "date_time" + date_time_fields << field_name + end + end + end + end + backend_index_fields = @module_field.backend_fields["index"].to_a rescue [] + backend_index_fields_contents = backend_index_fields.map do |field_name| + if field_name == slug_title + "\n <%= link_to #{module_modal_template}.#{field_name}, page_for_#{module_modal_template}(#{module_modal_template}), target: \"blank\" %>\n" + + "
\n"+ + " \n"+ + "
\n " + elsif date_fields.include?(field_name) + "<%= #{module_modal_template}.#{field_name}.strftime('%Y/%m/%d') rescue \"\" %>" + elsif year_month_fields.include?(field_name) + "<%= #{module_modal_template}.#{field_name}.strftime('%Y/%m') rescue \"\" %>" + elsif date_time_fields.include?(field_name) + "<%= #{module_modal_template}.#{field_name}.strftime('%Y/%m/%d %H:%M') rescue \"\" %>" + elsif field_name.include?(".") + "<%= #{module_modal_template}.#{field_name} rescue \"\" %>" + elsif fields.include?(field_name) || module_modal_template_related_members.include?(field_name) || field_name == "member_profile" #file or link or member + "<%= #{module_modal_template}.display_field(\"#{field_name}\").html_safe rescue \"\" %>" + else + "<%= #{module_modal_template}.#{field_name} %>" + end + end + backend_profile_fields = @module_field.backend_fields["profile"].to_a rescue [] + backend_profile_fields_contents = backend_profile_fields.map do |field_name| + if field_name == slug_title + "\n <%= link_to #{module_modal_template}.#{field_name}, page_for_#{module_modal_template}(#{module_modal_template}), target: \"blank\" %>\n" + + "
\n"+ + " \n"+ + "
\n " + elsif field_name.include?(".") + "<%= #{module_modal_template}.#{field_name} rescue \"\" %>" + elsif fields.include?(field_name) || module_modal_template_related_members.include?(field_name) || field_name == "member_profile" #file or link or member + "<%= #{module_modal_template}.display_field(\"#{field_name}\").html_safe rescue \"\" %>" + else + "<%= #{module_modal_template}.#{field_name} %>" + end + end + col_name_to_show = @module_field.frontend_fields["member_show"].to_a rescue [] + col_name_to_show_in_show_page = @module_field.frontend_fields["show"].to_a rescue [] + col_name_to_show_in_index_page = @module_field.frontend_fields["index"].to_a rescue [] + extra_translate_title = col_name_to_show_in_index_page.map{|field_name| #在個人外掛前台index頁面的欄位翻譯名稱hash + ["th-#{field_name}","I18n.t(\"#{@module_field.module_key}.#{field_name}\")"] + } + col_fields = get_fields_text(primary_modal_fields) + col_related_fields = @module_field.related_modal_fields.map{|field_values| get_fields_text(field_values)} + module_modal_template_related = @module_field.related_modal_name.select{|n| n.present?} + module_modal_template_related_main_field = @module_field.related_modal_fields.map{|field_values| + slug_titles = field_values.select{|field_value| (field_value[:slug_title] == "1" rescue false)} + if slug_titles.count == 0 + slug_titles = field_values + end + slug_titles.map{|field_value| field_value[:field_name]}.select{|t| t.present?}.first + } + locale_fields , none_locale_fields , locale_fields_input_fields,none_locale_fields_input_fields = get_input_fields(primary_modal_fields) + related_locale_fields = [] + related_none_locale_fields = [] + related_locale_fields_input_fields = [] + related_none_locale_fields_input_fields = [] + @module_field.related_modal_fields.each_with_index do |field_values,i| + related_modal_name = @module_field.related_modal_name[i] + f1 , f2 , f3 , f4 = get_input_fields(field_values,related_modal_name,related_modal_name) + related_locale_fields << f1 + related_none_locale_fields << f2 + related_locale_fields_input_fields << f3 + related_none_locale_fields_input_fields << f4 + end + datetime_field_types_hash = {"year_month"=>"%Y/%m","date"=>"%Y/%m/%d","time"=>"%H:%M","date_time"=>"%Y/%m/%d %H:%M"} + datetime_fields = primary_modal_fields.select{|field_value| datetime_field_types_hash.keys.include?(field_value[:field_type])}.map{|field_value| + [field_value[:field_name],datetime_field_types_hash[field_value[:field_type]]] + }.to_h + value_case_codes = ["value = #{module_modal_template}.send(field) rescue \"\"", + "if field.include?(\".\")", + "#{@blank_text}value = #{module_modal_template}", + "#{@blank_text}field.split(\".\").each{|f| value = value.send(f) rescue nil }", + "end", + "file_fields = #{module_modal_template_related_files}", + "link_fields = #{module_modal_template_related_links}", + "member_fields = #{module_modal_template_related_members}", + "if file_fields.include?(field)", + "#{@blank_text}files = #{module_modal_template}.send(field.pluralize)", + "#{@blank_text}value = files.map do |file|", + "#{@blank_text * 2}url = file.file.url", + "#{@blank_text * 2}title = (file.title.blank? ? File.basename(file.file.path) : file.title)", + "#{@blank_text * 2}\"
  • \#{title}
  • \"", + "#{@blank_text}end", + "#{@blank_text}value = value.join(\"\")", + "elsif link_fields.include?(field)", + "#{@blank_text}links = #{module_modal_template}.send(field.pluralize)", + "#{@blank_text}value = links.map do |link|", + "#{@blank_text * 2}url = link.url", + "#{@blank_text * 2}title = (link.title.blank? ? url : link.title)", + "#{@blank_text * 2}\"
  • \#{title}
  • \"", + "#{@blank_text}end", + "#{@blank_text}value = value.join(\"\")", + "elsif member_fields.include?(field)", + "#{@blank_text}members = #{module_modal_template}.send(field.pluralize)", + "#{@blank_text}value = members.map{|m|", + "#{@blank_text*2}path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'", + "#{@blank_text*2}((text_only rescue false) ? m.name : \"\#{m.name}\")", + "#{@blank_text}}", + "#{@blank_text}join_text = (text_only rescue false) ? \",\" : \"
    \"", + "#{@blank_text}value = value.join(join_text)", + "elsif field == \"member_profile\" || field == \"authors\"", + "#{@blank_text}value = get_authors_show(#{module_modal_template})", + "end", + "strftime_hash = #{datetime_fields}", + "if strftime_hash.keys.include?(field)", + "#{@blank_text}value = value.strftime(strftime_hash[field]) rescue value", + "end" + ].join("\n") + enable_one_line_title = @module_field.enable_one_line_title && @module_field.one_line_title_format.present? + tmp_title = enable_one_line_title ? "(title_is_paper_format ? #{module_modal_template}.create_link : value)" : "value" + display_field_code = value_case_codes + "\n" + + "if field == \"#{slug_title}\"\n" + + "#{@blank_text}link = OrbitHelper.url_to_plugin_show(#{module_modal_template}.to_param,'#{@module_field.module_key}')\n" + + "#{@blank_text}tmp_title = #{tmp_title}\n"+ + "#{@blank_text}url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)\n" + + "#{@blank_text}value = url_to_plugin_show_blank ? tmp_title : \"\#{tmp_title}\"\n" + + "end\n" + + "value" + value_case_codes += "\nvalue" + related_backend_index_fields = @module_field.related_modal_fields.map{|field_values| + field_values.map{|field_value| (field_value[:field_name] rescue nil)}.select{|t| t.present?} + } + related_backend_index_fields_contents = related_backend_index_fields.map.with_index{|field_names,i| + related_modal_name = @module_field.related_modal_name[i] + field_names.map{|field_name| "<%= #{related_modal_name}.#{field_name} %>"} + } + member_methods_define = primary_modal_fields.select{|f| (f[:field_type] == "member" rescue false)}.map{|field_value| + ["def #{field_value[:field_name].pluralize}", + " MemberProfile.find(self.#{field_value[:field_name].singularize}_ids) rescue []", + "end"] + }.flatten + date_time_strftime = {"date"=>"%Y/%m/%d","date_time"=>"%Y/%m/%d %H:%M","year_month"=>"%Y/%m"} + periodic_methods_define = primary_modal_fields.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value| + strftime_string = "" + if date_time_strftime.keys.include?(field_value[:field_type]) + strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")" + end + ["def #{field_value[:field_name]}", + " #{field_value[:field_name]}_start = self.#{field_value[:field_name]}_start#{strftime_string} rescue \"\"", + " #{field_value[:field_name]}_end = self.#{field_value[:field_name]}_end#{strftime_string} rescue \"\"", + " \"\#{#{field_value[:field_name]}_start} ~ \#{#{field_value[:field_name]}_end}\"", + "end"] + }.flatten + related_periodic_methods_define = @module_field.related_modal_fields.map{|field_values| + field_values.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value| + strftime_string = "" + if date_time_strftime.keys.include? field_value[:field_type] + strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")" + end + ["def #{field_value[:field_name]}", + " \"\#{self.#{field_value[:field_name]}_start#{strftime_string}} ~ \#{self.#{field_value[:field_name]}_end#{strftime_string}}\"", + "end"] + }.flatten + } + analysis_field_name = @module_field.backend_fields[:analysis][0] rescue "" + analysis_field_name = "year" if analysis_field_name.blank? + analysis_field_input_fields = "" + module_template = @module_field.module_key + iterate_step_text = "1.minute" + if analysis_field_name.present? + field_type = primary_modal_fields.select{|f| f[:field_name] == analysis_field_name}.first[:field_type] rescue "date_time" + + analysis_field_input_fields = ["start","end"].map{|f| + "<%=t(\"#{module_template}.extend_translate.#{f}_#{field_type}\")%>" + + generate_input_field(field_type,"#{analysis_field_name}_#{f}" ).gsub("<%= f.","<%= ").gsub(", :new_record => @#{module_modal_template}.new_record?","") + }.join("") + if field_type == "date" || field_type == "date_time" + iterate_step_text = "1.day" + elsif field_type == "year" + iterate_step_text = "1" + end + end + period_fields = primary_modal_fields.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|f| f[:field_name]} + time_fields = primary_modal_fields.select{|f| f[:field_type] == "time"}.map{|f| f[:field_name]} + before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\n") + module_modal_template_sort_hash = {} + @module_field.backend_fields[:sort_asc].to_a.each do |f| + module_modal_template_sort_hash[f.to_sym] = 1 + end rescue nil + @module_field.backend_fields[:sort_desc].to_a.each do |f| + module_modal_template_sort_hash[f.to_sym] = -1 + end rescue nil + if @module_field.backend_fields[:sort_desc].to_a.count != 0 + module_modal_template_sort_hash[:id] = -1 + end + all_fields_types = { + "member_profile"=>"authors", + "authors" => "authors" + } + all_fields_to_show = [] + @module_field.primary_modal_fields.each do |f| + field_name = f[:field_name] + if field_name.present? + all_fields_types[field_name] = f[:field_type] + all_fields_to_show << field_name + end + end + @module_field.related_modal_name.each_with_index do |k,i| + @module_field.related_modal_fields[i].to_a.map do |f| + field_name = f[:field_name] + if field_name.present? + field_name = "#{k}.#{field_name}" + all_fields_types[field_name] = f[:field_type] + all_fields_to_show << field_name + end + end + end + all_fields_to_show_in_index = @module_field.get_sorted_fields(:frontend_fields, :index, all_fields_to_show) + one_line_title_format_code = [] + scan_code = scan_word_block(@module_field.one_line_title_format) + one_line_title_format_code << "title = ''" + scan_code.each do |c| + left_space = c.match(/^[\s\'\",]+/) + right_space = c.match(/[\s\'\",]+$/) + variable_name = c.sub(/^[\s\'\",]+/,'').sub(/[\s\'\",]+$/, '') + if variable_name.present? + field_type = all_fields_types[variable_name] + if field_type + if_condition = "if self.#{variable_name}.present?" + variable_contents = "self.#{variable_name}" + if field_type == 'date' || field_type == 'year_month' || field_type == 'date_time' + variable_contents += ".strftime('%b. %Y')" + elsif field_type == 'year' + variable_contents += '.to_s' + elsif field_type == 'member' + variable_contents = "MemberProfile.where(:id.in=>self.#{variable_name}_ids).pluck(:tmp_name).map{|h| h[I18n.locale]}.to_sentence({:locale=>:en})" + elsif field_type == 'authors' + variable_contents = "get_authors_text(self, true, :en)" + if_condition += ' || self.member_profile_id.present?' + end + if left_space || right_space + left_space = left_space ? left_space[0] : '' + right_space = right_space ? right_space[0] : '' + one_line_title_format_code << "title += \"#{left_space.gsub('"','\\"')}\#{#{variable_contents}}#{right_space.gsub('"','\\"')}\" #{if_condition}" + else + one_line_title_format_code << "title += #{variable_contents} #{if_condition}" + end + end + end + end + one_line_title_format_code << "title.sub(/^\\s*,/,'').gsub(/,(\\s*,)+/,',')" + one_line_title_format_code = one_line_title_format_code.join("\n") + col_name_to_show_short = [] + col_name_to_show_short << analysis_field_name + col_name_to_show_short << slug_title + @match_pattern = {"module_template" => module_template, + "module_modal_template" => module_modal_template, + "module_modal_template_related" => module_modal_template_related, + "module_modal_template_related_files_fields" => module_modal_template_related_files_fields, + "all_fields_to_show" => all_fields_to_show , #所有該模組的欄位 + "all_fields_to_show_in_index" => all_fields_to_show_in_index , #所有該模組的欄位在前台index頁面 + "col_name_to_show_short" => col_name_to_show_short.to_s, #在會員前台頁面的顯示欄位 + "col_name_to_show" => col_name_to_show.to_s, #在會員前台頁面的顯示欄位 + "col_name_to_show_in_show_page" => col_name_to_show_in_show_page.to_s, #在個人外掛前台show頁面的顯示欄位 + "col_name_to_show_in_index_page" => col_name_to_show_in_index_page.to_s, #在個人外掛前台index頁面的顯示欄位 + "extra_translate_title" => extra_translate_title.map{|k,v| "\"#{k}\" => #{v}"}.join(", ").prepend("{").concat("}"), + "col_fields" => col_fields, + "col_related_fields" => col_related_fields, + "module_modal_template_file" => module_modal_template_related_files, + "module_modal_template_link" => module_modal_template_related_links, + "module_modal_template_sort_hash" => module_modal_template_sort_hash.to_s, + "col_name_to_show_in_index_page_arr" => col_name_to_show_in_index_page, + "related_backend_index_fields" => related_backend_index_fields, + "related_backend_index_fields_contents" => related_backend_index_fields_contents, + "backend_index_fields" => backend_index_fields, + "backend_index_fields_contents" => backend_index_fields_contents, + "module_modal_template_related_links_text" => module_modal_template_related_links_text, + "module_modal_template_related_files_text" => module_modal_template_related_files_text, + "locale_fields" => locale_fields, + "none_locale_fields" => none_locale_fields, + "none_locale_fields_input_fields" => none_locale_fields_input_fields, + "locale_fields_input_fields" => locale_fields_input_fields, + "related_locale_fields" => related_locale_fields, + "related_none_locale_fields" => related_none_locale_fields, + "related_none_locale_fields_input_fields" => related_none_locale_fields_input_fields, + "related_locale_fields_input_fields" => related_locale_fields_input_fields, + "module_modal_template_related_main_field" => module_modal_template_related_main_field, + "backend_profile_fields" => backend_profile_fields, + "backend_profile_fields_contents" => backend_profile_fields_contents, + "value_case_codes" => value_case_codes, + "display_field_code" => display_field_code, + "member_methods_define" => member_methods_define, + "analysis_field_name" => analysis_field_name, + "analysis_field_input_fields" => analysis_field_input_fields, + "before_save_codes" => before_save_codes, + "time_fields_text" => time_fields.to_s, + "iterate_step_text" => iterate_step_text, + "module_modal_template_related_members" => module_modal_template_related_members.to_s, + "periodic_methods_define" => periodic_methods_define, + "related_periodic_methods_define" => related_periodic_methods_define, + "period_fields_text" => period_fields.to_s, + "enable_one_line_title" => enable_one_line_title.to_s, + "one_line_title_format_code" => one_line_title_format_code, + "is_one_line_title" => (enable_one_line_title ? [true] : []), #used in parse_again block if condition + "slug_title_text" => slug_title + } + max_length = @match_pattern.keys.map{|k| k.length}.max + @match_pattern = @match_pattern.sort_by{|k,v| -k.length} + #sort_by{|k,v| (v.class != Array) ? (max_length - k.length) : -k.length} + @logs = [] + replace_files(files) + #Thread.new do + replace_dirs(dirs,false) + #end + copy_templates("#{cp_template_dir_path}modules/#{@module_field.module_key}/") + #render :html => @logs#@match_pattern#@logs.join("
    ").html_safe#@match_pattern + @module_field.update(:log_text=>"") + @module_field.update(:finished=>true) + add_plugin("downloaded_extensions.rb",@module_field.module_key) + bundle_install + render :json => {:success=>true,:url=>"/admin/#{module_modal_template.pluralize}/",:name=>@module_field.title} + rescue => e + @match_pattern = {"parse_again_start"=>"","parse_again_end"=>"","col_name_translate_yaml"=>""} + replace_files(files) + replace_dirs(dirs,false) + error = e.backtrace.join("
    ") + @module_field.update(:log_text=>error) + @module_field.update(:finished=>false) + render :json => {:success=>false,:error=>error} + end + end + def copy_templates(source) + templates = Dir.glob('app/templates/*/').select{|f| File.basename(f) != 'mobile'} + templates.each do |template| + FileUtils.cp_r(source,"#{template}modules/.") + end + end + def get_input_fields(field_values,extra_field_name=nil,module_modal_template = nil) + none_locale_fields = [] + locale_fields = [] + locale_fields_input_fields = [] + none_locale_fields_input_fields = [] + @index = 0 + field_values.each do |field_value| + field_name = field_value[:field_name] + field_type = field_value[:field_type] + next if field_name.blank? + next if field_type == "file" || field_type == "link" + localize = (field_value[:localize] == "1" rescue false) + periodic = (field_value[:periodic_time] == "1" rescue false) + input_field = generate_input_field(field_type,field_name,localize,extra_field_name,module_modal_template,periodic) + if localize + locale_fields << field_name + locale_fields_input_fields << input_field + else + none_locale_fields << field_name + none_locale_fields_input_fields << input_field + end + @index += 1 + end + return locale_fields , none_locale_fields , locale_fields_input_fields,none_locale_fields_input_fields + end + def generate_input_field(field_type,field_name,localize = false,extra_field_name = nil, module_modal_template = nil,periodic = false) + module_template = @module_field.module_key + module_modal_template = @module_field.primary_modal_name if module_modal_template.nil? + input_field = "" + field_value_text = "@#{module_modal_template}.#{field_name}" + field_name_text = "\"#{field_name}\"" + field_name_text = "locale" if localize + org_field_name = field_name + if periodic + if localize + field_name = "periodic_time_field" + else + field_name_text = "\"periodic_time_field\"" + end + end + placeholder = "#{module_template}.#{field_name}" + placeholder = "#{module_template}.#{extra_field_name}.#{field_name}" if extra_field_name + if localize + field_value_text = "@#{module_modal_template}.#{field_name}_translations[locale]" + end + case field_type + when "year" + input_field = datetime_picker_text(module_modal_template,field_name_text, "yyyy")#"<%= select_year((#{field_value_text} ? #{field_value_text}.to_i : DateTime.now.year), {:start_year => DateTime.now.year + 5, :end_year => 1930}, {:name => '#{module_modal_template}[#{field_name}]',:class => 'span1'} ) %>" + when "year_month" + input_field = datetime_picker_text(module_modal_template,field_name_text, "yyyy/MM") + when "date" + input_field = datetime_picker_text(module_modal_template,field_name_text, "yyyy/MM/dd") + when "time" + input_field = datetime_picker_text(module_modal_template,field_name_text, "HH:mm",true) + when "date_time" + input_field = datetime_picker_text(module_modal_template,field_name_text) + when "text_editor" + input_field = "<%= f.text_area #{field_name_text}, class: \"input-block-level ckeditor\", placeholder: t(\"#{placeholder}\"), value: (#{field_value_text} rescue nil) %>" + when "member" + input_field = "<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: '#{module_modal_template}[#{field_name.singularize}_ids][]', email_members: @#{module_modal_template}.#{field_name.pluralize},index:'#{@index}',select_name:'#{field_name.pluralize}'} %>" + else #text_field + input_field = "<%= f.text_field #{field_name_text}, class: \"input-block-level\", placeholder: t(\"#{placeholder}\"), value: (#{field_value_text} rescue nil) %>" + end + if localize + input_field.prepend("<%= f.fields_for :#{field_name}_translations do |f| %>\n ").concat("\n<% end %>") + end + if periodic + input_fields = [] + input_fields[0] = input_field.gsub("periodic_time_field","#{org_field_name}_start") + input_fields[1] = input_field.gsub("periodic_time_field","#{org_field_name}_end") + input_field = ["start","end"].map.with_index{|f,i| + "<%=t(\"#{module_template}.extend_translate.#{f}_#{field_type}\")%>" + + input_fields[i] + }.join("") + end + input_field + end + def datetime_picker_text(module_modal_template,field_name_text,format = "yyyy/MM/dd hh:mm",timepicker = false) + extra_txt = "" + extra_txt = ":picker_type => \"time\"," if timepicker + "<%= f.datetime_picker #{field_name_text},:format => \"#{format}\",#{extra_txt} :no_label => true, :new_record => @#{module_modal_template}.new_record? %>" + end + def get_fields_text(field_values) + fields_text = field_values.map do |field_value| + next if field_value[:field_type] == "file" || field_value[:field_type] == "link" || field_value[:field_name].blank? + type = "String" + default = "\"\"" + field_name = field_value[:field_name] + case field_value[:field_type] + when "year" + type = "Integer" + default = "DateTime.now.year" + when "date" + type = "Date" + default = "Date.today" + when "time" + type = "String" + default = "\"\"" + when "date_time" + type = "DateTime" + default = "DateTime.now" + when "year_month" + type = "DateTime" + default = "DateTime.now" + when "member" + type = "Array" + default = "[]" + field_name = "#{field_name.singularize}_ids" + end + no_localize_types = ["date","time","date_time","year_month"] + field_text = "" + if field_value[:periodic_time] == "1" && no_localize_types.include?(field_value[:field_type]) + field_text = [] + field_text[0] = "field :#{field_name}_start, :type => #{type}, :default => #{default}" + field_text[0] += ", :localize => true" if field_value[:localize] == "1" && !no_localize_types.include?(field_value[:field_type]) + field_text[0] += ", as: :slug_title" if field_value[:slug_title] == "1" + field_text[1] = "field :#{field_name}_end, :type => #{type}, :default => #{default}" + field_text[1] += ", :localize => true" if field_value[:localize] == "1" && !no_localize_types.include?(field_value[:field_type]) + field_text[1] += ", as: :slug_title" if field_value[:slug_title] == "1" + else + field_text = "field :#{field_name}, :type => #{type}, :default => #{default}" + field_text += ", :localize => true" if field_value[:localize] == "1" && !no_localize_types.include?(field_value[:field_type]) + field_text += ", as: :slug_title" if field_value[:slug_title] == "1" + end + field_text + end + fields_text = fields_text.flatten + fields_text.select{|t| t.present?}.join("\n") + end + def replace_dirs(dirs,is_array = true) + dirs.each_with_index do |dir,i| + if is_array + replace_dir(dir,i) + else + replace_dir(dir) + end + end + end + def replace_dir(dir,current_index = nil) + dir = replace_file(dir,current_index) + return true if dir.blank? + if dir.class == Array + replace_dirs(dir) + return true + end + sub_dirs = Dir.glob("#{dir}/*/") + files = Dir.glob("#{dir}/*").select { |fn| File.file?(fn) } + replace_files(files,current_index) + if sub_dirs.present? + sub_dirs.each do |sub_dir| + replace_dir(sub_dir,current_index) + end + else + return true + end + end + def replace_files(files,current_index = nil) + files.each do |file| + replace_file(file,current_index) + end + end + def replace_file(file,current_index = nil) + isfile = File.file?(file) + path = File.dirname(file) + file_name = File.basename(file) + new_filename = replace_text_with_pattern(file_name,true) + if new_filename.blank? + FileUtils.rm_rf("#{path}/#{file_name}") + elsif file_name != new_filename + if new_filename.class == Array + new_filename.each do |f| + next if f.blank? + FileUtils.cp_r("#{path}/#{file_name}", "#{path}/#{f}") + end + FileUtils.rm_rf("#{path}/#{file_name}") + else + FileUtils.mv("#{path}/#{file_name}", "#{path}/#{new_filename}") + end + end + if new_filename.blank? + return "" + else + is_array = new_filename.class == Array + if isfile + files = Array(new_filename) + files.each_with_index do |sub_file,i| + next if File.extname(sub_file).match(/(png|jpg)/i) + file_text = File.read("#{path}/#{sub_file}") + if is_array + file_text = replace_text_with_pattern(file_text,false,i,nil,true) + elsif current_index + file_text = replace_text_with_pattern(file_text,false,current_index,nil,true) + else + file_text = replace_text_with_pattern(file_text) + end + File.open("#{path}/#{sub_file}",'w+'){|f| f.write(file_text)} + end + end + if is_array + return new_filename.map{|sub_file| "#{path}/#{sub_file}" if sub_file.present?}.select{|f| f.present?} + else + return "#{path}/#{new_filename}" + end + end + end + def replace_text_with_pattern(text,is_file=false,i = nil,sub_i = nil,inner = false) + new_text = text + @match_pattern.each do |k,v| + next if !include_key(new_text,k) + vv = v + vv = vv[i] if i && vv.class == Array + vv = vv[sub_i] if sub_i && vv.class == Array + if vv.class == String + if i && vv == "" && is_file + new_text = "" + else + new_text = gsub_text_by_key_value(new_text,k,vv) + end + elsif vv.class == Array + if is_file + if v.count == 0 + new_text = "" + break + else + new_text = vv.map{|sub_v| gsub_text_by_key_value(new_text,k,sub_v)} + break + end + end + new_text = new_text.gsub(/[ \t]*parse_again_start((?:(?!parse_again_start).)+)parse_again_end[ \t]*(\r\n|\n|$)/m) do |ff| + @parse_again_mode = true + parse_content = $1 #parse_again block contents + result = ff + match_count = parse_content.match(/^ *\* *\d+/m) + match_count = match_count ? match_count[0] : nil + has_exist_condition = parse_content.split("\n")[0].match(/if[ ]+\w+/).present? + exist_condition = parse_content.split("\n")[0].match(/if[ ]+#{::Regexp.escape(k)}(?=\.| |$)/) + if has_exist_condition && exist_condition.nil? #if this block is for other variables, then not proccessing + @parse_again_mode = false + result + else + extra_cond = nil + if exist_condition + exist_condition = exist_condition[0] + parse_content = parse_content[ parse_content.index(exist_condition) + exist_condition.length..-1] + extra_cond = parse_content.match(/^\.count *(\!|\<|\>|\=)(\=|) *\d+/) + if extra_cond + extra_cond = extra_cond[0] + exist_condition += extra_cond + parse_content = parse_content[extra_cond.length..-1] + exist_condition = eval("vv"+extra_cond) ? exist_condition : nil + elsif vv.count == 0 + exist_condition = nil + end + if exist_condition.nil? + match_count = nil + parse_content = "" + result = "" + end + elsif match_count + parse_content = parse_content[match_count.length..-1] + end + parse_content = parse_content.sub(/[ \t]+\z/m, '').sub(/\A(\r\n|\n)/, '') + if include_key(parse_content,k) + vv_count = vv.count + if match_count + vv_count = [vv_count, match_count.strip[1..-1].to_i].min + end + if inner + result = (0...vv_count).map {|ii| replace_text_with_pattern(parse_content,false,i,ii,true) }.join("") + else + result = (0...vv_count).map {|ii| replace_text_with_pattern(parse_content,false,ii) }.join("") + end + elsif match_count || exist_condition + count = 1 + if match_count + count = match_count.strip[1..-1].to_i + end + result = (0...count).map {|ii| parse_content }.join("") + end + @parse_again_mode = false + result + end + end + new_text = gsub_text_by_key_value(new_text,k,vv.to_s) + end + end + return new_text + end + def include_key(text,key) + return text.include?(key) || text.include?(key.camelize) + end + def gsub_text_by_key_value(text,k,v) + @blank_texts = [] + if !@parse_again_mode + text.gsub(/\n(\s+)[^\n]*(#{k}|#{k.camelize})/m) {|ff| @blank_texts << $1.gsub(/(\r\n|\n)/,'')} + end + i = 0 + text = text.gsub(k + "s"){|ff| v.pluralize.gsub("\n","\n#{@blank_texts[i]}")} + text = text.gsub(k ){|ff| v.gsub("\n","\n#{@blank_texts[i]}")} + text = text.gsub(k.camelize + "s"){|ff| v.camelize.pluralize.gsub("\n","\n#{@blank_texts[i]}")} + text = text.gsub(k.camelize){|ff| v.camelize.gsub("\n","\n#{@blank_texts[i]}")} + end + def get_all_gem_plugins + extention_files = ["downloaded_extensions.rb","built_in_extensions.rb"] + gem_plugins = extention_files.map{|f| (File.read(f).scan(/\n\s*gem\s*["'](.*)["']\s*,/).flatten rescue [])}.flatten + end + def check_plugin_exist + gem_plugins = get_all_gem_plugins + can_install = !gem_plugins.include?(params[:plugin_name]) + can_install = (ModuleField.find(params[:id]).module_key == params[:plugin_name] rescue false) if !can_install + render :json => {:can_install => can_install } + end + def add_plugin(extention_file,plugin_name) + txt = File.read(extention_file) rescue nil + if txt.nil? + File.open(extention_file,'w+'){|f| f.write("")} + txt = "" + end + txt_scan = txt.scan(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/) + if txt_scan.count != 1 + delete_plugin(extention_file,plugin_name) + txt = File.read(extention_file) rescue "" + txt = txt + "\ngem \"#{plugin_name}\", path: \"#{Rails.root}/tmp/#{plugin_name}\"\n" + File.open(extention_file,'w+') do |f| + f.write(txt) + end + end + end + def delete_plugin(extention_file,plugin_name) + txt = File.read(extention_file) rescue nil + return if txt.nil? + txt_change = txt.gsub(/^[\s#]*gem\s*["']#{plugin_name}["'].*(\n|$)/m,'') + if txt_change != txt + File.open(extention_file,'w+') do |f| + f.write(txt_change) + end + end + end + def check_modal_name + id = params[:id].to_s + other_module_fields = ModuleField.where(:id.ne=>id) + primary_modal_names = other_module_fields.pluck(:primary_modal_name) + related_modal_names = other_module_fields.pluck(:related_modal_name).flatten.uniq + other_modal_names = primary_modal_names + related_modal_names + module_field = ModuleField.where(:id=>id).first + all_modal_names = ModuleField.get_modal_names_cache + if module_field.present? + except_modals = Dir.glob("tmp/#{module_field.module_key}/app/models/*.rb").map{|f| + fn = File.basename(f) + fn.slice(0,fn.length - 3) + } + all_modal_names = all_modal_names - except_modals + end + all_modal_names = all_modal_names + other_modal_names + all_modal_names = all_modal_names.uniq + self_modal_names = params[:modal_names] + invalid_modal_names = self_modal_names.select{|n| all_modal_names.include?(n)} + if invalid_modal_names.count != 0 + render :json => {:success=>false,:invalid_modal_names=>invalid_modal_names} + else + render :json => {:success=>true} + end + end + private + def module_field_params + module_field_params = params.require(:module_field).permit! rescue {} + if module_field_params[:related_modal_name].nil? + module_field_params[:related_modal_name] = [] + end + if module_field_params[:primary_modal_fields] + module_field_params[:primary_modal_fields] = module_field_params[:primary_modal_fields].sort_by{|k, h| h[:order].to_i}.map{|v| v[1]} + else + module_field_params[:primary_modal_fields] = [] + end + if module_field_params[:related_modal_fields] + module_field_params[:related_modal_fields] = module_field_params[:related_modal_fields].values.map{|h| h.sort_by{|k, h| h[:order].to_i}.map{|v| v[1]}} + else + module_field_params[:related_modal_fields] = [] + end + return module_field_params + end + + + def set_module_field + ModuleField.get_modal_names_cache + 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 + @module_field = ModuleField.find_by(:uid => uid) rescue ModuleField.find(params[:id] || params[:module_generator_id]) + end + def bundle_install + Bundler.with_clean_env { system("cd #{Rails.root} && bundle install") } + %x(kill -s USR2 `cat tmp/pids/unicorn.pid`) + sleep 2 + end +end \ No newline at end of file diff --git a/app/helpers/admin/module_generators_helper.rb b/app/helpers/admin/module_generators_helper.rb new file mode 100644 index 0000000..e69f0a8 --- /dev/null +++ b/app/helpers/admin/module_generators_helper.rb @@ -0,0 +1,6 @@ +module Admin::ModuleGeneratorsHelper + include OrbitBackendHelper + def thead_field_for_mg(field) + return I18n.t("module_generator.#{field}") + end +end \ No newline at end of file diff --git a/app/models/module_field.rb b/app/models/module_field.rb new file mode 100644 index 0000000..5691139 --- /dev/null +++ b/app/models/module_field.rb @@ -0,0 +1,158 @@ +class ModuleField + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include MemberHelper + field :one_line_title_format, :type => String, :default => "" + field :enable_one_line_title, :type => Boolean, :default => false + field :title, :type => String, :default => "",:localize => true + field :module_key, :type => String, :default => "" + field :primary_modal_name, :type => String, :default => "" + field :related_modal_name, :type => Array, :default => [] + field :primary_modal_fields, :type => Array, :default => [] + field :related_modal_fields, :type => Array, :default => [] #ex: [[],[]] + field :backend_fields, :type => Hash, :default => {} + field :frontend_fields, :type => Hash, :default => {} + field :log_text, :type => String, :default => "" + field :fields_order, :type => Hash, :default => {} + field :copy_id + field :finished, :type => Boolean, :default => false + before_save :change_extensions,:check_modal_name,:auto_add_display_fields + after_destroy do + delete_plugin("downloaded_extensions.rb",self.module_key) + restart_server + end + before_create do + if self.copy_id + copy_item = self.class.find(copy_id) rescue nil + if !copy_item.nil? + self.backend_fields = copy_item.backend_fields + self.frontend_fields = copy_item.frontend_fields + self.fields_order = copy_item.fields_order + end + end + end + def get_all_gem_plugins + extention_files = ["downloaded_extensions.rb","built_in_extensions.rb"] + gem_plugins = extention_files.map{|f| (File.read(f).scan(/\n\s*gem\s*["'](.*)["']\s*,/).flatten rescue [])}.flatten + end + def check_plugin_exist + gem_plugins = get_all_gem_plugins + can_install = !gem_plugins.include?(self.module_key) + can_install = (self.class.where(:module_key=>self.module_key,:id.ne=>self.id).count == 0 rescue false) if !can_install + return can_install + end + def change_extensions + if !check_plugin_exist + return false + else + extention_file = "downloaded_extensions.rb" + if self.module_key_changed? + if self.module_key_was.present? + delete_plugin(extention_file,module_key_was) + end + end + return true + end + end + def delete_plugin(extention_file,plugin_name) + txt = File.read(extention_file) rescue nil + return if txt.nil? + txt_change = txt.gsub(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/,'') + if txt_change != txt + File.open(extention_file,'w+') do |f| + f.write(txt_change) + end + end + end + def check_modal_name + primary_modal_names = self.class.where(:id.ne=>self.id).pluck(:primary_modal_name) + related_modal_names = self.class.where(:id.ne=>self.id).pluck(:related_modal_name).flatten.uniq + other_modal_names = primary_modal_names + related_modal_names + all_modal_names = self.class.get_modal_names_cache + except_modals = Dir.glob("tmp/#{self.module_key}/app/models/*.rb").map{|f| + fn = File.basename(f) + fn.slice(0,fn.length - 3) + } + all_modal_names = all_modal_names - except_modals + all_modal_names = all_modal_names + other_modal_names + all_modal_names = all_modal_names.uniq + self_modal_names = ([self.primary_modal_name]+self.related_modal_name).flatten + if self_modal_names.select{|n| all_modal_names.include?(n)}.count != 0 + return false + end + end + def get_sorted_fields(root_name, page_name, tds=nil) + if self.fields_order.present? + fields_order = (0...tds.count).to_a + if (self.fields_order["#{root_name}_#{page_name}"].present? rescue false) + self.fields_order["#{root_name}_#{page_name}"].to_a.each_with_index do |order,i| + fields_order[i] = order.to_i + end + end + if tds.respond_to?(:values) + tds = tds.values + end + tds = tds.sort_by.with_index{|td,i| fields_order[i]} + else + field_values = self[root_name][page_name] rescue [] + if field_values.present? + if tds.respond_to?(:values) + new_tds = {} + field_values.each do |field_value| + new_tds[field_value] = tds[field_value] if tds[field_value] + end + tds.each do |k,v| + if new_tds[k].nil? + new_tds[k] = v + end + end + tds = new_tds.values + else + new_tds = field_values.clone + tds.each do |v| + new_tds << v unless new_tds.include?(v) + end + tds = new_tds + end + else + if tds.respond_to?(:values) + tds = tds.values + end + end + end + tds + end + def auto_add_display_fields + change_primary_fields = self.primary_modal_fields.map{|f| f["field_name"]} - self.primary_modal_fields_was.to_a.map{|f| f["field_name"]} + change_related_fields = [] + self.related_modal_fields.each_with_index do |field_values,i| + old_field_values = self.related_modal_fields_was[i].to_a rescue [] + related_modal_name = self.related_modal_name[i].to_s + change_related_fields = change_related_fields + (field_values.to_a.map{|f| f["field_name"]} - old_field_values.map{|f| f["field_name"]}).select{|f| f.present?}.map{|f| "#{related_modal_name}.#{f}"} + end + change_fields = change_primary_fields + change_related_fields + change_fields = change_fields.select{|f| f.present?} + if change_fields.count > 0 + ["index","profile"].each do |f| + self.backend_fields[f] = self.backend_fields[f].to_a + change_fields + end + ["index","show","member_show"].each do |f| + self.frontend_fields[f] = self.frontend_fields[f].to_a + change_fields + end + end + end + def self.get_modal_names + name_routes = Rails.application.routes.named_routes.map{|k,v| k}.select{|s| s.to_s[0..4] == "admin"}.map{|s| s.to_s.split('admin_').last} + modal_names = name_routes.map{|n| n.camelize}.select{|n| (n.constantize rescue nil)} + modal_names = modal_names.map{|n| n.constantize}.select{|n| n.class == Class }.uniq + @@modal_names = modal_names.map{|n| n.to_s.underscore} + end + def self.get_modal_names_cache + @@modal_names ||= get_modal_names + end + def restart_server + %x(kill -s USR2 `cat tmp/pids/unicorn.pid`) + sleep 2 + end +end diff --git a/app/views/admin/module_generators/_form.html.erb b/app/views/admin/module_generators/_form.html.erb new file mode 100644 index 0000000..45f7132 --- /dev/null +++ b/app/views/admin/module_generators/_form.html.erb @@ -0,0 +1,295 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> + <%= stylesheet_link_tag "lib/togglebox"%> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= 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 :title_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("module_generator.module_name"), value: (@module_field.title_translations[locale] rescue nil) %> + <% end %> +
    +
    + +
    + <% end %> +
    + + + + +
    + + +
    +
    + +
    + <%= f.text_field :module_key, placeholder: thead_field_for_mg("module_key") %> +
    +
    +
    + +
    + <%= f.text_field :primary_modal_name, placeholder: thead_field_for_mg("primary_modal_name"), class: "primary_modal_name" %> +
    +
    +
    + +
    + <% f.object.related_modal_name.each_with_index do |related_modal_name,i| %> +
    + <%= text_field_tag "#{f.object_name}[related_modal_name][]", related_modal_name,placeholder: thead_field_for_mg("related_modal_name"), class: "related_modal_name", title: thead_field_for_mg("related_modal_name") %> + +
    + <% end %> + +
    +
    +
    + + + +
    + <% field_types = ["text_field","text_editor","file","link","year","year_month","date","time","date_time","member"].map{|field| [thead_field_for_mg(field),field]} + field_types1 = field_types.select{|a| a[1] != "file" && a[1] != "member"} + %> +
    +
    +

    <%=thead_field_for_mg("primary_modal_name")%> : <%= f.object.primary_modal_name%>

    + <% if f.object.primary_modal_fields.present? %> + <%= render :partial => 'render_table',locals: {:f => f,:root_name => "primary_modal_fields",:field_values => f.object.primary_modal_fields,:field_types => field_types } %> + <% else %> + <%= render :partial => 'render_table',locals: {:f => f,:root_name => "primary_modal_fields",:field_values => [nil,nil],:field_types => field_types,:@include_blank => true} %> + <% end %> + +
    + +
    +
    + +
    + <%= 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'), request.referer, :class=>"btn" %> +
    + + \ No newline at end of file diff --git a/app/views/admin/module_generators/_form_file.html.erb b/app/views/admin/module_generators/_form_file.html.erb new file mode 100644 index 0000000..8628623 --- /dev/null +++ b/app/views/admin/module_generators/_form_file.html.erb @@ -0,0 +1,55 @@ +<% if form_file.new_record? %> +
    +<% else %> +
    + <% if form_file.file.blank? %> + <%= t(:no_file) %> + <% else %> + <%= link_to content_tag(:i) + form_file.file_identifier, form_file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %> + <% end %> +<% end %> +
    + + + + <% @site_in_use_locales.each_with_index do |locale, i| %> + <%= locale %>"> + <%= f.fields_for :title_translations do |f| %> + <%= f.text_field locale, :class => "input-medium", placeholder: t(:alternative), :value => (form_file.title_translations[locale] rescue nil) %> + <% end %> + + <% end %> + + + + <% @site_in_use_locales.each_with_index do |locale, i| %> + <%= locale %>"> + <%= f.fields_for :description_translations do |f| %> + <%= f.text_field locale, :class => "input-medium", placeholder: t(:description), :value => (form_file.description_translations[locale] rescue nil) %> + <% end %> + + <% end %> + + + <% if form_file.new_record? %> + + + + <% else %> + + <%= f.hidden_field :id %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/admin/module_generators/_module_fields.html.erb b/app/views/admin/module_generators/_module_fields.html.erb new file mode 100644 index 0000000..00692ee --- /dev/null +++ b/app/views/admin/module_generators/_module_fields.html.erb @@ -0,0 +1,20 @@ +<% @module_fields.each do |module_field| %> + + + <% title = module_field.title %> + <% if module_field.finished %> + <%= title %> + <% else %> + <%= title %> + <% end %> + + <%= module_field.module_key %> + <%= link_to t(:edit) ,edit_admin_module_generator_path(module_field.id),:class=> "btn btn-primary" %> + <%= link_to thead_field_for_mg('fields_display_setting') ,admin_module_generator_fields_setting_path(module_field.id),:class=> "btn btn-primary" %> + <%= link_to thead_field_for_mg(:copy) ,admin_module_generator_copy_path(module_field.id),:class=> "btn btn-primary" %> + + <%= link_to thead_field_for_mg(:download) ,admin_module_generator_download_path(module_field.id),:class=> "btn btn-primary" %> + <%= t(:delete_) %> + + +<% end %> \ No newline at end of file diff --git a/app/views/admin/module_generators/_render_fields_check_table.html.erb b/app/views/admin/module_generators/_render_fields_check_table.html.erb new file mode 100644 index 0000000..2b679f4 --- /dev/null +++ b/app/views/admin/module_generators/_render_fields_check_table.html.erb @@ -0,0 +1,49 @@ +
    "> +<% object = f.object +%> +
    <%=thead_field_for_mg(page_name)%>
    + + +"> + + + <% tds = {} %> + <% ii = -1 %> + <% tmp_fields_order = {} %> + <% object.primary_modal_fields.each do |field_value| %> + <% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %> + <% field_name = field_value[:field_name] %> + <% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", field_name , (object.send(root_name)[page_name].include?(field_name) rescue false),:id=>nil,:class=>"#{page_name}_fields") %> + <% ii+=1 %> + <% tmp_fields_order = "" %> + <% tds[field_name] = "" %> + <% end %> + <% if !defined?(access_field_types) %> + <% f.object.related_modal_name.each_with_index do |related_modal_name,i| %> + <% field_values = f.object.related_modal_fields[i].to_a %> + <% field_values.each do |field_value| %> + <% field_name = related_modal_name+'.'+field_value[:field_name] %> + <% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", field_name , (object.send(root_name)[page_name].include?(field_name) rescue false),:id=>nil,:class=>"#{page_name}_fields") %> + <% ii+=1 %> + <% tmp_fields_order = "" %> + <% tds[field_name] = "" %> + <% end %> + <% end %> + <% author_name_translation = @module_field.author_name_translations[locale] rescue "" + author_name_translation = I18n.t("modules.author") if author_name_translation.blank? %> + <% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", "member_profile" , (object.send(root_name)[page_name].include?("member_profile") rescue false),:id=>nil) %> + <% ii+=1 %> + <% tmp_fields_order = "" %> + <% tds["member_profile"] = "" %> + <% end %> + <% + tds = object.get_sorted_fields(root_name, page_name, tds) + %> + <% tds.each_with_index do |td, i| %> + <% td = td.sub('${sort_order}', i.to_s) %> + <%= td.html_safe %> + <% end %> + + +
    #{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}
    #{content}#{tmp_fields_order}
    #{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}
    #{content}#{tmp_fields_order}
    #{author_name_translation}
    #{content}#{tmp_fields_order}
    +
    \ No newline at end of file diff --git a/app/views/admin/module_generators/_render_table.html.erb b/app/views/admin/module_generators/_render_table.html.erb new file mode 100644 index 0000000..dd5f962 --- /dev/null +++ b/app/views/admin/module_generators/_render_table.html.erb @@ -0,0 +1,79 @@ + + + + + + + + + + + + + <%= f.fields_for root_name do |f| %> + <% field_values.each_with_index do |field_value,i| %> + <% i = "new_field_index" if field_value.nil? && !@include_blank %> + + + + + + + + + + + <% end %> + <% end %> + +
    <%= t(:remove) %><%= thead_field_for_mg("field_name") %><%= thead_field_for_mg("translation_name") %><%= thead_field_for_mg("field_type") %><%= thead_field_for_mg("localize") %><%= thead_field_for_mg("slug_title") %><%= thead_field_for_mg("periodic_time") %>
    + + " value="<%= i %>"> + X<%= text_field_tag "#{f.object_name}[#{i}][field_name]",(field_value["field_name"] rescue nil) %> + <% @site_in_use_locales.each_with_index do |locale, ii| %> + "> + <%= f.fields_for "#{i}][translation_name" do |f| %> + <%= text_field_tag "#{f.object_name}[#{locale}]", (field_value["translation_name"][locale] rescue nil) , class: "input-block-level" %> + <% end %> + + <% end %> + <%= select_tag "#{f.object_name}[#{i}][field_type]",options_for_select(field_types,(field_value["field_type"] rescue nil)) %> + <%= hidden_field_tag "#{f.object_name}[#{i}][localize]", "0",:id=>nil %> + <%= check_box_tag "#{f.object_name}[#{i}][localize]", "1" , (field_value["localize"] == "1" rescue false),:id=>nil %> + + <%= hidden_field_tag "#{f.object_name}[#{i}][slug_title]", "0",:id=>nil %> + <%= check_box_tag "#{f.object_name}[#{i}][slug_title]", "1" , (field_value["slug_title"] == "1" rescue false),:id=>nil,:class=>"slug_title" %> + + <%= hidden_field_tag "#{f.object_name}[#{i}][periodic_time]", "0",:id=>nil %> + <%= check_box_tag "#{f.object_name}[#{i}][periodic_time]", "1" , (field_value["periodic_time"] == "1" rescue false),:id=>nil,:class=>"periodic_time" %> +
    + + \ No newline at end of file diff --git a/app/views/admin/module_generators/copy.html.erb b/app/views/admin/module_generators/copy.html.erb new file mode 100644 index 0000000..f93921b --- /dev/null +++ b/app/views/admin/module_generators/copy.html.erb @@ -0,0 +1,6 @@ +<%= form_for @module_field, url: admin_module_generators_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= f.hidden_field :copy_id, :value => params[:module_field_id] %> + <%= render partial: 'form', locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/module_generators/edit.html.erb b/app/views/admin/module_generators/edit.html.erb new file mode 100644 index 0000000..72e1afc --- /dev/null +++ b/app/views/admin/module_generators/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @module_field, url: admin_module_generator_path(@module_field), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= render partial: 'form', locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/module_generators/fields_setting.html.erb b/app/views/admin/module_generators/fields_setting.html.erb new file mode 100644 index 0000000..bd9d91e --- /dev/null +++ b/app/views/admin/module_generators/fields_setting.html.erb @@ -0,0 +1,120 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> +

    <%= @module_field.title %>

    +<%= form_for @module_field, url: admin_module_generator_update_fields_setting_path(@module_field), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + + +
    +

    <%= thead_field_for_mg('backend_page') %>

    +
    + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'index'} %> + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'profile'} %> + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'analysis',:access_field_types=>["date","date_time","year","year_month","time"]} %> + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'sort_asc',:access_field_types=>["date","date_time","year","year_month","time"]} %> + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'sort_desc',:access_field_types=>["date","date_time","year","year_month","time"]} %> +
    +

    <%= thead_field_for_mg('frontend_page') %>

    +
    + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'frontend_fields',:page_name=>'index'} %> + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'frontend_fields',:page_name=>'show'} %> + <%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'frontend_fields',:page_name=>'member_show'} %> +
    +
    + +
    + <%= 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'), request.referer, :class=>"btn" %> +
    +
    +<% end %> + + \ No newline at end of file diff --git a/app/views/admin/module_generators/index.html.erb b/app/views/admin/module_generators/index.html.erb new file mode 100644 index 0000000..ac5936c --- /dev/null +++ b/app/views/admin/module_generators/index.html.erb @@ -0,0 +1,52 @@ + + + + + + + + + + <%= render 'module_fields' %> + +
    <%= thead_field_for_mg("module_name") %><%= thead_field_for_mg("module_key") %><%= thead_field_for_mg("action") %>
    +
    " style="display: none;"> +
    +
    + +
    <%=thead_field_for_mg("generating_module")%>
    +
    +
    +
    +
    +
    + <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_module_generator_path, :class => 'btn btn-primary' %> +
    + +
    + \ No newline at end of file diff --git a/app/views/admin/module_generators/new.html.erb b/app/views/admin/module_generators/new.html.erb new file mode 100644 index 0000000..cc388c8 --- /dev/null +++ b/app/views/admin/module_generators/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @module_field, url: admin_module_generators_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= render partial: 'form', locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/bin/rails b/bin/rails new file mode 100644 index 0000000..38c2a68 --- /dev/null +++ b/bin/rails @@ -0,0 +1,12 @@ +#!/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_course/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 'rails/all' +require 'rails/engine/commands' diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..acc8ab2 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,54 @@ +en: + module_name: + module_generator: Module Generator + restful_actions: + fields_setting: Fields Setting + module_generator: + enable: Enable + one_line_title_format: "Paper Format Title" + download: Download + author_translation_name: Author translation name + module_generate: Module Generate + module_name: Module Name + module_key: Module Key + action: Action + primary_modal_name: Primary Modal Name + related_modal_name: Related Modal Name + field_name: Field Name + translation_name: translation_name + remove_text: Do you really want to delete this field? + field_type: Field Type + text_field: Text Field + text_editor: Text Editor + file: File + select: Select field + year: Year + year_month: Year Month + date: Date + time: Time + date_time: Date time + localize: Localize + add_field: Add field + fields_display_setting: Fields display setting + backend_page: Backend Page + frontend_page: Frontend Page + profile: Personal Profile + index: Index Page + show: Show Page + member_show: Member show page + slug_title: Slug title + please_choose_one_slug_title: Please choose one Slug title! + slug_title_can_only_choose_one: Slug title can only choose one! + please_choose_one_analysis_field: Please choose one analysis field! + analysis_field_can_only_choose_one: Analysis field can only choose one! + generate_module: Generate Module + member: Member + link: Link + analysis: Analysis Page + goto: "Go to " + generating_module: Generating Module + please_change_module_key: "Please change module name(This name already exist)." + copy: Copy + periodic_time: Periodic time + sort_asc: "Sort(Ascending)" + sort_desc: "Sort(Descending)" \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml new file mode 100644 index 0000000..a5dd70b --- /dev/null +++ b/config/locales/zh_tw.yml @@ -0,0 +1,54 @@ +zh_tw: + module_name: + module_generator: 模組生成器 + restful_actions: + fields_setting: 欄位設定 + module_generator: + enable: 啟用 + one_line_title_format: "論文格式標題" + download: 下載 + author_translation_name: 著作人翻譯名稱 + module_generate: 模組生成 + module_name: 模組名稱 + module_key: 模組Key + action: 動作 + primary_modal_name: 主要modal名稱(均英文小寫,可加底線) + related_modal_name: 關聯modal名稱(用來存論文類型、期刊等級...等) + field_name: 欄位名稱 + translation_name: 翻譯名稱 + remove_text: 您確定要刪除這個欄位嗎 + field_type: 欄位類型 + text_field: 文字欄位 + text_editor: 文字編輯器 + file: 檔案 + select: 選項欄位 + year: 年份 + year_month: 年月 + date: 日期 + time: 時間 + date_time: 日期與時間 + localize: 隨語言變化 + add_field: 新增欄位 + fields_display_setting: 欄位顯示設定 + backend_page: 後台頁面 + frontend_page: 前台頁面 + profile: 個人資料 + index: Index 頁面 + show: Show 頁面 + member_show: 會員show頁面 + slug_title: "頭銜標題(show頁面會顯示於網址)" + please_choose_one_slug_title: 請選擇一個頭銜標題! + slug_title_can_only_choose_one: 頭銜標題只能選擇一個! + please_choose_one_analysis_field: 請至少選擇一個分析欄位! + analysis_field_can_only_choose_one: 分析欄位只能選擇一個! + generate_module: 生成模組 + member: 會員 + link: 連結 + analysis: 分析頁面 + goto: "前往 " + generating_module: 正在生成模組中... + please_change_module_key: "請更改模組名稱(此名稱已存在)" + copy: 複製 + periodic_time: 週期性時間 + sort_asc: "排序(升序)" + sort_desc: "排序(降序)" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..73a63bc --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,19 @@ +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 + resources :module_generators do + get 'fields_setting' , to: 'module_generators#fields_setting' + post 'update_fields_setting' , to: 'module_generators#update_fields_setting' + patch 'update_fields_setting' , to: 'module_generators#update_fields_setting' + get 'generate_module' , to: 'module_generators#generate_module' + get 'copy' , to: 'module_generators#copy' + get 'download' , to: 'module_generators#download' + collection do + post 'check_plugin_exist' ,to: 'module_generators#check_plugin_exist' + post 'check_modal_name' ,to: 'module_generators#check_modal_name' + end + end + end + end +end diff --git a/lib/module_generator.rb b/lib/module_generator.rb new file mode 100644 index 0000000..734c535 --- /dev/null +++ b/lib/module_generator.rb @@ -0,0 +1,4 @@ +require "module_generator/engine" + +module ModuleGenerator +end diff --git a/lib/module_generator/engine.rb b/lib/module_generator/engine.rb new file mode 100644 index 0000000..1e13935 --- /dev/null +++ b/lib/module_generator/engine.rb @@ -0,0 +1,58 @@ +require "yaml" +module ModuleGenerator + class Engine < ::Rails::Engine + initializer "module_generator" do + OrbitApp.registration "ModuleGenerator", :type => "ModuleApp" do + base_url File.expand_path File.dirname(__FILE__) + categorizable + authorizable + side_bar do + head_label_i18n 'module_name.module_generator', icon_class: "icons-graduation" + available_for "users" + active_for_controllers (['admin/module_fields']) + head_link_path "admin_module_generators_path" + context_link 'module_generator.module_generate', + :link_path=>"admin_module_generators_path" , + :priority=>1, + :active_for_action=>{'admin/module_fields'=>'index'}, + :available_for => 'users' + end + end + end + end + def self.git_reset(commit,type) + ubuntu_version = `lsb_release -a | grep Release`.scan(/\d.*\d/)[0] + git = 'git' + if Float(ubuntu_version) <= 14.04 && Float(%x[git --version].scan(/\d.\d/)[0]) < 1.9 + if %x[uname -m].scan('64').count !=0 + cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_amd64.deb && dpkg -x git_1.9.1-1_amd64.deb ./git_1.9.1") + else + cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_i386.deb && dpkg -x git_1.9.1-1_i386.deb ./git_1.9.1") + end + git = 'git_1.9.1/usr/bin/git' + end + %x(cd #{ENV['PWD']} && #{git} fetch origin) + @branch = %x(cd #{ENV['PWD']} && #{git} rev-parse --abbrev-ref HEAD).gsub("\n","") + new_commit_id = %x(cd #{ENV['PWD']} && #{git} log #{@branch}..origin/#{@branch} --pretty=format:"%H") + new_updates = %x(cd #{ENV['PWD']} && #{git} log #{@branch}..origin/#{@branch} --pretty=format:"%ad' , '%s" --date=short).split("\n").map{|log| log.gsub("'","")} + if new_commit_id.present? + git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log' && v != 'dump' && v != 'tmp'}.collect do |v| + "#{git} add -f --all --ignore-errors '#{v}'" + end.join(' ; ') + git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log' && v != 'dump' && v != 'tmp'} + ['app/templates','config/mongoid.yml','config/extra_lang.txt']).collect do |v| + "#{git} add -f --all --ignore-errors '#{v}'" + end.join(' ; ') + git_restore = "#{git} checkout ." + time_now = Time.now.strftime('%Y_%m_%d_%H_%M') + if %x[#{git} config user.name].empty? + %x[#{git} config --global user.name "rulingcom"] + end + if %x[#{git} config user.email].empty? + %x[#{git} config --global user.email "orbit@rulingcom.com"] + end + puts "Updating orbit-kernel..." + system("cd #{ENV['PWD']} && bash -l -c \"#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} --allow-empty && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} clean -f -- app/models ; #{git} commit -m complete_#{type}_#{time_now} --allow-empty\" > /dev/null") + puts "Updated! " + new_updates.first.to_s + end + end +end \ No newline at end of file diff --git a/lib/module_generator/version.rb b/lib/module_generator/version.rb new file mode 100644 index 0000000..de8660c --- /dev/null +++ b/lib/module_generator/version.rb @@ -0,0 +1,3 @@ +module ModuleGenerator + VERSION = "0.0.1" +end diff --git a/lib/tasks/module_generator_tasks.rake b/lib/tasks/module_generator_tasks.rake new file mode 100644 index 0000000..3575392 --- /dev/null +++ b/lib/tasks/module_generator_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :module_generator do +# # Task goes here +# end diff --git a/module_generator.gemspec b/module_generator.gemspec new file mode 100644 index 0000000..7c72451 --- /dev/null +++ b/module_generator.gemspec @@ -0,0 +1,21 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +# require "rails" +require "module_generator/version" +# require "module_generator/engine" +# ModuleGenerator.git_reset('origin','update') +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "module_generator" + s.version = ModuleGenerator::VERSION + s.authors = ["Bohung"] + s.email = ["bohung@rulingcom.com"] + s.homepage = "http://www.rulingcom.com" + s.summary = "A Generator for Personal plugin." + s.description = "A Generator for Personal plugin." + s.license = "MIT" + + s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] + s.test_files = Dir["test/**/*"] +end \ No newline at end of file diff --git a/template_generator/.gitignore b/template_generator/.gitignore new file mode 100644 index 0000000..de5d954 --- /dev/null +++ b/template_generator/.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/template_generator/Gemfile b/template_generator/Gemfile new file mode 100644 index 0000000..d97db1e --- /dev/null +++ b/template_generator/Gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +# Declare your gem's dependencies in personal_course.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/template_generator/MIT-LICENSE b/template_generator/MIT-LICENSE new file mode 100644 index 0000000..f017636 --- /dev/null +++ b/template_generator/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2022 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/template_generator/README.rdoc b/template_generator/README.rdoc new file mode 100644 index 0000000..975440f --- /dev/null +++ b/template_generator/README.rdoc @@ -0,0 +1,3 @@ += PersonalPluginTemplate + +This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/template_generator/Rakefile b/template_generator/Rakefile new file mode 100644 index 0000000..182be0d --- /dev/null +++ b/template_generator/Rakefile @@ -0,0 +1,34 @@ +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 = 'PersonalPluginTemplate' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + + + +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/template_generator/app/assets/images/module_template/.keep b/template_generator/app/assets/images/module_template/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/app/assets/javascripts/module_template/application.js b/template_generator/app/assets/javascripts/module_template/application.js new file mode 100644 index 0000000..a1873dd --- /dev/null +++ b/template_generator/app/assets/javascripts/module_template/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/template_generator/app/assets/stylesheets/module_template/application.css b/template_generator/app/assets/stylesheets/module_template/application.css new file mode 100644 index 0000000..a443db3 --- /dev/null +++ b/template_generator/app/assets/stylesheets/module_template/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/template_generator/app/controllers/admin/module_modal_template_relateds_controller.rb b/template_generator/app/controllers/admin/module_modal_template_relateds_controller.rb new file mode 100644 index 0000000..1cd36cc --- /dev/null +++ b/template_generator/app/controllers/admin/module_modal_template_relateds_controller.rb @@ -0,0 +1,43 @@ +class Admin::ModuleModalTemplateRelatedsController < OrbitMemberController + + def index + end + + def new + @module_modal_template_related = ModuleModalTemplateRelated.new + @url = admin_module_modal_template_relateds_path + end + + def edit + @module_modal_template_related = ModuleModalTemplateRelated.find(params[:id]) + @url = admin_module_modal_template_related_path(@module_modal_template_related) + end + + def create + module_modal_template_related = ModuleModalTemplateRelated.create(module_modal_template_related_params) + @module_modal_template_relateds = ModuleModalTemplateRelated.all + end + + def update + module_modal_template_related = ModuleModalTemplateRelated.find(params[:id]) rescue nil + if !module_modal_template_related.nil? + module_modal_template_related.update_attributes(module_modal_template_related_params) + end + @module_modal_template_relateds = ModuleModalTemplateRelated.all + end + + def destroy + module_modal_template_related = ModuleModalTemplateRelated.find(params[:id]) rescue nil + if !module_modal_template_related.nil? + module_modal_template_related.destroy + end + @module_modal_template_relateds = ModuleModalTemplateRelated.all + end + + private + + def module_modal_template_related_params + params.require(:module_modal_template_related).permit! + end + +end \ No newline at end of file diff --git a/template_generator/app/controllers/admin/module_modal_templates_controller.rb b/template_generator/app/controllers/admin/module_modal_templates_controller.rb new file mode 100644 index 0000000..c10c4cb --- /dev/null +++ b/template_generator/app/controllers/admin/module_modal_templates_controller.rb @@ -0,0 +1,152 @@ +class Admin::ModuleModalTemplatesController < OrbitMemberController + include Admin::ModuleModalTemplatesHelper + layout "member_plugin" + before_action :set_module_modal_template, 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 + if params[:sort].present? + @module_modal_templates = ModuleModalTemplate.order_by(sort).page(params[:page]).per(10) + else + @module_modal_templates = ModuleModalTemplate.sort_hash.page(params[:page]).per(10) + end + end + def sort + case params[:sort] + when "status" + @sort = [[:is_top, params[:order]], + [:is_hot, params[:order]], + [:is_hidden,params[:order]], + [:id,params[:order]]] + when "category" + @sort = {:category_id=>params[:order]}.merge({:id=>params[:order]}) + else + if params[:sort].present? + s = params[:sort].to_s + @sort = {s=>params[:order]}.merge({:id=>params[:order]}) + else + @sort = {} + end + end + @sort + end + def new + @member = MemberProfile.find_by(:uid=>params[:uid].to_s) rescue nil + @module_modal_template = ModuleModalTemplate.new + end + + def create + module_modal_template = ModuleModalTemplate.create(module_modal_template_params) + redirect_to params[:referer_url] + end + + def show + end + def analysis + end + def analysis_report + role = params[:role_id] + analysis_field_name_start = params[:analysis_field_name_start] + analysis_field_name_end = params[:analysis_field_name_end] + graph_by = params[:graph_by] + + @data = get_chart_data(analysis_field_name_start,analysis_field_name_end,role,params[:graph_by],params[:time_zone]) + + render :layout => false + end + + def download_excel + analysis_field_name_start = params[:analysis_field_name_start] + analysis_field_name_end = params[:analysis_field_name_end] + @data = get_data_for_excel(analysis_field_name_start,analysis_field_name_end,params[:time_zone]) + @protocol = (request.referer.blank? ? "http" : URI(request.referer).scheme) + @host_url = "#{@protocol}://#{request.host_with_port}" + respond_to do |format| + format.xlsx { + response.headers['Content-Disposition'] = 'attachment; filename="module_modal_templates.xlsx"' + } + end + end + + def edit + end + + def destroy + @module_modal_template.destroy + redirect_to admin_module_modal_templates_path(:page => params[:page]) + end + + def update + @module_modal_template.update_attributes(module_modal_template_params) + @module_modal_template.save + redirect_to params[:referer_url] + end + + + def setting + end + + def frontend_setting + @member = MemberProfile.find_by(:uid=>params[:uid].to_s) rescue nil + @intro = ModuleModalTemplateIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? ModuleModalTemplateIntro.new({:member_profile_id=>@member.id}) : @intro + end + + def update_frontend_setting + @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil + @intro = ModuleModalTemplateIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? ModuleModalTemplateIntro.new({:member_profile_id=>@member.id}) : @intro + @intro.update_attributes(intro_params) + @intro.save + redirect_to URI.encode('/admin/members/'+@member.to_param+'/ModuleModalTemplate') + end + + def toggle_hide + if params[:ids] + @projects = ModuleModalTemplate.any_in(_id: params[:ids]) + + @projects.each do |project| + project.is_hidden = params[:disable] + project.save + end + end + + render json: {"success"=>true} + end + + private + + def module_modal_template_params + params.require(:module_modal_template).permit! + end + + def intro_params + params.require(:module_modal_template_intro).permit! rescue nil + end + + def get_settings + parse_again_start + @module_modal_template_relateds = ModuleModalTemplateRelated.all + parse_again_end + end + + def set_plugin + @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'ModuleModalTemplate'}.first + end + + def set_module_modal_template + 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 + @module_modal_template = ModuleModalTemplate.find_by(:uid => uid) rescue ModuleModalTemplate.find(params[:id]) + end +end \ No newline at end of file diff --git a/template_generator/app/controllers/module_templates_controller.rb b/template_generator/app/controllers/module_templates_controller.rb new file mode 100644 index 0000000..c1e891a --- /dev/null +++ b/template_generator/app/controllers/module_templates_controller.rb @@ -0,0 +1,172 @@ +class ModuleTemplatesController < ApplicationController + include Admin::ModuleModalTemplatesHelper + def index + params = OrbitHelper.params + module_modal_templates = ModuleModalTemplate.sort_for_frontend + page = OrbitHelper.page rescue Page.where(page_id: params[:page_id]).first + parse_again_start * 1 if is_one_line_title.count > 0 + title_is_paper_format = true + if page.custom_string_field == 'table' + title_is_paper_format = false + fields_to_show = page.custom_array_field rescue [] + if fields_to_show.blank? + fields_to_show = col_name_to_show_in_index_page + end + else + fields_to_show = col_name_to_show_short + end + parse_again_end + parse_again_start * 1 if is_one_line_title.count == 0 + title_is_paper_format = false + fields_to_show = page.custom_array_field rescue [] + if fields_to_show.blank? + fields_to_show = col_name_to_show_in_index_page + end + parse_again_end + if params[:keywords].present? + module_modal_templates = filter_keywords(module_modal_templates,params[:selectbox],params[:keywords]) + end + module_modal_templates = module_modal_templates.page(params[:page_no]).per(OrbitHelper.page_data_count) + module_modal_templates_list = module_modal_templates.collect do |module_modal_template| + {'jps' => fields_to_show.map{|field| {"value"=> get_display_field(module_modal_template,field, title_is_paper_format)}}} + end + + extras = extra_translate_title + choice_show = [] + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == 'slug_title_text' + headers << { + 'head-title' => t("module_template.#{fs}"), + 'col' => col + } + choice_show << t("module_template.#{fs}") + end + choice_value = fields_to_show + choice_value.unshift('default') + choice_select = choice_value.map { |iter| iter == params[:selectbox] ? 'selected' : '' } + choice_select = choice_select.map { |value| { 'choice_select' => value } } + choice_value = choice_value.map { |value| { 'choice_value' => value } } + choice_default = t('module_template.extend_translate.select_class') + choice_show.unshift(choice_default) + choice_show = choice_show.map { |value| { 'choice_show' => value } } + choice = choice_value.zip(choice_show, choice_select) + choice = choice.map { |value| value.inject :merge } + select_text = t('module_template.extend_translate.search_class') + search_text = t('module_template.extend_translate.word_to_search') + @_request = OrbitHelper.request + csrf_value = form_authenticity_token + extras = extras.merge({ 'url' => '/' + I18n.locale.to_s + params[:url], + 'select_text' => select_text, + 'search_text' => search_text, + 'search_value' => params[:keywords].to_s.gsub(/\"/,''), + 'csrf_value' => csrf_value + }) + extras["widget-title"] = I18n.t("module_key.module_template") + { + "module_modal_templates" => module_modal_templates_list, + "headers" => headers, + "extras" => extras, + "total_pages" => module_modal_templates.total_pages, + 'choice' => choice + } + end + + def show + params = OrbitHelper.params + plugin = ModuleModalTemplate.where(:is_hidden=>false).find_by(uid: params[:uid].to_s) + fields_to_show = col_name_to_show_in_show_page + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} + end + + def get_display_field(module_modal_template,field, title_is_paper_format=false) + text_only = false + display_field_code + return value + end + def get_fields_for_index + @page = Page.find(params[:page_id]) rescue nil + @fields_to_show = all_fields_to_show_in_index + @fields_to_show = @fields_to_show.map { |fs| [t("module_template.#{fs}"), fs] } + if @page.present? && @page.custom_string_field == 'table' + @default_fields_to_show = col_name_to_show_in_index_page + else + @default_fields_to_show = col_name_to_show_short + end + 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 + def filter_keywords(module_modal_templates,select_field,keywords) + member_fields = module_modal_template_related_members + file_fields = module_modal_template_related_files_text + link_fields = module_modal_template_related_links_text + if select_field == "default" + module_modal_templates = module_modal_templates.where(:slug_title=>/#{gsub_invalid_character(keywords)}/) + elsif select_field == "member_profile" + ms = MemberProfile.all.select{|m| m.name.include?(keywords)} + module_modal_templates = module_modal_templates.where(:member_profile_id.in=>ms.map{|m| m.id}) + elsif member_fields.include?(select_field) + ms = MemberProfile.all.select{|m| m.name.include?(keywords)} + m_ids = ms.map{|m| m.id.to_s } + tmp_module_modal_templates = module_modal_templates.select{|p| (p.send("#{select_field.singularize}_ids") & m_ids).count != 0} + module_modal_templates = module_modal_templates.where(:id.in=>tmp_module_modal_templates.map{|p| p.id}) + elsif select_field.split(".").count > 1 + relate_name = select_field.split(".").first + field_name = select_field.split(".").last.gsub(/^\$+/, '') + relate = relate_name.camelize.constantize + relate_ids = relate.where(field_name=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + module_modal_templates = module_modal_templates.where("#{relate_name.singularize}_id"=>{'$in'=>relate_ids}) + elsif (ModuleModalTemplate.fields[select_field].options[:type] == Date rescue false) + keywords = keywords.split(/[\/\-]/) + if keywords.count > 1 + Date.parse(keywords.join("/")) + else + start_time = Date.parse(keywords[0] + "/1/1") + end_time = Date.parse(keywords[0] + "/12/31") + module_modal_templates = module_modal_templates.where(select_field=>{'$gte'=>start_time,'$lte'=>end_time}) + end + elsif (ModuleModalTemplate.fields[select_field].options[:type] == DateTime rescue false) + keywords = keywords.split(/[\/\-]/) + if keywords.count > 1 + DateTime.parse(keywords.join("/")) + elsif keywords[0].include?(":") + tmp_module_modal_templates = module_modal_templates.select{|p| (p.send(select_field).strftime('%Y/%m/%d %H:%M').include?(keywords[0]) rescue false)} + module_modal_templates = module_modal_templates.where(:id.in=>tmp_module_modal_templates.map{|p| p.id}) + else + start_time = DateTime.parse(keywords[0] + "/1/1 00:00") + end_time = DateTime.parse(keywords[0] + "/12/31 23:59") + module_modal_templates = module_modal_templates.where(select_field=>{'$gte'=>start_time,'$lte'=>end_time}) + end + elsif (ModuleModalTemplate.fields[select_field].options[:type] == Integer rescue false) + tmp_module_modal_templates = module_modal_templates.select{|p| p.send(select_field).to_s.include?(keywords)} + module_modal_templates = module_modal_templates.where(:id.in=>tmp_module_modal_templates.map{|p| p.id}) + elsif file_fields.include?(select_field) + file_field = select_field.camelize.constantize + ids1 = file_field.where(:file=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + ids2 = file_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + ids = ids1 + ids2 + tmp_module_modal_templates = module_modal_templates.select{|p| (p.send("#{select_field}_ids") & ids).count != 0} + module_modal_templates = module_modal_templates.where(:id.in=>tmp_module_modal_templates.map{|p| p.id}) + elsif link_fields.include?(select_field) + link_field = select_field.camelize.constantize + ids1 = link_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + ids2 = link_field.where(:url=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + ids = ids1 + ids2 + tmp_module_modal_templates = module_modal_templates.select{|p| (p.send("#{select_field}_ids") & ids).count != 0} + module_modal_templates = module_modal_templates.where(:id.in=>tmp_module_modal_templates.map{|p| p.id}) + else + module_modal_templates = module_modal_templates.where(select_field=>/#{gsub_invalid_character(keywords)}/) + end + return module_modal_templates + end + def gsub_invalid_character(text) + text.to_s.gsub(/(\/|\*|\\|\]|\[|\(|\)|\.|\+|\?|\!)/){|ff| "\\"+ff} + end +end diff --git a/template_generator/app/helpers/admin/module_modal_templates_helper.rb b/template_generator/app/helpers/admin/module_modal_templates_helper.rb new file mode 100644 index 0000000..8169709 --- /dev/null +++ b/template_generator/app/helpers/admin/module_modal_templates_helper.rb @@ -0,0 +1,192 @@ +module Admin::ModuleModalTemplatesHelper + include OrbitBackendHelper + include OrbitFormHelper + alias :org_datetime_picker :datetime_picker + def get_authors_text(module_modal_template, is_to_sentence=false, locale=nil) + authors_text = Nokogiri::HTML(module_modal_template.authors.to_s).text + split_text = authors_text.match(/[、,,\/]/) + split_text = split_text.nil? ? '/' : split_text[0] + full_authors_names = get_member(module_modal_template).collect(&:name) + if authors_text.present? + authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))} + full_authors_names += authors_names + end + if is_to_sentence + full_authors_names.to_sentence({:locale=>locale}) + else + full_authors_names.join(split_text) + end + end + def get_authors_show(module_modal_template, is_to_sentence=false, locale=nil) + authors_text = Nokogiri::HTML(module_modal_template.authors.to_s).text + split_text = authors_text.match(/[、,,\/]/) + split_text = split_text.nil? ? '/' : split_text[0] + full_authors_names = [] + full_authors = get_member(module_modal_template).collect do |member| + member_name = member.name + full_authors_names << member_name + "#{member_name}" + end + if authors_text.present? + authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))} + full_authors += authors_names + end + if is_to_sentence + full_authors.to_sentence({:locale=>locale}) + else + full_authors.join(split_text) + end + end + def get_member(module_modal_template) + Array(MemberProfile.where(:id.in=>Array(module_modal_template).collect(&:member_profile_id).flatten)) + end + def get_member_show(module_modal_template) + get_member(module_modal_template).collect{|member| "#{member.name}"}.join('/') + end + def datetime_picker(*arg,**args) + org_datetime_picker(arg,args) + end + def time_iterate(start_time, end_time, step, &block) + begin + start_time = start_time.to_date if end_time.class == Date + yield(start_time) + end while (start_time += step) <= end_time + end + def parse_time(time_str,timezone="+08:00") + DateTime.parse("0000-01-01 " + time_str + timezone) + end + def page_for_module_modal_template(module_modal_template_object) + page = Page.where(:module=>"module_template").first + ("/#{I18n.locale}"+page.url+'/'+module_modal_template_object.to_param).gsub('//','/') rescue "#" + end + + def get_data_for_excel(analysis_field_name_start,analysis_field_name_end,timezone) + analysis_field_name_start = parse_date_time_field("analysis_field_name",analysis_field_name_start,timezone) + analysis_field_name_end = parse_date_time_field("analysis_field_name",analysis_field_name_end,timezone) + 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 + d["data"] = filter_data(ModuleModalTemplate, analysis_field_name_start, analysis_field_name_end, mps) + data << d + end + return data + end + def filter_data(data,analysis_field_name_start,analysis_field_name_end,mps = nil) + result = [] + if @periodic + all_ids = data.all.pluck(:id) rescue [] + out_of_range_ids1 = data.where(:analysis_field_name_start.gt => analysis_field_name_end).pluck(:id) rescue [] + out_of_range_ids2 = data.where(:analysis_field_name_end.lt => analysis_field_name_start).pluck(:id) rescue [] + result = data.where(:id.in=>(all_ids - out_of_range_ids1 - out_of_range_ids2)) rescue [] + else + result = data.where(:analysis_field_name.gte => analysis_field_name_start, :analysis_field_name.lte => analysis_field_name_end) rescue [] + end + result = result.where(:member_profile_id.in => mps) rescue [] unless mps.nil? + return result + end + def get_chart_data(analysis_field_name_start,analysis_field_name_end,role,type,timezone) + analysis_field_name_start = parse_date_time_field("analysis_field_name",analysis_field_name_start,timezone) + analysis_field_name_end = parse_date_time_field("analysis_field_name",analysis_field_name_end,timezone) + main_field_name = "" + time_fields = time_fields_text + max_iterate = 20 + iterate_step = iterate_step_text + iterate_count = ((analysis_field_name_end - analysis_field_name_start) / iterate_step * 1.day.second).ceil + if iterate_count > max_iterate + iterate_step = (iterate_step * (iterate_count / max_iterate.to_f).ceil).second + end + case type + when "default" + jls = [] + parse_again_start + when "module_modal_template_related" + jls = ModuleModalTemplateRelated.all + main_field_name = "module_modal_template_related_main_field" + parse_again_end + else + jls = [] + 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.send(main_field_name) rescue "N/A" + data["data"] = {} + time_iterate(analysis_field_name_start,analysis_field_name_end,iterate_step) do |analysis_field_name| + next_analysis_field_name = analysis_field_name + iterate_step + current_analysis_field_name = analysis_field_name + current_analysis_field_name = analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name") + next_analysis_field_name = next_analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name") + t = filter_data(jl.module_modal_templates, current_analysis_field_name, next_analysis_field_name, mps) + + if current_analysis_field_name.class == DateTime + current_analysis_field_name = display_date_time(current_analysis_field_name,timezone,iterate_step) + end + data["data"][current_analysis_field_name.to_s] = t + end + finaldata << data + end + data = {"name" => "N/A", "data" => {}} + time_iterate(analysis_field_name_start,analysis_field_name_end,iterate_step) do |analysis_field_name| + next_analysis_field_name = analysis_field_name + iterate_step + current_analysis_field_name = analysis_field_name + current_analysis_field_name = analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name") + next_analysis_field_name = next_analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name") + case type + when "default" + t = filter_data(ModuleModalTemplate, current_analysis_field_name, next_analysis_field_name, mps).count rescue 0 + parse_again_start + when "module_modal_template_related" + t = filter_data(ModuleModalTemplate, current_analysis_field_name, next_analysis_field_name, mps).where(:module_modal_template_related_id => nil).count rescue 0 + parse_again_end + else + t = filter_data(ModuleModalTemplate, current_analysis_field_name, next_analysis_field_name, mps).count rescue 0 + end + current_analysis_field_name = current_analysis_field_name.new_offset(timezone) if current_analysis_field_name.class == DateTime + if current_analysis_field_name.class == DateTime + current_analysis_field_name = display_date_time(current_analysis_field_name,timezone,iterate_step) + end + data["data"][current_analysis_field_name.to_s] = t + end + finaldata << data + finaldata + end + def parse_date_time_field(field,value,timezone="+08:00") + time_fields = time_fields_text + type = ModuleModalTemplate.fields[field].type rescue nil + if type.nil? + @periodic = true + type = ModuleModalTemplate.fields[field + "_start"].type + end + if time_fields.include?(field) + parse_time(value,timezone) + elsif type == Integer + value.to_i + elsif type == Date + Date.parse(value) + else + DateTime.parse(value+timezone).utc + end + end + def display_date_time(date_time,timezone,iterate_step) + date_time = date_time.new_offset(timezone) + if iterate_step > 1.year + date_time = date_time.strftime("%Y") + elsif iterate_step > 1.month + date_time = date_time.strftime("%Y/%m") + elsif iterate_step > 1.day + date_time = date_time.strftime("%Y/%m/%d") + else + date_time = date_time.strftime("%Y/%m/%d %H:%M") + end + return date_time + end +end \ No newline at end of file diff --git a/template_generator/app/models/module_modal_template.rb b/template_generator/app/models/module_modal_template.rb new file mode 100644 index 0000000..fbc1f50 --- /dev/null +++ b/template_generator/app/models/module_modal_template.rb @@ -0,0 +1,139 @@ +class ModuleModalTemplate + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include MemberHelper + include Admin::ModuleModalTemplatesHelper + include Slug + + col_fields + + module_modal_template_related_files_fields + + parse_again_start + belongs_to :module_modal_template_related + parse_again_end + + field :rss2_id + belongs_to :member_profile + index(module_modal_template_sort_hash, { unique: false, background: false }) + scope :sort_hash, ->{ order_by(module_modal_template_sort_hash) } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(module_modal_template_sort_hash) } + + parse_again_start + member_methods_define + parse_again_end + parse_again_start + periodic_methods_define + parse_again_end + before_save do + before_save_codes + end + def parse_time(time_str) + DateTime.parse("0000-01-01 " + time_str) + end + parse_again_start * 1 if is_one_line_title.count > 0 + def create_link + one_line_title_format_code + end + parse_again_end + def self.get_plugin_datas_to_member(datas) + page = Page.where(:module => "module_template").first rescue nil + parse_again_start * 1 if is_one_line_title.count > 0 + title_is_paper_format = true + if !page.nil? && page.custom_string_field == "table" + title_is_paper_format = false + if !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = col_name_to_show + end + else + fields_to_show = col_name_to_show_short + end + parse_again_end + parse_again_start * 1 if is_one_line_title.count == 0 + title_is_paper_format = false + if !page.nil? && !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = col_name_to_show + end + parse_again_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) + elsif (self.relations.include?(t.pluralize) rescue false) + fields_to_remove << t if (datas.where(t.pluralize.to_sym.ne=>[]).count == 0 rescue false) + elsif period_fields_text.include?(t) + fields_to_remove << t if (datas.select{|d| d.send(t) != " ~ " }.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("module_template.#{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| + pd_data << { "data_title" => p.display_field(t, false, title_is_paper_format) } + end + parse_again_start * 1 if module_modal_template_related.count > 0 + { + "pd_datas" => pd_data, + "type-sort" => (p.module_modal_template_related.sort_position.to_i rescue 1000), + "sort-index" => idx + } + parse_again_end + parse_again_start * 1 if module_modal_template_related.count == 0 + { + "pd_datas" => pd_data + } + parse_again_end + end + parse_again_start * 1 if module_modal_template_related.count > 0 + plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]} + parse_again_end + return [pd_title,plugin_datas] + 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 get_plugin_field_data(field) + module_modal_template = self + value_case_codes + + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value + + { + "key"=>field, + "title_class"=>"module_modal_template-#{field.gsub('_','-')}-field", + "value_class"=>"module_modal_template-#{field.gsub('_','-')}-value", + "title"=>I18n.t('module_template.'+field), + "value"=>value + } + end + + def display_field(field,text_only=false,title_is_paper_format=false) + module_modal_template = self + display_field_code + end +end \ No newline at end of file diff --git a/template_generator/app/models/module_modal_template_file.rb b/template_generator/app/models/module_modal_template_file.rb new file mode 100644 index 0000000..7dc3af4 --- /dev/null +++ b/template_generator/app/models/module_modal_template_file.rb @@ -0,0 +1,12 @@ +class ModuleModalTemplateFile + include Mongoid::Document + include Mongoid::Timestamps + + field :title, localize: true + field :description, localize: true + field :should_destroy, :type => Boolean + + mount_uploader :file, AssetUploader + + belongs_to :module_modal_template +end \ No newline at end of file diff --git a/template_generator/app/models/module_modal_template_intro.rb b/template_generator/app/models/module_modal_template_intro.rb new file mode 100644 index 0000000..b62fc5a --- /dev/null +++ b/template_generator/app/models/module_modal_template_intro.rb @@ -0,0 +1,3 @@ +class ModuleModalTemplateIntro < ModuleIntro + +end \ No newline at end of file diff --git a/template_generator/app/models/module_modal_template_link.rb b/template_generator/app/models/module_modal_template_link.rb new file mode 100644 index 0000000..142f69b --- /dev/null +++ b/template_generator/app/models/module_modal_template_link.rb @@ -0,0 +1,24 @@ +# encoding: utf-8 +require 'uri' + +class ModuleModalTemplateLink + include Mongoid::Document + include Mongoid::Timestamps + + field :url + field :title, localize: true + + belongs_to :module_modal_template + + before_validation :add_http + + #validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i + + protected + + def add_http + unless self.url[/^http:\/\//] || self.url[/^https:\/\//] + self.url = 'http://' + self.url + end + end +end \ No newline at end of file diff --git a/template_generator/app/models/module_modal_template_related.rb b/template_generator/app/models/module_modal_template_related.rb new file mode 100644 index 0000000..23cc2e0 --- /dev/null +++ b/template_generator/app/models/module_modal_template_related.rb @@ -0,0 +1,12 @@ +class ModuleModalTemplateRelated + include Mongoid::Document + include Mongoid::Timestamps + + col_related_fields + field :sort_position, type: Integer, default: 0 + + has_many :module_modal_templates + parse_again_start + related_periodic_methods_define + parse_again_end +end \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_template_relateds/_form.html.erb b/template_generator/app/views/admin/module_modal_template_relateds/_form.html.erb new file mode 100644 index 0000000..b043943 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_template_relateds/_form.html.erb @@ -0,0 +1,42 @@ +<%= form_for(@module_modal_template_related, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %> + + + + + +<% end %> \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_template_relateds/create.js.erb b/template_generator/app/views/admin/module_modal_template_relateds/create.js.erb new file mode 100644 index 0000000..2c9fce9 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_template_relateds/create.js.erb @@ -0,0 +1,2 @@ +$("#module_modal_template_relateds").html("<%= j render :partial => '/admin/module_modal_templates/module_modal_template_related' %>"); +$("#module_modal_template_related_modal").modal("hide"); diff --git a/template_generator/app/views/admin/module_modal_template_relateds/destroy.js.erb b/template_generator/app/views/admin/module_modal_template_relateds/destroy.js.erb new file mode 100644 index 0000000..2c9fce9 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_template_relateds/destroy.js.erb @@ -0,0 +1,2 @@ +$("#module_modal_template_relateds").html("<%= j render :partial => '/admin/module_modal_templates/module_modal_template_related' %>"); +$("#module_modal_template_related_modal").modal("hide"); diff --git a/template_generator/app/views/admin/module_modal_template_relateds/edit.js.erb b/template_generator/app/views/admin/module_modal_template_relateds/edit.js.erb new file mode 100644 index 0000000..f2c1dde --- /dev/null +++ b/template_generator/app/views/admin/module_modal_template_relateds/edit.js.erb @@ -0,0 +1 @@ +$('#module_modal_template_related_modal').html("<%= j render 'form' %>"); \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_template_relateds/new.js.erb b/template_generator/app/views/admin/module_modal_template_relateds/new.js.erb new file mode 100644 index 0000000..f2c1dde --- /dev/null +++ b/template_generator/app/views/admin/module_modal_template_relateds/new.js.erb @@ -0,0 +1 @@ +$('#module_modal_template_related_modal').html("<%= j render 'form' %>"); \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_template_relateds/update.js.erb b/template_generator/app/views/admin/module_modal_template_relateds/update.js.erb new file mode 100644 index 0000000..2c9fce9 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_template_relateds/update.js.erb @@ -0,0 +1,2 @@ +$("#module_modal_template_relateds").html("<%= j render :partial => '/admin/module_modal_templates/module_modal_template_related' %>"); +$("#module_modal_template_related_modal").modal("hide"); diff --git a/template_generator/app/views/admin/module_modal_templates/_form.html.erb b/template_generator/app/views/admin/module_modal_templates/_form.html.erb new file mode 100644 index 0000000..16a4b1e --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/_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/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + + +
    + + + + + + +
    + + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
    "> + parse_again_start + +
    + +
    + locale_fields_input_fields +
    +
    + parse_again_end +
    + <% end %> + + <% + links_hash = {} + module_modal_template_related_links_text.each do |link| + hash = {} + hash["html"] = add_attribute("form_link", f, link.pluralize.to_sym) + hash["count"] = @module_modal_template.send(link.pluralize).count rescue 0 + links_hash[link] = hash + %> +
    + +
    + + + <% if !@module_modal_template.new_record? && hash["count"] > 0 %> +
    + <% @module_modal_template.send(link.pluralize).each_with_index do |obj, i| %> + <% if !obj.new_record? %> + <%= f.fields_for link.pluralize.to_sym, obj do |f| %> + <%= render :partial => "form_link", :object => obj, :locals => {:f => f, :i => i} %> + <% end %> + <% end %> + <% end %> +
    +
    + <% end %> + + +
    +
    +

    + <%= t(:add) %> +

    + +
    +
    + <% end %> + + <% + files_hash = {} + module_modal_template_related_files_text.each do |file| + hash = {} + hash["html"] = add_attribute("form_file", f, file.pluralize.to_sym) + hash["count"] = @module_modal_template.send(file.pluralize).count rescue 0 + files_hash[file] = hash + %> +
    + +
    + + + <% if !@module_modal_template.new_record? && hash["count"] > 0 %> +
    + <% @module_modal_template.send(file.pluralize).each_with_index do |obj, i| %> + <% if !obj.new_record? %> + <%= f.fields_for file.pluralize.to_sym, obj do |f| %> + <%= render :partial => "form_file", :object => obj, :locals => {:f => f, :i => i} %> + <% end %> + <% end %> + <% end %> +
    +
    + <% end %> + + +
    +
    +

    + <%= t(:add) %> +

    + +
    +
    + <% end %> +
    + + + + +
    + + +
    + + <% if !@member.nil? %> + +
    + +
    + <%= @member.name rescue ''%> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
    +
    + + <% else %> + +
    + +
    + <% members = !@module_modal_template.member_profile_id.nil? ? MemberProfile.where(:id.in=>Array(@module_modal_template.member_profile_id)).to_a : [] %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'module_modal_template[member_profile_id][]', email_members: members,index:'0',select_name:'member_profile_id'} %> +
    +
    + + <% end %> + parse_again_start + +
    + +
    + none_locale_fields_input_fields +
    +
    + parse_again_end + parse_again_start + +
    + +
    + <%= f.select :module_modal_template_related_id, ModuleModalTemplateRelated.all.collect {|t| [ t.module_modal_template_related_main_field, t.id ]}, { include_blank: true } %> +
    +
    + parse_again_end +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    + +
    + <%= 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'), request.referer, :class=>"btn" %> +
    + \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/_form_file.html.erb b/template_generator/app/views/admin/module_modal_templates/_form_file.html.erb new file mode 100644 index 0000000..454adfa --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/_form_file.html.erb @@ -0,0 +1,55 @@ +<% if form_file.new_record? %> +
    +<% else %> +
    + <% if form_file.file.blank? %> + <%= t(:no_file) %> + <% else %> + <%= link_to content_tag(:i) + form_file.file_identifier, form_file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %> + <% end %> +<% end %> +
    + + + + <% @site_in_use_locales.each_with_index do |locale, i| %> + <%= locale %>"> + <%= f.fields_for :title_translations do |f| %> + <%= f.text_field locale, :class => "input-medium", placeholder: t(:alternative), :value => (form_file.title_translations[locale] rescue nil) %> + <% end %> + + <% end %> + + + + <% @site_in_use_locales.each_with_index do |locale, i| %> + <%= locale %>"> + <%= f.fields_for :description_translations do |f| %> + <%= f.text_field locale, :class => "input-medium", placeholder: t(:description), :value => (form_file.description_translations[locale] rescue nil) %> + <% end %> + + <% end %> + + + <% if form_file.new_record? %> + + + + <% else %> + + <%= f.hidden_field :id %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + + <% end %> +
    +
    \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/_form_link.html.erb b/template_generator/app/views/admin/module_modal_templates/_form_link.html.erb new file mode 100644 index 0000000..90239ad --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/_form_link.html.erb @@ -0,0 +1,26 @@ +
    + + <%= f.text_field :url, class: "input-large", placeholder: t(:url) %> + + + <% @site_in_use_locales.each_with_index do |locale, i| %> + <%= locale %>"> + <%= f.fields_for :title_translations do |f| %> + <%= f.text_field locale, :class => "input-large", placeholder: t(:url_alt), :value => (form_link.title_translations[locale] rescue nil) %> + <% end %> + + <% end %> + + + <% if form_link.new_record? %> + + + + <% else %> + + <%= f.hidden_field :id %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + + <% end %> +
    diff --git a/template_generator/app/views/admin/module_modal_templates/_module_modal_template_related.html.erb b/template_generator/app/views/admin/module_modal_templates/_module_modal_template_related.html.erb new file mode 100644 index 0000000..6e26327 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/_module_modal_template_related.html.erb @@ -0,0 +1,23 @@ + + + parse_again_start + <%= t("module_template.module_modal_template_related.related_backend_index_fields") %> + parse_again_end + <%= t(:action) %> + + + + <% @module_modal_template_relateds.each do |module_modal_template_related| %> + + parse_again_start + related_backend_index_fields_contents + parse_again_end + + + <%= t(:edit) %> + + <%= link_to t(:delete_), admin_module_modal_template_related_path(module_modal_template_related), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %> + + + <% end %> + \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/_module_modal_templates.html.erb b/template_generator/app/views/admin/module_modal_templates/_module_modal_templates.html.erb new file mode 100644 index 0000000..6fa4e0e --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/_module_modal_templates.html.erb @@ -0,0 +1,7 @@ +<% @module_modal_templates.each do |module_modal_template| %> + + parse_again_start + backend_index_fields_contents + parse_again_end + +<% end %> \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/analysis.html.erb b/template_generator/app/views/admin/module_modal_templates/analysis.html.erb new file mode 100644 index 0000000..5f0a13d --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/analysis.html.erb @@ -0,0 +1,118 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "//www.google.com/jsapi", "chartkick"%> + <%= javascript_include_tag "justgage.1.0.1.min" %> + <%= javascript_include_tag "raphael.2.1.0.min" %> + <%= javascript_include_tag "validator" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> +<% end %> +
    +
    +
    +
    +
    + +
    + analysis_field_input_fields +
    +
    +
    + +
    + parse_again_start + <%= t("module_template.module_modal_template_related.module_modal_template_related_main_field") %> + + parse_again_end +
    +
    +
    +
    + + Export +
    +
    +
    +
    + <% Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key).each do |role| %> +
    +

    <%= role.title %>

    +
    + loading +
    +
    + <% end %> +
    +
    + \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/analysis_report.html.erb b/template_generator/app/views/admin/module_modal_templates/analysis_report.html.erb new file mode 100644 index 0000000..5c2be7a --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/analysis_report.html.erb @@ -0,0 +1 @@ +<%= column_chart @data, :id => params[:role_id], :height => "350px", :xtitle => "#{I18n.t("module_template.analysis_field_name")}", :ytitle => "#{I18n.t("module_template.extend_translate.total_number")}" %> \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/download_excel.xlsx.axlsx b/template_generator/app/views/admin/module_modal_templates/download_excel.xlsx.axlsx new file mode 100644 index 0000000..9701112 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/download_excel.xlsx.axlsx @@ -0,0 +1,72 @@ +# encoding: utf-8 + +wb = xlsx_package.workbook +@data.each_with_index do |role,idx| + data = role["data"] + wb.add_worksheet(name: role["name"] + "-" + idx.to_s) do |sheet| + + heading = sheet.styles.add_style(:b => true, :locked => true) + + row = [t("module_template.member_profile")] + parse_again_start + @site_in_use_locales.each do |locale| + row << t("module_template.locale_fields") + " - " + t(locale.to_s) + end + parse_again_end + parse_again_start + row << t("module_template.none_locale_fields") + parse_again_end + parse_again_start + row << t("module_template.module_modal_template_related.module_modal_template_related_main_field") + parse_again_end + parse_again_start + row << t("module_template.module_modal_template_file") + @site_in_use_locales.each do |locale| + row << t("module_template.module_modal_template_file") + " " + t("description") + " - " + t(locale.to_s) + end + @site_in_use_locales.each do |locale| + row << t("module_template.module_modal_template_file") + " " + t("alternative") + " - " + t(locale.to_s) + end + parse_again_end + parse_again_start + row << t("module_template.module_modal_template_link") + @site_in_use_locales.each do |locale| + row << t("module_template.module_modal_template_link") + " " + t("url_alt") + " - " + t(locale.to_s) + end + parse_again_end + sheet.add_row row, :style => heading + + data.each do |module_modal_template| + row = [(module_modal_template.member_profile.name rescue "")] + parse_again_start + @site_in_use_locales.each do |locale| + row << module_modal_template.locale_fields_translations[locale.to_s] + end + parse_again_end + parse_again_start + row << module_modal_template.display_field("none_locale_fields",true) + parse_again_end + parse_again_start + row << (module_modal_template.module_modal_template_related.module_modal_template_related_main_field rescue "") + parse_again_end + parse_again_start + module_modal_template_files = module_modal_template.module_modal_template_files.asc(:created_at) + row << module_modal_template_files.collect{|f| (@host_url + f.file.url rescue nil)}.join(";") + @site_in_use_locales.each do |locale| + row << module_modal_template_files.collect{|l| l.description_translations[locale]}.join(";") + end + @site_in_use_locales.each do |locale| + row << module_modal_template_files.collect{|l| l.title_translations[locale]}.join(";") + end + parse_again_end + parse_again_start + module_modal_template_links = module_modal_template.module_modal_template_links.asc(:created_at) + row << module_modal_template_links.collect{|l| l.url}.join(";") + @site_in_use_locales.each do |locale| + row << module_modal_template_links.collect{|l| l.title_translations[locale]}.join(";") + end + parse_again_end + sheet.add_row row + end + end +end \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/edit.html.erb b/template_generator/app/views/admin/module_modal_templates/edit.html.erb new file mode 100644 index 0000000..16c9245 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @module_modal_template, url: admin_module_modal_template_path(@module_modal_template), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= render partial: 'form', locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/frontend_setting.html.erb b/template_generator/app/views/admin/module_modal_templates/frontend_setting.html.erb new file mode 100644 index 0000000..510218e --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/frontend_setting.html.erb @@ -0,0 +1,82 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> + +<%= form_for(:module_modal_template_intro, :url => update_frontend_setting_admin_module_modal_templates_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("modules.brief_intro") %> + <%= f.check_box :complete_list, :checked => @intro.complete_list %> <%= t("modules.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 %> \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/index.html.erb b/template_generator/app/views/admin/module_modal_templates/index.html.erb new file mode 100644 index 0000000..ed4a1e4 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/index.html.erb @@ -0,0 +1,24 @@ + + + + parse_again_start + <%= thead('module_template.backend_index_fields') %> + parse_again_end + + + + <%= render 'module_modal_templates' %> + +
    + +
    +
    + <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_module_modal_template_path, :class => 'btn btn-primary' %> + parse_again_start * 1 if module_modal_template_related + <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_module_modal_template_setting_path, :class => 'btn btn-primary pull-right' %> + parse_again_end +
    + +
    \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/new.html.erb b/template_generator/app/views/admin/module_modal_templates/new.html.erb new file mode 100644 index 0000000..f3445ad --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @module_modal_template, url: admin_module_modal_templates_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= render partial: 'form', locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/template_generator/app/views/admin/module_modal_templates/setting.html.erb b/template_generator/app/views/admin/module_modal_templates/setting.html.erb new file mode 100644 index 0000000..a570a33 --- /dev/null +++ b/template_generator/app/views/admin/module_modal_templates/setting.html.erb @@ -0,0 +1,72 @@ +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/jquery-ui-sortable.min" %> +<% end %> + + +
    + parse_again_start +
    +
    +

    + <%= t('add')%> + <%= t("module_template.module_modal_template_related.module_modal_template_related_main_field") %> +

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + <%= render :partial => 'module_modal_template_related', :locals => {:@module_modal_template_relateds => @module_modal_template_relateds} %> +
    +
    +
    +
    +
    +
    + parse_again_end +
    + +parse_again_start +
    + +
    + +parse_again_end \ No newline at end of file diff --git a/template_generator/app/views/module_templates/get_fields_for_index.html.erb b/template_generator/app/views/module_templates/get_fields_for_index.html.erb new file mode 100644 index 0000000..c594056 --- /dev/null +++ b/template_generator/app/views/module_templates/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| %> +
    • <%= t("module_template.#{fs}") %>
    • + <% end %> + <% else %> + <% @page.custom_array_field.each do |fs| %> +
    • <%= t("module_template.#{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 %> \ No newline at end of file diff --git a/template_generator/app/views/module_templates/index.html.erb b/template_generator/app/views/module_templates/index.html.erb new file mode 100644 index 0000000..648b75c --- /dev/null +++ b/template_generator/app/views/module_templates/index.html.erb @@ -0,0 +1 @@ +<%= render_view %> \ No newline at end of file diff --git a/template_generator/app/views/module_templates/show.html.erb b/template_generator/app/views/module_templates/show.html.erb new file mode 100644 index 0000000..648b75c --- /dev/null +++ b/template_generator/app/views/module_templates/show.html.erb @@ -0,0 +1 @@ +<%= render_view %> \ No newline at end of file diff --git a/template_generator/bin/rails b/template_generator/bin/rails new file mode 100644 index 0000000..38c2a68 --- /dev/null +++ b/template_generator/bin/rails @@ -0,0 +1,12 @@ +#!/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_course/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 'rails/all' +require 'rails/engine/commands' diff --git a/template_generator/config/locales/en.yml b/template_generator/config/locales/en.yml new file mode 100644 index 0000000..1d46adf --- /dev/null +++ b/template_generator/config/locales/en.yml @@ -0,0 +1,23 @@ +en: + module_name: + personal_plugin_template: personal_plugin_template_translate + plugin_templates: personal_plugin_template_translate + plugin_template: personal_plugin_template_translate + personal_plugin_template: + extend_translate: + start_time: Start time + end_time: End time + start_date: Start date + end_date: End date + start_date_time: Start date & time + end_date_time: End date & time + start_year: Start year + end_year: End year + start_year_month: Start year/month + end_year_month: End year/month + total_number: Total number + select_class: "——select class——" + search_class: "search class:" + word_to_search: "word to search:" + graph_by: "Graph By" + col_name_translate_yaml \ No newline at end of file diff --git a/template_generator/config/locales/zh_tw.yml b/template_generator/config/locales/zh_tw.yml new file mode 100644 index 0000000..b02335e --- /dev/null +++ b/template_generator/config/locales/zh_tw.yml @@ -0,0 +1,23 @@ +zh_tw: + module_name: + personal_plugin_template: personal_plugin_template_translate + plugin_templates: personal_plugin_template_translate + plugin_template: personal_plugin_template_translate + personal_plugin_template: + extend_translate: + start_time: 開始時間 + end_time: 結束時間 + start_date: 開始日期 + end_date: 結束日期 + start_date_time: 開始日期時間 + end_date_time: 結束日期時間 + start_year: 開始年分 + end_year: 結束年分 + start_year_month: 開始年月 + end_year_month: 結束年月 + total_number: 總數量 + select_class: "——選取分類——" + search_class: "搜尋類別:" + word_to_search: "關鍵字搜尋:" + graph_by: "Graph By" + col_name_translate_yaml \ No newline at end of file diff --git a/template_generator/config/routes.rb b/template_generator/config/routes.rb new file mode 100644 index 0000000..78174ce --- /dev/null +++ b/template_generator/config/routes.rb @@ -0,0 +1,32 @@ +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 'plugin_template_setting' => "module_modal_templates#setting" + resources :module_modal_templates do + collection do + get 'toggle_hide' => 'module_modal_templates#toggle_hide' + get 'analysis' + get 'analysis_report' + get "download_excel" + end + end + + resources :members do + collection do + scope '(:name-:uid)' do + resources :module_modal_templates do + collection do + get 'frontend_setting' => 'module_modal_templates#frontend_setting' + post 'update_frontend_setting' => 'module_modal_templates#update_frontend_setting' + end + end + end + end + end + parse_again_start + resources :module_modal_relateds + parse_again_end + end + end +end \ No newline at end of file diff --git a/template_generator/lib/module_template.rb b/template_generator/lib/module_template.rb new file mode 100644 index 0000000..09716f7 --- /dev/null +++ b/template_generator/lib/module_template.rb @@ -0,0 +1,4 @@ +require "module_template/engine" + +module ModuleTemplate +end diff --git a/template_generator/lib/module_template/engine.rb b/template_generator/lib/module_template/engine.rb new file mode 100644 index 0000000..f3ab454 --- /dev/null +++ b/template_generator/lib/module_template/engine.rb @@ -0,0 +1,21 @@ +module ModuleTemplate + class Engine < ::Rails::Engine + initializer "module_template" do + OrbitApp.registration "ModuleTemplate",:type=> 'ModuleApp' do + module_label 'module_key.module_modal_templates' + base_url File.expand_path File.dirname(__FILE__) + module :enable => true, :sort_number => '35', :app_name=>"ModuleModalTemplate", :intro_app_name=>"ModuleModalTemplateIntro",:path=>"/plugin/module_template/profile",:front_path=>"/profile",:admin_path=>"/admin/module_modal_templates/",:i18n=>'module_key.module_modal_templates', :module_app_name=>'ModuleModalTemplate', :one_line_title => enable_one_line_title, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/module_modal_templates/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/template_generator/lib/module_template/version.rb b/template_generator/lib/module_template/version.rb new file mode 100644 index 0000000..0e5dfb6 --- /dev/null +++ b/template_generator/lib/module_template/version.rb @@ -0,0 +1,3 @@ +module ModuleTemplate + VERSION = "0.0.1" +end diff --git a/template_generator/lib/tasks/module_template_tasks.rake b/template_generator/lib/tasks/module_template_tasks.rake new file mode 100644 index 0000000..1bbe653 --- /dev/null +++ b/template_generator/lib/tasks/module_template_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :module_template do +# # Task goes here +# end diff --git a/template_generator/module_template.gemspec b/template_generator/module_template.gemspec new file mode 100644 index 0000000..dd71954 --- /dev/null +++ b/template_generator/module_template.gemspec @@ -0,0 +1,19 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "module_template/version" + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "module_template" + s.version = ModuleTemplate::VERSION + s.authors = ["Bohung"] + s.email = ["bohung@rulingcom.com"] + s.homepage = "http://www.rulingcom.com" + s.summary = "module_template_description." + s.description = "module_template_description." + s.license = "MIT" + + s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] + s.test_files = Dir["test/**/*"] +end \ No newline at end of file diff --git a/template_generator/modules/module_template/index.html.erb b/template_generator/modules/module_template/index.html.erb new file mode 100644 index 0000000..5e61af0 --- /dev/null +++ b/template_generator/modules/module_template/index.html.erb @@ -0,0 +1,23 @@ + + + + + + + + + + + + +

    {{widget-title}}

    {{head-title}}
    {{value}}
    +{{pagination_goes_here}} + + \ No newline at end of file diff --git a/template_generator/modules/module_template/index_search1.html.erb b/template_generator/modules/module_template/index_search1.html.erb new file mode 100644 index 0000000..a94961d --- /dev/null +++ b/template_generator/modules/module_template/index_search1.html.erb @@ -0,0 +1,48 @@ + +

    {{widget-title}}

    +
    +
    + + {{select_text}} + + {{search_text}} + + + Clear +
    +
    + + + + + + + + + + + + +

    {{widget-title}}

    {{head-title}}
    {{value}}
    +{{pagination_goes_here}} + + \ No newline at end of file diff --git a/template_generator/modules/module_template/info.json b/template_generator/modules/module_template/info.json new file mode 100644 index 0000000..bdb0c2c --- /dev/null +++ b/template_generator/modules/module_template/info.json @@ -0,0 +1,20 @@ +{ + "frontend": [ + { + "filename" : "index", + "name" : { + "zh_tw" : "1. 列表", + "en" : "1. List" + }, + "thumbnail" : "thumb.png" + }, + { + "filename" : "index_search1", + "name" : { + "zh_tw" : "2. 列表(含搜尋)", + "en" : "2. List which includes search" + }, + "thumbnail" : "thumb.png" + } + ] +} \ No newline at end of file diff --git a/template_generator/modules/module_template/show.html.erb b/template_generator/modules/module_template/show.html.erb new file mode 100644 index 0000000..58a66d2 --- /dev/null +++ b/template_generator/modules/module_template/show.html.erb @@ -0,0 +1,8 @@ + + + + + + + +
    {{title}}{{value}}
    \ No newline at end of file diff --git a/template_generator/modules/module_template/thumbs/thumb.png b/template_generator/modules/module_template/thumbs/thumb.png new file mode 100644 index 0000000..266af56 Binary files /dev/null and b/template_generator/modules/module_template/thumbs/thumb.png differ diff --git a/template_generator/test/dummy/README.rdoc b/template_generator/test/dummy/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/template_generator/test/dummy/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/template_generator/test/dummy/Rakefile b/template_generator/test/dummy/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/template_generator/test/dummy/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/template_generator/test/dummy/app/assets/images/.keep b/template_generator/test/dummy/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/app/assets/javascripts/application.js b/template_generator/test/dummy/app/assets/javascripts/application.js new file mode 100644 index 0000000..a1873dd --- /dev/null +++ b/template_generator/test/dummy/app/assets/javascripts/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/template_generator/test/dummy/app/assets/stylesheets/application.css b/template_generator/test/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..a443db3 --- /dev/null +++ b/template_generator/test/dummy/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/template_generator/test/dummy/app/controllers/application_controller.rb b/template_generator/test/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/template_generator/test/dummy/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/template_generator/test/dummy/app/controllers/concerns/.keep b/template_generator/test/dummy/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/app/helpers/application_helper.rb b/template_generator/test/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/template_generator/test/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/template_generator/test/dummy/app/mailers/.keep b/template_generator/test/dummy/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/app/models/.keep b/template_generator/test/dummy/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/app/models/concerns/.keep b/template_generator/test/dummy/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/app/views/layouts/application.html.erb b/template_generator/test/dummy/app/views/layouts/application.html.erb new file mode 100644 index 0000000..593a778 --- /dev/null +++ b/template_generator/test/dummy/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Dummy + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/template_generator/test/dummy/bin/bundle b/template_generator/test/dummy/bin/bundle new file mode 100644 index 0000000..66e9889 --- /dev/null +++ b/template_generator/test/dummy/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/template_generator/test/dummy/bin/rails b/template_generator/test/dummy/bin/rails new file mode 100644 index 0000000..728cd85 --- /dev/null +++ b/template_generator/test/dummy/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/template_generator/test/dummy/bin/rake b/template_generator/test/dummy/bin/rake new file mode 100644 index 0000000..1724048 --- /dev/null +++ b/template_generator/test/dummy/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/template_generator/test/dummy/config.ru b/template_generator/test/dummy/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/template_generator/test/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/template_generator/test/dummy/config/application.rb b/template_generator/test/dummy/config/application.rb new file mode 100644 index 0000000..2217afe --- /dev/null +++ b/template_generator/test/dummy/config/application.rb @@ -0,0 +1,23 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require(*Rails.groups) +require "personal_course" + +module Dummy + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + end +end + diff --git a/template_generator/test/dummy/config/boot.rb b/template_generator/test/dummy/config/boot.rb new file mode 100644 index 0000000..6266cfc --- /dev/null +++ b/template_generator/test/dummy/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/template_generator/test/dummy/config/database.yml b/template_generator/test/dummy/config/database.yml new file mode 100644 index 0000000..1c1a37c --- /dev/null +++ b/template_generator/test/dummy/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/template_generator/test/dummy/config/environment.rb b/template_generator/test/dummy/config/environment.rb new file mode 100644 index 0000000..ee8d90d --- /dev/null +++ b/template_generator/test/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/template_generator/test/dummy/config/environments/development.rb b/template_generator/test/dummy/config/environments/development.rb new file mode 100644 index 0000000..ddf0e90 --- /dev/null +++ b/template_generator/test/dummy/config/environments/development.rb @@ -0,0 +1,37 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/template_generator/test/dummy/config/environments/production.rb b/template_generator/test/dummy/config/environments/production.rb new file mode 100644 index 0000000..b93a877 --- /dev/null +++ b/template_generator/test/dummy/config/environments/production.rb @@ -0,0 +1,78 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/template_generator/test/dummy/config/environments/test.rb b/template_generator/test/dummy/config/environments/test.rb new file mode 100644 index 0000000..053f5b6 --- /dev/null +++ b/template_generator/test/dummy/config/environments/test.rb @@ -0,0 +1,39 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/template_generator/test/dummy/config/initializers/assets.rb b/template_generator/test/dummy/config/initializers/assets.rb new file mode 100644 index 0000000..d2f4ec3 --- /dev/null +++ b/template_generator/test/dummy/config/initializers/assets.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/template_generator/test/dummy/config/initializers/backtrace_silencers.rb b/template_generator/test/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/template_generator/test/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/template_generator/test/dummy/config/initializers/cookies_serializer.rb b/template_generator/test/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..7a06a89 --- /dev/null +++ b/template_generator/test/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file diff --git a/template_generator/test/dummy/config/initializers/filter_parameter_logging.rb b/template_generator/test/dummy/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/template_generator/test/dummy/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/template_generator/test/dummy/config/initializers/inflections.rb b/template_generator/test/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/template_generator/test/dummy/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/template_generator/test/dummy/config/initializers/mime_types.rb b/template_generator/test/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/template_generator/test/dummy/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/template_generator/test/dummy/config/initializers/session_store.rb b/template_generator/test/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000..e766b67 --- /dev/null +++ b/template_generator/test/dummy/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/template_generator/test/dummy/config/initializers/wrap_parameters.rb b/template_generator/test/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/template_generator/test/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/template_generator/test/dummy/config/locales/en.yml b/template_generator/test/dummy/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/template_generator/test/dummy/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/template_generator/test/dummy/config/routes.rb b/template_generator/test/dummy/config/routes.rb new file mode 100644 index 0000000..752cab9 --- /dev/null +++ b/template_generator/test/dummy/config/routes.rb @@ -0,0 +1,4 @@ +Rails.application.routes.draw do + + mount PersonalCourse::Engine => "/personal_course" +end diff --git a/template_generator/test/dummy/config/secrets.yml b/template_generator/test/dummy/config/secrets.yml new file mode 100644 index 0000000..7973e7d --- /dev/null +++ b/template_generator/test/dummy/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 7c3d6006ba19a38b126337be5c954acc76ea069fc59ab3b64ddb42e42883655978b5162d26bdcfeb9f363e5626a2c34e2036a9b0a010c9adceabbcdc01daa3cd + +test: + secret_key_base: f25e944e4db0a66681fe04d9a9f325978e481cabf76235247d86f881ab7c1616d542fb4a80306c539569becaeb9fee301d583845d11860df915e14e2224712b9 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/template_generator/test/dummy/lib/assets/.keep b/template_generator/test/dummy/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/log/.keep b/template_generator/test/dummy/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/dummy/public/404.html b/template_generator/test/dummy/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/template_generator/test/dummy/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
    +
    +

    The page you were looking for doesn't exist.

    +

    You may have mistyped the address or the page may have moved.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/template_generator/test/dummy/public/422.html b/template_generator/test/dummy/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/template_generator/test/dummy/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
    +
    +

    The change you wanted was rejected.

    +

    Maybe you tried to change something you didn't have access to.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/template_generator/test/dummy/public/500.html b/template_generator/test/dummy/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/template_generator/test/dummy/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
    +
    +

    We're sorry, but something went wrong.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/template_generator/test/dummy/public/favicon.ico b/template_generator/test/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/template_generator/test/integration/navigation_test.rb b/template_generator/test/integration/navigation_test.rb new file mode 100644 index 0000000..97a94c9 --- /dev/null +++ b/template_generator/test/integration/navigation_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class NavigationTest < ActionDispatch::IntegrationTest + fixtures :all + + # test "the truth" do + # assert true + # end +end + diff --git a/template_generator/test/module_template_test.rb b/template_generator/test/module_template_test.rb new file mode 100644 index 0000000..57137f7 --- /dev/null +++ b/template_generator/test/module_template_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ModuleTemplateTest < ActiveSupport::TestCase + test "truth" do + assert_kind_of Module, ModuleTemplate + end +end diff --git a/template_generator/test/test_helper.rb b/template_generator/test/test_helper.rb new file mode 100644 index 0000000..a553d9a --- /dev/null +++ b/template_generator/test/test_helper.rb @@ -0,0 +1,19 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) +ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)] +ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) +require "rails/test_help" + +# Filter out Minitest backtrace while allowing backtrace from other libraries +# to be shown. +Minitest.backtrace_filter = Minitest::BacktraceFilter.new + +# Load support files +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + +# Load fixtures from the engine +if ActiveSupport::TestCase.method_defined?(:fixture_path=) + ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) +end diff --git a/test/dummy/README.rdoc b/test/dummy/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/test/dummy/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/test/dummy/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/test/dummy/app/assets/images/.keep b/test/dummy/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/assets/javascripts/application.js b/test/dummy/app/assets/javascripts/application.js new file mode 100644 index 0000000..a1873dd --- /dev/null +++ b/test/dummy/app/assets/javascripts/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..a443db3 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/test/dummy/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/test/dummy/app/controllers/concerns/.keep b/test/dummy/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/test/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/test/dummy/app/mailers/.keep b/test/dummy/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/models/.keep b/test/dummy/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/models/concerns/.keep b/test/dummy/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb new file mode 100644 index 0000000..593a778 --- /dev/null +++ b/test/dummy/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Dummy + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle new file mode 100644 index 0000000..66e9889 --- /dev/null +++ b/test/dummy/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails new file mode 100644 index 0000000..728cd85 --- /dev/null +++ b/test/dummy/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake new file mode 100644 index 0000000..1724048 --- /dev/null +++ b/test/dummy/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/test/dummy/config.ru b/test/dummy/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/test/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb new file mode 100644 index 0000000..2217afe --- /dev/null +++ b/test/dummy/config/application.rb @@ -0,0 +1,23 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require(*Rails.groups) +require "personal_course" + +module Dummy + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + end +end + diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb new file mode 100644 index 0000000..6266cfc --- /dev/null +++ b/test/dummy/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml new file mode 100644 index 0000000..1c1a37c --- /dev/null +++ b/test/dummy/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb new file mode 100644 index 0000000..ee8d90d --- /dev/null +++ b/test/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb new file mode 100644 index 0000000..ddf0e90 --- /dev/null +++ b/test/dummy/config/environments/development.rb @@ -0,0 +1,37 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb new file mode 100644 index 0000000..b93a877 --- /dev/null +++ b/test/dummy/config/environments/production.rb @@ -0,0 +1,78 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb new file mode 100644 index 0000000..053f5b6 --- /dev/null +++ b/test/dummy/config/environments/test.rb @@ -0,0 +1,39 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb new file mode 100644 index 0000000..d2f4ec3 --- /dev/null +++ b/test/dummy/config/initializers/assets.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/test/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..7a06a89 --- /dev/null +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/test/dummy/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/test/dummy/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/test/dummy/config/initializers/session_store.rb b/test/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000..e766b67 --- /dev/null +++ b/test/dummy/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/test/dummy/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb new file mode 100644 index 0000000..752cab9 --- /dev/null +++ b/test/dummy/config/routes.rb @@ -0,0 +1,4 @@ +Rails.application.routes.draw do + + mount PersonalCourse::Engine => "/personal_course" +end diff --git a/test/dummy/config/secrets.yml b/test/dummy/config/secrets.yml new file mode 100644 index 0000000..7973e7d --- /dev/null +++ b/test/dummy/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 7c3d6006ba19a38b126337be5c954acc76ea069fc59ab3b64ddb42e42883655978b5162d26bdcfeb9f363e5626a2c34e2036a9b0a010c9adceabbcdc01daa3cd + +test: + secret_key_base: f25e944e4db0a66681fe04d9a9f325978e481cabf76235247d86f881ab7c1616d542fb4a80306c539569becaeb9fee301d583845d11860df915e14e2224712b9 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/test/dummy/lib/assets/.keep b/test/dummy/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/log/.keep b/test/dummy/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/public/404.html b/test/dummy/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/test/dummy/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
    +
    +

    The page you were looking for doesn't exist.

    +

    You may have mistyped the address or the page may have moved.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/test/dummy/public/422.html b/test/dummy/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/test/dummy/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
    +
    +

    The change you wanted was rejected.

    +

    Maybe you tried to change something you didn't have access to.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/test/dummy/public/500.html b/test/dummy/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/test/dummy/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
    +
    +

    We're sorry, but something went wrong.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/test/dummy/public/favicon.ico b/test/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb new file mode 100644 index 0000000..97a94c9 --- /dev/null +++ b/test/integration/navigation_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class NavigationTest < ActionDispatch::IntegrationTest + fixtures :all + + # test "the truth" do + # assert true + # end +end + diff --git a/test/module_field_test.rb b/test/module_field_test.rb new file mode 100644 index 0000000..796bb27 --- /dev/null +++ b/test/module_field_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ModuleFieldTest < ActiveSupport::TestCase + test "truth" do + assert_kind_of Module, ModuleGenerator + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..a553d9a --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,19 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) +ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)] +ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) +require "rails/test_help" + +# Filter out Minitest backtrace while allowing backtrace from other libraries +# to be shown. +Minitest.backtrace_filter = Minitest::BacktraceFilter.new + +# Load support files +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + +# Load fixtures from the engine +if ActiveSupport::TestCase.method_defined?(:fixture_path=) + ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) +end