Skip to content

Commit

Permalink
photos / about
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Apr 15, 2024
1 parent 20b6f80 commit 1b80599
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 3 deletions.
21 changes: 21 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class PhotosController < ApplicationController


def create
end

def update
current_user.update(resource_params)

redirect_to "/" + current_user.username + "/about"
end

def destroy
end


private
def resource_params
params.require(:user).permit(photos_attributes: [:image])
end
end
6 changes: 6 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def albums
render "show"
end

def about
@title = "Albums"
@section = "albums"
render "about"
end

private

def get_meta_tags
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/photos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PhotosHelper
end
4 changes: 4 additions & 0 deletions app/models/photo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Photo < ApplicationRecord
belongs_to :user
has_one_attached :image
end
4 changes: 2 additions & 2 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ def self.top_countries(profile_id)
.order("count DESC")
end

def self.series_by_month(profile_id)
def self.series_by_month(profile_id, range: 12)
ListeningEvent.where(resource_profile_id: profile_id)
.group_by_month(:created_at, range: 12.months.ago.midnight..Time.now).count
.group_by_month(:created_at, range: range.months.ago.midnight..Time.now).count
.map { |k, v|
{count: v, day: k}
}
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class User < ApplicationRecord
has_many :reposted_tracks, through: :reposts, source: :track
has_many :track_comments
has_many :posts
has_many :photos
has_many :listening_events
has_many :invitations, class_name: to_s, as: :invited_by
has_many :oauth_credentials
Expand Down Expand Up @@ -50,6 +51,8 @@ class User < ApplicationRecord
store_attribute :settings, :tbk_commerce_code, :string
store_attribute :settings, :tbk_test_mode, :boolean

accepts_nested_attributes_for :photos, allow_destroy: true

scope :artists, -> { where(role: "artist").where.not(username: nil) }
# Ex:- scope :active, -> {where(:active => true)}
def has_invitations_left?
Expand Down
1 change: 1 addition & 0 deletions app/views/insights/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= turbo_stream.update("modal") {""} %>
15 changes: 15 additions & 0 deletions app/views/photos/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= turbo_frame_tag "modal" do %>
<%= render "shared/modal" do %>
<%= form_for current_user, url: photo_path(current_user.id), data: {turbo_frame: "_top"} do |form| %>
<h1 class="text-2xl my-2">Upload a Image</h1>
<%= form.fields_for :photos, Photo.new do |f| %>
<div class="space-y-2">
<%= f.file_field :image %>
<%= f.submit %>
</div>
<% end %>
<% end %>
<% end %>
<% end %>
72 changes: 72 additions & 0 deletions app/views/users/about.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@


<div class="relative mx-auto max-w-7xl px-4 sm:static sm:px-6 lg:px-8">

<div class="flex space-x-5">


<div>
<div class="space-y-2 my-6">
<div class="p-2">
<div class="text-4xl font-extrabold"><%= @user.followers(User).size %></div>
<div class="text-muted">Followers</div>
</div>

<div class="p-2">
<div class="text-4xl font-extrabold"><%= Track.series_by_month(@user.id, range: 1).first[:count] %></div>
<div class="text-sm text-muted">Monthly Listeners</div>
</div>


<% Track.top_countries(@user.id).each do |location|%>
<div class="p-2">
<div class="text-xl font-bold"><%= location&.country %></div>
<div class="text-sm text-muted"> <%= location.count %> listeners</div>
</div>
<% end %>

<!--
<div class="DVWIV41y6daOMjQKR8Zj">
<a rel="noopener noreferrer" target="_blank" href="https://instagram.com/xxx/" class="muHL0_3HjlqTZDoapgc9">
<svg data-encore-id="icon" role="img" aria-hidden="true" class="Svg-sc-ytk21e-0 bneLcE oORVTPvg6eTQflVKKgw8" viewBox="0 0 24 24">
<path d="M12 3.803c2.67 0 2.986.01 4.041.059.975.044 1.504.207 1.857.344.435.16.828.416 1.151.748.332.323.588.716.748 1.151.137.353.3.882.345 1.857.047 1.055.058 1.37.058 4.041 0 2.67-.01 2.986-.058 4.041-.045.975-.208 1.505-.345 1.857A3.315 3.315 0 0 1 17.9 19.8c-.352.137-.882.3-1.856.344-1.055.048-1.371.058-4.041.058-2.67 0-2.987-.01-4.041-.058-.975-.044-1.505-.207-1.857-.344a3.096 3.096 0 0 1-1.151-.748 3.096 3.096 0 0 1-.749-1.151c-.137-.353-.3-.883-.344-1.857-.048-1.055-.058-1.371-.058-4.041 0-2.67.01-2.987.058-4.041.045-.975.207-1.505.344-1.857a3.08 3.08 0 0 1 .749-1.151 3.096 3.096 0 0 1 1.15-.749c.353-.137.883-.3 1.858-.344 1.054-.048 1.37-.058 4.04-.058H12zM12.002 2c-2.716 0-3.057.012-4.124.06-1.066.05-1.793.22-2.428.466A4.91 4.91 0 0 0 3.678 3.68a4.91 4.91 0 0 0-1.153 1.772c-.247.635-.416 1.363-.465 2.427C2.012 8.943 2 9.286 2 12.002c0 2.715.012 3.056.06 4.123.05 1.066.218 1.791.465 2.426a4.909 4.909 0 0 0 1.153 1.772c.5.508 1.105.902 1.772 1.153.635.248 1.363.417 2.428.465 1.064.049 1.407.06 4.123.06s3.056-.01 4.123-.06c1.067-.049 1.79-.217 2.426-.465a5.111 5.111 0 0 0 2.925-2.925c.247-.635.416-1.363.465-2.427.048-1.064.06-1.407.06-4.123s-.012-3.057-.06-4.123c-.05-1.067-.218-1.791-.465-2.426a4.902 4.902 0 0 0-1.153-1.771 4.91 4.91 0 0 0-1.772-1.155c-.635-.247-1.363-.416-2.428-.464-1.064-.048-1.406-.06-4.122-.06L12.002 2z"></path>
<path d="M12 6.867a5.135 5.135 0 1 0 0 10.27 5.135 5.135 0 0 0 0-10.27zm0 8.47a3.334 3.334 0 1 1 0-6.67 3.334 3.334 0 0 1 0 6.67zm5.338-7.473a1.2 1.2 0 1 0 0-2.4 1.2 1.2 0 0 0 0 2.4z"></path>
</svg>
<span class="text-sm text-muted">Instagram</span>
</a>
</div>
-->
</div>
</div>

<div class="sm:max-w-lg py-5">
<h1 class="text-4xl font-bold tracking-tight text-default sm:text-6xl">
<%= @user.username %>
</h1>
<p class="text-muted">
<%= @user.country %>, <%= @user.city %>
</p>
<p class="mt-4 text-xl text-subtle">
<%= @user.bio %>
</p>
</div>

</div>

<div class="flex justify-end">
<%= link_to new_photo_path, class: "button-sm-outline", data: {turbo_frame: "modal"} do %>
New Image
<% end %>
</div>

<div class="grid grid-cols-2 md:grid-cols-3 gap-4 my-6">
<% current_user.photos.each do |image| %>
<div>
<%= image_tag image.image.variant(resize_to_fill: [350, 250]) , class: "h-auto max-w-full rounded-lg" %>
</div>
<% end %>
</div>


</div>

2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
end
end

resources :photos
resource :spotlight
resources :playlists do
resources :comments
Expand Down Expand Up @@ -142,6 +143,7 @@
get "/playlists", to: "users#playlists"
get "/reposts", to: "users#reposts"
get "/albums", to: "users#albums"
get "/about", to: "users#about"
end
end

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20240415033320_create_photos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreatePhotos < ActiveRecord::Migration[7.0]
def change
create_table :photos do |t|
t.references :user, null: false, foreign_key: true
t.text :description
t.string "tags", default: [], array: true
t.timestamps
end
end
end
12 changes: 11 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/factories/photos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :photo do
user { nil }
description { "MyText" }
end
end
15 changes: 15 additions & 0 deletions spec/helpers/photos_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the PhotosHelper. For example:
#
# describe PhotosHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe PhotosHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/photo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Photo, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/requests/photos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rails_helper'

RSpec.describe "Photos", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end

0 comments on commit 1b80599

Please sign in to comment.