Class: ProjectOrganizationsController

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

#set_time_zone

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, #cumulative_projects_created_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_initials, #project_link, #project_login_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #taxonworks_classification, #week_in_review_graphs

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



77
78
79
80
# File 'app/controllers/project_organizations_controller.rb', line 77

def autocomplete
  @organizations = Queries::Organization::Autocomplete.new(params.require(:term)).autocomplete
  render 'organizations/autocomplete'
end

#createObject

POST /project_organizations POST /project_organizations.json



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

def create
  @project_organization = ProjectOrganization.new(project_organization_params)

  respond_to do |format|
    if @project_organization.save
      format.html { redirect_to @project_organization, notice: 'Organization was successfully added to the project.' }
      format.json { render :show, status: :created, location: @project_organization }
    else
      format.html {
        flash[:notice] = "Failed to add the organization to the project. #{@project_organization.error_messages}."
        redirect_to project_organizations_path
      }
      format.json { render json: @project_organization.errors, status: :unprocessable_content }
    end
  end
end

#destroyObject

DELETE /project_organizations/1 DELETE /project_organizations/1.json



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

def destroy
  respond_to do |format|
    if @project_organization.destroy
      format.html { redirect_to project_organizations_path, status: :see_other, notice: 'Organization was successfully removed from the project.' }
      format.json { head :no_content }
    else
      format.html {
        flash[:notice] = @project_organization.error_messages.join('; ')
        redirect_to project_organizations_path
      }
      format.json { render json: @project_organization.errors, status: :unprocessable_content }
    end
  end
end

#downloadObject

GET /project_organizations/download



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

def download
  send_data Export::CSV.generate_csv(
    ProjectOrganization.where(project_id: sessions_current_project_id)), type: 'text', filename: "project_organizations_#{DateTime.now}.tsv"
end

#indexObject

GET /project_organizations GET /project_organizations.json



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/project_organizations_controller.rb', line 11

def index
  respond_to do |format|
    format.html {
      @recent_objects = Organization.joins(:project_organizations).where(project_organizations: {project_id: sessions_current_project_id}).created_this_week.order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @project_organizations = ProjectOrganization.where(project_id: sessions_current_project_id)
        .includes(organization: [:depictions])
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



30
31
32
33
# File 'app/controllers/project_organizations_controller.rb', line 30

def list
  @organizations = Organization.joins(:project_organizations).where(project_organizations: {project_id: sessions_current_project_id}).page(params[:page])
  render '/organizations/list'
end

#project_organization_paramsObject (private)



88
89
90
# File 'app/controllers/project_organizations_controller.rb', line 88

def project_organization_params
  params.require(:project_organization).permit(:organization_id)
end

#set_project_organizationObject (private)



84
85
86
# File 'app/controllers/project_organizations_controller.rb', line 84

def set_project_organization
  @project_organization = ProjectOrganization.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /project_organizations/1.json



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

def show
end