Skip to content

Commit

Permalink
specs + track form attribution
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 24, 2023
1 parent 5f01fb2 commit c416737
Show file tree
Hide file tree
Showing 22 changed files with 472 additions and 188 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ gem "ruby-openai", "~> 4.2"
gem "qdrant-ruby", "~> 0.9.2"
# gem "pgvector", "~> 0.2"

gem "plain", github: "chaskiq/plain", branch: "main" #path: "/Users/michelson/Documents/rubyonrails/plain"
# gem "plain", path: "/Users/michelson/Documents/rubyonrails/plain"
# gem "plain-rails", path: "/Users/michelson/Documents/rubyonrails/plain"
gem "plain-rails", github: "chaskiq/plain", branch: "documents" #path: "/Users/michelson/Documents/rubyonrails/plain"
# gem "plain-rails", "0.1.2" #, path: "/Users/michelson/Documents/rubyonrails/plain"

# sentry

Expand All @@ -102,6 +103,7 @@ gem "sentry-sidekiq"


group :development, :test do
gem "pry"
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
Expand Down
15 changes: 9 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
GIT
remote: https://github.com/chaskiq/plain.git
revision: e1cab4e39570d38f4ef14e7ccb63784c1a5d6af3
branch: main
revision: c775ad400d207f0a8d972bbae4da1360919fa9a5
branch: documents
specs:
plain (0.1.0)
coderay (~> 1.1)
plain-rails (0.1.2)
front_matter_parser (~> 1.0.1)
langchainrb (~> 0.6.8)
langchainrb (~> 0.6.12)
qdrant-ruby (~> 0.9.2)
rails (>= 7.0.6)
redcarpet (~> 2.3.0)
Expand Down Expand Up @@ -391,6 +390,9 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.3)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.3)
puma (5.6.6)
nio4r (~> 2.0)
Expand Down Expand Up @@ -611,7 +613,8 @@ DEPENDENCIES
omniauth-twitch
omniauth-twitter
pg (~> 1.1)
plain!
plain-rails!
pry
puma (~> 5.0)
qdrant-ruby (~> 0.9.2)
rails (~> 7.0.6)
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ def edit
def update
@track = current_user.tracks.friendly.find(params[:id])
@tab = params[:track][:tab] || "basic-info-tab"
@track.update(track_params)
puts @track.errors.as_json
if params[:nonpersist]
@track.assign_attributes(track_params)
@track.valid?
else
flash.now[:notice] = "Track was successfully updated."
@track.update(track_params)
end
# puts @track.errors.as_json
@track.tab = @tab
flash.now[:notice] = "Track was successfully updated."
end

def private_access
Expand Down Expand Up @@ -107,6 +112,7 @@ def track_params
:display_comments, :display_stats, :include_in_rss,
:offline_listening, :enable_app_playblack,
:cover,
:copyright, :attribution, :noncommercial, :copies,
tags: []
)
end
Expand Down
16 changes: 8 additions & 8 deletions app/helpers/tailwind_form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def field_details(attribute, object, options)
def text_field(attribute, options = {})
@template.content_tag :div, class: "w-full sm:w-full" do
[
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2"),
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil),
super(attribute, options.reverse_merge(class: "input")),
field_details(attribute, object, options)
].join.html_safe
Expand All @@ -41,7 +41,7 @@ def text_field(attribute, options = {})
def email_field(attribute, options = {})
@template.content_tag :div, class: "w-full sm:w-full" do
[
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2"),
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil),
super(attribute, options.reverse_merge(class: "input")),
field_details(attribute, object, options)
].join.html_safe
Expand All @@ -51,7 +51,7 @@ def email_field(attribute, options = {})
def password_field(attribute, options = {})
@template.content_tag :div, class: "w-full sm:w-full" do
[
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2"),
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil),
super(attribute, options.reverse_merge(class: "input")),
field_details(attribute, object, options)
].join.html_safe
Expand All @@ -61,7 +61,7 @@ def password_field(attribute, options = {})
def number_field(attribute, options = {})
@template.tag.div(class: "w-full sm:w-full py-2") do
[
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2"),
options[:label].is_a?(FalseClass) ? @template.content_tag(:div) : @template.label_tag(tr(options[:label] || attribute), nil),
super(attribute, options.reverse_merge(class: "input")),
field_details(attribute, object, options)
].join.html_safe
Expand All @@ -70,7 +70,7 @@ def number_field(attribute, options = {})

def link_field(attribute, options = {})
@template.tag.div(class: "w-full sm:w-full py-2") do
@template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2") +
@template.label_tag(tr(options[:label] || attribute), nil) +
@template.tag.div(class: "flex") do
@template.tag.span(class: "inline-flex items-center px-3 text-sm text-gray-900 dark:bg-gray-900 bg-gray-200 border border-r-0 border-gray-300 rounded-l-md dark:bg-gray-600 dark:text-gray-400 dark:border-gray-600") do
options[:link]
Expand All @@ -82,7 +82,7 @@ def link_field(attribute, options = {})

def right_indicator_field(attribute, options = {})
@template.tag.div(class: "w-full sm:w-full py-2") do
@template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2") +
@template.label_tag(tr(options[:label] || attribute), nil) +
@template.tag.div(class: "flex") do
@template.tag.input(name: "#{object.class.table_name.singularize}[#{attribute}]", value: object.send(attribute), class: "rounded-none rounded-l-lg bg-gray-50 border text-gray-900 focus:ring-blue-500 focus:border-blue-500 block flex-1 min-w-0 w-full text-sm border-gray-300 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500") +
@template.tag.span(class: "inline-flex items-center px-3 text-sm text-gray-900 dark:bg-gray-900 bg-gray-200 border border-l-0 border-gray-300 rounded-r-md dark:bg-gray-600 dark:text-gray-400 dark:border-gray-600") do
Expand All @@ -94,7 +94,7 @@ def right_indicator_field(attribute, options = {})

def text_area(attribute, options = {})
@template.tag.div(class: "w-full sm:w-full py-2") do
@template.label_tag(tr(options[:label] || attribute), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2") +
@template.label_tag(tr(options[:label] || attribute), nil) +
super(attribute, options.reverse_merge(class: "block w-full rounded-md border-0 py-1.5 dark:bg-gray-900 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-brand-600 sm:text-sm sm:leading-6")) +
field_details(attribute, object, options)
end
Expand All @@ -103,7 +103,7 @@ def text_area(attribute, options = {})
#def select_field(object_name, method_name, template_object, options = {})
# puts options
# @template.tag.div(class: "w-full sm:w-full py-2", "data-controller": "select") do
# @template.label_tag(tr(options[:label] || object_name), nil, class: "block text-gray-700 dark:text-white text-sm font-bold mb-2") +
# @template.label_tag(tr(options[:label] || object_name), nil) +
# super(object_name, method_name, template_object, options.reverse_merge(class: "select")) +
# @template.tag.div(data: {"select-target": "holder"}) { "" } +
# field_details(object_name, object, options)
Expand Down
12 changes: 12 additions & 0 deletions app/models/event_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ class EventSchedule < ApplicationRecord

accepts_nested_attributes_for :schedule_schedulings, allow_destroy: true

validates :start_date, :end_date, presence: true
validate :start_date_before_end_date

private

def start_date_before_end_date
return if start_date.blank? || end_date.blank?

if start_date >= end_date
errors.add(:start_date, "must be before end date")
end
end
end
26 changes: 23 additions & 3 deletions app/models/event_ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class EventTicket < ApplicationRecord

# has_many :pending_comments, -> { where(state: 'pending') }, class_name: 'Comment', as: :commentable


store_accessor :settings, :show_sell_until, :boolean
store_accessor :settings, :show_after_sold_out, :boolean
store_accessor :settings, :fee_type, :string
Expand All @@ -18,10 +17,31 @@ class EventTicket < ApplicationRecord
store_accessor :settings, :sales_channel, :string
store_accessor :settings, :after_purchase_message, :string

# scope :purchased_tickets, -> { where(:attibute => value)}
# Ex:- scope :active, -> {where(:active => true)}
validates :title, presence: true
validates :price, presence: true
validates :qty, presence: true
validates :selling_start, presence: true
validates :selling_end, presence: true
validates :short_description, presence: true

validates :title, :price, :qty, :selling_start, :selling_end, :short_description, presence: true
validate :selling_start_before_selling_end


def free?
price.to_i == 0
end

private

def selling_start_before_selling_end
return if selling_start.blank? || selling_end.blank?

if selling_start >= selling_end
errors.add(:selling_start, "must be before selling end")
end
end
# scope :purchased_tickets, -> { where(:attibute => value)}
# Ex:- scope :active, -> {where(:active => true)}

end
14 changes: 12 additions & 2 deletions app/models/schedule_scheduling.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
class ScheduleScheduling < ApplicationRecord
belongs_to :event_schedule

validates :title, :start_date, :end_date, :short_description, presence: true
validates :name, :start_date, :end_date, :short_description, presence: true

validates :start_date, comparison: { greater_than: :end_date }
validates :end_date, comparison: { greater_than: :start_date }

validate :dates_within_event_schedule

private

def dates_within_event_schedule
return if event_schedule.blank? || start_date.blank? || end_date.blank?
if start_date < event_schedule.start_date || end_date > event_schedule.end_date
errors.add(:base, "Schedule dates must be within the event schedule dates")
end
end
end
2 changes: 1 addition & 1 deletion app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def update_mp3(temp_file = nil)

temp_file.rewind
end

# Use the path of the temp file in the Mp3Converter
mp3_path = Mp3Converter.new(temp_file.path).run
mp3_file = File.open(mp3_path)
Expand Down Expand Up @@ -300,5 +299,6 @@ def self.get_tracks_by_tag(tag)
tag = tag.downcase
includes(:user).where('? = ANY (tags)', tag)
end


end
Empty file removed app/views/player/new.html.erb
Empty file.
25 changes: 14 additions & 11 deletions app/views/playlists/_basic_info_tab.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
<div class="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">


<%= form.label :cover %>
<div class="mt-1 sm:mt-0 sm:col-span-6">
<%= render "shared/upload_field",
form: form,
attribute: :cover,
image_url: form.object.cover_url(:small)
%>
</div>


<div class="sm:col-span-6">
<div class="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">

<div class="sm:col-span-4">
<%= form.text_field :title %>
</div>

<div class="sm:col-span-6">
<%= form.label :cover %>
<div class="mt-1 sm:mt-0 sm:col-span-6">
<%= render "shared/upload_field",
form: form,
attribute: :cover,
image_url: form.object.cover_url(:small)
%>
</div>
</div>

<div class="sm:col-span-6">
<%= form.text_area :description %>
</div>

<div class="sm:col-span-4">
<%= form.label :playlist_type %>
<%= form.select :playlist_type, Category::Genres.plain, label: "Playlist type" %>
</div>

<div class="sm:col-span-1">
<div class="sm:col-span-2">
<%= form.label :release_date %>
<%= form.datetime_field :release_date %>
</div>

Expand Down
Loading

0 comments on commit c416737

Please sign in to comment.