Class: ContainersController

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

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#autocompleteObject



94
95
96
97
98
99
# File 'app/controllers/containers_controller.rb', line 94

def autocomplete
  @containers = Queries::Container::Autocomplete.new(
    params.require(:term), 
    {project_id: sessions_current_project_id}
  ).autocomplete
end

#container_paramsObject (private)



106
107
108
# File 'app/controllers/containers_controller.rb', line 106

def container_params
  params.require(:container).permit(:parent_id, :type, :name, :disposition, :size_x, :size_y, :size_z)
end

#createObject

POST /containers POST /containers.json



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/containers_controller.rb', line 42

def create
  @container = Container.new(container_params)
  respond_to do |format|
    if @container.save
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container was successfully created.')}
      format.json { render :show, status: :created, location: @container.metamorphosize }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container was NOT successfully created.')}
      format.json { render json: @container.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /containers/1 DELETE /containers/1.json



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/containers_controller.rb', line 71

def destroy
  @container.destroy
  respond_to do |format|
    back = URI(request.referrer).path
    path = container_path(@container)
    if @container.destroyed?
      format.html { redirect_to back == path ? containers_url : back, notice: 'Container was successfully destroyed.' }
      format.json { head :no_content }
    else
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Container was not destroyed, ' + @container.errors.full_messages.join('; ')) }
      format.json { render json: @container.errors, status: :unprocessable_entity }
    end
  end
end

#editObject

GET /containers/1/edit



33
34
# File 'app/controllers/containers_controller.rb', line 33

def edit
end

#forObject

GET /containers/for/global_id



19
20
21
22
23
24
25
# File 'app/controllers/containers_controller.rb', line 19

def for
  object = GlobalID::Locator.locate(params.require(:global_id))
  @container = object.respond_to?(:containable?) ? object.container : nil
  render(json: { 'message' => 'Record not found' }, status: :unauthorized) if !object.is_community? && object.project_id != sessions_current_project_id
  render(json: { success: false}, status: :not_found) and return if @container.nil?
  render :show
end

#indexObject

GET /containers GET /containers.json



8
9
10
11
# File 'app/controllers/containers_controller.rb', line 8

def index
  @recent_objects = Container.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

#listObject



36
37
38
# File 'app/controllers/containers_controller.rb', line 36

def list
  @containers = Container.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10)
end

#newObject

GET /containers/new



28
29
30
# File 'app/controllers/containers_controller.rb', line 28

def new
  @container = Container.new
end

#searchObject



86
87
88
89
90
91
92
# File 'app/controllers/containers_controller.rb', line 86

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

#set_containerObject (private)



102
103
104
# File 'app/controllers/containers_controller.rb', line 102

def set_container
  @container = Container.with_project_id(sessions_current_project_id).find(params[:id])
end

#showObject

GET /containers/1 GET /containers/1.json



15
16
# File 'app/controllers/containers_controller.rb', line 15

def show
end

#updateObject

PATCH/PUT /containers/1 PATCH/PUT /containers/1.json



57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/containers_controller.rb', line 57

def update
  respond_to do |format|
    if @container.update(container_params)
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container was successfully updated.')}
      format.json { head :no_content }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container was NOT successfully updated.')}
      format.json { render json: @container.errors, status: :unprocessable_entity }
    end
  end
end