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 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

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



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

def autocomplete
  @sources =  Queries::SourceFilterQuery.new(params[:term], project_id: sessions_current_project_id).by_project_all.limit(50)
  data     = @sources.collect do |t|
    {id:              t.id,
     label:           ApplicationController.helpers.source_tag(t),
     response_values: {
       params[:method] => t.id
     },
     label_html:      ApplicationController.helpers.source_tag(t)
    }
  end
  render :json => data
end

- (Object) create



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/project_sources_controller.rb', line 15

def create
  @project_source = ProjectSource.new(project_source_params) 
  if @project_source.save
    @source = @project_source.source
    flash[:notice] = 'Added source to project.'
  else 
    flash[:notice] = "Failed to add source to project. #{@project_source.error_messages}."
    render source_path(@project_source.source)
  end
end

- (Object) destroy



26
27
28
29
30
31
# File 'app/controllers/project_sources_controller.rb', line 26

def destroy
  @project_source = ProjectSource.find(params[:id])
  @source = @project_source.source
  @project_source.destroy 
  render :create # same code
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)



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

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