From 00b2dacaf0fb22a384faf1fb770428153fea6e9a Mon Sep 17 00:00:00 2001 From: William Dewey Date: Fri, 11 Oct 2024 16:16:23 -0500 Subject: [PATCH 1/3] remove methods to edit now that we are using baserow for data ingest --- app/controllers/monasteries_controller.rb | 128 ----------------- .../religious_figures_controller.rb | 130 ------------------ app/views/items/show.html.erb | 1 - app/views/monasteries/_form.html.erb | 43 ------ app/views/monasteries/_index_intro.html.erb | 3 +- app/views/monasteries/edit.html.erb | 1 - .../monasteries/items/_edit_link.html.erb | 1 - app/views/monasteries/new.html.erb | 1 - config/routes.rb | 8 -- 9 files changed, 1 insertion(+), 315 deletions(-) delete mode 100644 app/views/monasteries/_form.html.erb delete mode 100644 app/views/monasteries/edit.html.erb delete mode 100644 app/views/monasteries/items/_edit_link.html.erb delete mode 100644 app/views/monasteries/new.html.erb diff --git a/app/controllers/monasteries_controller.rb b/app/controllers/monasteries_controller.rb index 94374cf..816e824 100644 --- a/app/controllers/monasteries_controller.rb +++ b/app/controllers/monasteries_controller.rb @@ -22,132 +22,4 @@ def index render_overridable "items", "search_preset", false, res: @res end - def new - id = generate_id - @res = { - "title" => "", - "date_display" => "", - "spatial" => { - "name" => "" - }, - "description" => "", - "relation" => "", - "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 - id = params[:id] - @res = @items_api.get_item_by_id(id) - check_response - @res = @res.first - if @res - url = @res["uri_html"] - @html = Net::HTTP.get(URI.parse(url)) if url - @title = item_title - render "monasteries/edit" - else - @title = t "item.no_item", id: id, - default: "No item with identifier #{id} found!" - render_overridable("items", "show_not_found", false, status: 404) - end - end - - def update - json = JSON.parse(params[:monastery]) - id = params[:id] - 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 - - 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 \ No newline at end of file diff --git a/app/controllers/religious_figures_controller.rb b/app/controllers/religious_figures_controller.rb index 3a8fe30..1999973 100644 --- a/app/controllers/religious_figures_controller.rb +++ b/app/controllers/religious_figures_controller.rb @@ -22,134 +22,4 @@ def index render_overridable("items", "search_preset", false) end - def edit - id = params[:id] - @res = @items_api.get_item_by_id(id) - check_response - @res = @res.first - if @res - url = @res["uri_html"] - @html = Net::HTTP.get(URI.parse(url)) if url - @title = item_title - render "religious_figures/edit" - else - @title = t "item.no_item", id: id, - default: "No item with identifier #{id} found!" - render_overridable("items", "show_not_found", false, status: 404) - end - end - - def update - json = JSON.parse(params[:figure]) - id = params[:id] - json["description"] = params[:description] - json["title"] = params[:title] - json["date_display"] = params[:date_display] - json["date_not_before"] = date_standardize(params[:date_not_before], false) - json["date_not_after"] = date_standardize(params[:date_not_after], false) - json["spatial"]["name"] = params[:spatial_name] - json["relation"] = params[:relation] - rdf = [] - idx = 0 - # loop through all the numbered keys - while params.has_key?("name_#{idx}") - figure = {"subject" => params[:title]} - name = params["name_#{idx}"] - fig_id = params["id_#{idx}"] - figure["object"] = "[#{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, auth_header.merge({:content_type => :json }) ) - redirect_to religious_figures_item_path(id) - end - - def new - id = generate_id - @res = { - "title" => "", - "date_not_before" => "", - "date_not_after" => "", - "spatial" => { - "name" => "" - }, - "description" => "", - "relation" => "", - "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 \ No newline at end of file diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 6888b19..18f0a76 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -1,4 +1,3 @@

<%= sanitize @res["title"] %>

-<%= render_overridable("items", "edit_link") %> <%= render_overridable("items", "show_metadata") %> <%# render_overridable("items", "show_content") %> diff --git a/app/views/monasteries/_form.html.erb b/app/views/monasteries/_form.html.erb deleted file mode 100644 index 8494777..0000000 --- a/app/views/monasteries/_form.html.erb +++ /dev/null @@ -1,43 +0,0 @@ -<%= form_tag(path, method: :put) do %> - <%= label_tag "title", "name of monastery" %> - <%= text_field_tag "title", monastery["title"] %> -
- <%= label_tag "date_display", "founding date" %> - <%= text_field_tag "date_display", monastery["date_display"] %> -
- <%= label_tag "spatial_name", "location of monastery" %> - <%= text_field_tag "spatial_name", monastery["spatial"]["name"] %> -
- <%= label_tag "description", "description" %> - <%= text_area_tag "description", monastery["description"] %> -
- <%= label_tag "relation", "BDRC number" %> - <%= text_field_tag "relation", monastery["relation"] %> -
-

Associated figures

- <% monastery["rdf"].each_with_index do |figure, index| %> - <% if figure["predicate"] != "sameAs" %> - <% name = parse_md_brackets(figure["subject"]) %> - <% id = parse_md_parentheses(figure["subject"]) %> -

<%= name %>

-
- <%= label_tag "name_#{index}", "name of figure" %> - <%= text_field_tag "name_#{index}", name %> -
- <%= label_tag "id_#{index}", "figure ID (please check for consistency)" %> - <%= text_field_tag "id_#{index}", id %> -
- <%= label_tag "predicate_#{index}", "role" %> - <%= text_field_tag "predicate_#{index}", figure["predicate"] %> - <%= hidden_field_tag "object_#{index}", monastery["name"] %> -
- <%= label_tag "source_#{index}", "associated teachings" %> - <%= text_field_tag "source_#{index}", figure["source"] %> -
- <%= label_tag "note_#{index}", "note" %> - <%= text_area_tag "note_#{index}", figure["note"] %> - <% end %> - <% end %> - <%= hidden_field_tag "monastery", monastery.to_json %> - <%= submit_tag %> -<% end %> \ No newline at end of file diff --git a/app/views/monasteries/_index_intro.html.erb b/app/views/monasteries/_index_intro.html.erb index cb0d4b6..f6061f2 100644 --- a/app/views/monasteries/_index_intro.html.erb +++ b/app/views/monasteries/_index_intro.html.erb @@ -1,2 +1 @@ -

Tibetan Buddhist monasteries and the figures that are associated with them.

-<%= link_to "new monastery", monasteries_new_path %> \ No newline at end of file +

Tibetan Buddhist monasteries and the figures that are associated with them.

\ No newline at end of file diff --git a/app/views/monasteries/edit.html.erb b/app/views/monasteries/edit.html.erb deleted file mode 100644 index b7c6bcd..0000000 --- a/app/views/monasteries/edit.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render partial: "form", locals: { monastery: @res, path: monasteries_update_path } %> \ No newline at end of file diff --git a/app/views/monasteries/items/_edit_link.html.erb b/app/views/monasteries/items/_edit_link.html.erb deleted file mode 100644 index 7c87d57..0000000 --- a/app/views/monasteries/items/_edit_link.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= link_to "edit info for this monastery", monasteries_edit_path(@res) %> \ No newline at end of file diff --git a/app/views/monasteries/new.html.erb b/app/views/monasteries/new.html.erb deleted file mode 100644 index c228749..0000000 --- a/app/views/monasteries/new.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render partial: "form", locals: { monastery: @res, path: monasteries_create_path } %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6e644fa..16edc12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,18 +2,10 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html scope "/religious_figures", defaults: { section: "religious_figures" } do get "/", to: "religious_figures#index", as: :religious_figures_home - get "/new", to: "religious_figures#new", as: :religious_figures_new - put "/new", to: "religious_figures#create", as: :religious_figures_create - get "/item/:id/edit", to: "religious_figures#edit", as: :religious_figures_edit - put "/item/:id/update", to: "religious_figures#update", as: :religious_figures_update Orchid::Routing.draw(section: "religious_figures", scope: "/religious_figures", routes: ["browse", "browse_facet", "item", "search"]) end scope "/monasteries", defaults: { section: "monasteries" } do get "/", to: "monasteries#index", as: :monasteries_home - get "/new", to: "monasteries#new", as: :monasteries_new - put "/new", to: "monasteries#create", as: :monasteries_create - get "/item/:id/edit", to: "monasteries#edit", as: :monasteries_edit - put "/item/:id/update", to: "monasteries#update", as: :monasteries_update Orchid::Routing.draw(section: "monasteries", scope: "/monasteries", routes: ["browse", "browse_facet", "item", "search"]) end end From 8275690d99be6e5068bee68e8fb488b4927e2874 Mon Sep 17 00:00:00 2001 From: wkdewey Date: Sun, 27 Oct 2024 14:26:56 -0500 Subject: [PATCH 2/3] update ruby version --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.ruby-version b/.ruby-version index 711ee4f..9cec716 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.3 \ No newline at end of file +3.1.6 diff --git a/Gemfile b/Gemfile index 7501ad8..8bd1107 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.1.3' +ruby '3.1.6' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index efd9bf9..834a359 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -276,7 +276,7 @@ DEPENDENCIES web-console (>= 3.3.0) RUBY VERSION - ruby 3.1.3p185 + ruby 3.1.6p260 BUNDLED WITH 2.2.28 From 8d8874c3368b5d230c38b82165d3c371cd006348 Mon Sep 17 00:00:00 2001 From: wkdewey Date: Sun, 27 Oct 2024 14:50:23 -0500 Subject: [PATCH 3/3] add database.example.yml --- config/database.example.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 config/database.example.yml diff --git a/config/database.example.yml b/config/database.example.yml new file mode 100644 index 0000000..0d02f24 --- /dev/null +++ b/config/database.example.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3