From 58e471830cdc32979e11942c049ca1696f86fd15 Mon Sep 17 00:00:00 2001 From: Danilo Resende Date: Mon, 4 Jun 2012 10:00:08 -0300 Subject: [PATCH] Organiznado locales/interface --- Gemfile | 1 + README.rdoc | 5 +- app/controllers/application_controller.rb | 2 +- app/models/permission.rb | 6 +- app/models/role.rb | 8 +- app/views/admin/projects/index.html.erb | 26 ++-- app/views/admin/users/show.html.erb | 53 ------- app/views/projects/index.html.erb | 12 +- app/views/session/new.html.erb | 28 ++-- app/views/shared/_form_errors.html.erb | 13 ++ app/views/users/edit.html.erb | 36 +---- app/views/users/index.html.erb | 13 +- app/views/users/new.html.erb | 41 +---- config/initializers/simple_form.rb | 178 ++++++++++++++++++++++ config/locales/simple_form.en.yml | 26 ++++ config/locales/views/defaults/pt-BR.yml | 5 + config/locales/views/projects/pt-BR.yml | 2 + config/locales/views/session/pt-BR.yml | 5 + config/locales/views/users/pt-BR.yml | 2 + config/routes.rb | 2 +- lib/cranelift.rb | 1 + lib/templates/erb/scaffold/_form.html.erb | 13 ++ 22 files changed, 322 insertions(+), 156 deletions(-) delete mode 100644 app/views/admin/users/show.html.erb create mode 100644 app/views/shared/_form_errors.html.erb create mode 100644 config/initializers/simple_form.rb create mode 100644 config/locales/simple_form.en.yml create mode 100644 config/locales/views/session/pt-BR.yml create mode 100644 lib/templates/erb/scaffold/_form.html.erb diff --git a/Gemfile b/Gemfile index 589e8d2..501a9bd 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'sqlite3' gem 'bootstrap-sass', '~> 2.0.3' gem 'kaminari' +gem 'simple_form' # Gems used only for assets and not required # in production environments by default. diff --git a/README.rdoc b/README.rdoc index 120e515..0910e17 100644 --- a/README.rdoc +++ b/README.rdoc @@ -7,8 +7,11 @@ Um Projeto do Cercomp... Twitter Bootstrap SCSS http://railsapps.github.com/twitter-bootstrap-rails.html +Simple-form c/ Bootstrap + https://github.com/plataformatec/simple_form + Alguma documentação dos bindings SVN http://www.cs.toronto.edu/~james/svn/ruby_docs.html Datepicker p/ bootstrap - http://www.eyecon.ro/bootstrap-datepicker/ \ No newline at end of file + http://www.eyecon.ro/bootstrap-datepicker/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3927917..8959536 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,7 +45,7 @@ def can?(action, controller) return false if current_user.role.nil? current_user.role.permissions.each do |permission| - if permission.controller == controller and permission.actions.split.include?(action) + if permission[:controller] == controller and permission[:actions].split.include?(action) return true break end diff --git a/app/models/permission.rb b/app/models/permission.rb index 789c4ee..90847ab 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -1,12 +1,12 @@ # encoding: utf-8 class Permission @@defaults = { - gerente: [ + 'Gerente' => [ { name: 'Gerenciar Projetos', controller: 'projects', actions: 'all' }, { name: 'Gerenciar Usuários', controller: 'users', actions: 'all' }, - { name: 'Gerenciar Ips', controller: 'ips', actions: 'all' } + { name: 'Gerenciar Ips', controller: 'ips', actions: 'all' } ], - comum: [ + 'Usuário Comum' => [ { name: 'Visualizer Projeto', controller: 'projects', actions: 'show' }, { name: 'Visualizar Usuário', controller: 'users', actions: 'show' } ] diff --git a/app/models/role.rb b/app/models/role.rb index dd4a81b..4ed31ac 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -10,13 +10,13 @@ class Role < ActiveRecord::Base :uniqueness => true, :length => {:in => 3..32} + def permissions + return Permission::defaults[name] + end + def self.defaults gerente = Role.find_or_create_by_name('Gerente', :description => 'Gerencia o sistema') - gerente.permissions = Permission::defaults[:gerente] - comum = Role.find_or_create_by_name('Usuário Comum', :description => 'Usuário comum do sistema') - comum.permissions = Permission.defaults[:comum] - { gerente: gerente, comum: comum } end end diff --git a/app/views/admin/projects/index.html.erb b/app/views/admin/projects/index.html.erb index aa646b7..47e2e10 100644 --- a/app/views/admin/projects/index.html.erb +++ b/app/views/admin/projects/index.html.erb @@ -1,25 +1,29 @@

Listing projects

- +
- - - - - + + + <% @projects.each do |project| %> - + - - - + + <% end %>
NameDescription<%= t('name', :scope => 'activerecord.attributes.project') %><%= t('description', :scope => 'activerecord.attributes.project') %><%= t('actions', :scope => 'application') %>
<%= project.name %> <%= project.description %><%= link_to 'Show', [:admin, project] %><%= link_to 'Edit', edit_admin_project_path(project) %><%= link_to 'Destroy', [:admin, project], confirm: 'Are you sure?', method: :delete %><%= link_to t('edit', :scope => 'application'), edit_admin_project_path(project) %><%= link_to t('destroy', :scope => 'application'), + [:admin, project], confirm: 'Are you sure?', method: :delete %>

-<%= link_to 'New Project', new_admin_project_path %> + + +<%= link_to t('new_obj', :scope => 'application', :obj => t('activerecord.models.project')), new_admin_project_path %> diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb deleted file mode 100644 index f401822..0000000 --- a/app/views/admin/users/show.html.erb +++ /dev/null @@ -1,53 +0,0 @@ -

- Login: - <%= @user.login %> -

- -

- Password: - <%= @user.password %> -

- -

- Password confirmation: - <%= @user.password_confirmation %> -

- -

- Admin: - <%= @user.admin %> -

- -

- Rele: - <%= @user.role_id %> -

- -

- Ip block: - <%= @user.ip_block %> -

- -

- Name: - <%= @user.name %> -

- -

- Email: - <%= @user.email %> -

- -

- Active: - <%= @user.active %> -

- -

- Login type: - <%= @user.login_type %> -

- - -<%= link_to 'Edit', edit_admin_user_path(@user) %> | -<%= link_to 'Back', admin_users_path %> diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index f31b6ea..652f6b3 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -1,12 +1,10 @@ -

Listing projects

+

<%= t('.title') %>

- +
- - - - - + + + <% @projects.each do |project| %> diff --git a/app/views/session/new.html.erb b/app/views/session/new.html.erb index b4d000b..925d915 100644 --- a/app/views/session/new.html.erb +++ b/app/views/session/new.html.erb @@ -1,16 +1,20 @@

Login

-<%= form_tag login_path do %> -

- <%= label_tag :login %> - <%= text_field_tag :login %> -

+<%= form_tag login_path, :class => 'form-horizontal' do %> +
+ <%= label_tag :login, t('.login'), :class => 'control-label' %> +
+ <%= text_field_tag :login %> +
+
-

- <%= label_tag :password %> - <%= password_field_tag :password %> -

+
+ <%= label_tag :password, t('.password'), :class => 'control-label' %> +
+ <%= password_field_tag :password %> +
+
-

- <%= submit_tag :login %> -

+
+ <%= submit_tag :login, :class => 'btn btn-primary' %> +
<% end %> diff --git a/app/views/shared/_form_errors.html.erb b/app/views/shared/_form_errors.html.erb new file mode 100644 index 0000000..df2bb4e --- /dev/null +++ b/app/views/shared/_form_errors.html.erb @@ -0,0 +1,13 @@ +<% if object.errors.any? %> +
+ <% # TODO internacionalização aki %> +

<%= pluralize(object.errors.count, "erro") %> impediram esse objeto de ser salvo:

+ + +
+<% end %> + diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 2d31a8d..b766063 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,33 +1,13 @@

<%= t('.title') %>

+
-<%= form_for(@user) do |f| %> - <% if @user.errors.any? %> -
-

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

+<%= simple_form_for(@user, :html => { :class => 'form-horizontal' } ) do |f| %> + + <%= f.input :name %> + <%= f.input :password %> + <%= f.input :password_confirmation %> - -
- <% end %> - -
- <%= f.label :name %> - <%= f.text_field :name %> -
-
- <%= f.label :password %> - <%= f.password_field :password %> -
-
- <%= f.label :password_confirmation %> - <%= f.password_field :password_confirmation %> +
+ <%= f.button :submit, :class => 'btn-primary' %>
- -
- <%= f.submit %> -
- <% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 2e51bca..c415a7e 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,6 +1,6 @@

<%= t('.title') %>

-
NameDescription<%= t('name', :scope => 'activerecord.attributes.project') %><%= t('description', :scope => 'activerecord.attributes.project') %><%= t('actions', :scope => 'application') %>
+
@@ -8,10 +8,19 @@ <% @users.each do |user| %> - + <% attrs = "data-url='#{url_for(edit_admin_user_path(user))}' style='cursor: pointer'" if current_user.admin? %> + > <% end %>
Nome Papel
<%= user.name %> <%= user.role.try(:name) %> <%= user.email %>
+ +<% if current_user.admin? %> + +<% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 60c8c38..4ac48da 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,39 +1,14 @@

Cadastro de Usuário

-<%= form_for @user do |f| %> - <% if @user.errors.any? %> -
-

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

+<%= simple_form_for(@user, :html => {:class => 'form-horizontal'}) do |f| %> - -
- <% end %> + <%= f.input :login %> + <%= f.input :name %> + <%= f.input :email %> + <%= f.input :password %> + <%= f.input :password_confirmation %> -
- <%= f.label :login %> - <%= f.text_field :login %> -
-
- <%= f.label :name %> - <%= f.text_field :name %> -
-
- <%= f.label :email %> - <%= f.text_field :email %> -
-
- <%= f.label :password %> - <%= f.password_field :password %> -
-
- <%= f.label :password_confirmation %> - <%= f.password_field :password_confirmation %> -
-
- <%= f.submit %> +
+ <%= f.button :submit, :class => 'btn-primary' %>
<% end %> diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb new file mode 100644 index 0000000..a9c3852 --- /dev/null +++ b/config/initializers/simple_form.rb @@ -0,0 +1,178 @@ +# 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 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 => :lookup` + # to the input. If so, they will retrieve the values from the model + # if any exists. If you want to enable the lookup for any of those + # extensions by default, you can change `b.optional` to `b.use`. + + # Calculates maxlength from length validations for string inputs + b.optional :maxlength + + # 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 :label_input + b.use :hint, :wrap_with => { :tag => :span, :class => :hint } + b.use :error, :wrap_with => { :tag => :span, :class => :error } + end + + config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b| + b.use :html5 + b.use :placeholder + b.use :label + b.wrapper :tag => 'div', :class => 'controls' do |ba| + ba.use :input + ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } + ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + end + end + + config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b| + b.use :html5 + b.use :placeholder + b.use :label + b.wrapper :tag => 'div', :class => 'controls' do |input| + input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend| + prepend.use :input + end + input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' } + input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } + end + end + + config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b| + b.use :html5 + b.use :placeholder + b.use :label + b.wrapper :tag => 'div', :class => 'controls' do |input| + input.wrapper :tag => 'div', :class => 'input-append' do |append| + append.use :input + end + input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' } + input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } + end + end + + # Wrappers for forms and inputs using the Twitter Bootstrap toolkit. + # Check the Bootstrap docs (http://twitter.github.com/bootstrap) + # to learn about the different styles for forms and inputs, + # buttons and other elements. + config.default_wrapper = :bootstrap + + # 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 = 'alert alert-error' + + # ID to add for error notification helper. + # config.error_notification_id = nil + + # 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. Please note that when using :boolean_style = :nested, + # SimpleForm will force this option to be a label. + # 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| "#{required} #{label}" } + + # You can define the class to use on all labels. Default is nil. + config.label_class = 'control-label' + + # You can define the class to use on all forms. Default is simple_form. + # config.form_class = :simple_form + + # 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 default HTML5 validations (novalidate option). + # Default is enabled. + config.browser_validations = false + + # Collection of methods to detect if a file type was given. + # config.file_methods = [ :mounted_as, :file?, :public_filename ] + + # 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 } + + # Default priority for time_zone inputs. + # config.time_zone_priority = nil + + # Default priority for country inputs. + # config.country_priority = nil + + # Default size for text inputs. + # config.default_input_size = 50 + + # 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? +end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml new file mode 100644 index 0000000..0df11fe --- /dev/null +++ b/config/locales/simple_form.en.yml @@ -0,0 +1,26 @@ +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:" + # Labels and hints 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.' + diff --git a/config/locales/views/defaults/pt-BR.yml b/config/locales/views/defaults/pt-BR.yml index 9d13144..2895ccb 100644 --- a/config/locales/views/defaults/pt-BR.yml +++ b/config/locales/views/defaults/pt-BR.yml @@ -10,6 +10,11 @@ pt-BR: obj_successfully_updated: "%{obj} atualizado com sucesso!" obj_successfully_destroyed: "%{obj} removido com sucesso!" ip_not_allowed: Seu IP não é liberado para acessar a aplicação + actions: Ações + show: Mostrar + edit: Editar + destroy: Remover + new_obj: "Novo %{obj}" layouts: application: login: Login diff --git a/config/locales/views/projects/pt-BR.yml b/config/locales/views/projects/pt-BR.yml index f1fb06d..5008856 100644 --- a/config/locales/views/projects/pt-BR.yml +++ b/config/locales/views/projects/pt-BR.yml @@ -1,2 +1,4 @@ pt-BR: projects: + index: + title: 'Lista de projetos' diff --git a/config/locales/views/session/pt-BR.yml b/config/locales/views/session/pt-BR.yml new file mode 100644 index 0000000..54eefdf --- /dev/null +++ b/config/locales/views/session/pt-BR.yml @@ -0,0 +1,5 @@ +pt-BR: + session: + new: + login: Login + password: Senha diff --git a/config/locales/views/users/pt-BR.yml b/config/locales/views/users/pt-BR.yml index 4e7e8da..86d5268 100644 --- a/config/locales/views/users/pt-BR.yml +++ b/config/locales/views/users/pt-BR.yml @@ -1,5 +1,7 @@ pt-BR: users: + index: + title: Lista de Usuários Cadastrados no Sistema new: title: Cadastro de Usuário edit: diff --git a/config/routes.rb b/config/routes.rb index e6bddc0..a3da771 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ # Users routes get 'editaccount' => 'users#edit' - resources :users, :except => [:destroy, :edit], :path_names => { + resources :users, :except => [:show, :destroy, :edit], :path_names => { :new => :signup } do end diff --git a/lib/cranelift.rb b/lib/cranelift.rb index 54e7031..2629790 100644 --- a/lib/cranelift.rb +++ b/lib/cranelift.rb @@ -1,3 +1,4 @@ +require 'net/https' require 'svn/client' module Cranelift diff --git a/lib/templates/erb/scaffold/_form.html.erb b/lib/templates/erb/scaffold/_form.html.erb new file mode 100644 index 0000000..201a069 --- /dev/null +++ b/lib/templates/erb/scaffold/_form.html.erb @@ -0,0 +1,13 @@ +<%%= simple_form_for(@<%= singular_table_name %>) do |f| %> + <%%= f.error_notification %> + +
+ <%- attributes.each do |attribute| -%> + <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %> + <%- end -%> +
+ +
+ <%%= f.button :submit %> +
+<%% end %>