Skip to content

Commit

Permalink
Merge pull request #18 from tatiananantes/Album
Browse files Browse the repository at this point in the history
Album
  • Loading branch information
tatiananantes authored Dec 17, 2021
2 parents c054ebe + 2fd6832 commit 40337b3
Show file tree
Hide file tree
Showing 51 changed files with 166 additions and 17 deletions.
3 changes: 0 additions & 3 deletions app/assets/stylesheets/album.scss

This file was deleted.

16 changes: 16 additions & 0 deletions app/assets/stylesheets/albums.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Place all the styles related to the Albums controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
.modal {
.modal-body {
.img-thumbnail {
width: 100%;
background: transparent;
padding: 0;
border: 0;
}
}
}

.albums {
img {
margin-top: 20px;
}
}
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "bootstrap";
@import "posts";
@import "users";
@import "albums";
@import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css");
@import url("https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;600;700&display=swap");

Expand Down Expand Up @@ -87,7 +88,7 @@ body {
}

#flash {
.flash.alert {
.flash.alert, .flash.notice {
position: fixed;
bottom: 5%;
background: rgba(67,118,212, 0.8);
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
.post-body {
img {
max-width: 100%;
width: 100%;
margin-bottom: 10px;
}
}
Expand All @@ -57,6 +58,7 @@

.post-container {
width: 90vw;
max-width: 100%;
margin: 0 auto;
@media (min-width: 768px) {
width: 60vw;
Expand Down
23 changes: 22 additions & 1 deletion app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
color: #4376d4;
}
}
img {
.img-profile {
height: 200px;
width: 200px;
background: white;
Expand All @@ -28,4 +28,25 @@
margin-bottom: 15px;
border: 1px solid rgba(0, 0, 0, 0.2);
}
}

.album-viewer {
padding: 20px 0;
width: 85%;
a {
display: block;
}
img {
width: 100%;
}
.album-cover {
box-shadow: 0 3px 4px -4px black;
padding: 4px;
border-radius: 4px;
text-align: center;
a {
color: #333;
text-decoration: none;
}
}
}
2 changes: 1 addition & 1 deletion app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def album_params
end

def find_user
@user = User.find_by_id(session[:user_id])
@user = User.find_by_id(params[:user_id])
end

end
28 changes: 28 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
class PhotosController < ApplicationController
before_action :find_user
before_action :find_album


def new
@photo = Photo.new
end

def create

@photo = @album.photos.create(photo_params.merge(user_id: @user.id, album_id: @album.id))
redirect_to user_album_path(@user, @album)
end


private

def photo_params
params.require(:photo).permit(:image)
end

def find_user
@user = User.find_by_id(params[:user_id])
end

def find_album
@album = @user.albums.find_by_id(params[:album_id])
end
end
10 changes: 8 additions & 2 deletions app/views/albums/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<% @user.albums.reverse.each do |album| %>
<p><%= album.name%></p>
<%end%>
<p>
<a href="/users/<%=@user.id%>/albums/<%=album.id%>">
<%= album.name %>
</a>
</p>
<%end%>


51 changes: 49 additions & 2 deletions app/views/albums/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
<%=@album.name%>
<h1><%= @album.name %></h1>

This is an album

<% if @user.id == session[:user_id]%>
<div class="text-right">
<%= link_to "Add new photo to album", new_user_album_photo_path(@user, @album), :class => "btn btn-primary"%>
</div>
<%end%>

<div class= "row albums">
<% @album.photos.reverse.each do |photo| %>
<div class="col-sm-3">
<a href="#" type="button" data-bs-toggle="modal" data-bs-target="#exampleModal">
<%= image_tag photo.image.variant(resize_to_limit: [600, 600]), class: "img-fluid img-thumbnail" %>
</a>
</div>
<% end %>
</div>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body text-center">

</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

<script>
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget;
// Extract info from data-bs-* attributes
var recipient = button.innerHTML;
// If necessary, you could initiate an AJAX request here
// and then do the updating in a callback.
//
// Update the modal's content.
var modalBody = exampleModal.querySelector('.modal-body');

modalBody.innerHTML = recipient;
})

</script>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
</div>
</div>
</body>
</html>
</html>
15 changes: 15 additions & 0 deletions app/views/photos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="center-block">
<div class="form-group-wrap">

<%= form_with model: [ @user, @album, @album.photos.build ], local: true do |form| %>

<div class="form-group">
<%= form.label :image, class: "control-label"%>
<%= form.file_field :image, class:"form-control", required: "true" %>
</div>
<div class="form-group">
<%= form.submit "Create!", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
Empty file added app/views/photos/show.html.erb
Empty file.
28 changes: 22 additions & 6 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,37 @@
<div class="col-sm-4 col-lg-5">
<div class="profile-main">
<% if @user.avatar.attached? %>
<%= image_tag @user.avatar.variant(resize_to_limit: [200, 200]) %>
<%= image_tag @user.avatar.variant(resize_to_limit: [200, 200]), class: "img-fluid img-profile" %>
<%end%>
<div>
<div style="width: 100%;">
<h1 class="h3"> <%= @user.username %> </h1>
<p>Member since: <%= @user.created_at.strftime("%d %B %G") %></p>
<% if @user.id == session[:user_id]%>
<%= link_to "Edit details", edit_user_path(@user) %>
<%end%>

<% @user.albums.reverse.each do |album| %>
<p><a href="/users/<%=@user.id%>/albums/<%=album.id%>"><%= album.name%></p></a>
<%end%>
<div class="row album-viewer">
<% if @user.albums.count > 0 %>
<div class="soft-top border-top">
<h3 class="h4">Albums</h3>
</div>
<% end %>
<% @user.albums.reverse.each do |album| %>
<% if album.photos.count > 0 %>
<div class="col-sm-3">
<div class="bg-white album-cover">
<a href="/users/<%=@user.id%>/albums/<%=album.id%>">
<%= image_tag album.photos[0].image.variant(resize_to_limit: [100, 100]), class: "img-fluid rounded" %>
<p><%= album.name %></p>
</a>
</div>
</div>
<%end%>
<%end%>
</div>

<% if @user.id == session[:user_id]%>
<%= link_to "Create album", new_user_album_path(@user) %>
<%= link_to "My albums", user_albums_path(@user) %>
<%end%>

</div>
Expand Down
Binary file added storage/17/n0/17n0z0ax86um2f1ndmf2dmjf41pp
Binary file not shown.
Binary file added storage/41/wv/41wvw035n9togu8062z31f92uh44
Binary file not shown.
Binary file added storage/4w/qj/4wqjeb2ovx5vlwe4hxy4d24wbr4a
Binary file not shown.
Binary file added storage/5u/t5/5ut5jzklcuxk90ckwcqv9rf886sy
Binary file not shown.
Binary file added storage/7k/gw/7kgwm7db4eq49kne1htiexe9ee7g
Binary file not shown.
Binary file added storage/93/2y/932y0olko4lxx2x5x7x37ponefdx
Binary file not shown.
Binary file added storage/9r/fv/9rfvupjlhjcp5ybsmvtcbkihhd84
Binary file not shown.
Binary file added storage/gb/gl/gbglday37bcvvymkfbbumag72hvm
Binary file not shown.
Binary file added storage/gw/g9/gwg9fvkju6el6neys085fq6piw4k
Binary file not shown.
Binary file added storage/l1/kd/l1kdqljgriomj2hn8tq7bus0q9k1
Binary file not shown.
Binary file added storage/ov/i1/ovi1qvablgmw29eosw84nt2wyxnj
Binary file not shown.
Binary file added storage/qd/q1/qdq14a80ys1h981xtjbqtazfaa5b
Binary file not shown.
Binary file added storage/uo/7v/uo7vzh8yha2b3tyx37z0rc9oywyg
Binary file not shown.
Binary file added storage/v3/jp/v3jpu4b67yq02plqghehoj6e0ra8
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added storage/wf/02/wf02utupoh0xrq4rsdlogk8jac1u
Binary file not shown.

0 comments on commit 40337b3

Please sign in to comment.