Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing site model details #463

Merged
merged 8 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ Metrics/MethodLength:
- filter_settings
Metrics/AbcSize:
Max: 60
Naming/AccessorMethodName:
Enabled: false
atruskie marked this conversation as resolved.
Show resolved Hide resolved
Style/BlockDelimiters:
EnforcedStyle: semantic
AllowBracesOnProceduralOneLiners: true
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent
Layout/LeadingCommentSpace:
Expand Down
104 changes: 47 additions & 57 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class SitesController < ApplicationController
include Api::ControllerHelper

Expand All @@ -9,15 +11,15 @@ def index

respond_to do |format|
#format.html # index.html.erb
format.json {
format.json do
@sites, opts = Settings.api_response.response_advanced(
api_filter_params,
Access::ByPermission.sites(current_user, Access::Core.levels, [@project.id]),
Site,
Site.filter_settings
api_filter_params,
Access::ByPermission.sites(current_user, Access::Core.levels, [@project.id]),
Site,
Site.filter_settings
)
respond_index(opts)
}
end
end
end

Expand All @@ -26,9 +28,7 @@ def show_shallow
do_load_resource
do_authorize_instance

respond_to do |format|
format.json { respond_show }
end
respond_to { |format| format.json { respond_show } }
end

# GET /projects/:project_id/sites/:id
Expand All @@ -50,7 +50,7 @@ def new
do_set_attributes
do_authorize_instance

# initialise lat/lng to Brisbane-ish
# initialize lat/lng to Brisbane-ish
@site.longitude = 152
@site.latitude = -27
respond_to do |format|
Expand Down Expand Up @@ -97,10 +97,10 @@ def update
format.html { redirect_to [@project, @site], notice: 'Site was successfully updated.' }
format.json { respond_show }
else
format.html {
format.html do

render action: 'edit'
}
end
format.json { respond_change_fail }
end
end
Expand All @@ -127,9 +127,7 @@ def upload_instructions
get_project
do_authorize_instance

respond_to do |format|
format.html
end
respond_to { |format| format.html }
end

# GET /projects/:project_id/sites/:id/harvest
Expand All @@ -149,58 +147,53 @@ def harvest
def orphans
do_authorize_class

@sites = Site.find_by_sql("SELECT * FROM sites s
WHERE s.id NOT IN (SELECT site_id FROM projects_sites)
ORDER BY s.name")

respond_to do |format|
format.html
end
@sites = Site.find_by_sql('SELECT * FROM sites s WHERE s.id NOT IN (SELECT site_id FROM projects_sites) ORDER BY s.name')

respond_to { |format| format.html }
end

# GET|POST /sites/filter
def filter
do_authorize_class

filter_response, opts = Settings.api_response.response_advanced(
api_filter_params,
Access::ByPermission.sites(current_user),
Site,
Site.filter_settings
api_filter_params,
Access::ByPermission.sites(current_user),
Site,
Site.filter_settings
)
respond_filter(filter_response, opts)
end

def nav_menu
{
anchor_after: 'baw.shared.links.projects.title',
menu_items: [
{
title: 'baw.shared.links.projects.title',
href: project_path(@project),
tooltip: 'baw.shared.links.projects.description',
icon: nil,
indentation: 1,
#predicate:
},
{
title: 'baw.shared.links.site.title',
href: project_site_path(@project, @site),
tooltip: 'baw.shared.links.site.description',
icon: nil,
indentation: 2,
#predicate:
},
# {
# title: 'baw.shared.links.ethics_statement.title',
# href: ethics_statement_path,
# tooltip: 'baw.shared.links.ethics_statement.description',
# icon: nil,
# indentation: 0,
# predicate: lambda { |user| action_name == 'ethics_statement' }
# }
]
anchor_after: 'baw.shared.links.projects.title',
menu_items: [
{
title: 'baw.shared.links.projects.title',
href: project_path(@project),
tooltip: 'baw.shared.links.projects.description',
icon: nil,
indentation: 1
#predicate:
},
{
title: 'baw.shared.links.site.title',
href: project_site_path(@project, @site),
tooltip: 'baw.shared.links.site.description',
icon: nil,
indentation: 2
#predicate:
}
# {
# title: 'baw.shared.links.ethics_statement.title',
# href: ethics_statement_path,
# tooltip: 'baw.shared.links.ethics_statement.description',
# icon: nil,
# indentation: 0,
# predicate: lambda { |user| action_name == 'ethics_statement' }
# }
]
}
end

Expand All @@ -210,9 +203,7 @@ def get_project
@project = Project.find(params[:project_id])

# avoid the same project assigned more than once to a site
if defined?(@site) && !@site.projects.include?(@project)
@site.projects << @project
end
@site.projects << @project if defined?(@site) && !@site.projects.include?(@project)
end

def site_params
Expand All @@ -222,5 +213,4 @@ def site_params
def site_show_params
params.permit(:id, :project_id, site: {})
end

end
Loading