Skip to content

Commit

Permalink
Merge pull request #399 from ncbo/copy_uri_fix
Browse files Browse the repository at this point in the history
Resolves the issue with the 'copy-to-clipboard' (#390) and the issue with bad display of long values (#396)
  • Loading branch information
alexskr authored Mar 6, 2025
2 parents 2447a8a + a202933 commit d503b76
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 39 deletions.
4 changes: 4 additions & 0 deletions app/assets/images/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions app/components/concept_details_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ def row_hash_properties(properties_set, ontology_acronym, &block)

values = data[:values]
url = data[:key]

is_list = values.is_a?(Array) && values.size > 1
style_as_badge = values.is_a?(Array) && values.size > 1 && short_values(values)

ajax_links = Array(values).map do |v|
if block_given?
capture(v, &block)
else
if v.is_a?(String)
get_link_for_cls_ajax(v, ontology_acronym, '_blank', is_list)
get_link_for_cls_ajax(v, ontology_acronym, '_blank', style_as_badge)
else
display_in_multiple_languages([v].to_h, style_as_badge: true)
end
Expand All @@ -63,6 +62,18 @@ def row_hash_properties(properties_set, ontology_acronym, &block)
out
end

def short_values(vals)
vals.each do |str|
word_count = str.split.count
character_count = str.length

unless word_count < 10 && character_count < 100
return false
end
end
true
end

def properties_set_by_keys(keys, concept_properties, exclude_keys = [])
concept_properties&.select do |k, v|
(keys.include?(k) || !keys.select { |key| v[:key].to_s.include?(key) }.empty?) && !exclude_keys.include?(k) &&
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class AdminController < ApplicationController

def index
@users = LinkedData::Client::Models::User.all

if session[:user].nil? || !session[:user].admin?
redirect_to controller: 'login', action: 'index', redirect: '/admin'
else
update_info(false)
render action: 'index'
end
end

def update_info
def update_info(render_response = true)
response = { update_info: {}, errors: '', success: '', notices: '' }
json = LinkedData::Client::HTTP.get("#{ADMIN_URL}update_info", params, raw: true)

Expand All @@ -32,14 +34,15 @@ def update_info
response[:errors] = update_info['error']
response[:update_info] = update_info
else
@update_info = update_info.symbolize_keys
response[:update_info] = update_info
response[:notices] = update_info['notes'] if update_info['notes']
response[:success] = 'Update info successfully retrieved'
end
rescue StandardError => e
response[:errors] = "Problem retrieving update info - #{e.message}"
end
render json: response
render json: response if render_response
end

def update_check_enabled
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,11 @@ def get_link_for_cls_ajax(cls_id, ont_acronym, target = nil, style_as_badge = fa
if style_as_badge
render ChipButtonComponent.new(text: cls_id)
else
content_tag(:span, cls_id)
content_tag(:div, cls_id)
end
end
end


def get_link_for_ont_ajax(ont_acronym)
# Ajax call will replace the acronym with an ontology name (triggered by class='ont4ajax')
href_ont = " href='#{bp_ont_link(ont_acronym)}' "
Expand Down
16 changes: 0 additions & 16 deletions app/javascript/controllers/clipboard_controller.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ application.register("change-requests", ChangeRequestsController)
import LanguageChangeController from "./language_change_controller"
application.register("language-change", LanguageChangeController)

import ClipboardController from "./clipboard_controller"
application.register("clipboard", ClipboardController)
import ClipboardComponentController from '../../components/clipboard_component/clipboard_component_controller'
application.register('clipboard', ClipboardComponentController)

import LoadChartController from "./load_chart_controller"
application.register("load-chart", LoadChartController)
Expand Down
14 changes: 5 additions & 9 deletions app/views/admin/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,11 @@
%div#site-admin-appliance-id.mb-5
%div.site-admin-page-header
APPLIANCE ID
%dive.site-admin-page-section
%div{'data-controller': 'clipboard'}
%div#appliance-id
%span{'data-clipboard-target': 'source'}
%div{class: 'd-flex align-items-center mt-2'}
= tag.button('Copy to clipboard', 'data-action': 'clipboard#copy',
class: 'btn btn-sm btn-outline-secondary')
%span{'data-clipboard-target': 'copiedIndicator',
class: 'hidden text-success fw-semibold ms-2'} Copied!
%div.site-admin-page-section
%div#appliance-id
%span
= content_tag(:span, style: 'display: inline-block;') do
= render ClipboardComponent.new(message: @update_info[:appliance_id], title: 'Copy Appliance ID', show_content: false)

-# Ontology Administration tab
%div.tab-pane.fade{id: "ontology-admin", role: "tabpanel", aria: { labelledby: "ontology-admin-tab" }}
Expand Down
8 changes: 3 additions & 5 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
-# User's API key
%h4{class: 'pb-2 my-4 border-bottom'} API Key
= tag.p("Your API key can be used to access the #{$SITE} RESTful API and services", class: 'text-muted')
%div{'data-controller': 'clipboard'}
%span{'data-clipboard-target': 'source'}= session[:user].apikey
%div{class: 'd-flex align-items-center mt-2'}
= tag.button 'Copy to clipboard', 'data-action': 'clipboard#copy', class: 'btn btn-sm btn-outline-secondary'
%span{'data-clipboard-target': 'copiedIndicator', class: 'hidden text-success fw-semibold ms-2'} Copied!
= session[:user].apikey
= content_tag(:span, style: 'display: inline-block;') do
= render ClipboardComponent.new(message: session[:user].apikey, title: 'Copy API Key', show_content: false)

-# User's subscriptions
- unless @user.subscription.blank?
Expand Down

0 comments on commit d503b76

Please sign in to comment.