Skip to content

Commit

Permalink
Conversation marking feature written, all specs passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nerakdon committed Aug 6, 2015
1 parent f99070d commit db6d94a
Show file tree
Hide file tree
Showing 22 changed files with 274 additions and 148 deletions.
29 changes: 27 additions & 2 deletions app/controllers/night_train/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module NightTrain
class ApplicationController < ::ApplicationController
helper BoxesHelper
helper ConversationsHelper
helper MessagesHelper
before_filter :load_box
before_filter :load_objects
before_action :set_locale
Expand All @@ -19,6 +20,10 @@ def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end

def load_box
@box = send(NightTrain.configuration.current_user_method).box(params[:box_division].to_sym)
end

def load_objects
@objects = {}
@objects['conversations'] = {}
Expand All @@ -32,8 +37,28 @@ def load_objects
end
end

def load_box
@box = send(NightTrain.configuration.current_user_method).box(params[:box_division].to_sym)
def respond_to_marking
if !@box.errors.all.empty?
respond_to do |format|
format.html {
flash[:error] = @box.message
show
}
format.json { render :results, status: :unprocessable_entity }
end
else
respond_to do |format|
format.html {
if @box.results.all.empty?
flash[:alert] = @box.message
else
flash[:notice] = @box.message
end
show
}
format.json { render :results, status: :accepted }
end
end
end
end
end
26 changes: 2 additions & 24 deletions app/controllers/night_train/boxes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class BoxesController < NightTrain::ApplicationController
# GET /box/in
def show
@conversations = @conversations.page(params[:page])
render :show
end

# PATCH/PUT /box/in
def update
if params[:mark_to_set].present? && @objects.present?
@box.mark params[:mark_to_set], @objects
@box.mark(params[:mark_to_set], @objects)
end
respond_to_marking
end
Expand All @@ -24,29 +25,6 @@ def destroy
end

private
def respond_to_marking
if @box.errors.any?
respond_to do |format|
format.html {
flash[:error] = @box.message
show
}
format.json { render json: { message: @box.message }, status: :unprocessable_entity }
end
else
respond_to do |format|
format.html {
if @box.results.empty?
flash[:alert] = @box.message
else
flash[:notice] = @box.message
end
show
}
format.json { render :results, status: :accepted }
end
end
end

def load_conversations
@conversations = @box.conversations
Expand Down
28 changes: 1 addition & 27 deletions app/controllers/night_train/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ class ConversationsController < NightTrain::ApplicationController
# GET /box/in/conversations/1
def show
@messages = @conversation.messages.page(params[:page])
respond_to do |format|
format.html
format.json
end
render :show
end

# PATCH/PUT /box/in/conversations/1
Expand All @@ -28,29 +25,6 @@ def destroy
end

private
def respond_to_marking
if @box.errors.any?
respond_to do |format|
format.html {
flash[:error] = @box.errors.values.to_sentence
show
}
format.json { render json: { message: @box.message }, status: :unprocessable_entity }
end
else
respond_to do |format|
format.html {
if @box.results.any?
flash[:notice] = @box.message
else
flash[:alert] = @box.message
end
show
}
format.json { render :results, status: :accepted }
end
end
end

def load_conversation
@conversation = @box.find_conversation(params[:id])
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/night_train/messages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module NightTrain
class MessagesController < NightTrain::ApplicationController
before_filter :load_message

# GET /box/in/messages/1
def show
respond_to do |format|
format.json { render :show }
end
end

# PATCH/PUT /box/in/messages/1
def update
if params[:mark_to_set].present?
@box.mark params[:mark_to_set], @message
end
respond_to_marking
end

private

def load_message
@message = @box.find_message(params[:id])
end
end
end
53 changes: 53 additions & 0 deletions app/helpers/night_train/messages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module NightTrain
module MessagesHelper
def message_class(box, message)
css_classes = []

if message.is_unread_for?(@box.parent)
css_classes << 'unread'
else
css_classes << 'read'
end

if message.draft
css_classes << 'draft'
end

if box.division == :trash
unless message.is_trashed_for?(box.parent)
css_classes << 'hide'
end
else
unless message.is_untrashed_for?(box.parent)
css_classes << 'hide'
end
end
css_classes.join(' ')
end

def message_trashed_toggle(message)
render partial: 'night_train/messages/trashed_toggle', locals: { message: message }
end

def message_read_toggle(message)
render partial: 'night_train/messages/read_toggle', locals: { message: message }
end

def message_deleted_toggle(message)
render partial: 'night_train/messages/deleted_toggle', locals: { message: message }
end

def message_toggle(message, icon, mark_to_set, title, options = {})
options[:remote] = true
options[:id] = "mark_#{mark_to_set}_#{message.id}"
options[:method] = :put
options[:title] = title
render partial: 'night_train/messages/toggle', locals: {
message: message,
icon: icon,
mark_to_set: mark_to_set,
options: options
}
end
end
end
Loading

0 comments on commit db6d94a

Please sign in to comment.