Class: ProjectSourcesController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



47
48
49
50
51
52
53
54
# File 'app/controllers/project_sources_controller.rb', line 47

def autocomplete
  @sources = Queries::Source::Autocomplete.new(
    params.require(:term),
    {project_id: sessions_current_project_id, limit_to_project: true} 
  ).autocomplete

  render 'sources/autocomplete'
end

- (Object) create



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/project_sources_controller.rb', line 15

def create
  @project_source = ProjectSource.new(project_source_params) 

  respond_to do |format|
    if @project_source.save
      @source = @project_source.source 
      format.html { flash[:notice] = 'Added source to project.' }
      format.json { render action: 'show', status: :created, location: @project_source }
      format.js { }
    else
      format.html {
        flash[:notice] = "Failed to add source to project. #{@project_source.error_messages}."
        render source_path(@project_source.source)
      }
      format.json { render json: @project_source.errors, status: :unprocessable_entity }
      format.js { }
    end
  end
end

- (Object) destroy



35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/project_sources_controller.rb', line 35

def destroy
  @project_source = ProjectSource.find(params[:id])
  @source = @project_source.source
  @project_source.destroy 

  respond_to do |format|
    format.html { redirect_to sources_url }
    format.json { head :no_content }
    format.js { render :create }
  end
end

- (Object) index

GET /project_sources



5
6
7
8
# File 'app/controllers/project_sources_controller.rb', line 5

def index
  @recent_objects =  Source.joins(:project_sources).where(project_sources: {project_id: sessions_current_project_id}).updated_in_last(1.month).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



10
11
12
13
# File 'app/controllers/project_sources_controller.rb', line 10

def list
  @sources = Source.joins(:project_sources).where(project_sources: {project_id: sessions_current_project_id}).page(params[:page])
  render '/sources/list'
end

- (Object) project_source_params (protected)



58
59
60
# File 'app/controllers/project_sources_controller.rb', line 58

def project_source_params
  params.require(:project_source).permit(:source_id, :project_id)
end