Skip to content

Commit

Permalink
WIP refactoring and stanardizing secondary menus
Browse files Browse the repository at this point in the history
See #275
  • Loading branch information
atruskie committed Dec 14, 2016
1 parent 47f8fc2 commit 7eefa74
Show file tree
Hide file tree
Showing 22 changed files with 551 additions and 175 deletions.
4 changes: 0 additions & 4 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

$grid-float-breakpoint: 992px;

ul.nav-pills > li > a {
padding: 5px 10px;
}

@import "bootstrap-sprockets";
@import "bootstrap";

Expand Down
36 changes: 36 additions & 0 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ body {
padding-top: 60px;
}

/**
* sidebar menus
* These definitions have parallels in https://github.com/QutBioacoustics/baw-client/blob/master/src/app/navigation/_navigation.scss#L1
*/

.left-nav-bar, .right-nav-bar {
ul.nav-pills > li {
& > a, & > button {
padding: 5px 10px;
text-align: left;
}
}

a>.fa, a>.glyphicon {
color: $text-color;
}
}

.left-nav-bar {

@for $i from 0 through 4 {
.indentation-#{$i} {
$step: ($i * 10%);
width: 100% - $step;
margin-left: $step !important;
font-size: 100% - ($step / 2);
}
}
}



/**
* End sidebar menus
*/

h1 {
margin-bottom: 30px;
}
Expand Down
84 changes: 84 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def user_signed_in?
super
end

def global_nav_menu
NAV_MENU
end

protected

# Add archived at header to HTTP response
Expand Down Expand Up @@ -564,4 +568,84 @@ def should_check_authorization?
!is_devise_controller && !is_admin_controller
end

# title and tooltip are translate keys
NAV_MENU = [
{
title: 'baw.shared.links.home.title',
href: Api::UrlHelpers.root_path,
tooltip: 'baw.shared.links.home.description',
icon: 'home',
},
{
title: 'baw.shared.links.log_in.title',
href: lambda { |user| Api::UrlHelpers.new_user_session_path },
tooltip: 'baw.shared.links.log_in.description',
icon: 'sign-in',
predicate: lambda { |user| user.blank? },
},
{
title: 'baw.shared.links.profile.title',
href: lambda { |user| Api::UrlHelpers.my_account_path },
tooltip: 'baw.shared.links.profile.title',
icon: 'user',
predicate: lambda { |user| !user.blank? },
},
{
title: 'baw.shared.links.register.title',
href: Api::UrlHelpers.new_user_registration_path,
tooltip: 'baw.shared.links.register.description',
icon: 'user-plus',
predicate: lambda { |user| user.blank? },
},
{
title: 'baw.shared.links.annotations.title',
href: lambda { |user| Api::UrlHelpers.audio_events_user_account_path(user) },
tooltip: 'baw.shared.links.annotations.description',
icon: 'square-o',
predicate: lambda { |user| !user.blank? },
},
{
title: 'baw.shared.links.projects.title',
href: Api::UrlHelpers.projects_path,
tooltip: 'baw.shared.links.projects.description',
icon: 'globe',
},
{
title: 'baw.shared.links.audio_analysis.title',
href: Api::UrlHelpers.make_audio_analysis_path,
tooltip: 'baw.shared.links.audio_analysis.description',
icon: 'server',
ribbon: 'beta'
},
{
title: 'baw.shared.links.library.title',
href: Api::UrlHelpers.make_library_path,
tooltip: 'baw.shared.links.library.description',
icon: 'book'
},
{
title: 'baw.shared.links.data_request.title',
href: Api::UrlHelpers.data_request_path,
tooltip: 'baw.shared.links.data_request.description',
icon: 'table',
},
{
title: 'baw.shared.links.upload_audio.title',
href: Api::UrlHelpers.data_upload_path,
tooltip: 'baw.shared.links.upload_audio.description',
icon: 'envelope',
},
{
title: 'baw.shared.links.report_problem.title',
href: Api::UrlHelpers.bug_report_path,
tooltip: 'baw.shared.links.report_problem.description',
icon: 'bug',
},
{
title: 'baw.shared.links.website_status.title',
href: Api::UrlHelpers.website_status_path,
tooltip: 'baw.shared.links.website_status.description',
icon: 'line-chart',
}
].freeze
end
59 changes: 46 additions & 13 deletions app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def index
end

@random_projects = Access::ByPermission
.projects(current_user)
.includes(:creator)
.references(:creator)
.order("RANDOM()")
.take(3)
.projects(current_user)
.includes(:creator)
.references(:creator)
.order('RANDOM()')
.take(3)

respond_to do |format|
format.html
Expand Down Expand Up @@ -254,6 +254,38 @@ def cors_preflight
fail CustomErrors::BadRequestError, "CORS preflight request to '#{params[:requested_route]}' was not valid. Required headers: Origin, Access-Control-Request-Method. Optional headers: Access-Control-Request-Headers."
end

def nav_menu
{
#anchor_after: 'baw.shared.links.home.title',
menu_items: [
{
title: 'baw.shared.links.disclaimers.title',
href: disclaimers_path,
tooltip: 'baw.shared.links.disclaimers.description',
icon: nil,
indentation: 0,
predicate: lambda { |user| action_name == 'disclaimers' }
},
{
title: 'baw.shared.links.credits.title',
href: credits_path,
tooltip: 'baw.shared.links.credits.description',
icon: nil,
indentation: 0,
predicate: lambda { |user| action_name == 'credits' }
},
{
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

private

def recent_audio_recordings
Expand All @@ -272,18 +304,18 @@ def recent_audio_events

if current_user.blank?
@recent_audio_events = AudioEvent
.order(order_by_coalesce)
.limit(7)
.order(order_by_coalesce)
.limit(7)
elsif Access::Core.is_admin?(current_user)
@recent_audio_events = AudioEvent
.includes([:creator, audio_recording: {site: :projects}])
.order(order_by_coalesce)
.limit(10)
.includes([:creator, audio_recording: {site: :projects}])
.order(order_by_coalesce)
.limit(10)
else
@recent_audio_events = Access::ByPermission
.audio_events(current_user, Access::Core.levels)
.includes([:updater, audio_recording: :site])
.order(order_by_coalesce).limit(10)
.audio_events(current_user, Access::Core.levels)
.includes([:updater, audio_recording: :site])
.order(order_by_coalesce).limit(10)
end

end
Expand Down Expand Up @@ -344,4 +376,5 @@ def annotation_download_params
:selected_timezone_name)
end


end
32 changes: 32 additions & 0 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,38 @@ def filter
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' }
# }
]
}
end

private

def get_project
Expand Down
Loading

0 comments on commit 7eefa74

Please sign in to comment.