Class: ContentsController

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/contents_controller.rb', line 94

def autocomplete
  @contents = Content.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
  data = @contents.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.(t)
    }
  end

  render json: data
end

#content_paramsObject (private)



132
133
134
# File 'app/controllers/contents_controller.rb', line 132

def content_params
  params.require(:content).permit(:text, :otu_id, :topic_id)
end

#createObject

POST /contents POST /contents.json



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/contents_controller.rb', line 37

def create
  @content = Content.new(content_params)

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

#destroyObject

DELETE /contents/1 DELETE /contents/1.json



67
68
69
70
71
72
73
# File 'app/controllers/contents_controller.rb', line 67

def destroy
  @content.destroy!
  respond_to do |format|
    format.html { redirect_to contents_url }
    format.json { head :no_content }
  end
end

#downloadObject

GET /contents/download



110
111
112
113
114
115
# File 'app/controllers/contents_controller.rb', line 110

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

#editObject

GET /contents/1/edit



32
33
# File 'app/controllers/contents_controller.rb', line 32

def edit
end

#filterObject

GET /contents/filter.json



89
90
91
92
# File 'app/controllers/contents_controller.rb', line 89

def filter
  @contents = filtered_content
  render '/contents/index'
end

#filtered_contentObject (private)



119
120
121
122
123
124
125
# File 'app/controllers/contents_controller.rb', line 119

def filtered_content
  p =  params.permit(:otu_id, :topic_id, :hours_ago, :most_recent_updates).to_h.symbolize_keys
  p[:most_recent_updates] = 10 if p.empty?
  Queries::ContentFilterQuery.new(p)
    .all
    .with_project_id(sessions_current_project_id)
end

#indexObject

GET /contents GET /contents.json



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/contents_controller.rb', line 8

def index
  respond_to do |format|
    format.html do
      @recent_objects = Content.where(project_id: sessions_current_project_id).recently_updated(10)
      render '/shared/data/all/index'
    end
    format.json {
      @contents = filtered_content
    }
  end
end

#listObject



75
76
77
# File 'app/controllers/contents_controller.rb', line 75

def list
  @contents = Content.with_project_id(sessions_current_project_id).order(:id).page(params[:page])
end

#newObject

GET /contents/new



27
28
29
# File 'app/controllers/contents_controller.rb', line 27

def new
  @content = Content.new
end

#searchObject



79
80
81
82
83
84
85
86
# File 'app/controllers/contents_controller.rb', line 79

def search
  if params[:id].blank?
    redirect_to content_path,
                notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to content_path(params[:id])
  end
end

#set_contentObject (private)



127
128
129
130
# File 'app/controllers/contents_controller.rb', line 127

def set_content
  @content = Content.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @content
end

#showObject

GET /contents/1 GET /contents/1.json



23
24
# File 'app/controllers/contents_controller.rb', line 23

def show
end

#updateObject

PATCH/PUT /contents/1 PATCH/PUT /contents/1.json



53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/contents_controller.rb', line 53

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