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 4 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
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ 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
Style/BracesAroundHashParameters:
Expand Down
98 changes: 47 additions & 51 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 @@ -11,10 +13,10 @@ def index
#format.html # index.html.erb
format.json {
@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)
}
Expand All @@ -38,7 +40,7 @@ def show
do_authorize_instance

respond_to do |format|
format.html { @site.update_location_obfuscated(current_user) }
format.html do @site.update_location_obfuscated(current_user) end
format.json { respond_show }
end
end
Expand All @@ -50,7 +52,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 All @@ -75,10 +77,10 @@ def create

respond_to do |format|
if @site.save
format.html { redirect_to [@project, @site], notice: 'Site was successfully created.' }
format.html do redirect_to [@project, @site], notice: 'Site was successfully created.' end
format.json { respond_create_success(project_site_path(@project, @site)) }
else
format.html { render action: 'new' }
format.html do render action: 'new' end
format.json { respond_change_fail }
end
end
Expand All @@ -94,13 +96,13 @@ def update

respond_to do |format|
if @site.update_attributes(site_params)
format.html { redirect_to [@project, @site], notice: 'Site was successfully updated.' }
format.html do redirect_to [@project, @site], notice: 'Site was successfully updated.' end
format.json { respond_show }
else
format.html {
format.html do

render action: 'edit'
}
end
format.json { respond_change_fail }
end
end
Expand All @@ -116,7 +118,7 @@ def destroy
add_archived_at_header(@site)

respond_to do |format|
format.html { redirect_to project_sites_url(@project) }
format.html do redirect_to project_sites_url(@project) end
format.json { respond_destroy }
end
end
Expand Down Expand Up @@ -149,58 +151,55 @@ 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")
@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

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 +209,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 +219,4 @@ def site_params
def site_show_params
params.permit(:id, :project_id, site: {})
end

end
Loading