From e6d6824991ee3cb22bb1d95a03d2e03617cb7831 Mon Sep 17 00:00:00 2001 From: luke-schleicher Date: Mon, 13 Feb 2017 12:03:01 -0600 Subject: [PATCH 1/4] fixed user account pull request issues --- app/views/advisors/_delete_advisor.html.erb | 2 +- app/views/advisors/index.html.erb | 2 +- app/views/devise/shared/_links.html.erb | 4 ---- config/locales/devise.en.yml | 2 +- config/routes.rb | 4 +++- spec/features/advisor_spec.rb | 13 ++++++++----- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/views/advisors/_delete_advisor.html.erb b/app/views/advisors/_delete_advisor.html.erb index cd10203..d966e48 100644 --- a/app/views/advisors/_delete_advisor.html.erb +++ b/app/views/advisors/_delete_advisor.html.erb @@ -1 +1 @@ -<%= link_to "Delete Advisor?", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?" } %> \ No newline at end of file +<%= button_to "Delete", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?"} %> \ No newline at end of file diff --git a/app/views/advisors/index.html.erb b/app/views/advisors/index.html.erb index e2a823f..fb341a8 100644 --- a/app/views/advisors/index.html.erb +++ b/app/views/advisors/index.html.erb @@ -6,7 +6,7 @@ Last Name Email Admin Status - Delete + Delete? <% @advisors.each do |advisor| %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 5cc7e44..6f4bef4 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -2,10 +2,6 @@ <%= link_to "Log in", new_session_path(resource_name) %>
<% end -%> - - <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> <%= link_to "Forgot your password?", new_password_path(resource_name) %>
<% end -%> diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index e9a0665..41479e0 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -38,7 +38,7 @@ en: destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." signed_up_as_admin: "Admin successfully added." signed_up_as_advisor: "Advisor successfully added." - signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_inactive: "Advisor successfully signed up. However, we could not sign advisor in because their account is not yet activated." signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." diff --git a/config/routes.rb b/config/routes.rb index 1696dd8..75e2d55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ get 'advisors/sign_out', to: 'advisors/sessions#destroy' end + resources :advisors, only: [:index, :update, :destroy] + scope :api do scope :v1 do resources :students @@ -19,6 +21,6 @@ get 'angular_app/index' - resources :advisors, only: [:index, :update, :destroy] + end diff --git a/spec/features/advisor_spec.rb b/spec/features/advisor_spec.rb index eedc41f..654f0e4 100644 --- a/spec/features/advisor_spec.rb +++ b/spec/features/advisor_spec.rb @@ -192,16 +192,16 @@ end scenario 'it deletes the advisor', js: true do - expect{ click_on('Delete Advisor?') }.to change(Advisor, :count).by(-1) + expect{ click_on('Delete') }.to change(Advisor, :count).by(-1) end scenario 'it renders a flash message', js: true do - click_on('Delete Advisor?') + click_on('Delete') expect(page).to have_css('#flash') end scenario 'it remains on the advisors index page', js: true do - click_on('Delete Advisor?') + click_on('Delete') expect(current_path).to eq(advisors_path) end @@ -216,8 +216,11 @@ click_on('View advisors') end - scenario 'it does not display a delete link', js: true do - expect(page).to_not have_content('Delete Advisor?') + scenario 'it does not display a delete link', js: true, test_me: true do + + within(:css, "td:last-child") do + expect(page).to_not have_content('Delete') + end end end From 3bc4a6c6189e12d5ee02303da1577758e159ec51 Mon Sep 17 00:00:00 2001 From: luke-schleicher Date: Mon, 13 Feb 2017 12:45:20 -0600 Subject: [PATCH 2/4] made basic navbar --- app/assets/javascripts/app.js | 14 +++++++++++ .../controllers/AdvisorsIndexCtrl.js | 5 ++++ app/views/angular_app/index.html.erb | 2 +- public/templates/advisors.html | 0 public/templates/dashboard-header.html | 25 +++++++++++++------ public/templates/dashboard-main.html | 1 - 6 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/controllers/AdvisorsIndexCtrl.js create mode 100644 public/templates/advisors.html diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js index 2f323ac..cc855e9 100644 --- a/app/assets/javascripts/app.js +++ b/app/assets/javascripts/app.js @@ -20,6 +20,7 @@ planner.run(['$rootScope', function($rootScope){ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/students'); $stateProvider + .state('dashboard', { url: '', views: { @@ -32,6 +33,7 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, } } }) + .state('dashboard.students', { url: '/students', resolve: { @@ -49,6 +51,7 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, } } }) + .state('dashboard.meetings', { url: '/classes', views: { @@ -57,5 +60,16 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, controller: 'MeetingsIndexCtrl', } } + }) + + .state('dashboard.advisors', { + url: '/advisors', + views: { + "dashboardMain@": { + templateUrl: '/templates/advisors.html', + controller: 'AdvisorsIndexCtrl', + } + } }); + }]); diff --git a/app/assets/javascripts/controllers/AdvisorsIndexCtrl.js b/app/assets/javascripts/controllers/AdvisorsIndexCtrl.js new file mode 100644 index 0000000..f33f932 --- /dev/null +++ b/app/assets/javascripts/controllers/AdvisorsIndexCtrl.js @@ -0,0 +1,5 @@ +planner.controller('AdvisorsIndexCtrl', ['$scope', function($scope) { + + + +}]); diff --git a/app/views/angular_app/index.html.erb b/app/views/angular_app/index.html.erb index 2215700..8dc5ee2 100644 --- a/app/views/angular_app/index.html.erb +++ b/app/views/angular_app/index.html.erb @@ -1,4 +1,4 @@ +
-
diff --git a/public/templates/advisors.html b/public/templates/advisors.html new file mode 100644 index 0000000..e69de29 diff --git a/public/templates/dashboard-header.html b/public/templates/dashboard-header.html index 2380b25..a391d7a 100644 --- a/public/templates/dashboard-header.html +++ b/public/templates/dashboard-header.html @@ -1,15 +1,24 @@ - -

Welcome, admin_name!

- -

Sign Out

-

Edit my account settings

+

Add new admin or advisor

View advisors

-

Dashboard

+
+ +

Dashboard

-Students -Classes + Students + Classes + +
diff --git a/public/templates/dashboard-main.html b/public/templates/dashboard-main.html index 6e72b29..31800c0 100644 --- a/public/templates/dashboard-main.html +++ b/public/templates/dashboard-main.html @@ -1,2 +1 @@ -Dashboard-main
From 2fd268ae3fca16c62e65e397d92618352c4f5539 Mon Sep 17 00:00:00 2001 From: luke-schleicher Date: Mon, 13 Feb 2017 13:49:56 -0600 Subject: [PATCH 3/4] refactored to prepare to change advisors link to angular app --- .../advisors/registrations_controller.rb | 13 ++++---- app/controllers/application_controller.rb | 6 ++++ app/views/advisors/_delete_advisor.html.erb | 1 - .../advisors/_update_advisor_status.html.erb | 4 --- app/views/advisors/index.html.erb | 25 -------------- app/views/devise/registrations/edit.html.erb | 2 +- app/views/layouts/application.html.erb | 5 ++- app/views/shared/_flash.html.erb | 8 +++-- app/views/shared/_navbar.html.erb | 12 +++++++ public/templates/advisors.html | 33 +++++++++++++++++++ public/templates/dashboard-header.html | 17 +--------- 11 files changed, 69 insertions(+), 57 deletions(-) delete mode 100644 app/views/advisors/_delete_advisor.html.erb delete mode 100644 app/views/advisors/_update_advisor_status.html.erb delete mode 100644 app/views/advisors/index.html.erb create mode 100644 app/views/shared/_navbar.html.erb diff --git a/app/controllers/advisors/registrations_controller.rb b/app/controllers/advisors/registrations_controller.rb index bf58ca1..0cac695 100644 --- a/app/controllers/advisors/registrations_controller.rb +++ b/app/controllers/advisors/registrations_controller.rb @@ -4,6 +4,7 @@ class Advisors::RegistrationsController < Devise::RegistrationsController skip_before_action :require_no_authentication, only: [:new, :create] before_action :require_admin, only: [:new, :create] + before_action :require_current_advisor, only: [:edit] # GET /resource/sign_up def new @@ -44,14 +45,14 @@ def create end # GET /resource/edit - # def edit - # super - # end + def edit + super + end # PUT /resource - # def update - # super - # end + def update + super + end # DELETE /resource # def destroy diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cfb80f2..b669134 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -21,4 +21,10 @@ def require_admin end end + def require_current_advisor + unless current_advisor.id == params[:id].to_i + redirect_back(fallback_location: root_path) + end + end + end diff --git a/app/views/advisors/_delete_advisor.html.erb b/app/views/advisors/_delete_advisor.html.erb deleted file mode 100644 index d966e48..0000000 --- a/app/views/advisors/_delete_advisor.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= button_to "Delete", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?"} %> \ No newline at end of file diff --git a/app/views/advisors/_update_advisor_status.html.erb b/app/views/advisors/_update_advisor_status.html.erb deleted file mode 100644 index 100a9f4..0000000 --- a/app/views/advisors/_update_advisor_status.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= form_for advisor do |f| %> - <%= f.check_box :is_admin %> - <%= f.submit 'Update' %> -<% end %> \ No newline at end of file diff --git a/app/views/advisors/index.html.erb b/app/views/advisors/index.html.erb deleted file mode 100644 index fb341a8..0000000 --- a/app/views/advisors/index.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -

All Advisors

- - - - - - - - - - <% @advisors.each do |advisor| %> - - - - - - - - <% end %> -
First NameLast NameEmailAdmin StatusDelete?
<%= advisor.first_name %><%= advisor.last_name %><%= advisor.email %> - <%= advisor_status(advisor) %> - - <%= advisor_deletion(advisor) %> -
- diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index a6adcea..29b00a7 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,4 +1,4 @@ -

Edit <%= resource_name.to_s.humanize %>

+

Edit Your Account

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> <%= devise_error_messages! %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e97ed48..b69539c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,7 +9,10 @@ + <%= render 'shared/navbar' %> <%= render "shared/flash" %> - <%= yield %> +
+ <%= yield %> +
diff --git a/app/views/shared/_flash.html.erb b/app/views/shared/_flash.html.erb index 0bff4e8..3a65797 100644 --- a/app/views/shared/_flash.html.erb +++ b/app/views/shared/_flash.html.erb @@ -1,7 +1,9 @@ <% if flash.any? %>
- <% flash.each do |k, v| %> -

<%= v %>

- <% end %> +
+ <% flash.each do |k, v| %> +

<%= v %>

+ <% end %> +
<% end %> \ No newline at end of file diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb new file mode 100644 index 0000000..5020c8e --- /dev/null +++ b/app/views/shared/_navbar.html.erb @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/public/templates/advisors.html b/public/templates/advisors.html index e69de29..198d661 100644 --- a/public/templates/advisors.html +++ b/public/templates/advisors.html @@ -0,0 +1,33 @@ +

All Advisors

+ + + + + + + + + + <% @advisors.each do |advisor| %> + + + + + + + + <% end %> +
First NameLast NameEmailAdmin StatusDelete?
<%= advisor.first_name %><%= advisor.last_name %><%= advisor.email %> + <%= form_for advisor do |f| %> + <%= f.check_box :is_admin %> + <%= f.submit 'Update' %> + <% end %> + + <%= button_to "Delete", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?"} %> +
+ +Add new admin or advisor + + + + diff --git a/public/templates/dashboard-header.html b/public/templates/dashboard-header.html index a391d7a..99919a9 100644 --- a/public/templates/dashboard-header.html +++ b/public/templates/dashboard-header.html @@ -1,24 +1,9 @@ - - -
-

Add new admin or advisor

-

View advisors

-
-

Dashboard

Students Classes + Advisors
From 9bd88e15392a4310a163af35d845c42105abfe5b Mon Sep 17 00:00:00 2001 From: luke-schleicher Date: Mon, 13 Feb 2017 14:37:29 -0600 Subject: [PATCH 4/4] Advisors index and dashboard refactored --- app/assets/javascripts/app.js | 12 +----------- .../javascripts/controllers/AdvisorsIndexCtrl.js | 5 ----- app/controllers/advisors/registrations_controller.rb | 4 +++- app/views/advisors/_delete_advisor.html.erb | 1 + app/views/advisors/_update_advisor_status.html.erb | 4 ++++ .../views/advisors/index.html.erb | 8 +++----- app/views/devise/registrations/new.html.erb | 6 ++++-- app/views/devise/shared/_links.html.erb | 4 ---- app/views/shared/_navbar.html.erb | 1 + public/templates/dashboard-header.html | 2 +- 10 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 app/assets/javascripts/controllers/AdvisorsIndexCtrl.js create mode 100644 app/views/advisors/_delete_advisor.html.erb create mode 100644 app/views/advisors/_update_advisor_status.html.erb rename public/templates/advisors.html => app/views/advisors/index.html.erb (65%) diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js index cc855e9..0b0de41 100644 --- a/app/assets/javascripts/app.js +++ b/app/assets/javascripts/app.js @@ -60,16 +60,6 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, controller: 'MeetingsIndexCtrl', } } - }) - - .state('dashboard.advisors', { - url: '/advisors', - views: { - "dashboardMain@": { - templateUrl: '/templates/advisors.html', - controller: 'AdvisorsIndexCtrl', - } - } }); - + }]); diff --git a/app/assets/javascripts/controllers/AdvisorsIndexCtrl.js b/app/assets/javascripts/controllers/AdvisorsIndexCtrl.js deleted file mode 100644 index f33f932..0000000 --- a/app/assets/javascripts/controllers/AdvisorsIndexCtrl.js +++ /dev/null @@ -1,5 +0,0 @@ -planner.controller('AdvisorsIndexCtrl', ['$scope', function($scope) { - - - -}]); diff --git a/app/controllers/advisors/registrations_controller.rb b/app/controllers/advisors/registrations_controller.rb index 0cac695..7fa7fb0 100644 --- a/app/controllers/advisors/registrations_controller.rb +++ b/app/controllers/advisors/registrations_controller.rb @@ -31,7 +31,9 @@ def create # Commented Out to Override Devise's Automatic Login Upon Creation # sign_up(resource_name, resource) - respond_with resource, location: after_sign_up_path_for(resource) + redirect_to advisors_path + + # respond_with resource, location: after_sign_up_path_for(resource) else set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}" expire_data_after_sign_in! diff --git a/app/views/advisors/_delete_advisor.html.erb b/app/views/advisors/_delete_advisor.html.erb new file mode 100644 index 0000000..d966e48 --- /dev/null +++ b/app/views/advisors/_delete_advisor.html.erb @@ -0,0 +1 @@ +<%= button_to "Delete", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?"} %> \ No newline at end of file diff --git a/app/views/advisors/_update_advisor_status.html.erb b/app/views/advisors/_update_advisor_status.html.erb new file mode 100644 index 0000000..100a9f4 --- /dev/null +++ b/app/views/advisors/_update_advisor_status.html.erb @@ -0,0 +1,4 @@ +<%= form_for advisor do |f| %> + <%= f.check_box :is_admin %> + <%= f.submit 'Update' %> +<% end %> \ No newline at end of file diff --git a/public/templates/advisors.html b/app/views/advisors/index.html.erb similarity index 65% rename from public/templates/advisors.html rename to app/views/advisors/index.html.erb index 198d661..f8a743f 100644 --- a/public/templates/advisors.html +++ b/app/views/advisors/index.html.erb @@ -14,13 +14,11 @@

All Advisors

<%= advisor.last_name %> <%= advisor.email %> - <%= form_for advisor do |f| %> - <%= f.check_box :is_admin %> - <%= f.submit 'Update' %> - <% end %> + <%= advisor_status(advisor) %> + - <%= button_to "Delete", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?"} %> + <%= advisor_deletion(advisor) %> <% end %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 9deaaf9..e6ec54e 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,4 +1,4 @@ -

Sign up

+

Add An Advisor

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> @@ -37,8 +37,10 @@
- <%= f.submit "Sign up" %> + <%= f.submit "Create Advisor" %>
<% end %> <%= render "devise/shared/links" %> + +<%= link_to "Back", :back %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 6f4bef4..9cad183 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -1,7 +1,3 @@ -<%- if controller_name != 'sessions' %> - <%= link_to "Log in", new_session_path(resource_name) %>
-<% end -%> - <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> <%= link_to "Forgot your password?", new_password_path(resource_name) %>
<% end -%> diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 5020c8e..151268b 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -1,6 +1,7 @@