Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 26, 2023
1 parent a67f9c8 commit 18e9218
Show file tree
Hide file tree
Showing 30 changed files with 734 additions and 294 deletions.
Binary file added app/assets/images/layout/asc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/layout/desc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/components/agent_search_input_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class AgentSearchInputComponent < ViewComponent::Base

def initialize(id:, agent_type: nil, name_prefix: nil, parent_id: , edit_on_modal: false, deletable: false)
super
def initialize(id:, agent_type: nil, name_prefix: nil, parent_id: , show_affiliations: true, edit_on_modal: false, deletable: false)
@id = id
@agent_type = agent_type
@name_prefix = name_prefix
@parent_id = parent_id
@edit_on_modal = edit_on_modal
@show_affiliations = show_affiliations
@deletable = deletable
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
= render SearchInputComponent.new(name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=",
= hidden_field_tag "#{@name_prefix}[#{@id}]"
= render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=",
item_base_url:"/agents/#{@id}?parent_id=#{@parent_id}&edit_on_modal=#{@edit_on_modal}&name_prefix=#{@name_prefix}&deletable=#{@deletable}&agent_id=", id_key: 'id',
use_cache: false,
actions_links: {create_new_agent: {link: "/agents/new?name=&id=#{@id}&parent_id=#{@parent_id}&new_agent=false&type=#{@agent_type}&show_affiliations=false&edit_on_modal=#{@edit_on_modal}&name_prefix=#{@name_prefix}[#{@id}]", target:'_self'}}) do |s|
actions_links: {create_new_agent: {link: "/agents/new?name=&id=#{@id}&parent_id=#{@parent_id}&type=#{@agent_type}&show_affiliations=#{@show_affiliations}&edit_on_modal=#{@edit_on_modal}&name_prefix=#{@name_prefix}[#{@id}]", target:'_self'}}) do |s|
- s.template do
%a{href: "LINK", class: "search-content", 'data-turbo-frame': '_self'}
%p.search-element.home-searched-ontology
Expand Down
4 changes: 2 additions & 2 deletions app/components/nested_agent_search_input_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class NestedAgentSearchInputComponent < ViewComponent::Base

include Turbo::FramesHelper, AgentHelper

def initialize(label: nil, agents:, agent_type:, name_prefix:, edit_on_modal: false, parent_id: nil)
super
def initialize(label: nil, agents:, agent_type:, name_prefix:, show_affiliations: true, edit_on_modal: false, parent_id: nil)
@agents = agents
@agent_type = agent_type
@name_prefix = name_prefix
@edit_on_modal = edit_on_modal
@parent_id = parent_id
@label = label
@show_affiliations = show_affiliations
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
= @label
- c.template do
= render TurboFrameComponent.new(id: agent_id_frame_id('NEW_RECORD', @parent_id)) do
= render AgentSearchInputComponent.new(id: 'NEW_RECORD', agent_type: @agent_type, name_prefix: @name_prefix,
= render AgentSearchInputComponent.new(id: 'NEW_RECORD', agent_type: @agent_type,
name_prefix: @name_prefix, show_affiliations: @show_affiliations,
parent_id: @parent_id, edit_on_modal: @edit_on_modal)

- c.empty_state do
= hidden_field_tag agent_field_name('', @name_prefix+"[#{Array(@agents).size}]")
- Array(@agents).each_with_index do |agent, i|
- if agent
- if agent&.agentType
- c.row do
= render partial: 'agents/agent_show', locals: {agent: agent, name_prefix: @name_prefix+"[#{i}]", edit_on_modal: @edit_on_modal, parent_id: @parent_id}
= render partial: 'agents/agent_show', locals: {agent_id: i, agent: agent, name_prefix: @name_prefix, edit_on_modal: @edit_on_modal, parent_id: @parent_id}
5 changes: 3 additions & 2 deletions app/components/search_input_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ class SearchInputComponent < ViewComponent::Base

renders_one :template

def initialize(name: '', placeholder: '', actions_links: {},
def initialize(id: '',
name: '', placeholder: '', actions_links: {},
scroll_down: true, use_cache: true,
ajax_url:,
item_base_url:,
id_key:,
links_target: '_top')
super
@id = id
@name = name
@placeholder = placeholder
@actions_links = actions_links
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%div.search-inputs{'data-controller': 'search-input',
%div.search-inputs{id: @id, 'data-controller': 'search-input',
'data-search-input-ajax-url-value': @ajax_url,
'data-search-input-item-link-base-value': @item_base_url,
'data-search-input-id-key-value': @id_key,
Expand Down
43 changes: 29 additions & 14 deletions app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def show
not_found("Agent with id #{@agent.id}") if @agent.nil?

@agent_id = params[:id] || agent_id(@agent)
@name_prefix = params[:name_prefix] ? "#{params[:name_prefix]}[#{params[:id]}]" : ''
@name_prefix = params[:name_prefix]
@edit_on_modal = params[:edit_on_modal]&.eql?('true')
@deletable = params[:deletable]&.eql?('true')
end
Expand All @@ -38,9 +38,8 @@ def new
@agent.creator = session[:user].id
@agent.agentType = params[:type] || 'person'
@agent.name = params[:name]
@new_agent = params[:new_agent].nil? || params[:new_agent].eql?('true')
@name_prefix = params[:name_prefix] || ''
@show_affiliations = params[:show_affiliations]&.eql?('true')
@show_affiliations = params[:show_affiliations].nil? || params[:show_affiliations]&.eql?('true')
end

def create
Expand All @@ -56,27 +55,34 @@ def create
streams = [alert_success(id: alert_id) { success_message }]

streams << prepend('agents_table_content', partial: 'agents/show_line', locals: { agent: new_agent })

streams << replace_agent_form(new_agent, frame_id: params[:id], parent_id: parent_id, name_prefix: name_prefix) if params[:parent_id]
streams << replace_agent_form(new_agent, agent_id: nil, frame_id: params[:id], parent_id: parent_id, name_prefix: name_prefix) if params[:parent_id]

render_turbo_stream(*streams)
end
end

def edit
@agent = LinkedData::Client::Models::Agent.find("#{REST_URI}/Agents/#{params[:id]}")
@agent = LinkedData::Client::Models::Agent.find("#{rest_url}/Agents/#{params[:id]}")
@name_prefix = params[:parent_id] || ''
@show_affiliations = params[:show_affiliations].nil? || params[:show_affiliations].eql?('true')
end

def show_search
id = params[:parent_id]
id = params[:id]
parent_id = params[:parent_id]
name_prefix = params[:name_prefix]
agent_type = params[:agent_type]
agent_deletable = params[:deletable].to_s.eql?('true')

attribute_template_output = render_to_string(inline: helpers.agent_search_input(id, agent_type, deletable: agent_deletable))
render_turbo_stream(replace(id) { attribute_template_output } )
attribute_template_output = helpers.agent_search_input(id, agent_type,
parent_id: parent_id,
name_prefix: name_prefix,
deletable: agent_deletable)
render_turbo_stream(replace(helpers.agent_id_frame_id(id, parent_id)) { render_to_string(inline: attribute_template_output) } )

end


def update
agent_update, agent = update_agent(params[:id].split('/').last, agent_params)
parent_id = params[:parent_id]
Expand All @@ -100,7 +106,7 @@ def update

def destroy
error = nil
@agent = LinkedData::Client::Models::Agent.find("#{REST_URI}/Agents/#{params[:id]}")
@agent = LinkedData::Client::Models::Agent.find("#{rest_url}/Agents/#{params[:id]}")
success_text = ''

if @agent.nil?
Expand Down Expand Up @@ -134,12 +140,14 @@ def destroy

private

def replace_agent_form(agent, frame_id: nil, parent_id:, partial: 'agents/agent_show', name_prefix: '')
def replace_agent_form(agent, agent_id: nil, frame_id: nil, parent_id:, partial: 'agents/agent_show', name_prefix: '')

frame_id = frame_id ? agent_id_frame_id(frame_id, parent_id) : agent_frame_id(agent, parent_id)

replace(frame_id, partial: partial,
locals: { agent: agent, name_prefix: name_prefix, parent_id: parent_id, edit_on_modal: false })
replace(frame_id, partial: partial, layout: false ,
locals: { agent_id: agent_id, agent: agent, name_prefix: name_prefix, parent_id: parent_id,
edit_on_modal: false,
deletable: true})
end

def save_agent(params)
Expand All @@ -149,7 +157,7 @@ def save_agent(params)
end

def update_agent(id = params[:id], params)
agent = LinkedData::Client::Models::Agent.find("#{REST_URI}/Agents/#{id}")
agent = LinkedData::Client::Models::Agent.find("#{rest_url}/Agents/#{id}")

params[:creator] = session[:user].id if (agent.creator.nil? || agent.creator.empty?) && (params[:creator] || '').empty?

Expand Down Expand Up @@ -179,4 +187,11 @@ def agent_params
end
p
end

def find_agent_display_all(id = params[:id])
# TODO fix in the api client, the find with params
LinkedData::Client::Models::Agent.where({ display: 'all' }) do |obj|
obj.id.to_s.eql?("#{rest_url}/Agents/#{id}")
end.first
end
end
14 changes: 14 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ def remote_file_exists?(url)
check
end

def rest_url
# Split the URL into protocol and path parts
protocol, path = REST_URI.split("://", 2)

# Remove duplicate "//"
cleaned_url = REST_URI.gsub(/\/\//, '/')

# Remove the last '/' in the path part
cleaned_path = path.chomp('/')
# Reconstruct the cleaned URL
"#{protocol}://#{cleaned_path}"
end


def check_http_file(url)
session = Net::HTTP.new(url.host, url.port)
session.use_ssl = true if url.port == 443
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/concerns/submission_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ def submission_params(params)
v
end
end
p["copyrightHolder"] = p["copyrightHolder"].first if p["copyrightHolder"] # TODO automatize

if p["copyrightHolder"]&.first&.include?("id") # TODO automatize
p["copyrightHolder"] = p["copyrightHolder"].first["id"]
elsif p["copyrightHolder"]
p["copyrightHolder"] = ''
end


submission_metadata.each do |m|
m_attr = m['attribute'].to_sym
Expand Down
13 changes: 7 additions & 6 deletions app/helpers/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ def link_to_agent_edit(agent, parent_id = nil)
end


def link_to_search_agent(parent_id , agent_type, deletable)
link_to("/agents/show_search?parent_id=#{parent_id}&agent_type=#{agent_type}&deletable=#{deletable}", class: 'btn btn-sm btn-light') do
def link_to_search_agent(id, parent_id , name_prefix, agent_type, deletable)
link_to("/agents/show_search?id=#{id}&parent_id=#{parent_id}&agent_type=#{agent_type}&deletable=#{deletable}&name_prefix=#{name_prefix}", class: 'btn btn-sm btn-light') do
inline_svg_tag "x.svg", width: "25", height: "25"
end
end

def agent_search_input(id, agent_type, deletable: false)
render TurboFrameComponent.new(id: agent_id_frame_id(id, '')) do
def agent_search_input(id, agent_type, parent_id: , name_prefix:, deletable: false)
render TurboFrameComponent.new(id: agent_id_frame_id(id, parent_id)) do
render AgentSearchInputComponent.new(id: id, agent_type: agent_type,
parent_id: '', deletable: deletable,
name_prefix: name_prefix,
parent_id: parent_id, deletable: deletable,
edit_on_modal: false)
end
end
Expand Down Expand Up @@ -99,7 +100,7 @@ def display_agent(agent, link: true)

out = agent.name.to_s
identifiers = display_identifiers(agent.identifiers, link: link)
out = "#{out} (#{identifiers})" unless identifiers.empty?
out = "#{out} ( #{identifiers} )" unless identifiers.empty?
affiliations = Array(agent.affiliations).map { |a| display_agent(a, link: link) }.join(', ')
out = "#{out} (affiliations: #{affiliations})" unless affiliations.empty?
out
Expand Down
6 changes: 4 additions & 2 deletions app/helpers/inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ def text_input(name:, value:, label: nil, disabled: false, help: nil, error_mess
helper_text: help)
end

def select_input(name:, values:, id: nil, label: nil, selected: nil, multiple: false, help: nil, data: {})
def select_input(name:, values:, id: nil, label: nil, selected: nil, multiple: false, help: nil, open_to_add: false, data: {})
render Input::SelectComponent.new(label: input_label(label, name), id: id || name, name: name, value: values,
selected: selected,
multiple: multiple,
helper_text: help, data: data)
helper_text: help,
open_to_add_values: open_to_add,
data: data)
end

def check_input(id:, name:, value:, label: '', checked: false)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/metadata_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def metadata_categories
end
def ontology_relation?(attr_label)
relations_attr = metadata_categories['relations']
relations_attr.include?(attr_label.to_s)
!attr_label.to_s.eql?('hasPriorVersion') && relations_attr.include?(attr_label.to_s)
end

def attr_uri?(attr_label)
Expand Down
Loading

0 comments on commit 18e9218

Please sign in to comment.