mirror of
https://github.com/danbee/my-images
synced 2025-03-04 08:49:05 +00:00
Merge 5f79654684 into 71c7ba2acf
This commit is contained in:
commit
ad8341ae43
2
.hound.yml
Normal file
2
.hound.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
rubocop:
|
||||||
|
version: 1.22.1
|
||||||
2
Gemfile
2
Gemfile
@ -30,8 +30,6 @@ group :development do
|
|||||||
end
|
end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem "better_errors"
|
|
||||||
gem "binding_of_caller"
|
|
||||||
gem "pry"
|
gem "pry"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
10
Gemfile.lock
10
Gemfile.lock
@ -71,14 +71,8 @@ GEM
|
|||||||
archive-zip (0.12.0)
|
archive-zip (0.12.0)
|
||||||
io-like (~> 0.3.0)
|
io-like (~> 0.3.0)
|
||||||
base64 (0.2.0)
|
base64 (0.2.0)
|
||||||
better_errors (2.10.1)
|
|
||||||
erubi (>= 1.0.0)
|
|
||||||
rack (>= 0.9.0)
|
|
||||||
rouge (>= 1.0.0)
|
|
||||||
bigdecimal (3.1.7)
|
bigdecimal (3.1.7)
|
||||||
bindex (0.8.1)
|
bindex (0.8.1)
|
||||||
binding_of_caller (1.0.1)
|
|
||||||
debug_inspector (>= 1.2.0)
|
|
||||||
bootsnap (1.18.3)
|
bootsnap (1.18.3)
|
||||||
msgpack (~> 1.2)
|
msgpack (~> 1.2)
|
||||||
builder (3.2.4)
|
builder (3.2.4)
|
||||||
@ -99,7 +93,6 @@ GEM
|
|||||||
rexml
|
rexml
|
||||||
crass (1.0.6)
|
crass (1.0.6)
|
||||||
date (3.3.4)
|
date (3.3.4)
|
||||||
debug_inspector (1.2.0)
|
|
||||||
delayed_job (4.1.11)
|
delayed_job (4.1.11)
|
||||||
activesupport (>= 3.0, < 8.0)
|
activesupport (>= 3.0, < 8.0)
|
||||||
delayed_job_active_record (4.1.8)
|
delayed_job_active_record (4.1.8)
|
||||||
@ -257,7 +250,6 @@ GEM
|
|||||||
rake (13.1.0)
|
rake (13.1.0)
|
||||||
regexp_parser (2.9.0)
|
regexp_parser (2.9.0)
|
||||||
rexml (3.2.6)
|
rexml (3.2.6)
|
||||||
rouge (4.2.1)
|
|
||||||
rspec-core (3.13.0)
|
rspec-core (3.13.0)
|
||||||
rspec-support (~> 3.13.0)
|
rspec-support (~> 3.13.0)
|
||||||
rspec-expectations (3.13.0)
|
rspec-expectations (3.13.0)
|
||||||
@ -342,8 +334,6 @@ PLATFORMS
|
|||||||
arm64-darwin-22
|
arm64-darwin-22
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
better_errors
|
|
||||||
binding_of_caller
|
|
||||||
bootsnap
|
bootsnap
|
||||||
capybara
|
capybara
|
||||||
delayed_job_active_record
|
delayed_job_active_record
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
ul.images {
|
.images {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: 0.75rem;
|
grid-gap: 0.75rem;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(2, 1fr);
|
||||||
@ -19,6 +19,31 @@ ul.images {
|
|||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
padding: 0.25rem;
|
padding: 0.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__upload {
|
||||||
|
aspect-ratio: 1 / 1;
|
||||||
|
|
||||||
|
&-form {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-label {
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 2px;
|
||||||
|
outline: 1px dashed white;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
opacity: 0.4;
|
||||||
|
width: 100%;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 380px) {
|
@media (min-width: 380px) {
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
padding: 0.5rem 2rem;
|
padding: 0.5rem 2rem;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
width: 1.2rem;
|
width: 1.2rem;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
|||||||
@ -8,19 +8,18 @@ class ImagesController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@image = @current_user.images.find(params[:id])
|
@image = @current_user.images.find(params[:id])
|
||||||
|
|
||||||
if turbo_frame_request?
|
|
||||||
render partial: "tags/tags", locals: {
|
|
||||||
image: @image,
|
|
||||||
tags: @image.tags
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@image = Image.create(permitted_params)
|
permitted_params[:images].select(&:present?).each do |image|
|
||||||
|
@image = Image.create(
|
||||||
|
user_id: permitted_params[:user_id],
|
||||||
|
album_id: permitted_params[:album_id],
|
||||||
|
image: image,
|
||||||
|
)
|
||||||
@current_user.images << @image
|
@current_user.images << @image
|
||||||
TagImageJob.perform_later(image_id: @image.id)
|
TagImageJob.perform_later(image_id: @image.id)
|
||||||
|
end
|
||||||
|
|
||||||
redirect_for(@image)
|
redirect_for(@image)
|
||||||
end
|
end
|
||||||
@ -53,6 +52,6 @@ class ImagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def permitted_params
|
def permitted_params
|
||||||
params.require(:image).permit(:user_id, :album_id, :image)
|
params.require(:image).permit(:user_id, :album_id, images: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,7 +5,7 @@ class TagsController < ApplicationController
|
|||||||
image = @current_user.images.find(params[:image_id])
|
image = @current_user.images.find(params[:image_id])
|
||||||
tag = params[:tag]
|
tag = params[:tag]
|
||||||
|
|
||||||
if !image.tags.include?(tag)
|
if !image.tags.include?(tag) && tag.present?
|
||||||
image.tags << tag
|
image.tags << tag
|
||||||
image.save
|
image.save
|
||||||
redirect_to image, turbo_frame: "tags"
|
redirect_to image, turbo_frame: "tags"
|
||||||
|
|||||||
@ -3,5 +3,6 @@
|
|||||||
import "@hotwired/turbo-rails"
|
import "@hotwired/turbo-rails"
|
||||||
import Rails from "@rails/ujs";
|
import Rails from "@rails/ujs";
|
||||||
import { Application } from "@hotwired/stimulus";
|
import { Application } from "@hotwired/stimulus";
|
||||||
|
import "controllers"
|
||||||
|
|
||||||
Rails.start();
|
Rails.start();
|
||||||
|
|||||||
9
app/javascript/controllers/application.js
Normal file
9
app/javascript/controllers/application.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Application } from "@hotwired/stimulus"
|
||||||
|
|
||||||
|
const application = Application.start()
|
||||||
|
|
||||||
|
// Configure Stimulus development experience
|
||||||
|
application.debug = true
|
||||||
|
window.Stimulus = application
|
||||||
|
|
||||||
|
export { application }
|
||||||
3
app/javascript/controllers/index.js
Normal file
3
app/javascript/controllers/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { application } from "controllers/application"
|
||||||
|
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
|
||||||
|
eagerLoadControllersFrom("controllers", application)
|
||||||
15
app/javascript/controllers/uploads_controller.js
Normal file
15
app/javascript/controllers/uploads_controller.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Controller } from "@hotwired/stimulus";
|
||||||
|
|
||||||
|
export default class extends Controller {
|
||||||
|
static targets = ["form", "fileField"];
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
this.element.addEventListener("dragenter", (event) => {
|
||||||
|
console.log(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.fileFieldTarget.addEventListener("change", (event) => {
|
||||||
|
this.formTarget.submit();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,13 +15,28 @@
|
|||||||
method: :delete, data: { confirm: 'Are you sure?' } %>
|
method: :delete, data: { confirm: 'Are you sure?' } %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h2>Upload New Image</h2>
|
<li class="images__upload" data-controller="uploads">
|
||||||
|
<%= form_for(
|
||||||
<%= simple_form_for @images.new do |f| %>
|
@images.new,
|
||||||
<%= f.input :user_id, as: :hidden %>
|
html: {
|
||||||
<%= f.input :album_id, as: :hidden %>
|
class: "images__upload-form",
|
||||||
<%= f.input :image, as: :file %>
|
data: {"uploads-target": "form"}
|
||||||
<%= f.submit %>
|
}
|
||||||
|
) do |f| %>
|
||||||
|
<%= f.hidden_field :user_id %>
|
||||||
|
<%= f.hidden_field :album_id %>
|
||||||
|
<%= f.file_field(
|
||||||
|
:images,
|
||||||
|
class: "images__upload-input",
|
||||||
|
multiple: true,
|
||||||
|
accept: "image/*",
|
||||||
|
data: {"uploads-target": "fileField"}
|
||||||
|
) %>
|
||||||
|
<label for="image_images" class="images__upload-label">
|
||||||
|
<span>↑</span>
|
||||||
|
Upload
|
||||||
|
</label>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|||||||
@ -4,10 +4,10 @@
|
|||||||
→
|
→
|
||||||
<%= link_to @image.album.title, album_images_path(@image.album) %>
|
<%= link_to @image.album.title, album_images_path(@image.album) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
→
|
|
||||||
<%= @image.image.name %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<h2><%= @image.image.name %></h2>
|
||||||
|
|
||||||
<div class="show-image" data-image-id="<%= @image.id %>">
|
<div class="show-image" data-image-id="<%= @image.id %>">
|
||||||
<div class="image-container">
|
<div class="image-container">
|
||||||
<%= render "image", image: @image %>
|
<%= render "image", image: @image %>
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
<% content_for :title, "My Images" %>
|
<% content_for :title, "My Images" %>
|
||||||
|
|
||||||
<div class="centre-stage">
|
<div class="centre-stage">
|
||||||
<%= link_to '/auth/github', class: "github-button", method: :post do %>
|
<%= button_to(
|
||||||
|
'/auth/github',
|
||||||
|
class: "github-button",
|
||||||
|
method: :post,
|
||||||
|
data: {turbo: false}
|
||||||
|
) do %>
|
||||||
<%= image_tag "github.svg" %>
|
<%= image_tag "github.svg" %>
|
||||||
Sign in with GitHub
|
Sign in with GitHub
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
pin "application"
|
pin "application"
|
||||||
pin "@rails/ujs", to: "@rails--ujs.js" # @7.1.3
|
pin "@rails/ujs", to: "@rails--ujs.js" # @7.1.3
|
||||||
pin "@hotwired/stimulus", to: "@hotwired--stimulus.js" # @3.2.2
|
|
||||||
pin "@hotwired/turbo-rails", to: "@hotwired--turbo-rails.js" # @8.0.4
|
pin "@hotwired/turbo-rails", to: "@hotwired--turbo-rails.js" # @8.0.4
|
||||||
pin "@hotwired/turbo", to: "@hotwired--turbo.js" # @8.0.4
|
pin "@hotwired/turbo", to: "@hotwired--turbo.js" # @8.0.4
|
||||||
pin "@rails/actioncable/src", to: "@rails--actioncable--src.js" # @7.1.3
|
pin "@rails/actioncable/src", to: "@rails--actioncable--src.js" # @7.1.3
|
||||||
|
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
||||||
|
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
||||||
|
pin_all_from "app/javascript/controllers", under: "controllers"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user