Skip to content

Commit 9df9162

Browse files
committed
view: optimize view for different message type
1 parent 371ca93 commit 9df9162

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

app/controllers/trained_messages_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ def update
118118
# DELETE /trained_messages/1 or /trained_messages/1.json
119119
def destroy
120120
@trained_message.destroy!
121+
return_url = params[:return_url] || trained_messages_path
121122

122123
respond_to do |format|
123-
format.html { redirect_to trained_messages_path, notice: "Trained message was successfully destroyed.", status: :see_other }
124+
format.html { redirect_to return_url, notice: "Trained message was successfully destroyed.", status: :see_other }
124125
format.json { head :no_content }
125126
end
126127
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
module TrainedMessagesHelper
2+
def message_type_classes(message_type)
3+
case message_type
4+
when "spam"
5+
"bg-red-100 text-red-800"
6+
when "ham"
7+
"bg-green-100 text-green-800"
8+
when "maybe_spam"
9+
"bg-orange-100 text-orange-800"
10+
when "maybe_ham"
11+
"bg-lime-100 text-lime-800"
12+
when "untrained"
13+
"bg-gray-100 text-gray-800"
14+
else
15+
"bg-gray-100 text-gray-800"
16+
end
17+
end
218
end

app/views/trained_messages/index.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@
178178
</span>
179179
<% end %>
180180
</td>
181-
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500
182-
<%= trained_message.message_type == 'spam' ? 'bg-red-100 text-red-800' : trained_message.message_type == 'ham' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-green-800'%>">
181+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 <%= message_type_classes(trained_message.message_type) %>">
183182
<%= trained_message.message_type&.humanize || 'Unknown' %>
184183
</td>
185184
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">

app/views/trained_messages/show.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111

1212
<%= link_to "Edit this trained message", edit_trained_message_path(@trained_message), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
1313
<%= link_to "Back to trained messages", trained_messages_path(index_params), class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
14-
<%= button_to "Destroy this trained message", @trained_message, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", class: "w-full rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
14+
<%
15+
return_url = trained_messages_path(index_params)
16+
%>
17+
<%= button_to "Destroy this trained message", @trained_message, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", class: "w-full rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" }, params: { return_url: return_url } %>
1518
</div>

0 commit comments

Comments
 (0)