Skip to content

Commit

Permalink
Merge pull request #631 from ontohub/589-help_buttons_linking_to_wiki…
Browse files Browse the repository at this point in the history
…_pages

Context sensitive help, fixes #589.
  • Loading branch information
nning committed Feb 1, 2014
2 parents fb4314c + 4dd75d4 commit e795954
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 51 deletions.
98 changes: 52 additions & 46 deletions app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
module LinkHelper

def sort_link_list(collection)
hash = {}

collection.each_with_index do |link, i|
if link.entity_mappings.empty?
hash["empty#{i}"] = [{link: link, target: ''}]
else
link.entity_mappings.each do |mapping|
sym = mapping.source.to_s.to_sym
if hash[sym]
hash[sym] << {link: link, target: mapping.target}
else
hash[sym] = [{link: link, target: mapping.target}]
end
end
end
end
include ExternalMapping

hash
def counter_link(url, counter, subject)
text = content_tag(:strong, counter || '?')
text << content_tag(:span, counter == 1 ? subject : subject.pluralize)

link_to text, url
end

def fancy_link(resource)
return nil unless resource

Expand All @@ -29,11 +17,11 @@ def fancy_link(resource)
data_type, value = determine_image_type(resource)

name = block_given? ? yield(resource) : resource

unless resource.is_a? Array
title = resource.respond_to?(:title) ? resource.title : nil
else

if resource.is_a? Array
title = resource.last.respond_to?(:title) ? resource.last.title : nil
else
title = resource.respond_to?(:title) ? resource.title : nil
end

if resource.is_a? Ontology
Expand All @@ -47,16 +35,33 @@ def fancy_link(resource)
:title => title
end

def format_links(*args, &block)
options = args.extract_options!
args = %w(xml json) if args.empty?
args.flatten!

options[:url] ||= {}

links = ''
links << capture(&block) << ' ' if block_given?
links << args.collect do |f|
content_tag :li, link_to(f.to_s.upcase, params.merge(options[:url]).merge(format: f), title: "Get this page as #{f.upcase}")
end.join("")

content_tag('ul', links.html_safe, class: 'formats')
end

def determine_image_type(resource)
if resource.is_a?(Repository) && resource.is_private
return ['data-type', "Private#{resource.class.to_s}"]
end

unless resource.is_a? Ontology
return ['data-type', resource.class.to_s]
unless resource.is_a?(Ontology)
return ['data-type', resource.class.to_s]
end

data_type = 'data-ontologyclass'

distributed_type = ->(distributed_ontology) do
if distributed_ontology.homogeneous?
"distributed_homogeneous_ontology"
Expand All @@ -80,33 +85,34 @@ def determine_image_type(resource)

def ontology_link_to(resource)
data_type, value = determine_image_type(resource)

content_tag(:span, class: 'ontology_title') do
link_to resource, {}, data_type => value
end
end

def counter_link(url, counter, subject)
text = content_tag(:strong, counter || '?')
text << content_tag(:span, counter==1 ? subject : subject.pluralize)

link_to text, url
def sort_link_list(collection)
hash = {}

collection.each_with_index do |link, i|
if link.entity_mappings.empty?
hash["empty#{i}"] = [{link: link, target: ""}]
else
link.entity_mappings.each do |mapping|
sym = mapping.source.to_s.to_sym
if hash[sym]
hash[sym] << {link: link, target: mapping.target}
else
hash[sym] = [{link: link, target: mapping.target}]
end
end
end
end

hash
end

def format_links(*args, &block)
options = args.extract_options!
args = %w(xml json) if args.empty?
args.flatten!

options[:url] ||= {}

links = ''
links << capture(&block) << ' ' if block_given?
links << args.collect{ |f|
content_tag :li, link_to(f.to_s.upcase, params.merge(options[:url]).merge(:format => f), :title => "Get this page as #{f.upcase}")
}.join("")

content_tag('ul', links.html_safe, :class => 'formats')

def wiki_link(controller, action)
generate_external_link controller, action, 'controller', 'wiki'
end

end
1 change: 1 addition & 0 deletions app/views/shared/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
= menu_entry 'Symbols', :entities_search if !! Settings.display_symbols_tab
= menu_entry 'Logics', :logics
= menu_entry 'Mappings', :links
%li= wiki_link controller_name, action_name

= render partial: 'shared/session'
13 changes: 8 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Application < Rails::Application
config.sass.load_paths << Compass::Frameworks['blueprint'].stylesheets_directory
config.sass.load_paths << Compass::Frameworks['compass'].stylesheets_directory
end

# Mailer Layout for Devise https://github.com/plataformatec/devise/issues/1671
config.to_prepare { Devise::Mailer.layout "mailer" }

Expand Down Expand Up @@ -66,21 +66,24 @@ class Application < Rails::Application
config.assets.version = '1.0'

config.i18n.enforce_available_locales = true

# Including Jstree Themes Styles in Precompiling
config.assets.precompile += %w(jstree-themes/**/*)


#Including the external mappings Yaml-file
config.external_url_mapping = APP_CONFIG = YAML.load(File.read(Rails.root + "config/external_link_mapping.yml"))

config.before_initialize do
# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = Settings.asset_host

# ActionMailer settings
c = Settings.action_mailer
(c[:default_url_options] ||= {})[:host] ||= Settings.hostname
c.each do |key,val|
config.action_mailer.send("#{key}=", val)
end

end
end
end
111 changes: 111 additions & 0 deletions config/external_link_mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
wiki:
root: "http://wiki.ontohub.org/index.php/"
controller:
ontologies:
index: "ontology_overview"
show: "ontology_details"
edit: "ontology_edit"
retry_failed: "ontology_retry"
categories:
index: "category_based_search"
show: "category_details"
ontology_types:
index: "list_ontology_types"
show: "ontology_type_details"
formality_levels:
index: "list_formality_levels"
show: "formality_level_details"
user_sessions:
new: "login"
destroy: "logout"
users:
show: "user_details"
keys:
new: "add_ssh_keys"
index: "list_ssh_keys"
supports:
index: "list_logic_supported_languages"
logics:
new: "add_logic"
edit: "edit_logic"
show: "logic_details"
index: "list_logics"
languages:
new: "add_language"
edit: "edit_language"
show: "language_details"
index: "list_languages"
logic_mappings:
new: "add_logic_mapping"
edit: "edit_logic_mapping"
show: "logic_mapping_details"
index: "list_logic_mappings"
serialzations:
new: "add_serialization"
edit: "edit_serialization"
show: "serialization_details"
index: "list_serializations"
links:
show: "see_link_details"
index: "list_links"
teams:
index: "list_teams"
new: "create_team"
edit: "edit_team"
show: "team_details"
permissions:
index: "list_permissions"
edit: "edit_permission"
destroy: "remove_permissions"
repositories:
index: "list_repositories"
new: "create_repository"
edit: "edit_repository"
show: "repository_details"
url_maps:
index: "list_iri_mappings"
new: "add_iri_mapping"
edit: "edit_iri_mapping"
destroy: "remove_iri_mapping"
errors:
index: "list_errors"
children:
index: "list_defined_ontologies"
entities:
index: "list_entities"
sentences:
index: "list_sentences"
link_versions:
index: "list_link_versions"
ontology_versions:
index: "list_ontology_version"
tasks:
index: "list_tasks"
new: "add_task"
destroy: "remove_task"
license_models:
index: "list_license_models"
new: "add_license_model"
destroy: "remove_license_model"
tools:
index: "list_tools"
new: "add_tool"
destroy: "remove_tool"
projects:
index: "list_projects"
new: "add_project"
destroy: "remove_project"
comments:
index: "list_comments"
new: "add_comment"
destroy: "remove_comment"
foramlity_levels:
index: "list_formality_level"
files:
files: "list_files"
new: "add_new_file"
history: "list_repository_history"
home:
show: ""
graphs:
index: "show_graph"
23 changes: 23 additions & 0 deletions lib/external_mapping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ExternalMapping

def generate_external_link(controller, action, second_level, external_target)
mappings = Ontohub::Application.config.external_url_mapping[external_target]
root = mappings['root']
target = get_mapping_for mappings, second_level, controller, action

link_to 'Help', root + target
end

def get_mapping_for(mapping, *args)
args.each do |level|
mapping = mapping[level]
unless mapping
mapping = ''
break
end
end

mapping
end

end
22 changes: 22 additions & 0 deletions spec/lib/external_mapping_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'
include ExternalMapping
describe ExternalMapping do

context 'external_wiki_links' do

before do
@mappings = Ontohub::Application.config.external_url_mapping["wiki"]
@root = @mappings["root"]
end

it 'should link to wiki root for non existing actions' do
link = @root+(get_mapping_for @mappings, "controller", "graphs", "show")
link.should == @root
end

it 'should link to specific wiki page' do
link = @root+(get_mapping_for @mappings, "controller", "graphs", "index")
link.should == @root+"show_graph"
end
end
end

0 comments on commit e795954

Please sign in to comment.