Skip to content

Commit

Permalink
More work on nav overhaul
Browse files Browse the repository at this point in the history
- label placement is now automatic
- made helper link functions for new, edit, delete, and visualize
- almost completed site page
- add a custom 'annotation' icon
- removed unnecessary association for `update_location_obfuscated`
- added and info_bar widget partial for the right hand side actions bar
- refactored common link cruft into _nav_buton.html.haml and
_nav_item.html.haml
  • Loading branch information
atruskie committed Jan 12, 2017
1 parent e6452c8 commit c0aaf12
Show file tree
Hide file tree
Showing 45 changed files with 387 additions and 245 deletions.
21 changes: 20 additions & 1 deletion app/assets/javascripts/shared.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
$(document).ready(function () {
$('body').tooltip({selector: "[data-toggle~='tooltip']"})
var body = $('body');
body.tooltip({
selector: "[data-toggle~='tooltip']",
container: 'body',
placement: function getPlacement(tooltip, element) {
var rect = element.getBoundingClientRect(),
top = rect.top,
left = rect.left,
docHeight = body.outerHeight(),
docWidth = body.outerWidth(),
vertical = 0.5 * docHeight - top,
verticalPlacement = vertical > 0 ? 'bottom' : 'top',
horizontal = 0.5 * docWidth - left,
horizontalPlacement = horizontal > 0 ? 'right' : 'left',
// if the page is wider than taller, choose horizontal
//placement = Math.abs(horizontal) > Math.abs(vertical) ? horizontalPlacement : verticalPlacement;
placement = rect.width + 200 < docWidth ? horizontalPlacement : verticalPlacement;
return placement
}
})
});


Expand Down
56 changes: 36 additions & 20 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ body {

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

a>.fa, a>.glyphicon {
a .fa, a > .glyphicon {
color: $text-color;
}
}
Expand All @@ -35,23 +35,37 @@ body {

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



/**
* End sidebar menus
*/

.fa-baw-annotation {
&:before {
content: $fa-var-square-o;
position: relative;
margin-left: 0.25em;
}

&:after {
content: $fa-var-th-large;
font-size: (2/3) * 100%;
position: relative;
top: -2px;
left: calc(-1em - (1/3 * 1px));
}
}

h1 {
margin-bottom: 30px;
}

h3 {
margin-top: 30px;
}
Expand All @@ -77,6 +91,7 @@ h3 {
}
}
}

.thumbnail.right-caption img {
float: left;
margin-right: 9px;
Expand All @@ -90,7 +105,7 @@ h3 {
padding: 0px 4px;
h3 {
margin: 0px;
float:left;
float: left;
}
}

Expand Down Expand Up @@ -142,6 +157,7 @@ h3 {
font-family: FontAwesome;
content: '\f044\0009';
}

.btn-destroy:before {
font-family: FontAwesome;
content: '\f00d\0009';
Expand All @@ -161,10 +177,10 @@ button.list-group-item[disabled] {
/* Home page styles */

.home-arrow {
padding-top:100px;
height:210px;
padding-top: 100px;
height: 210px;
font-weight: bold;
font-size:40px;
font-size: 40px;
vertical-align: middle;
text-align: center;
display: table-cell;
Expand Down Expand Up @@ -198,8 +214,8 @@ footer {
/* Project styles */

.project_sites {
height:400px;
overflow:auto;
height: 400px;
overflow: auto;
}

.project_thumbnail {
Expand All @@ -219,18 +235,18 @@ select[multiple] {
min-width: 20px;
border: 1px solid #555;
white-space: nowrap;
background-color:white;
padding:0 2px;
background-color: white;
padding: 0 2px;
}

/* end Project styles */

/* Site styles */

.map-placeholder {
border:1px solid black;
height:400px;
display:block;
border: 1px solid black;
height: 400px;
display: block;
line-height: 400px;
text-align: center;
}
Expand Down
84 changes: 1 addition & 83 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ def user_signed_in?
super
end

def global_nav_menu
NAV_MENU
end

protected

Expand Down Expand Up @@ -568,84 +565,5 @@ 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
79 changes: 37 additions & 42 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ApplicationHelper


def titles(which_title = :title)
which_title_sym = which_title.to_s.to_sym

Expand All @@ -26,55 +27,49 @@ def bootstrap_class_for(flash_type)
flash_type_keys.include?(flash_type.to_s) ? flash_types[flash_type.to_sym] : 'alert-info'
end

# make our custom url generation methods available to views
include Api::CustomUrlHelpers

def menu_definition
current_user = controller.current_user
has_custom_menu = controller.respond_to?(:nav_menu)

items = controller.global_nav_menu
def destroy_button(href, model_name, icon = 'trash')
render partial: 'shared/nav_button', locals: {
href: href,
title: t('helpers.titles.destroy') + ' ' + t('baw.shared.links.' + model_name + '.title').downcase,
tooltip: t('helpers.tooltips.destroy', model: model_name),
icon: icon,
method: :delete,
confirm: t('helpers.confirm.destroy', model: model_name)
}
end

# insert custom_items into the stream
if has_custom_menu
custom_menu = has_custom_menu ? controller.nav_menu : nil
custom_items = custom_menu[:menu_items]
custom_insert_point = custom_menu[:anchor_after]
def edit_link(href, model_name, icon = 'pencil')
render partial: 'shared/nav_item', locals: {
href: href,
title: t('helpers.titles.edit') + ' ' + t('baw.shared.links.' + model_name + '.title').downcase,
tooltip: t('helpers.tooltips.edit', model: model_name),
icon: icon
}
end

insert_index = nil
insert_index = items.find_index { | menu_item|
menu_item[:title] == custom_insert_point
} unless custom_insert_point.nil?
def new_link(href, model_name, icon = 'plus')
render partial: 'shared/nav_item', locals: {
href: href,
title: t('helpers.titles.new') + ' ' + t('baw.shared.links.' + model_name + '.title').downcase,
tooltip: t('helpers.tooltips.new', model: model_name),
icon: icon
}
end

if insert_index.nil?
# or add custom items to the end if they didn't find a place
items = items + [nil] + custom_items
else
items = items[0..insert_index] + custom_items + items[insert_index+1..-1]
end
end
def listen_link(site)
play_details = site.get_bookmark_or_recording
play_link = play_details.blank? ? nil : make_listen_path(play_details[:audio_recording], play_details[:start_offset_seconds])

# filter items based on their predicate (if it exists)
items = items.select { |menu_item|
next true if menu_item.nil?
next true unless menu_item.include?(:predicate)
return nil if play_link.blank?

next menu_item[:predicate].call(current_user)
render partial: 'shared/nav_item', locals: {
href: play_link,
title: t('baw.shared.links.listen.title'),
tooltip: t('baw.shared.links.listen.description'),
icon: 'headphones'
}
end

# finally transform any dynamic hrefs
items = items.map { |menu_item|
next menu_item if menu_item.nil?
next menu_item unless menu_item[:href].respond_to?(:call)

# clone hash so we don't overwrite values
new_item = menu_item.dup
new_item[:href] = menu_item[:href].call(current_user)
next new_item
}

# noinspection RubyUnnecessaryReturnStatement
return items
end

end
Loading

0 comments on commit c0aaf12

Please sign in to comment.