Skip to content

Commit

Permalink
changing profile page
Browse files Browse the repository at this point in the history
Users can now see the items they have listed and its related information, including who has purchased the item. Also added CSS to make the table for both listed items and order history more readable.
  • Loading branch information
keigoomura committed Nov 21, 2024
1 parent 028074e commit 83a10d4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
5 changes: 0 additions & 5 deletions app/assets/stylesheets/auth.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,4 @@ body {

.home-link:hover {
color: #3498db;
}

/* Add padding to main content when on profile page */
body.profile-page {
padding-top: 35px; /* Adjust this value as needed */
}
25 changes: 25 additions & 0 deletions app/assets/stylesheets/profile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Add padding to main content when on profile page */
body.profile-page {
padding-top: 35px; /* Adjust this value as needed */
}

.profile-table {
border-collapse: separate;
border-spacing: 20px 0;
}

.profile-table th,
.profile-table td {
padding-bottom: 15px;
text-align: left;
}

.wrapped-item {
word-wrap: break-word;
max-width: 300px;
}

.wrapped-description {
word-wrap: break-word;
max-width: 300px;
}
1 change: 1 addition & 0 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ def handle_register

def show_profile
@orders = Order.includes(:item).where(user_id: session[:user]['id'])
@listed_items = Item.where(user_id: session[:user]['id']).order(created_at: :desc)
end
end
52 changes: 47 additions & 5 deletions app/views/user/show_profile.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
<h1><%= @username %></h1>
<h2><strong>Your Order History:</strong></h2>
<h1><%= @username%>'s Profile</h1>

<table>
<h2><strong>Your Listed Items:</strong></h2>
<% if @listed_items.empty? %>
<p>No items listed yet.</p>
<% else %>
<table class="profile-table">
<thead>
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Description</th>
<th>Remaining Quantity</th>
<th>Purchased By</th>
</tr>
</thead>
<tbody>
<% @listed_items.each do |item| %>
<tr>
<td class="wrapped-item"><%= item.name %></td>
<td><%= item.price %></td>
<td class="wrapped-description"><%= item.description %></td>
<td><%= item.remaining_quantity %></td>
<td>
<% if item.orders.any? %>
<ul style="list-style-type: none; padding-left: 0;">
<% item.orders.each do |order| %>
<li><%= order.user.username %> (Qty: <%= order.quantity %>)</li>
<% end %>
</ul>
<% else %>
No purchases yet
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

<h2><strong>Your Order History:</strong></h2>
<% if @orders.empty? %>
<p>No orders yet.</p>
<% else %>
<table class="profile-table">
<thead>
<tr>
<th>Item Name</th>
Expand All @@ -13,11 +54,12 @@
<tbody>
<% @orders.each do |order| %>
<tr>
<td><%= order.item.name %></td>
<td class="wrapped-item"><%= order.item.name %></td>
<td><%= order.quantity %></td>
<td><%= order.item.price %></td>
<td><%= order.quantity * order.item.price %></td>
</tr>
<% end %>
</tbody>
</table>
</table>
<% end %>

0 comments on commit 83a10d4

Please sign in to comment.