diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -69,6 +69,7 @@ gem 'jquery-datatables-rails' #----------- user interface ----------------- +gem 'simple_form' #select 2 gem 'select2-rails' #ace editor diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,6 +241,9 @@ childprocess (>= 0.5, < 2.0) rubyzip (~> 1.2, >= 1.2.2) sexp_processor (4.12.0) + simple_form (4.1.0) + actionpack (>= 5.0) + activemodel (>= 5.0) spring (2.1.0) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -320,6 +323,7 @@ sassc-rails select2-rails selenium-webdriver + simple_form spring spring-watcher-listen (~> 2.0.0) sqlite3 diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -2,13 +2,6 @@ before_action :admin_authorization - verify :method => :post, :only => ['clear_all', - 'start_exam', - 'start_grading', - 'stop_all', - 'clear_terminated'], - :redirect_to => {:action => 'index'} - def index redirect_to :action => 'list' end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -15,15 +15,6 @@ before_action :authenticate_by_ip_address, :only => [:list] - # COMMENTED OUT: filter in each action instead - # before_filter :verify_time_limit, :only => [:submit] - - verify :method => :post, :only => [:submit], - :redirect_to => { :action => :index } - - # COMMENT OUT: only need when having high load - # caches_action :index, :login - # NOTE: This method is not actually needed, 'config/routes.rb' has # assigned action login as a default action. def index diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -2,8 +2,6 @@ before_action :authenticate - verify :method => :post, :only => ['create'], - :redirect_to => { :action => 'list' } before_filter :admin_authorization, :only => ['console','show', 'reply','hide','list_all'] diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -11,12 +11,6 @@ @problems = Problem.order(date_added: :desc) end - # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) - verify :method => :post, :only => [ :create, :quick_create, - :do_manage, - :do_import, - ], - :redirect_to => { :action => :index } def show @problem = Problem.find(params[:id]) @@ -29,7 +23,7 @@ def create @problem = Problem.new(problem_params) - @description = Description.new(params[:description]) + @description = Description.new(problem_params[:description]) if @description.body!='' if !@description.save render :action => new and return diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -2,13 +2,6 @@ before_action :authenticate, :check_viewability -# -# COMMENT OUT: filter in each action instead -# -# before_filter :verify_time_limit, :only => [:submit] - - verify :method => :post, :only => [:submit], - :redirect_to => { :action => :index } def index prepare_index_information diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -6,15 +6,6 @@ before_action :admin_authorization - # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) - verify :method => :post, :only => [ - :create, :create_from_list, - :update, - :manage_contest, - :bulk_mail - ], - :redirect_to => { :action => :list } - def index @user_count = User.count if params[:page] == 'all' diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,9 +19,6 @@ before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] - verify :method => :post, :only => [:chg_passwd], - :redirect_to => { :action => :index } - #in_place_edit_for :user, :alias_for_editing #in_place_edit_for :user, :email_for_editing diff --git a/app/models/group.rb b/app/models/group.rb --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,8 +1,8 @@ class Group < ActiveRecord::Base - has_many :groups_problems, class_name: GroupProblem + has_many :groups_problems, class_name: 'GroupProblem' has_many :problems, :through => :groups_problems - has_many :groups_users, class_name: GroupUser + has_many :groups_users, class_name: 'GroupUser' has_many :users, :through => :groups_users #has_and_belongs_to_many :problems diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -4,10 +4,10 @@ has_and_belongs_to_many :contests, :uniq => true #has_and_belongs_to_many :groups - has_many :groups_problems, class_name: GroupProblem + has_many :groups_problems, class_name: 'GroupProblem' has_many :groups, :through => :groups_problems - has_many :problems_tags, class_name: ProblemTag + has_many :problems_tags, class_name: 'ProblemTag' has_many :tags, through: :problems_tags has_many :test_pairs, :dependent => :delete_all diff --git a/app/models/tag.rb b/app/models/tag.rb --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,4 @@ class Tag < ActiveRecord::Base - has_many :problems_tags, class_name: ProblemTag + has_many :problems_tags, class_name: 'ProblemTag' has_many :problems, through: :problems_tags end diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,7 @@ has_and_belongs_to_many :roles #has_and_belongs_to_many :groups - has_many :groups_users, class_name: GroupUser + has_many :groups_users, class_name: 'GroupUser' has_many :groups, :through => :groups_users has_many :test_requests, -> {order(submitted_at: :desc)} diff --git a/app/views/announcements/new.html.erb b/app/views/announcements/new.html.erb deleted file mode 100644 --- a/app/views/announcements/new.html.erb +++ /dev/null @@ -1,46 +0,0 @@ -
- Title
- <%= f.text_field :title %>
-
- Notes (shown internally, used to organize announcements)
- <%= f.text_field :notes %>
-
- Body
- <%= f.text_area :body %>
-
- Author
- <%= f.text_field :author %>
-
- Published
- <%= f.check_box :published %>
-
- Show on front page?
- <%= f.check_box :frontpage %>
-
- Show only in contest?
- <%= f.check_box :contest_only %>
-
- <%= f.submit "Create" %> -
-<% end %> - -<%= link_to 'Back', announcements_path %> diff --git a/app/views/announcements/new.html.haml b/app/views/announcements/new.html.haml new file mode 100644 --- /dev/null +++ b/app/views/announcements/new.html.haml @@ -0,0 +1,14 @@ +%h1 New announcement += error_messages_for :announcement += simple_form_for(@announcement) do |f| + .row + .col-md-6 + = f.input :title + = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' + = f.input :body + = f.input :author + = f.input :published + = f.input :frontpage, label: 'Display in the front page only?' + = f.input :contest_only, label: 'Display in contest only?' + = f.button :submit, "Create", class: 'btn btn-primary' + = link_to 'Back', announcements_path, class: 'btn btn-default' diff --git a/app/views/announcements/show.html.erb b/app/views/announcements/show.html.erb deleted file mode 100644 --- a/app/views/announcements/show.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -- Author: - <%=h @announcement.author %> -
- -- Title: - <%=h @announcement.title %> -
- -- Notes: - <%=h @announcement.notes %> -
- -- Body: - <%=h markdown(@announcement.body) %> -
- -- Published: - <%=h @announcement.published %> -
- -- Show on front page: - <%=h @announcement.frontpage %> -
- -- Show only in contest: - <%=h @announcement.contest_only %> -
- -<%= link_to 'Edit', edit_announcement_path(@announcement) %> | -<%= link_to 'Back', announcements_path %> diff --git a/app/views/announcements/show.html.haml b/app/views/announcements/show.html.haml new file mode 100644 --- /dev/null +++ b/app/views/announcements/show.html.haml @@ -0,0 +1,24 @@ +%p + %b Author: + = h @announcement.author +%p + %b Title: + = h @announcement.title +%p + %b Notes: + = h @announcement.notes +%p + %b Body: + = h markdown(@announcement.body) +%p + %b Published: + = h @announcement.published +%p + %b Show on front page: + = h @announcement.frontpage +%p + %b Show only in contest: + = h @announcement.contest_only += link_to 'Edit', edit_announcement_path(@announcement) +| += link_to 'Back', announcements_path diff --git a/app/views/problems/index.html.haml b/app/views/problems/index.html.haml --- a/app/views/problems/index.html.haml +++ b/app/views/problems/index.html.haml @@ -8,7 +8,7 @@ = link_to 'Turn off all problems', {:action => 'turn_all_off'}, class: 'btn btn-default btn-sm' = link_to 'Turn on all problems', {:action => 'turn_all_on'}, class: 'btn btn-default btn-sm' .submitbox - = form_tag :action => 'quick_create' do + = form_tag action: 'quick_create', controller: 'problems' do %b Quick New: %label{:for => "problem_name"} Name = text_field 'problem', 'name' diff --git a/app/views/problems/new.html.erb b/app/views/problems/new.html.erb --- a/app/views/problems/new.html.erb +++ b/app/views/problems/new.html.erb @@ -5,4 +5,4 @@ <%= submit_tag "Create" %> <% end %> -<%= link_to 'Back', :action => 'list' %> +<%= link_to 'Back', problems_path %> diff --git a/app/views/user_admin/edit.html.haml b/app/views/user_admin/edit.html.haml --- a/app/views/user_admin/edit.html.haml +++ b/app/views/user_admin/edit.html.haml @@ -10,4 +10,4 @@ = link_to 'Show', :action => 'show', :id => @user | -= link_to 'Back', :action => 'list' += link_to 'Back', :action => 'index' diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -22,4 +22,4 @@ Rails.application.config.active_record.belongs_to_required_by_default = false # Do not halt callback chains when a callback returns false. Previous versions had true. -ActiveSupport.halt_callback_chains_on_return_false = true +# ActiveSupport.halt_callback_chains_on_return_false = true diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb new file mode 100644 --- /dev/null +++ b/config/initializers/simple_form.rb @@ -0,0 +1,179 @@ +# frozen_string_literal: true +# +# Uncomment this and change the path if necessary to include your own +# components. +# See https://github.com/plataformatec/simple_form#custom-components to know +# more about custom components. +# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f } +# +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + # Wrappers are used by the form builder to generate a + # complete input. You can remove any component from the + # wrapper, change the order or even add your own to the + # stack. The options given below are used to wrap the + # whole input. + config.wrappers :default, class: :input, + hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b| + ## Extensions enabled by default + # Any of these extensions can be disabled for a + # given input by passing: `f.input EXTENSION_NAME => false`. + # You can make any of these extensions optional by + # renaming `b.use` to `b.optional`. + + # Determines whether to use HTML5 (:email, :url, ...) + # and required attributes + b.use :html5 + + # Calculates placeholders automatically from I18n + # You can also pass a string as f.input placeholder: "Placeholder" + b.use :placeholder + + ## Optional extensions + # They are disabled unless you pass `f.input EXTENSION_NAME => true` + # to the input. If so, they will retrieve the values from the model + # if any exists. If you want to enable any of those + # extensions by default, you can change `b.optional` to `b.use`. + + # Calculates maxlength from length validations for string inputs + # and/or database column lengths + b.optional :maxlength + + # Calculate minlength from length validations for string inputs + b.optional :minlength + + # Calculates pattern from format validations for string inputs + b.optional :pattern + + # Calculates min and max from length validations for numeric inputs + b.optional :min_max + + # Calculates readonly automatically from readonly attributes + b.optional :readonly + + ## Inputs + # b.use :input, class: 'input', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :label_input + b.use :hint, wrap_with: { tag: :span, class: :hint } + b.use :error, wrap_with: { tag: :span, class: :error } + + ## full_messages_for + # If you want to display the full error message for the attribute, you can + # use the component :full_error, like: + # + # b.use :full_error, wrap_with: { tag: :span, class: :error } + end + + # The default wrapper to be used by the FormBuilder. + config.default_wrapper = :default + + # Define the way to render check boxes / radio buttons with labels. + # Defaults to :nested for bootstrap config. + # inline: input + label + # nested: label > input + config.boolean_style = :nested + + # Default class for buttons + config.button_class = 'btn' + + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # Use :to_sentence to list all errors for each field. + # config.error_method = :first + + # Default tag used for error notification helper. + config.error_notification_tag = :div + + # CSS class to add for error notification helper. + config.error_notification_class = 'error_notification' + + # Series of attempts to detect a default label method for collection. + # config.collection_label_methods = [ :to_label, :name, :title, :to_s ] + + # Series of attempts to detect a default value method for collection. + # config.collection_value_methods = [ :id, :to_s ] + + # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none. + # config.collection_wrapper_tag = nil + + # You can define the class to use on all collection wrappers. Defaulting to none. + # config.collection_wrapper_class = nil + + # You can wrap each item in a collection of radio/check boxes with a tag, + # defaulting to :span. + # config.item_wrapper_tag = :span + + # You can define a class to use in all item wrappers. Defaulting to none. + # config.item_wrapper_class = nil + + # How the label text should be generated altogether with the required text. + # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" } + + # You can define the class to use on all labels. Default is nil. + # config.label_class = nil + + # You can define the default class to be used on forms. Can be overriden + # with `html: { :class }`. Defaulting to none. + # config.default_form_class = nil + + # You can define which elements should obtain additional classes + # config.generate_additional_classes_for = [:wrapper, :label, :input] + + # Whether attributes are required by default (or not). Default is true. + # config.required_by_default = true + + # Tell browsers whether to use the native HTML5 validations (novalidate form option). + # These validations are enabled in SimpleForm's internal config but disabled by default + # in this configuration, which is recommended due to some quirks from different browsers. + # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations, + # change this configuration to true. + config.browser_validations = false + + # Collection of methods to detect if a file type was given. + # config.file_methods = [ :mounted_as, :file?, :public_filename, :attached? ] + + # Custom mappings for input types. This should be a hash containing a regexp + # to match as key, and the input type that will be used when the field name + # matches the regexp as value. + # config.input_mappings = { /count/ => :integer } + + # Custom wrappers for input types. This should be a hash containing an input + # type as key and the wrapper that will be used for all inputs with specified type. + # config.wrapper_mappings = { string: :prepend } + + # Namespaces where SimpleForm should look for custom input classes that + # override default inputs. + # config.custom_inputs_namespaces << "CustomInputs" + + # Default priority for time_zone inputs. + # config.time_zone_priority = nil + + # Default priority for country inputs. + # config.country_priority = nil + + # When false, do not use translations for labels. + # config.translate_labels = true + + # Automatically discover new inputs in Rails' autoload path. + # config.inputs_discovery = true + + # Cache SimpleForm inputs discovery + # config.cache_discovery = !Rails.env.development? + + # Default class for inputs + # config.input_class = nil + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = 'checkbox' + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true + + # Defines which i18n scope will be used in Simple Form. + # config.i18n_scope = 'simple_form' + + # Defines validation classes to the input_field. By default it's nil. + # config.input_field_valid_class = 'is-valid' + # config.input_field_error_class = 'is-invalid' +end diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb new file mode 100644 --- /dev/null +++ b/config/initializers/simple_form_bootstrap.rb @@ -0,0 +1,439 @@ +# frozen_string_literal: true + +# Please do not make direct changes to this file! +# This generator is maintained by the community around simple_form-bootstrap: +# https://github.com/rafaelfranca/simple_form-bootstrap +# All future development, tests, and organization should happen there. +# Background history: https://github.com/plataformatec/simple_form/issues/1561 + +# Uncomment this and change the path if necessary to include your own +# components. +# See https://github.com/plataformatec/simple_form#custom-components +# to know more about custom components. +# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f } + +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + # Default class for buttons + config.button_class = 'btn' + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = 'form-check-label' + + # How the label text should be generated altogether with the required text. + config.label_text = lambda { |label, required, explicit_label| "#{label} #{required}" } + + # Define the way to render check boxes / radio buttons with labels. + config.boolean_style = :inline + + # You can wrap each item in a collection of radio/check boxes with a tag + config.item_wrapper_tag = :div + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + config.include_default_input_wrapper_class = false + + # CSS class to add for error notification helper. + config.error_notification_class = 'alert alert-danger' + + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # :to_sentence to list all errors for each field. + config.error_method = :to_sentence + + # add validation classes to `input_field` + config.input_field_error_class = 'is-invalid' + config.input_field_valid_class = 'is-valid' + + + # vertical forms + # + # vertical default_wrapper + config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'form-control-label' + b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # vertical input for boolean + config.wrappers :vertical_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb| + bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + bb.use :label, class: 'form-check-label' + bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # vertical input for radio buttons and check boxes + config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| + ba.use :label_text + end + b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # vertical input for inline radio buttons and check boxes + config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| + ba.use :label_text + end + b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # vertical file input + config.wrappers :vertical_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :readonly + b.use :label + b.use :input, class: 'form-control-file', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # vertical multi select + config.wrappers :vertical_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'form-control-label' + b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba| + ba.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid' + end + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # vertical range input + config.wrappers :vertical_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :readonly + b.optional :step + b.use :label + b.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + + # horizontal forms + # + # horizontal default_wrapper + config.wrappers :horizontal_form, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'col-sm-3 col-form-label' + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid' + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # horizontal input for boolean + config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper tag: 'label', class: 'col-sm-3' do |ba| + ba.use :label_text + end + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |wr| + wr.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb| + bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + bb.use :label, class: 'form-check-label' + bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + end + + # horizontal input for radio buttons and check boxes + config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'col-sm-3 form-control-label' + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # horizontal input for inline radio buttons and check boxes + config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'col-sm-3 form-control-label' + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # horizontal file input + config.wrappers :horizontal_file, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :readonly + b.use :label, class: 'col-sm-3 form-control-label' + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, error_class: 'is-invalid', valid_class: 'is-valid' + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # horizontal multi select + config.wrappers :horizontal_multi_select, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'col-sm-3 control-label' + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba| + ba.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |bb| + bb.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid' + end + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # horizontal range input + config.wrappers :horizontal_range, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :readonly + b.optional :step + b.use :label, class: 'col-sm-3 form-control-label' + b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid' + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + + # inline forms + # + # inline default_wrapper + config.wrappers :inline_form, tag: 'span', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'sr-only' + + b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # inline input for boolean + config.wrappers :inline_boolean, tag: 'span', class: 'form-check flex-wrap justify-content-start mr-sm-2', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :label, class: 'form-check-label' + b.use :error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + + # bootstrap custom forms + # + # custom input for boolean + config.wrappers :custom_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox' do |bb| + bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid' + bb.use :label, class: 'custom-control-label' + bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + config.wrappers :custom_boolean_switch, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox-switch' do |bb| + bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid' + bb.use :label, class: 'custom-control-label' + bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + end + + # custom input for radio buttons and check boxes + config.wrappers :custom_collection, item_wrapper_class: 'custom-control', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| + ba.use :label_text + end + b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # custom input for inline radio buttons and check boxes + config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| + ba.use :label_text + end + b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # custom file input + config.wrappers :custom_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :readonly + b.use :label, class: 'form-control-label' + b.wrapper :custom_file_wrapper, tag: 'div', class: 'custom-file' do |ba| + ba.use :input, class: 'custom-file-input', error_class: 'is-invalid', valid_class: 'is-valid' + ba.use :label, class: 'custom-file-label' + ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + end + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # custom multi select + config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'form-control-label' + b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba| + ba.use :input, class: 'custom-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid' + end + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # custom range input + config.wrappers :custom_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :readonly + b.optional :step + b.use :label, class: 'form-control-label' + b.use :input, class: 'custom-range', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + + # Input Group - custom component + # see example app and config at https://github.com/rafaelfranca/simple_form-bootstrap + # config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + # b.use :html5 + # b.use :placeholder + # b.optional :maxlength + # b.optional :minlength + # b.optional :pattern + # b.optional :min_max + # b.optional :readonly + # b.use :label, class: 'form-control-label' + # b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba| + # ba.optional :prepend + # ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid' + # ba.optional :append + # end + # b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } + # b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + # end + + + # Floating Labels form + # + # floating labels default_wrapper + config.wrappers :floating_labels_form, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :minlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :label, class: 'form-control-label' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + # custom multi select + config.wrappers :floating_labels_select, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| + b.use :html5 + b.optional :readonly + b.use :input, class: 'custom-select custom-select-lg', error_class: 'is-invalid', valid_class: 'is-valid' + b.use :label, class: 'form-control-label' + b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' } + b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } + end + + + # The default wrapper to be used by the FormBuilder. + config.default_wrapper = :vertical_form + + # Custom wrappers for input types. This should be a hash containing an input + # type as key and the wrapper that will be used for all inputs with specified type. + config.wrapper_mappings = { + boolean: :vertical_boolean, + check_boxes: :vertical_collection, + date: :vertical_multi_select, + datetime: :vertical_multi_select, + file: :vertical_file, + radio_buttons: :vertical_collection, + range: :vertical_range, + time: :vertical_multi_select + } + + # enable custom form wrappers + # config.wrapper_mappings = { + # boolean: :custom_boolean, + # check_boxes: :custom_collection, + # date: :custom_multi_select, + # datetime: :custom_multi_select, + # file: :custom_file, + # radio_buttons: :custom_collection, + # range: :custom_range, + # time: :custom_multi_select + # } +end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml new file mode 100644 --- /dev/null +++ b/config/locales/simple_form.en.yml @@ -0,0 +1,31 @@ +en: + simple_form: + "yes": 'Yes' + "no": 'No' + required: + text: 'required' + mark: '*' + # You can uncomment the line below if you need to overwrite the whole required html. + # When using html, text and mark won't be used. + # html: '*' + error_notification: + default_message: "Please review the problems below:" + # Examples + # labels: + # defaults: + # password: 'Password' + # user: + # new: + # email: 'E-mail to sign in.' + # edit: + # email: 'E-mail.' + # hints: + # defaults: + # username: 'User name to sign in.' + # password: 'No special characters, please.' + # include_blanks: + # defaults: + # age: 'Rather not say' + # prompts: + # defaults: + # age: 'Select your age' diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -38,6 +38,8 @@ get 'turn_all_on' get 'import' get 'manage' + get 'quick_create' + post 'do_manage' end end @@ -92,6 +94,7 @@ resources :user_admin do collection do match 'bulk_manage', via: [:get, :post] + get 'bulk_mail' get 'user_stat' get 'import' get 'new_list' @@ -100,6 +103,7 @@ get 'active' get 'mass_mailing' match 'create_from_list', via: [:get, :post] + post 'grant_admin' end member do get 'clear_last_ip' diff --git a/lib/templates/haml/scaffold/_form.html.haml b/lib/templates/haml/scaffold/_form.html.haml new file mode 100644 --- /dev/null +++ b/lib/templates/haml/scaffold/_form.html.haml @@ -0,0 +1,12 @@ +-# frozen_string_literal: true += simple_form_for(@<%= singular_table_name %>) do |f| + = f.error_notification + = f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? + + .form-inputs + <%- attributes.each do |attribute| -%> + = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> + <%- end -%> + + .form-actions + = f.button :submit diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/system/announcements_test.rb b/test/system/announcements_test.rb new file mode 100644 --- /dev/null +++ b/test/system/announcements_test.rb @@ -0,0 +1,37 @@ +require "application_system_test_case" + +class AnnouncementsTest < ApplicationSystemTestCase + test "add new announcement" do + visit root_path + fill_in "Login", with: "admin" + fill_in "Password", with: "admin" + click_on "Login" + + assert_text "MAIN" + assert_text "Submission" + + within :css, 'header' do + click_on "Manage" + click_on "Announcements" + end + assert_text "+ Add announcement" + + click_on "Add announcement", match: :first + + fill_in 'Title', with: 'test' + fill_in 'Body', with: 'test body 12345' + check 'Published' + + click_on 'Create' + + visit list_main_path + + assert_text "test body 12345" + + end + # test "visiting the index" do + # visit announcements_url + # + # assert_selector "h1", text: "Announcement" + # end +end diff --git a/test/test_helper.rb b/test/test_helper.rb --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,5 @@ -ENV["RAILS_ENV"] = "test" -require File.expand_path('../../config/environment', __FILE__) +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' require 'rails/test_help' #reporter for beautiful result @@ -22,6 +22,7 @@ # Add more helper methods to be used by all tests here... - self.use_transactional_fixtures = true + self.use_transactional_tests = true + #self.use_instantiated_fixtures = false self.use_instantiated_fixtures = false end