Class: ConveyancesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/conveyances_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, #cumulative_projects_created_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, #sound_cumulative_gb_per_year, #sound_gb_per_year, #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



28
29
30
31
32
33
34
35
# File 'app/controllers/conveyances_controller.rb', line 28

def api_index
  @conveyances = Queries::Conveyance::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('conveyances.conveyance_object_type, conveyances.conveyance_object_id, conveyances.position')
    .page(params[:page])
    .per(params[:per])
  render '/conveyances/api/v1/index'
end

#api_showObject



37
38
39
# File 'app/controllers/conveyances_controller.rb', line 37

def api_show
  render '/conveyances/api/v1/show'
end

#autocompleteObject



95
96
97
98
99
100
# File 'app/controllers/conveyances_controller.rb', line 95

def autocomplete
  @conveyances = Queries::Conveyance::Autocomplete.new(
    params[:term], project_id: sessions_current_project_id,
    polymorphic_types: params[:polymorphic_types_allowed]
  ).autocomplete
end

#conveyance_paramsObject (private)



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/conveyances_controller.rb', line 114

def conveyance_params
  params.require(:conveyance).permit(
    :sound_id,
    :conveyance_object_id,
    :conveyance_object_type,
    :position,
    :start_time,
    :end_time,
    sound_attributes: [
      :sound_file,
      :name
    ]
  )
end

#createObject

POST /conveyances or /conveyances.json



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

def create
  @conveyance = Conveyance.new(conveyance_params)

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

#destroyObject

DELETE /conveyances/1 or /conveyances/1.json



86
87
88
89
90
91
92
93
# File 'app/controllers/conveyances_controller.rb', line 86

def destroy
  @conveyance.destroy!

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

#editObject

GET /conveyances/1/edit



54
55
# File 'app/controllers/conveyances_controller.rb', line 54

def edit
end

#indexObject

GET /conveyances or /conveyances.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/conveyances_controller.rb', line 9

def index
  respond_to do |format|
    format.html {
      @recent_objects = Conveyance.where(
        project_id: sessions_current_project_id
      ).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @conveyances = Queries::Conveyance::Filter.new(params)
        .all
        .where(project_id: sessions_current_project_id)
        .where(Queries::Annotator::polymorphic_params(params, Conveyance)) # TODO: -> configured?
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



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

def list
  @conveyances = Conveyance.where(project_id: sessions_current_project_id).page(params[:page])
end


102
103
# File 'app/controllers/conveyances_controller.rb', line 102

def navigation
end

#newObject



49
50
51
# File 'app/controllers/conveyances_controller.rb', line 49

def new
  @conveyance = Conveyance.new
end

#select_optionsObject



105
106
107
# File 'app/controllers/conveyances_controller.rb', line 105

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

#set_conveyanceObject (private)



110
111
112
# File 'app/controllers/conveyances_controller.rb', line 110

def set_conveyance
  @conveyance = Conveyance.find(params[:id])
end

#showObject

GET /conveyances/1 or /conveyances/1.json



46
47
# File 'app/controllers/conveyances_controller.rb', line 46

def show
end

#updateObject

PATCH/PUT /conveyances/1 or /conveyances/1.json



73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/conveyances_controller.rb', line 73

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