add shop name to lists in clothes index
This commit is contained in:
		
							parent
							
								
									9568545d61
								
							
						
					
					
						commit
						33381abdee
					
				@ -4,9 +4,22 @@ defmodule PokemonCoutureWeb.ClothesController do
 | 
			
		||||
  alias PokemonCouture.Shops
 | 
			
		||||
  alias PokemonCouture.Shops.Clothes
 | 
			
		||||
 | 
			
		||||
  def create_shop_map(clothes, map) do
 | 
			
		||||
    case map[clothes.location] do
 | 
			
		||||
      nil ->
 | 
			
		||||
        Map.put(map, clothes.location, [clothes])
 | 
			
		||||
      list_of_clothes when is_list(list_of_clothes) ->
 | 
			
		||||
        Map.put(map, clothes.location, list_of_clothes ++ [clothes])
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def index(conn, _params) do
 | 
			
		||||
    clothes = Shops.list_clothes()
 | 
			
		||||
    render(conn, "index.html", clothes: clothes)
 | 
			
		||||
    clothes_map =
 | 
			
		||||
      clothes
 | 
			
		||||
      |> Enum.reduce(%{}, &create_shop_map/2)
 | 
			
		||||
    # IO.inspect(clothes_map)
 | 
			
		||||
    render(conn, "index.html", clothes: clothes, clothes_map: clothes_map)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def new(conn, _params) do
 | 
			
		||||
 | 
			
		||||
@ -1,31 +1,31 @@
 | 
			
		||||
<h1>Listing Clothes</h1>
 | 
			
		||||
<%= for {shop, list_of_clothes} <- @clothes_map do %>
 | 
			
		||||
  <h2> <%= shop %></h2>
 | 
			
		||||
  <table>
 | 
			
		||||
    <thead>
 | 
			
		||||
      <tr>
 | 
			
		||||
        <th>Name</th>
 | 
			
		||||
        <th>Color</th>
 | 
			
		||||
        <th>Game</th>
 | 
			
		||||
        <th></th>
 | 
			
		||||
      </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    <tbody>
 | 
			
		||||
  <%= for clothes <- list_of_clothes do %>
 | 
			
		||||
      <tr>
 | 
			
		||||
        <td><%= clothes.name %></td>
 | 
			
		||||
        <td><%= clothes.color %></td>
 | 
			
		||||
        <td><%= clothes.game %></td>
 | 
			
		||||
 | 
			
		||||
<table>
 | 
			
		||||
  <thead>
 | 
			
		||||
    <tr>
 | 
			
		||||
      <th>Name</th>
 | 
			
		||||
      <th>Location</th>
 | 
			
		||||
      <th>Game</th>
 | 
			
		||||
 | 
			
		||||
      <th></th>
 | 
			
		||||
    </tr>
 | 
			
		||||
  </thead>
 | 
			
		||||
  <tbody>
 | 
			
		||||
<%= for clothes <- @clothes do %>
 | 
			
		||||
    <tr>
 | 
			
		||||
      <td><%= clothes.name %></td>
 | 
			
		||||
      <td><%= clothes.color %></td>
 | 
			
		||||
      <td><%= clothes.location %></td>
 | 
			
		||||
      <td><%= clothes.game %></td>
 | 
			
		||||
 | 
			
		||||
      <td>
 | 
			
		||||
        <span><%= link "Show", to: Routes.clothes_path(@conn, :show, clothes) %></span>
 | 
			
		||||
        <span><%= link "Edit", to: Routes.clothes_path(@conn, :edit, clothes) %></span>
 | 
			
		||||
        <span><%= link "Delete", to: Routes.clothes_path(@conn, :delete, clothes), method: :delete, data: [confirm: "Are you sure?"] %></span>
 | 
			
		||||
      </td>
 | 
			
		||||
    </tr>
 | 
			
		||||
        <td>
 | 
			
		||||
          <span><%= link "Show", to: Routes.clothes_path(@conn, :show, clothes) %></span>
 | 
			
		||||
          <span><%= link "Edit", to: Routes.clothes_path(@conn, :edit, clothes) %></span>
 | 
			
		||||
          <span><%= link "Delete", to: Routes.clothes_path(@conn, :delete, clothes), method: :delete, data: [confirm: "Are you sure?"] %></span>
 | 
			
		||||
        </td>
 | 
			
		||||
      </tr>
 | 
			
		||||
  <% end %>
 | 
			
		||||
    </tbody>
 | 
			
		||||
  </table>
 | 
			
		||||
<% end %>
 | 
			
		||||
  </tbody>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
<span><%= link "New Clothes", to: Routes.clothes_path(@conn, :new) %></span>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user