Skip to content

Commit

Permalink
TB-2 Admin and user profiles added
Browse files Browse the repository at this point in the history
  • Loading branch information
hamitturkukaya committed Apr 18, 2014
1 parent 0c4f887 commit 0f86715
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 105 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea/
*.gem
*.gem
*.log
.bundle/
*.bundle/install.log
74 changes: 55 additions & 19 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,27 @@ def generate_exception_notification

def add_exception_notification_to_environments
config = <<-CODE
config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier" <[email protected]>},
:exception_recipients => %w{[email protected]}
}
config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier" <[email protected]>},
:exception_recipients => %w{[email protected]}
}
CODE

configure_environment('production', config)
configure_environment('staging', config)

inject_into_file 'config/initializers/exception_notification.rb', :before => 'config.add_notifier :email, {' do <<-RUBY
unless Rails.env == 'development'
RUBY
end

inject_into_file 'config/initializers/exception_notification.rb', :before => '# Campfire notifier sends notifications to your Campfire room.' do <<-RUBY
end
RUBY
end

end

def leftovers
Expand Down Expand Up @@ -252,33 +262,30 @@ def generate_hq_namespace
def setup_profile_editors
# Inserting routes
inject_into_file 'config/routes.rb', :after => "namespace :hq do\n" do <<-RUBY
# Routing for admin profile editing
match '/profile', to: 'profile#edit', via: :get
match '/profile', to: 'profile#update', via: [:patch, :put]
root to: 'dashboard#index'
resource :admin_profile, except: [:destroy], path: 'profile'
RUBY
end

inject_into_file 'config/routes.rb', :after => "'welcome#index'\n" do <<-RUBY
# Routing for user profile editing
match '/profile', to: 'profile#edit', via: :get
match '/profile', to: 'profile#update', via: [:patch, :put]
resource :user_profile, except: [:destroy], path: 'profile'
RUBY
end

# Copying HAML templates
copy_file 'app/views/hq/profile/edit.html.haml', 'app/views/hq/profile/edit.html.haml'
copy_file 'app/views/profile/edit.html.haml', 'app/views/profile/edit.html.haml'

copy_file 'app/controllers/profile_controller.rb', 'app/controllers/profile_controller.rb'
end

def set_time_zone
add_set_user_time_zone_method_to_application_controller
add_time_zone_to_user
end

def create_profile
add_profile_models
add_profile_controllers
add_profile_views
end

def create_hierapolis_theme
remove_file 'lib/templates/rails/responders_controller/controller.rb'
remove_file 'lib/templates/haml/scaffold/_form.html.haml'
Expand Down Expand Up @@ -420,6 +427,12 @@ def add_time_zone_to_user
generate 'migration AddTimeZoneToUser time_zone:string -s'
end

def add_profile_models
say 'Creating Profile Models'
generate 'model user_profile first_name:string last_name:string gsm:string user:references -s'
generate 'model admin_profile first_name:string last_name:string gsm:string admin:references -s'
end

def add_set_user_time_zone_method_to_application_controller
say 'Add set_user_time_zone method to application controller'
inject_into_file 'app/controllers/application_controller.rb', :after => 'protected' do <<-CODE
Expand All @@ -433,9 +446,32 @@ def set_user_time_zone
inject_into_file 'app/controllers/application_controller.rb', :after => 'class ApplicationController < ActionController::Base' do <<-CODE
before_filter :set_user_time_zone
respond_to :html, :json
CODE
end
end

def add_profile_controllers
copy_file 'app/controllers/hq/admin_profiles_controller.rb', 'app/controllers/hq/admin_profiles_controller.rb'
copy_file 'app/controllers/user_profiles_controller.rb', 'app/controllers/user_profiles_controller.rb'
end

def add_profile_views
directory 'app/views/hq/admin_profiles', 'app/views/hq/admin_profiles'
directory 'app/views/user_profiles', 'app/views/user_profiles'

inject_into_file 'app/models/user.rb', :after => ":recoverable, :rememberable, :trackable, :validatable\n" do <<-RUBY
has_one :user_profile
accepts_nested_attributes_for :user_profile
RUBY
end

inject_into_file 'app/models/admin.rb', :after => ":recoverable, :rememberable, :trackable, :validatable\n" do <<-RUBY
has_one :admin_profile
accepts_nested_attributes_for :admin_profile
RUBY
end
end
end
end
7 changes: 7 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def customization
invoke :setup_devise
invoke :setup_time_zone
invoke :setup_bullet_config
invoke :setup_hq_namespace
invoke :setup_profiles
end

def customize_gemfile
Expand Down Expand Up @@ -174,6 +176,11 @@ def setup_time_zone
build :set_time_zone
end

def setup_profiles
say 'Setup profiles'
build :create_profile
end

def run_bundle
end

Expand Down
46 changes: 46 additions & 0 deletions templates/app/controllers/hq/admin_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# encoding: UTF-8
class Hq::AdminProfilesController < Hq::ApplicationController
before_action :set_admin_profile, only: [:show, :edit, :update, :destroy]
add_breadcrumb I18n.t('activerecord.models.admin_profiles'), :hq_admin_profile_path

def show
if current_admin.admin_profile.present?
add_breadcrumb @admin_profile.first_name, hq_admin_profile_path
respond_with([:hq, @admin_profile])
else
redirect_to new_hq_admin_profile_path
end
end

def new
add_breadcrumb t('tooltips.new'), new_hq_admin_profile_path
@admin_profile = current_admin.build_admin_profile
respond_with([:hq, @admin_profile])
end

def edit
add_breadcrumb @admin_profile.id, hq_admin_profile_path
add_breadcrumb t('tooltips.edit'), edit_hq_admin_profile_path
end

def create
@admin_profile = current_admin.build_admin_profile(admin_profile_params)
@admin_profile.save
respond_with([:hq, @admin_profile], location: hq_admin_profile_path)
end

def update
@admin_profile.update(admin_profile_params)
respond_with([:hq, @admin_profile], location: hq_admin_profile_path)
end

private

def set_admin_profile
@admin_profile = current_admin.admin_profile
end

def admin_profile_params
params.require(:admin_profile).permit(:first_name, :gsm, :last_name)
end
end
25 changes: 0 additions & 25 deletions templates/app/controllers/hq/profile_controller.rb

This file was deleted.

26 changes: 0 additions & 26 deletions templates/app/controllers/profile_controller.rb

This file was deleted.

46 changes: 46 additions & 0 deletions templates/app/controllers/user_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# encoding: UTF-8
class UserProfilesController < ApplicationController
before_action :set_user_profile, only: [:show, :edit, :update, :destroy]
add_breadcrumb I18n.t('activerecord.models.user_profiles'), :user_profile_path

def show
if current_user.user_profile.present?
add_breadcrumb @user_profile.first_name, user_profile_path
respond_with(@user_profile)
else
redirect_to new_user_profile_path
end
end

def new
add_breadcrumb t('tooltips.new'), new_user_profile_path
@user_profile = current_user.build_user_profile
respond_with(@user_profile)
end

def edit
add_breadcrumb @user_profile.id, user_profile_path
add_breadcrumb t('tooltips.edit'), edit_user_profile_path
end

def create
@user_profile = current_user.build_user_profile(user_profile_params)
@user_profile.save
respond_with(@user_profile, location: user_profile_path)
end

def update
@user_profile.update(user_profile_params)
respond_with(@user_profile, location: user_profile_path)
end

private

def set_user_profile
@user_profile = current_user.user_profile
end

def user_profile_params
params.require(:user_profile).permit(:first_name, :gsm, :last_name)
end
end
15 changes: 15 additions & 0 deletions templates/app/views/hq/admin_profiles/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.panel.panel-default
.panel-heading
%i.icon-edit.icon-large
= yield :form_title
.panel-body
= simple_form_for([:hq, @admin_profile], url: hq_admin_profile_path) do |f|
= f.error_notification

.form-inputs
= f.input :first_name
= f.input :last_name
= f.input :gsm
.form-actions
= f.button :submit, class: 'btn btn-default'
= link_to t('cancel'), hq_admin_profile_path, class: 'btn'
3 changes: 3 additions & 0 deletions templates/app/views/hq/admin_profiles/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- content_for :form_title do
= t('tt.edit', resource_name: AdminProfile.model_name.human)
= render 'form'
3 changes: 3 additions & 0 deletions templates/app/views/hq/admin_profiles/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- content_for :form_title do
= t('tt.new', resource_name: AdminProfile.model_name.human)
= render 'form'
13 changes: 13 additions & 0 deletions templates/app/views/hq/admin_profiles/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- content_for :toolbar do
= link_to edit_hq_admin_profile_path, class: 'btn btn-default' do
%i.icon-pencil
= t('action_button.edit')
.panel.panel-default
.panel-heading
%i.icon-edit.icon-large
= t('tt.show', resource_name: AdminProfile.model_name.human)
.panel-body
= show_for @admin_profile do |s|
= s.attribute :first_name
= s.attribute :last_name
= s.attribute :gsm
17 changes: 0 additions & 17 deletions templates/app/views/hq/profile/edit.html.haml

This file was deleted.

17 changes: 0 additions & 17 deletions templates/app/views/profile/edit.html.haml

This file was deleted.

16 changes: 16 additions & 0 deletions templates/app/views/user_profiles/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.panel.panel-default
.panel-heading
%i.icon-edit.icon-large
= yield :form_title
.panel-body
= simple_form_for(@user_profile, url: user_profile_path) do |f|
= f.error_notification

.form-inputs
= f.input :first_name
= f.input :last_name
= f.input :gsm

.form-actions
= f.button :submit, class: 'btn btn-default'
= link_to t('cancel'), user_profile_path, class: 'btn'
Loading

0 comments on commit 0f86715

Please sign in to comment.