From 652c56dafdd6d31eda97829be6807ad5f6fdf985 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 11 Feb 2014 15:53:20 +0000 Subject: [PATCH] * VRFS-924 haml added --- admin/Gemfile | 2 + admin/app/admin/bands.rb | 6 ++- admin/app/admin/jam_ruby_users.rb | 8 +++- admin/app/admin/recordings.rb | 48 +++++++++++++++++-- admin/app/assets/javascripts/active_admin.js | 2 + .../app/views/admin/recordings/_form.html.erb | 15 ++++++ .../recordings/_recorded_track.html.haml | 9 ++-- .../_recorded_track_fields.html.erb | 6 +++ admin/config/application.rb | 3 ++ admin/config/initializers/active_admin.rb | 3 ++ admin/config/routes.rb | 17 +++++++ ruby/lib/jam_ruby/models/band.rb | 4 ++ ruby/lib/jam_ruby/models/instrument.rb | 4 ++ ruby/lib/jam_ruby/models/recording.rb | 7 ++- web/config/application.rb | 2 +- 15 files changed, 119 insertions(+), 17 deletions(-) diff --git a/admin/Gemfile b/admin/Gemfile index 8a4306801..a7a1d1e2c 100644 --- a/admin/Gemfile +++ b/admin/Gemfile @@ -52,6 +52,8 @@ gem 'postgres-copy', '0.6.0' gem 'aws-sdk', '1.29.1' gem 'bugsnag' gem 'gon' +gem 'cocoon' +gem 'haml-rails' gem 'resque' gem 'resque-retry' gem 'resque-failed-job-mailer' diff --git a/admin/app/admin/bands.rb b/admin/app/admin/bands.rb index 5e7dd2f80..17bcfee13 100644 --- a/admin/app/admin/bands.rb +++ b/admin/app/admin/bands.rb @@ -1,3 +1,7 @@ -ActiveAdmin.register JamRuby::Band, :as => 'Band' do +ActiveAdmin.register JamRuby::Band, :as => 'Band' do + collection_action :autocomplete_band_name, :method => :get + controller do + autocomplete :band, :name, :full => true + end end diff --git a/admin/app/admin/jam_ruby_users.rb b/admin/app/admin/jam_ruby_users.rb index 6332400ed..79890b3cf 100644 --- a/admin/app/admin/jam_ruby_users.rb +++ b/admin/app/admin/jam_ruby_users.rb @@ -1,5 +1,8 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do + + collection_action :autocomplete_user_email, :method => :get + menu :label => 'Users', :parent => 'Users' config.sort_order = 'created_at DESC' @@ -11,7 +14,8 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do filter :created_at filter :updated_at - form do |ff| + + form do |ff| ff.inputs "Details" do ff.input :email ff.input :admin @@ -95,6 +99,8 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do controller do + autocomplete :user, :email, :full => true + def create @jam_ruby_user = JamRuby::User.new(params[:jam_ruby_user]) @jam_ruby_user.administratively_created = true diff --git a/admin/app/admin/recordings.rb b/admin/app/admin/recordings.rb index e8a347ad7..210509560 100644 --- a/admin/app/admin/recordings.rb +++ b/admin/app/admin/recordings.rb @@ -1,18 +1,56 @@ ActiveAdmin.register JamRuby::Recording, :as => 'Recording' do - menu :label => 'Recordings', :parent => 'Recordings' + menu :label => 'Recording', :parent => 'Recordings' config.sort_order = 'DESC updated_at' config.batch_actions = false # config.clear_action_items! config.filters = false - #form :partial => 'form' - - collection_action :autocomplete_user_email, :method => :get + form :partial => 'form' controller do - autocomplete :user, :email + def new + @recording = JamRuby::Recording.new + super + end + + def create + owner = User.find_by_email!(params[:jam_ruby_recording][:owner]) + band = User.find_by_band!(params[:jam_ruby_recording][:band]) + recording = Recording.new + recording.owner = owner + recording.band = band + recording.save + redirect_to("/admin/recordings/#{recording.id}") + end + + def edit + @recording = resource + super + end + + + def update + owner = User.find_by_email!(params[:jam_ruby_recording][:owner]) + band = Band.find_by_name!(params[:jam_ruby_recording][:band]) + recorded_tracks = params[:jam_ruby_recording][:recorded_tracks] + recorded_tracks.each do |recorded_track| + track = RecordedTrack.new + track.client_id ||= 'fake' + track.track_id ||= 'fake' + track.client_track_id ||= 'fake' + track.sound ||= 'stereo' + track.recording = resource + track.user = User.find_by_email!(recorded_track[:user]) + track.instrument = Instrument.find_by_instrument!(recorded_track[:instrument]) + resource.recorded_tracks << track + end + resource.owner = owner + resource.band = band + resource.save + redirect_to("/admin/recordings/#{resource.id}") + end end diff --git a/admin/app/assets/javascripts/active_admin.js b/admin/app/assets/javascripts/active_admin.js index 0ebd669c5..8d8a2f0b3 100644 --- a/admin/app/assets/javascripts/active_admin.js +++ b/admin/app/assets/javascripts/active_admin.js @@ -5,6 +5,8 @@ //= require jquery.ui.widget //= require jquery.ui.datepicker //= require jquery.ui.dialog +//= require jquery.ui.autocomplete +//= require cocoon //= require active_admin/application //= require autocomplete-rails //= require base diff --git a/admin/app/views/admin/recordings/_form.html.erb b/admin/app/views/admin/recordings/_form.html.erb index e69de29bb..ceb327eb9 100644 --- a/admin/app/views/admin/recordings/_form.html.erb +++ b/admin/app/views/admin/recordings/_form.html.erb @@ -0,0 +1,15 @@ +<%= semantic_form_for([:admin, @recording], :html => {:multipart => true}, :url => @recording.new_record? ? admin_recordings_path : "/admin/recordings/#{@recording.id}") do |f| %> + <%= f.semantic_errors *f.object.errors.keys %> + <%= f.inputs do %> + <%= f.input :owner, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path %> + <%= f.input :band, :as => :autocomplete, :url => autocomplete_band_name_admin_bands_path %> + + <%= f.fields_for :recorded_tracks do |recorded_track| %> + <%= render 'recorded_track', f: recorded_track %> + <% end %> + + <%= link_to_add_association 'add track', f, :recorded_tracks %> + + <% end %> + <%= f.actions %> +<% end %> diff --git a/admin/app/views/admin/recordings/_recorded_track.html.haml b/admin/app/views/admin/recordings/_recorded_track.html.haml index 25baacf6f..88c59eda8 100644 --- a/admin/app/views/admin/recordings/_recorded_track.html.haml +++ b/admin/app/views/admin/recordings/_recorded_track.html.haml @@ -1,5 +1,4 @@ - -<%= f.inputs do %> - <%= f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path %> - <%= f.input :instrument, :collection => Instrument.all %> -<% end %> \ No newline at end of file +.nested-fields + = f.inputs :name => "Track" do + = f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path + = f.input :instrument, :collection => Instrument.all \ No newline at end of file diff --git a/admin/app/views/admin/recordings/_recorded_track_fields.html.erb b/admin/app/views/admin/recordings/_recorded_track_fields.html.erb index e69de29bb..e8a91c1a3 100644 --- a/admin/app/views/admin/recordings/_recorded_track_fields.html.erb +++ b/admin/app/views/admin/recordings/_recorded_track_fields.html.erb @@ -0,0 +1,6 @@ +
  • +
    + <%= f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path %> + <%= f.input :instrument, :collection => Instrument.all %> +
    +
  • \ No newline at end of file diff --git a/admin/config/application.rb b/admin/config/application.rb index b3a1218c4..3ddc73a81 100644 --- a/admin/config/application.rb +++ b/admin/config/application.rb @@ -16,6 +16,9 @@ end include JamRuby +User = JamRuby::User +Band = JamRuby::Band + module JamAdmin class Application < Rails::Application diff --git a/admin/config/initializers/active_admin.rb b/admin/config/initializers/active_admin.rb index 2db685656..4976f7673 100644 --- a/admin/config/initializers/active_admin.rb +++ b/admin/config/initializers/active_admin.rb @@ -165,4 +165,7 @@ ActiveAdmin.setup do |config| # config.csv_options = {} config.view_factory.footer = Footer + + config.register_javascript 'autocomplete-rails.js' + config.register_stylesheet 'jquery.ui.theme.css' end diff --git a/admin/config/routes.rb b/admin/config/routes.rb index a86cb918a..05aed06bc 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -9,16 +9,33 @@ JamAdmin::Application.routes.draw do devise_for :users, :class_name => "JamRuby::User", :path_prefix => '/admin', :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'} + + scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do root :to => "admin/dashboard#index" + namespace :admin do + resources :users do + get :autocomplete_user_email, :on => :collection + end + end + + namespace :admin do + resources :bands do + get :autocomplete_band_name, :on => :collection + end + end + ActiveAdmin.routes(self) + + match '/api/artifacts' => 'artifacts#update_artifacts', :via => :post match '/api/mix/:id/enqueue' => 'admin/mixes#mix_again', :via => :post mount Resque::Server.new, :at => "/resque" + # The priority is based upon order of creation: # first created -> highest priority. diff --git a/ruby/lib/jam_ruby/models/band.rb b/ruby/lib/jam_ruby/models/band.rb index 63d764cd9..3a297c4b9 100644 --- a/ruby/lib/jam_ruby/models/band.rb +++ b/ruby/lib/jam_ruby/models/band.rb @@ -273,6 +273,10 @@ module JamRuby true end + def to_s + name + end + private def self.validate_genres(genres, is_nil_ok) if is_nil_ok && genres.nil? diff --git a/ruby/lib/jam_ruby/models/instrument.rb b/ruby/lib/jam_ruby/models/instrument.rb index 2764a930c..9925dd360 100644 --- a/ruby/lib/jam_ruby/models/instrument.rb +++ b/ruby/lib/jam_ruby/models/instrument.rb @@ -49,5 +49,9 @@ module JamRuby MAP_ICON_NAME[self.id] end + def to_s + description + end + end end diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index e02ec22eb..c55b21c99 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -17,7 +17,6 @@ module JamRuby belongs_to :band, :class_name => "JamRuby::Band", :inverse_of => :recordings belongs_to :music_session, :class_name => "JamRuby::MusicSession", :inverse_of => :recordings - validates :music_session, :presence => true validate :not_already_recording, :on => :create validate :not_still_finalizing_previous, :on => :create validate :not_playback_recording, :on => :create @@ -36,7 +35,7 @@ module JamRuby end def not_already_recording - if music_session.is_recording? + if music_session && music_session.is_recording? errors.add(:music_session, ValidationMessages::ALREADY_BEING_RECORDED) end end @@ -45,7 +44,7 @@ module JamRuby # after a recording is done, users need to keep or discard it. # this checks if the previous recording is still being finalized - unless music_session.is_recording? + unless !music_session || music_session.is_recording? previous_recording = music_session.most_recent_recording if previous_recording previous_recording.recorded_tracks.each do |recorded_track| @@ -64,7 +63,7 @@ module JamRuby end def not_playback_recording - if music_session.is_playing_recording? + if music_session && music_session.is_playing_recording? errors.add(:music_session, ValidationMessages::ALREADY_PLAYBACK_RECORDING) end end diff --git a/web/config/application.rb b/web/config/application.rb index 8d080b833..24aef184f 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -21,7 +21,7 @@ if defined?(Bundler) # Bundler.require(:default, :assets, Rails.env) end -include JamRuby + include JamRuby # require "rails/test_unit/railtie" module SampleApp