add admin flash messaging and styles

This commit is contained in:
Mark Moser 2016-08-24 12:15:12 -05:00
parent 35f33e8215
commit 0058168c3e
8 changed files with 36 additions and 7 deletions

View File

@ -25,6 +25,16 @@
background-color: #f39c12; background-color: #f39c12;
} }
.success {
@extend .error;
background-color: $brand-success;
}
.notice {
@extend .error;
background-color: $brand-info;
}
[data-id="live-coder-finish-later"] { [data-id="live-coder-finish-later"] {
.warning { .warning {
margin-top: 0; margin-top: 0;

View File

@ -14,7 +14,7 @@ module Admin
@question = Question.create(process_question_params) @question = Question.create(process_question_params)
if @question.persisted? if @question.persisted?
redirect_to admin_questions_path, flash: { notice: "Sucessfully created question" } redirect_to admin_questions_path, flash: { success: "Sucessfully created question" }
else else
flash[:error] = "Failed to save question." flash[:error] = "Failed to save question."
render :new render :new
@ -36,7 +36,7 @@ module Admin
if @question.update_attributes(process_question_params) if @question.update_attributes(process_question_params)
redirect_to admin_question_path(@question.to_i), redirect_to admin_question_path(@question.to_i),
flash: { notice: "Sucessfully updated question" } flash: { success: "Sucessfully updated question" }
else else
flash[:error] = "Failed to update question." flash[:error] = "Failed to update question."
render :edit render :edit

View File

@ -14,7 +14,7 @@ module Admin
if @user.persisted? if @user.persisted?
# TODO: UserMailer.welcome(@user, default_passwd).deliver_now # TODO: UserMailer.welcome(@user, default_passwd).deliver_now
redirect_to admin_users_path, flash: { notice: "Sucessfully created user #{@user.name}" } redirect_to admin_users_path, flash: { success: "Sucessfully created user #{@user.name}" }
else else
flash[:error] = "Failed to save user." flash[:error] = "Failed to save user."
render :new render :new
@ -34,7 +34,7 @@ module Admin
if @user.update_attributes(user_params) if @user.update_attributes(user_params)
redirect_to admin_user_path(@user.to_i), redirect_to admin_user_path(@user.to_i),
flash: { notice: "Sucessfully updated #{@user.name}" } flash: { success: "Sucessfully updated #{@user.name}" }
else else
flash[:error] = "Failed to update user." flash[:error] = "Failed to update user."
render :edit render :edit

View File

@ -1,6 +1,8 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
add_flash_types :warning, :success
def current_recruiter def current_recruiter
user_parms = { id: session[:user], role: %w(admin recruiter) } user_parms = { id: session[:user], role: %w(admin recruiter) }
@current_recruiter ||= User.find_by(user_parms) if session[:user] @current_recruiter ||= User.find_by(user_parms) if session[:user]

View File

@ -16,7 +16,7 @@ class RecruiterController < ApplicationController
if @candidate.persisted? if @candidate.persisted?
CandidateMailer.welcome(@candidate).deliver_now CandidateMailer.welcome(@candidate).deliver_now
RecruiterMailer.candidate_created(@candidate).deliver_now RecruiterMailer.candidate_created(@candidate).deliver_now
redirect_to recruiter_path, flash: { notice: "Sucessfully created candidate #{@candidate.name}" } redirect_to recruiter_path, flash: { success: "Sucessfully created candidate #{@candidate.name}" }
else else
flash[:error] = "Failed to save candidate." flash[:error] = "Failed to save candidate."
render :form render :form

View File

@ -0,0 +1,15 @@
<% if flash[:error].present? %>
<div class="error"><%= flash[:error] %></div>
<% end %>
<% if flash[:success].present? %>
<div class="success"><%= flash[:success] %></div>
<% end %>
<% if flash[:warning].present? %>
<div class="warning"><%= flash[:warning] %></div>
<% end %>
<% if flash[:notice].present? %>
<div class="notice"><%= flash[:notice] %></div>
<% end %>

View File

@ -150,7 +150,9 @@
</div> </div>
<div class="error">This is a sample error message.</div> <div class="error">This is a sample error message.</div>
<div class="success">This is a sample success message.</div>
<div class="warning">This is a sample warning message.</div>
<div class="notice">This is a sample notice message.</div>
<hr> <hr>

View File

@ -74,7 +74,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
end end
end end
assert_redirected_to recruiter_path assert_redirected_to recruiter_path
assert flash[:notice] assert flash[:success]
end end
test "should fail creation with message" do test "should fail creation with message" do