Skip to content

Commit

Permalink
Merge pull request #12 from wkdewey/new_data_forms
Browse files Browse the repository at this point in the history
New data forms
  • Loading branch information
wkdewey authored May 12, 2023
2 parents 4030992 + a29a15e commit ab43d09
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 13 deletions.
63 changes: 57 additions & 6 deletions app/controllers/monasteries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def index
end

def new
id = params[:id]
id = generate_id
@res = {
"title" => "",
"date_display" => "",
Expand All @@ -32,12 +32,57 @@ def new
},
"description" => "",
"relation" => "",
"rdf" => []
"rdf" => [
{
"subject" => "",
"object" => "",
"predicate" => "",
"source" => "",
"note" => ""
}
]
}
render "monasteries/new"
end

def create
json = JSON.parse(params[:monastery])
id = generate_id
json["identifier"] = id
json["collection"] = "tibetan_monasteries"
json["collection_desc"] = "tibetan_monasteries"
json["category"] = "Monasteries"
json["description"] = params[:description]
json["title"] = params[:title]
json["date_display"] = params[:date_display]
json["date_not_before"] = date_standardize(params[:date_display], false)
json["spatial"]["name"] = params[:spatial_name]
json["relation"] = params[:relation]
rdf = []
idx = 0
# loop through all the numbered keys
while params.has_key?("id_#{idx}") && params["id_#{idx}"].length > 0
figure = {"object" => params[:title]}
name = params["name_#{idx}"]
fig_id = params["id_#{idx}"]
figure["subject"] = "[#{name}](#{fig_id})"
figure["predicate"] = params["predicate_#{idx}"]
figure["source"] = params["source_#{idx}"]
figure["note"] = params["note_#{idx}"]
rdf << figure
idx += 1
end
json["rdf"] = rdf
# below should be refactored into more general helper methods
project_dir = File.join(File.dirname(__FILE__), "..", "..")
# path to the gem's config files
general_config_path = File.join(project_dir, "config")
# at some point I also need to factor into environments, private.yml for passwords
@options = read_config("#{general_config_path}/public.yml")
# auth_header = construct_auth_header(@options)
index_url = File.join(@options["es_path"], @options["es_index"])
RestClient.put("#{index_url}/_doc/#{id}", json.to_json, {:content_type => :json })
redirect_to monasteries_item_path(id)
end

def edit
Expand Down Expand Up @@ -69,7 +114,7 @@ def update
rdf = []
idx = 0
# loop through all the numbered keys
while params.has_key?("name_#{idx}")
while params.has_key?("id_#{idx}") && params["id_#{idx}"].length > 0
figure = {"object" => params[:title]}
name = params["name_#{idx}"]
fig_id = params["id_#{idx}"]
Expand All @@ -87,16 +132,22 @@ def update
general_config_path = File.join(project_dir, "config")
# at some point I also need to factor into environments, private.yml for passwords
@options = read_config("#{general_config_path}/public.yml")
auth_header = construct_auth_header(@options)
#auth_header = construct_auth_header(@options)
index_url = File.join(@options["es_path"], @options["es_index"])
RestClient.put("#{index_url}/_doc/#{id}", json.to_json, auth_header.merge({:content_type => :json }) )
RestClient.put("#{index_url}/_doc/#{id}", json.to_json, {:content_type => :json } )
redirect_to monasteries_item_path(id)
end

private

def generate_id

#query api and determine nubmer of items
options = {
"f" => ["category|Monasteries"]
}
@res = @items_api.query(options)
count = @res.count
"mon_#{count + 1}"
end

end
55 changes: 53 additions & 2 deletions app/controllers/religious_figures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,69 @@ def new
},
"description" => "",
"relation" => "",
"rdf" => []
"rdf" => [
{
"subject" => "",
"object" => "",
"predicate" => "",
"source" => "",
"note" => ""
}
]
}
render "religious_figures/new"
end

def create
json = JSON.parse(params[:figure])
id = generate_id
json["identifier"] = id
json["collection"] = "tibetan_monasteries"
json["collection_desc"] = "tibetan_monasteries"
json["category"] = "Religious Figures"
json["description"] = params[:description]
json["title"] = params[:title]
json["date_not_before"] = date_standardize(params[:date_not_before], false)
json["date_not_after"] = date_standardize(params[:date_not_afterr], false)
json["spatial"]["name"] = params[:spatial_name]
json["relation"] = params[:relation]
rdf = []
idx = 0
# loop through all the numbered keys
while params.has_key?("id_#{idx}") && params["id_#{idx}"].length > 0
figure = {"object" => params[:title]}
name = params["name_#{idx}"]
fig_id = params["id_#{idx}"]
figure["subject"] = "[#{name}](#{fig_id})"
figure["predicate"] = params["predicate_#{idx}"]
figure["source"] = params["source_#{idx}"]
figure["note"] = params["note_#{idx}"]
rdf << figure
idx += 1
end
json["rdf"] = rdf
# below should be refactored into more general helper methods
project_dir = File.join(File.dirname(__FILE__), "..", "..")
# path to the gem's config files
general_config_path = File.join(project_dir, "config")
# at some point I also need to factor into environments, private.yml for passwords
@options = read_config("#{general_config_path}/public.yml")
#auth_header = construct_auth_header(@options)
index_url = File.join(@options["es_path"], @options["es_index"])
RestClient.put("#{index_url}/_doc/#{id}", json.to_json, {:content_type => :json } )
redirect_to religious_figures_item_path(id)
end

private

def generate_id

#query api and determine nubmer of items
options = {
"f" => ["category|Religious Figures"]
}
@res = @items_api.query(options)
count = @res.count
"fig_#{count + 1}"
end

end
1 change: 0 additions & 1 deletion app/views/monasteries/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%= form_tag(path, method: :put) do %>
<%# byebug %>
<%= label_tag "title", "name of monastery" %>
<%= text_field_tag "title", monastery["title"] %>
<br>
Expand Down
8 changes: 7 additions & 1 deletion app/views/monasteries/items/_show_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
<% figures.each do |figure| %>
<% id = parse_md_parentheses(figure["subject"]) %>
<% name = parse_md_brackets(figure["subject"]) %>
<h4><%= link_to name, religious_figures_item_path(id) %></h4>
<h4>
<% if id %>
<%= link_to name, religious_figures_item_path(id) %>
<% else %>
<%= name %>
<% end %>
</h4>
<ul>
<li>Role: <%= figure["predicate"] %></li>
<li>Associated Teaching: <%= figure["source"] %></li>
Expand Down
3 changes: 1 addition & 2 deletions app/views/religious_figures/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<%= form_tag(path, method: :put) do %>
<%# byebug %>
<%= label_tag "title", "name of monastery" %>
<%= label_tag "title", "name of religious figure" %>
<%= text_field_tag "title", figure["title"] %>
<br>
<%= label_tag "date_not_before", "birth date" %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/religious_figures/items/_show_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
<% monasteries.each do |monastery| %>
<% id = parse_md_parentheses(monastery["object"]) %>
<% name = parse_md_brackets(monastery["object"]) %>
<h4><%= link_to name, monasteries_item_path(id) %></h4>
<h4>
<% if name %>
<%= link_to name, monasteries_item_path(id) %>
<% else %>
<%= name %>
<% end%>
</h4>
<ul>
<li>Role: <%= monastery["predicate"] %></li>
<li>Associated Teaching: <%= monastery["source"] %></li>
Expand Down

0 comments on commit ab43d09

Please sign in to comment.