Class: SoundsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/sounds_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#api_indexObject

GET /api/v1/sounds



24
25
26
27
28
29
# File 'app/controllers/sounds_controller.rb', line 24

def api_index
  @sounds = Queries::Sound::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .page(params[:page]).per(params[:per])
  render '/sounds/api/v1/index'
end

#autocompleteObject



94
95
96
97
98
99
# File 'app/controllers/sounds_controller.rb', line 94

def autocomplete
  @sounds = Sound.where(project_id: sessions_current_project_id)
    .where('name ilike ?', "%#{ params.require(:term)}%")
    .order(:name)
    .limit(20)
end

#createObject

POST /sounds or /sounds.json



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/sounds_controller.rb', line 45

def create
  @sound = Sound.new(sound_params)

  respond_to do |format|
    if @sound.save
      format.html { redirect_to @sound, notice: 'Sound was successfully created.' }
      format.json { render :show, status: :created, location: @sound }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @sound.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /sounds/1 or /sounds/1.json



73
74
75
76
77
78
79
80
# File 'app/controllers/sounds_controller.rb', line 73

def destroy
  @sound.destroy!

  respond_to do |format|
    format.html { redirect_to sounds_path, status: :see_other, notice: 'Sound was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /sounds/1/edit



41
42
# File 'app/controllers/sounds_controller.rb', line 41

def edit
end

#indexObject

GET /sounds or /sounds.json



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/sounds_controller.rb', line 9

def index
  respond_to do |format|
    format.html do
      @recent_objects = Sound.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @sounds = Queries::Sound::Filter.new(params).all
        .where(project_id: sessions_current_project_id)
        .page(params[:page]).per(params[:per])
    }
  end
end

#listObject



90
91
92
# File 'app/controllers/sounds_controller.rb', line 90

def list
  @sounds = Sound.where(project_id: sessions_current_project_id).page(params[:page]).per(params[:per])
end

#newObject

GET /sounds/new



36
37
38
# File 'app/controllers/sounds_controller.rb', line 36

def new
  @sound = Sound.new
end

#select_optionsObject



82
83
84
85
86
87
# File 'app/controllers/sounds_controller.rb', line 82

def select_options
  @sounds = Sound.select_optimized(
    sessions_current_user_id, 
    sessions_current_project_id,
   params.require(:target))
end

#set_soundObject (private)

Use callbacks to share common setup or constraints between actions.



103
104
105
# File 'app/controllers/sounds_controller.rb', line 103

def set_sound
  @sound = Sound.find(params[:id])
end

#showObject

GET /sounds/1 or /sounds/1.json



32
33
# File 'app/controllers/sounds_controller.rb', line 32

def show
end

#sound_paramsObject (private)

Only allow a list of trusted parameters through.



108
109
110
# File 'app/controllers/sounds_controller.rb', line 108

def sound_params
  params.require(:sound).permit(:name, :sound_file)
end

#updateObject

PATCH/PUT /sounds/1 or /sounds/1.json



60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/sounds_controller.rb', line 60

def update
  respond_to do |format|
    if @sound.update(sound_params)
      format.html { redirect_to @sound, notice: 'Sound was successfully updated.' }
      format.json { render :show, status: :ok, location: @sound }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @sound.errors, status: :unprocessable_entity }
    end
  end
end