Permalink
Browse files

administracao do toggle e dos services

  • Loading branch information...
1 parent aa8bc7c commit e11e5b89d3408cb56b29b9f2803e4a11f2e764eb Alexander Borges committed Feb 1, 2013
Showing with 4,587 additions and 6 deletions.
  1. +5 −4 .components
  2. +3 −0 Gemfile
  3. +2 −0 Gemfile.lock
  4. +39 −0 admin/app.rb
  5. +47 −0 admin/controllers/accounts.rb
  6. +6 −0 admin/controllers/base.rb
  7. +47 −0 admin/controllers/services.rb
  8. +26 −0 admin/controllers/sessions.rb
  9. +47 −0 admin/controllers/toggles.rb
  10. +40 −0 admin/views/accounts/_form.haml
  11. +15 −0 admin/views/accounts/edit.haml
  12. +31 −0 admin/views/accounts/index.haml
  13. +14 −0 admin/views/accounts/new.haml
  14. +10 −0 admin/views/base/_sidebar.haml
  15. +25 −0 admin/views/base/index.haml
  16. +31 −0 admin/views/layouts/application.haml
  17. +10 −0 admin/views/services/_form.haml
  18. +15 −0 admin/views/services/edit.haml
  19. +31 −0 admin/views/services/index.haml
  20. +14 −0 admin/views/services/new.haml
  21. +30 −0 admin/views/sessions/new.haml
  22. +22 −0 admin/views/toggles/_form.haml
  23. +15 −0 admin/views/toggles/edit.haml
  24. +35 −0 admin/views/toggles/index.haml
  25. +14 −0 admin/views/toggles/new.haml
  26. +2 −0 config/apps.rb
  27. +16 −0 db/migrate/004_create_accounts.rb
  28. +11 −2 db/schema.rb
  29. +28 −0 db/seeds.old
  30. +28 −0 db/seeds.rb
  31. +38 −0 models/account.rb
  32. +95 −0 public/admin/stylesheets/base.css
  33. +364 −0 public/admin/stylesheets/themes/amro/style.css
  34. +290 −0 public/admin/stylesheets/themes/bec-green/style.css
  35. +301 −0 public/admin/stylesheets/themes/bec/style.css
  36. +287 −0 public/admin/stylesheets/themes/blue/style.css
  37. +373 −0 public/admin/stylesheets/themes/default/style.css
  38. +305 −0 public/admin/stylesheets/themes/djime-cerulean/style.css
  39. +279 −0 public/admin/stylesheets/themes/kathleene/style.css
  40. +345 −0 public/admin/stylesheets/themes/olive/style.css
  41. +269 −0 public/admin/stylesheets/themes/orange/style.css
  42. +302 −0 public/admin/stylesheets/themes/reidb-greenish/style.css
  43. +281 −0 public/admin/stylesheets/themes/ruby/style.css
  44. +391 −0 public/admin/stylesheets/themes/warehouse/style.css
  45. 0 public/index.html
  46. +8 −0 spec/models/account_spec.rb
View
@@ -1,7 +1,8 @@
----
-:orm: activerecord
+---
:test: rspec
-:mock: mocha
+:stylesheet: none
+:admin_renderer: haml
:script: none
+:orm: activerecord
+:mock: mocha
:renderer: haml
-:stylesheet: none
View
@@ -4,11 +4,14 @@ source :rubygems
# gem 'thin' # or mongrel
# gem 'trinidad', :platform => 'jruby'
+# gem 'bootstrap-on', :group => :development
+
# Project requirements
gem 'rake'
gem 'sinatra-flash', :require => 'sinatra/flash'
# Component requirements
+gem 'bcrypt-ruby', :require => "bcrypt"
gem 'haml'
gem 'activerecord', :require => "active_record"
gem 'mysql2'
View
@@ -13,6 +13,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
+ bcrypt-ruby (3.0.1)
builder (3.0.4)
diff-lcs (1.1.3)
haml (3.1.7)
@@ -92,6 +93,7 @@ PLATFORMS
DEPENDENCIES
activerecord
+ bcrypt-ruby
haml
mocha
mysql2
View
@@ -0,0 +1,39 @@
+class Admin < Padrino::Application
+ use ActiveRecord::ConnectionAdapters::ConnectionManagement
+ register Padrino::Rendering
+ register Padrino::Mailer
+ register Padrino::Helpers
+ register Padrino::Admin::AccessControl
+
+ ##
+ # Application configuration options
+ #
+ # set :raise_errors, true # Raise exceptions (will stop application) (default for test)
+ # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
+ # set :show_exceptions, true # Shows a stack trace in browser (default for development)
+ # set :logging, true # Logging in STDOUT for development and file for production (default only for development)
+ # set :public_folder, "foo/bar" # Location for static assets (default root/public)
+ # set :reload, false # Reload application files (default in development)
+ # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
+ # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
+ # disable :sessions # Disabled sessions by default (enable if needed)
+ # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
+ #
+
+ set :admin_model, 'Account'
+ set :login_page, "/admin/sessions/new"
+
+ enable :sessions
+ disable :store_location
+
+ access_control.roles_for :any do |role|
+ role.protect "/"
+ role.allow "/sessions"
+ end
+
+ access_control.roles_for :admin do |role|
+ role.project_module :toggles, '/toggles'
+ role.project_module :accounts, '/accounts'
+ end
+end
@@ -0,0 +1,47 @@
+Admin.controllers :accounts do
+
+ get :index do
+ @accounts = Account.all
+ render 'accounts/index'
+ end
+
+ get :new do
+ @account = Account.new
+ render 'accounts/new'
+ end
+
+ post :create do
+ @account = Account.new(params[:account])
+ if @account.save
+ flash[:notice] = 'Account was successfully created.'
+ redirect url(:accounts, :edit, :id => @account.id)
+ else
+ render 'accounts/new'
+ end
+ end
+
+ get :edit, :with => :id do
+ @account = Account.find(params[:id])
+ render 'accounts/edit'
+ end
+
+ put :update, :with => :id do
+ @account = Account.find(params[:id])
+ if @account.update_attributes(params[:account])
+ flash[:notice] = 'Account was successfully updated.'
+ redirect url(:accounts, :edit, :id => @account.id)
+ else
+ render 'accounts/edit'
+ end
+ end
+
+ delete :destroy, :with => :id do
+ account = Account.find(params[:id])
+ if account != current_account && account.destroy
+ flash[:notice] = 'Account was successfully destroyed.'
+ else
+ flash[:error] = 'Unable to destroy Account!'
+ end
+ redirect url(:accounts, :index)
+ end
+end
@@ -0,0 +1,6 @@
+Admin.controllers :base do
+
+ get :index, :map => "/" do
+ render "base/index"
+ end
+end
@@ -0,0 +1,47 @@
+Admin.controllers :services do
+
+ get :index do
+ @services = Service.all
+ render 'services/index'
+ end
+
+ get :new do
+ @service = Service.new
+ render 'services/new'
+ end
+
+ post :create do
+ @service = Service.new(params[:service])
+ if @service.save
+ flash[:notice] = 'Service was successfully created.'
+ redirect url(:services, :edit, :id => @service.id)
+ else
+ render 'services/new'
+ end
+ end
+
+ get :edit, :with => :id do
+ @service = Service.find(params[:id])
+ render 'services/edit'
+ end
+
+ put :update, :with => :id do
+ @service = Service.find(params[:id])
+ if @service.update_attributes(params[:service])
+ flash[:notice] = 'Service was successfully updated.'
+ redirect url(:services, :edit, :id => @service.id)
+ else
+ render 'services/edit'
+ end
+ end
+
+ delete :destroy, :with => :id do
+ service = Service.find(params[:id])
+ if service.destroy
+ flash[:notice] = 'Service was successfully destroyed.'
+ else
+ flash[:error] = 'Unable to destroy Service!'
+ end
+ redirect url(:services, :index)
+ end
+end
@@ -0,0 +1,26 @@
+Admin.controllers :sessions do
+
+ get :new do
+ render "/sessions/new", nil, :layout => false
+ end
+
+ post :create do
+ if account = Account.authenticate(params[:email], params[:password])
+ set_current_account(account)
+ redirect url(:base, :index)
+ elsif Padrino.env == :development && params[:bypass]
+ account = Account.first
+ set_current_account(account)
+ redirect url(:base, :index)
+ else
+ params[:email], params[:password] = h(params[:email]), h(params[:password])
+ flash[:warning] = "Login or password wrong."
+ redirect url(:sessions, :new)
+ end
+ end
+
+ delete :destroy do
+ set_current_account(nil)
+ redirect url(:sessions, :new)
+ end
+end
@@ -0,0 +1,47 @@
+Admin.controllers :toggles do
+
+ get :index do
+ @toggles = Toggle.all
+ render 'toggles/index'
+ end
+
+ get :new do
+ @toggle = Toggle.new
+ render 'toggles/new'
+ end
+
+ post :create do
+ @toggle = Toggle.new(params[:toggle])
+ if @toggle.save
+ flash[:notice] = 'Toggle was successfully created.'
+ redirect url(:toggles, :edit, :id => @toggle.id)
+ else
+ render 'toggles/new'
+ end
+ end
+
+ get :edit, :with => :id do
+ @toggle = Toggle.find(params[:id])
+ render 'toggles/edit'
+ end
+
+ put :update, :with => :id do
+ @toggle = Toggle.find(params[:id])
+ if @toggle.update_attributes(params[:toggle])
+ flash[:notice] = 'Toggle was successfully updated.'
+ redirect url(:toggles, :edit, :id => @toggle.id)
+ else
+ render 'toggles/edit'
+ end
+ end
+
+ delete :destroy, :with => :id do
+ toggle = Toggle.find(params[:id])
+ if toggle.destroy
+ flash[:notice] = 'Toggle was successfully destroyed.'
+ else
+ flash[:error] = 'Unable to destroy Toggle!'
+ end
+ redirect url(:toggles, :index)
+ end
+end
@@ -0,0 +1,40 @@
+.group
+ =f.label :name
+ =f.error_message_on :name
+ =f.text_field :name, :class => :text_field
+ %span.description Ex: a simple text
+
+.group
+ =f.label :surname
+ =f.error_message_on :surname
+ =f.text_field :surname, :class => :text_field
+ %span.description Ex: a simple text
+
+.group
+ =f.label :email
+ =f.error_message_on :email
+ =f.text_field :email, :class => :text_field
+ %span.description Ex: a simple text
+
+.group
+ =f.label :password
+ =f.error_message_on :password
+ =f.password_field :password, :class => :password_field
+ %span.description Ex: a simple text
+
+.group
+ =f.label :password_confirmation
+ =f.error_message_on :password_confirmation
+ =f.password_field :password_confirmation, :class => :password_field
+ %span.description Ex: a simple text
+
+.group
+ =f.label :role
+ =f.error_message_on :role
+ =f.select :role, :options => access_control.roles
+ %span.description Ex: a simple text
+
+
+.group.navform.wat-cf
+ =f.submit pat(:save), :class => :button
+ =f.submit pat(:cancel), :onclick => "window.location='#{url(:accounts, :index)}';return false", :class => :button
@@ -0,0 +1,15 @@
+.block
+ .secondary-navigation
+ %ul.wat-cf
+ %li.first=link_to pat(:list), url(:accounts, :index)
+ %li=link_to pat(:new), url(:accounts, :new)
+ %li.active=link_to pat(:edit), url(:accounts, :edit, :id => @account.id)
+ .content
+ %h2.title
+ =pat(:edit)
+ =mt(:account)
+ .inner
+ -form_for :account, url(:accounts, :update, :id => @account.id), :method => :put, :class => :form do |f|
+ =partial "accounts/form", :locals => { :f => f }
+
+-content_for :sidebar, partial("base/sidebar")
@@ -0,0 +1,31 @@
+.block
+ .secondary-navigation
+ %ul.wat-cf
+ %li.first.active=link_to pat(:list), url(:accounts, :index)
+ %li=link_to pat(:new), url(:accounts, :new)
+ .content
+ %h2.title
+ =pat(:all)
+ =mt(:accounts)
+ .inner
+ %table.table
+ %tr
+ %th.first=mat(:account, :id)
+ %th=mat(:account, :name)
+ %th=mat(:account, :surname)
+ %th=mat(:account, :email)
+ %th.last="&nbsp;"
+ -@accounts.each do |account|
+ %tr
+ %td.first=account.id
+ %td=account.name
+ %td=account.surname
+ %td=account.email
+ %td.last
+ =button_to pat(:edit), url(:accounts, :edit, :id => account.id), :method => :get, :class => :button_to
+ ="|"
+ =button_to pat(:delete), url(:accounts, :destroy, :id => account.id), :method => :delete, :class => :button_to, :onsubmit => "return confirm('#{pat(:confirm)}')"
+ .actions-bar.wat-cf
+ .actions="&nbsp;"
+
+-content_for :sidebar, partial("base/sidebar")
@@ -0,0 +1,14 @@
+.block
+ .secondary-navigation
+ %ul.wat-cf
+ %li.first=link_to pat(:list), url(:accounts, :index)
+ %li.active=link_to pat(:new), url(:accounts, :new)
+ .content
+ %h2.title
+ =pat(:new)
+ =mt(:account)
+ .inner
+ -form_for :account, url(:accounts, :create), :class => :form do |f|
+ =partial "accounts/form", :locals => { :f => f }
+
+-content_for :sidebar, partial("base/sidebar")
@@ -0,0 +1,10 @@
+.block
+ %h3 Feature Toggle Admin
+ .content
+ %p
+ Servico de configuracao de features
+.block
+ %h3 Links
+ %ul.navigation
+ %li=link_to("Toggles", "/admin/toggles")
+ %li=link_to("Services", "/admin/services")
Oops, something went wrong.

0 comments on commit e11e5b8

Please sign in to comment.