Class: ProjectSourcesController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Instance Method Details

#autocompleteObject



55
56
57
58
59
60
61
62
# File 'app/controllers/project_sources_controller.rb', line 55

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

#createObject



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

#destroyObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/project_sources_controller.rb', line 35

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

  respond_to do |format|
    if @project_source.destroy
      format.html { redirect_to sources_url }
      format.json { head :no_content }
      format.js { render :create } # TODO: remove?
    else
      format.html {
        flash[:notice] = @project_source.error_messages.join('; ')
        render source_path(@project_source.source)
      }
      format.json { render json: @project_source.errors, status: :unprocessable_entity }
      format.js { } # TODO: remove
    end
  end
end

#downloadObject

GET /project_sources/download



65
66
67
68
# File 'app/controllers/project_sources_controller.rb', line 65

def download
  send_data Export::Download.generate_csv(
    ProjectSource.where(project_id: sessions_current_project_id)), type: 'text', filename: "project_sources_#{DateTime.now}.csv"
end

#indexObject

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

#listObject



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

#project_source_paramsObject (protected)



72
73
74
# File 'app/controllers/project_sources_controller.rb', line 72

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