Class: ProjectSourcesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/project_sources_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

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

#autocompleteObject



55
56
57
58
59
60
61
62
63
# 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



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

def download
  send_data Export::Csv.generate_csv(
    ProjectSource.where(project_id: sessions_current_project_id)), type: 'text', filename: "project_sources_#{DateTime.now}.tsv"
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)



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

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