From 6d4169a15f3cc054734f1445f7e7fd1d415ef366 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Thu, 31 Oct 2024 13:56:59 -0700 Subject: [PATCH 1/6] Initial commit of change request attribution --- app/controllers/change_requests_controller.rb | 4 +++- app/lib/kgcl/renderers/new_synonym_content.rb | 8 ++++++++ app/lib/kgcl/renderers/node_obsoletion_content.rb | 8 ++++++++ app/lib/kgcl/renderers/node_rename_content.rb | 8 ++++++++ app/lib/kgcl/renderers/remove_synonym_content.rb | 8 ++++++++ app/lib/kgcl/templates/footer.erb | 9 +++++++++ app/lib/kgcl/templates/new_synonym_body.erb | 5 ++--- app/lib/kgcl/templates/node_obsoletion_body.erb | 5 ++--- app/lib/kgcl/templates/node_rename_body.erb | 5 ++--- app/lib/kgcl/templates/remove_synonym_body.erb | 5 ++--- app/views/change_requests/_create_synonym.html.haml | 4 +++- app/views/change_requests/_node_obsoletion.html.haml | 4 +++- app/views/change_requests/_node_rename.html.haml | 4 +++- app/views/change_requests/_remove_synonym.html.haml | 4 +++- 14 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 app/lib/kgcl/templates/footer.erb diff --git a/app/controllers/change_requests_controller.rb b/app/controllers/change_requests_controller.rb index d46738a25..80fbe9608 100644 --- a/app/controllers/change_requests_controller.rb +++ b/app/controllers/change_requests_controller.rb @@ -60,6 +60,8 @@ def set_common_instance_variables @concept_label = params[:concept_label] @concept_id = params[:concept_id] @ont_acronym = params[:ont_acronym] - @username = session[:user].username + @user = LinkedData::Client::Models::User.get( + session[:user].id, include: 'username,githubId,orcidId', display_links: 'false', display_context: 'false' + ) end end diff --git a/app/lib/kgcl/renderers/new_synonym_content.rb b/app/lib/kgcl/renderers/new_synonym_content.rb index d8da90f47..7871ba4df 100644 --- a/app/lib/kgcl/renderers/new_synonym_content.rb +++ b/app/lib/kgcl/renderers/new_synonym_content.rb @@ -48,6 +48,14 @@ def get_binding binding end + def github_id + @params[:github_id] + end + + def orcid_id + @params[:orcid_id] + end + def qualifier @params[:create_synonym][:qualifier] end diff --git a/app/lib/kgcl/renderers/node_obsoletion_content.rb b/app/lib/kgcl/renderers/node_obsoletion_content.rb index cf51fbc0d..86506e51f 100644 --- a/app/lib/kgcl/renderers/node_obsoletion_content.rb +++ b/app/lib/kgcl/renderers/node_obsoletion_content.rb @@ -45,6 +45,14 @@ def get_binding binding end + def github_id + @params[:github_id] + end + + def orcid_id + @params[:orcid_id] + end + def username @params[:username] end diff --git a/app/lib/kgcl/renderers/node_rename_content.rb b/app/lib/kgcl/renderers/node_rename_content.rb index c2dfd4c97..4f2e24e56 100644 --- a/app/lib/kgcl/renderers/node_rename_content.rb +++ b/app/lib/kgcl/renderers/node_rename_content.rb @@ -41,6 +41,14 @@ def get_binding binding end + def github_id + @params[:github_id] + end + + def orcid_id + @params[:orcid_id] + end + def new_concept_label @params[:node_rename][:new_preferred_name] end diff --git a/app/lib/kgcl/renderers/remove_synonym_content.rb b/app/lib/kgcl/renderers/remove_synonym_content.rb index f8ae83b00..cddefd8ae 100644 --- a/app/lib/kgcl/renderers/remove_synonym_content.rb +++ b/app/lib/kgcl/renderers/remove_synonym_content.rb @@ -43,6 +43,14 @@ def get_binding binding end + def github_id + @params[:github_id] + end + + def orcid_id + @params[:orcid_id] + end + def synonym_label @params[:remove_synonym][:synonym] end diff --git a/app/lib/kgcl/templates/footer.erb b/app/lib/kgcl/templates/footer.erb new file mode 100644 index 000000000..e6aaf8d3f --- /dev/null +++ b/app/lib/kgcl/templates/footer.erb @@ -0,0 +1,9 @@ +**Comment:** <%= comment %> + +<% if github_id.present? %> +Proposal generated by: @<%= github_id %> +<% else %> +Proposal generated by: BioPortal user '<%= username %>' +<% end %> + +ORCID: <%= orcid_id %> \ No newline at end of file diff --git a/app/lib/kgcl/templates/new_synonym_body.erb b/app/lib/kgcl/templates/new_synonym_body.erb index b36f06ed6..ddd9d7d47 100644 --- a/app/lib/kgcl/templates/new_synonym_body.erb +++ b/app/lib/kgcl/templates/new_synonym_body.erb @@ -4,6 +4,5 @@ --- -Comment: <%= comment %> - -This request comes from BioPortal user: <%= username %> \ No newline at end of file +<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %> +<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %> \ No newline at end of file diff --git a/app/lib/kgcl/templates/node_obsoletion_body.erb b/app/lib/kgcl/templates/node_obsoletion_body.erb index e29395219..770261446 100644 --- a/app/lib/kgcl/templates/node_obsoletion_body.erb +++ b/app/lib/kgcl/templates/node_obsoletion_body.erb @@ -4,6 +4,5 @@ --- -Comment: <%= comment %> - -This request comes from BioPortal user: <%= username %> \ No newline at end of file +<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %> +<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %> \ No newline at end of file diff --git a/app/lib/kgcl/templates/node_rename_body.erb b/app/lib/kgcl/templates/node_rename_body.erb index f84a22c3f..c748d1136 100644 --- a/app/lib/kgcl/templates/node_rename_body.erb +++ b/app/lib/kgcl/templates/node_rename_body.erb @@ -4,6 +4,5 @@ --- -Comment: <%= comment %> - -This request comes from BioPortal user: <%= username %> \ No newline at end of file +<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %> +<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %> \ No newline at end of file diff --git a/app/lib/kgcl/templates/remove_synonym_body.erb b/app/lib/kgcl/templates/remove_synonym_body.erb index c8a9b49d3..bf730ed59 100644 --- a/app/lib/kgcl/templates/remove_synonym_body.erb +++ b/app/lib/kgcl/templates/remove_synonym_body.erb @@ -4,6 +4,5 @@ --- -Comment: <%= comment %> - -This request comes from BioPortal user: <%= username %> \ No newline at end of file +<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %> +<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %> \ No newline at end of file diff --git a/app/views/change_requests/_create_synonym.html.haml b/app/views/change_requests/_create_synonym.html.haml index 7c00f40bd..ddb5b32fd 100644 --- a/app/views/change_requests/_create_synonym.html.haml +++ b/app/views/change_requests/_create_synonym.html.haml @@ -5,8 +5,10 @@ = form_with scope: :create_synonym, url: change_requests_path, local: false do |f| = hidden_field_tag 'concept_id', @concept_id = hidden_field_tag 'concept_label', @concept_label + = hidden_field_tag 'github_id', @user.githubId = hidden_field_tag 'ont_acronym', @ont_acronym - = hidden_field_tag 'username', @username + = hidden_field_tag 'orcid_id', @user.orcidId + = hidden_field_tag 'username', @user.username = hidden_field_tag 'operation', KGCL::Operations::NEW_SYNONYM %div{class: 'modal-body'} %div.mb-3 diff --git a/app/views/change_requests/_node_obsoletion.html.haml b/app/views/change_requests/_node_obsoletion.html.haml index 80f98f4a9..c59877fb6 100644 --- a/app/views/change_requests/_node_obsoletion.html.haml +++ b/app/views/change_requests/_node_obsoletion.html.haml @@ -1,8 +1,10 @@ = form_with scope: :node_obsoletion, url: change_requests_path, local: false, class: 'mb-5' do |f| = hidden_field_tag 'concept_id', @concept_id = hidden_field_tag 'concept_label', @concept_label + = hidden_field_tag 'github_id', @user.githubId = hidden_field_tag 'ont_acronym', @ont_acronym - = hidden_field_tag 'username', @username + = hidden_field_tag 'orcid_id', @user.orcidId + = hidden_field_tag 'username', @user.username = hidden_field_tag 'operation', KGCL::Operations::NODE_OBSOLETION %div.mb-2 = f.label :comment, "Proposal: obsolete '#{@concept_label}'", for: 'node_obsoletion_comment', class: 'form-label' diff --git a/app/views/change_requests/_node_rename.html.haml b/app/views/change_requests/_node_rename.html.haml index dca4e874f..ba1da7251 100644 --- a/app/views/change_requests/_node_rename.html.haml +++ b/app/views/change_requests/_node_rename.html.haml @@ -2,8 +2,10 @@ = form_with scope: :node_rename, url: change_requests_path, local: false, class: 'mb-5' do |f| = hidden_field_tag 'concept_id', @concept_id = hidden_field_tag 'concept_label', @concept_label + = hidden_field_tag 'github_id', @user.githubId = hidden_field_tag 'ont_acronym', @ont_acronym - = hidden_field_tag 'username', @username + = hidden_field_tag 'orcid_id', @user.orcidId + = hidden_field_tag 'username', @user.username = hidden_field_tag 'operation', KGCL::Operations::NODE_RENAME %div.mb-3 = f.label :new_preferred_name, 'Preferred name', class: 'form-label' diff --git a/app/views/change_requests/_remove_synonym.html.haml b/app/views/change_requests/_remove_synonym.html.haml index 39254fad3..1e53b342d 100644 --- a/app/views/change_requests/_remove_synonym.html.haml +++ b/app/views/change_requests/_remove_synonym.html.haml @@ -5,8 +5,10 @@ = form_with scope: :remove_synonym, url: change_requests_path, local: false do |f| = hidden_field_tag 'concept_id', @concept_id = hidden_field_tag 'concept_label', @concept_label + = hidden_field_tag 'github_id', @user.githubId = hidden_field_tag 'ont_acronym', @ont_acronym - = hidden_field_tag 'username', @username + = hidden_field_tag 'orcid_id', @user.orcidId + = hidden_field_tag 'username', @user.username = hidden_field_tag 'operation', KGCL::Operations::REMOVE_SYNONYM %div{class: 'modal-body'} %div.mb-3 From 571410b8cc9724d100fbeac4eac11f37d164892b Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Fri, 1 Nov 2024 14:48:05 -0700 Subject: [PATCH 2/6] Add a base class for common methods --- app/lib/kgcl/renderers/issue_content.rb | 56 +++++++++++++++++++ app/lib/kgcl/renderers/new_synonym_content.rb | 45 +++------------ .../kgcl/renderers/node_obsoletion_content.rb | 41 ++------------ app/lib/kgcl/renderers/node_rename_content.rb | 41 +++----------- .../kgcl/renderers/remove_synonym_content.rb | 41 +++----------- 5 files changed, 82 insertions(+), 142 deletions(-) create mode 100644 app/lib/kgcl/renderers/issue_content.rb diff --git a/app/lib/kgcl/renderers/issue_content.rb b/app/lib/kgcl/renderers/issue_content.rb new file mode 100644 index 000000000..597e81d23 --- /dev/null +++ b/app/lib/kgcl/renderers/issue_content.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module KGCL + module Renderers + # Base class for generating GitHub issue content for ontology change requests + class IssueContent + attr_reader :params + + def initialize(params) + @params = params + end + + def render + tr = KGCL::TemplateRenderer.new( + title_template: title_template, + body_template: body_template, + bind_klass: self + ) + tr.render + end + + def concept_id + @params[:concept_id] + end + + def concept_label + @params[:concept_label] + end + + def curie + @params[:curie] + end + + def github_id + @params[:github_id] + end + + def orcid_id + @params[:orcid_id] + end + + def username + @params[:username] + end + + # These methods should be defined in subclasses to provide unique templates + def title_template + raise NotImplementedError, 'Subclasses must define a title_template' + end + + def body_template + raise NotImplementedError, 'Subclasses must define a body_template' + end + end + end +end diff --git a/app/lib/kgcl/renderers/new_synonym_content.rb b/app/lib/kgcl/renderers/new_synonym_content.rb index 7871ba4df..de149adaf 100644 --- a/app/lib/kgcl/renderers/new_synonym_content.rb +++ b/app/lib/kgcl/renderers/new_synonym_content.rb @@ -12,50 +12,15 @@ module Renderers # # @see https://github.com/INCATools/kgcl KGCL documentation # - class NewSynonymContent - attr_reader :params - - def initialize(params) - @params = params - end - - def render - tr = KGCL::TemplateRenderer.new( - title_template: 'new_synonym_title.erb', - body_template: 'new_synonym_body.erb', - bind_klass: self - ) - tr.render - end - + class NewSynonymContent < IssueContent def comment @params[:create_synonym][:comment] end - def concept_id - @params[:concept_id] - end - - def concept_label - @params[:concept_label] - end - - def curie - @params[:curie] - end - def get_binding binding end - def github_id - @params[:github_id] - end - - def orcid_id - @params[:orcid_id] - end - def qualifier @params[:create_synonym][:qualifier] end @@ -64,8 +29,12 @@ def synonym_label @params[:create_synonym][:preferred_label] end - def username - @params[:username] + def title_template + 'new_synonym_title.erb' + end + + def body_template + 'new_synonym_body.erb' end end end diff --git a/app/lib/kgcl/renderers/node_obsoletion_content.rb b/app/lib/kgcl/renderers/node_obsoletion_content.rb index 86506e51f..ca0b8fe3f 100644 --- a/app/lib/kgcl/renderers/node_obsoletion_content.rb +++ b/app/lib/kgcl/renderers/node_obsoletion_content.rb @@ -9,52 +9,21 @@ module Renderers # # @see https://github.com/INCATools/kgcl KGCL documentation # - class NodeObsoletionContent - attr_reader :params - - def initialize(params) - @params = params - end - - def render - tr = KGCL::TemplateRenderer.new( - title_template: 'node_obsoletion_title.erb', - body_template: 'node_obsoletion_body.erb', - bind_klass: self - ) - tr.render - end - + class NodeObsoletionContent < IssueContent def comment @params[:node_obsoletion][:comment] end - def concept_id - @params[:concept_id] - end - - def concept_label - @params[:concept_label] - end - - def curie - @params[:curie] - end - def get_binding binding end - def github_id - @params[:github_id] - end - - def orcid_id - @params[:orcid_id] + def title_template + 'node_obsoletion_title.erb' end - def username - @params[:username] + def body_template + 'node_obsoletion_body.erb' end end end diff --git a/app/lib/kgcl/renderers/node_rename_content.rb b/app/lib/kgcl/renderers/node_rename_content.rb index 4f2e24e56..9315284f8 100644 --- a/app/lib/kgcl/renderers/node_rename_content.rb +++ b/app/lib/kgcl/renderers/node_rename_content.rb @@ -9,52 +9,25 @@ module Renderers # # @see https://github.com/INCATools/kgcl KGCL documentation # - class NodeRenameContent - attr_reader :params - - def initialize(params) - @params = params - end - - def render - tr = KGCL::TemplateRenderer.new( - title_template: 'node_rename_title.erb', - body_template: 'node_rename_body.erb', - bind_klass: self - ) - tr.render - end - + class NodeRenameContent < IssueContent def comment @params[:node_rename][:comment] end - def concept_label - @params[:concept_label] - end - - def curie - @params[:curie] - end - def get_binding binding end - def github_id - @params[:github_id] - end - - def orcid_id - @params[:orcid_id] - end - def new_concept_label @params[:node_rename][:new_preferred_name] end - def username - @params[:username] + def title_template + 'node_rename_title.erb' + end + + def body_template + 'node_rename_body.erb' end end end diff --git a/app/lib/kgcl/renderers/remove_synonym_content.rb b/app/lib/kgcl/renderers/remove_synonym_content.rb index cddefd8ae..84d9e4da2 100644 --- a/app/lib/kgcl/renderers/remove_synonym_content.rb +++ b/app/lib/kgcl/renderers/remove_synonym_content.rb @@ -11,52 +11,25 @@ module Renderers # # @see https://github.com/INCATools/kgcl KGCL documentation # - class RemoveSynonymContent - attr_reader :params - - def initialize(params) - @params = params - end - - def render - tr = KGCL::TemplateRenderer.new( - title_template: 'remove_synonym_title.erb', - body_template: 'remove_synonym_body.erb', - bind_klass: self - ) - tr.render - end - + class RemoveSynonymContent < IssueContent def comment @params[:remove_synonym][:comment] end - def concept_label - @params[:concept_label] - end - - def curie - @params[:curie] - end - def get_binding binding end - def github_id - @params[:github_id] - end - - def orcid_id - @params[:orcid_id] - end - def synonym_label @params[:remove_synonym][:synonym] end - def username - @params[:username] + def title_template + 'remove_synonym_title.erb' + end + + def body_template + 'remove_synonym_body.erb' end end end From fdab109d8dd6cf27bc2804383efa8ac909fe7907 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Fri, 1 Nov 2024 15:34:54 -0700 Subject: [PATCH 3/6] Fix unit tests --- spec/lib/issue_content_generator_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/lib/issue_content_generator_spec.rb b/spec/lib/issue_content_generator_spec.rb index 1f6298b6e..4198a8f92 100644 --- a/spec/lib/issue_content_generator_spec.rb +++ b/spec/lib/issue_content_generator_spec.rb @@ -20,9 +20,11 @@ --- - Comment: Please add this! + **Comment:** Please add this! - This request comes from BioPortal user: Daenerys Targaryen + Proposal generated by: BioPortal user 'Daenerys Targaryen' + + ORCID: HEREDOC content = KGCL::IssueContentGenerator.call(params) @@ -36,6 +38,8 @@ curie: 'MONDO:0009662', concept_label: 'mucopolysaccharidosis type 7', username: 'Sansa Stark', + github_id: 'sstark', + orcid_id: '0000-1234-5678-0000', remove_synonym: { synonym: 'Gus deficiency', comment: "I don't think this is correct!" } } @@ -47,9 +51,11 @@ --- - Comment: I don't think this is correct! + **Comment:** I don't think this is correct! + + Proposal generated by: @sstark - This request comes from BioPortal user: Sansa Stark + ORCID: 0000-1234-5678-0000 HEREDOC content = KGCL::IssueContentGenerator.call(params) From 14942a16c298f30aed972f132f6c5b1359b0dd89 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Wed, 6 Nov 2024 16:39:52 -0800 Subject: [PATCH 4/6] Convert some UJS to Turbo Streams and Stimulus --- app/controllers/change_requests_controller.rb | 6 +++--- .../controllers/change_requests_controller.js | 10 ++++++++++ app/javascript/controllers/index.js | 3 +++ app/views/change_requests/_node_obsoletion.html.haml | 5 +++-- app/views/change_requests/_node_rename.html.haml | 5 +++-- app/views/change_requests/create.js.erb | 3 --- app/views/change_requests/create.turbo_stream.haml | 4 ++++ app/views/change_requests/node_obsoletion.js.erb | 10 ---------- .../change_requests/node_obsoletion.turbo_stream.haml | 2 ++ app/views/change_requests/node_rename.js.erb | 10 ---------- .../change_requests/node_rename.turbo_stream.haml | 2 ++ app/views/concepts/_details.html.haml | 7 ++++--- 12 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 app/javascript/controllers/change_requests_controller.js delete mode 100644 app/views/change_requests/create.js.erb create mode 100644 app/views/change_requests/create.turbo_stream.haml delete mode 100644 app/views/change_requests/node_obsoletion.js.erb create mode 100644 app/views/change_requests/node_obsoletion.turbo_stream.haml delete mode 100644 app/views/change_requests/node_rename.js.erb create mode 100644 app/views/change_requests/node_rename.turbo_stream.haml diff --git a/app/controllers/change_requests_controller.rb b/app/controllers/change_requests_controller.rb index 80fbe9608..33833e11b 100644 --- a/app/controllers/change_requests_controller.rb +++ b/app/controllers/change_requests_controller.rb @@ -5,11 +5,11 @@ class ChangeRequestsController < ApplicationController before_action :set_common_instance_variables, except: [:create] def node_obsoletion - respond_to :js + respond_to :turbo_stream end def node_rename - respond_to :js + respond_to :turbo_stream end def create_synonym @@ -27,7 +27,7 @@ def create @issue = IssueCreatorService.call(params) flash.now.notice = helpers.change_request_success_message if @issue['id'].present? - respond_to :js + respond_to :turbo_stream end private diff --git a/app/javascript/controllers/change_requests_controller.js b/app/javascript/controllers/change_requests_controller.js new file mode 100644 index 000000000..d573ad58f --- /dev/null +++ b/app/javascript/controllers/change_requests_controller.js @@ -0,0 +1,10 @@ +import { Controller } from "@hotwired/stimulus" + +// Connects to data-controller="change-requests" +export default class extends Controller { + static targets = [ 'addProposalForm' ] + + clearProposalForm() { + this.addProposalFormTarget.innerHTML = ''; + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index c4d0fd2b2..dc2be48f5 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -4,5 +4,8 @@ import { application } from "./application" +import ChangeRequestsController from "./change_requests_controller" +application.register("change-requests", ChangeRequestsController) + import ClipboardController from "./clipboard_controller" application.register("clipboard", ClipboardController) diff --git a/app/views/change_requests/_node_obsoletion.html.haml b/app/views/change_requests/_node_obsoletion.html.haml index c59877fb6..182a0e2fa 100644 --- a/app/views/change_requests/_node_obsoletion.html.haml +++ b/app/views/change_requests/_node_obsoletion.html.haml @@ -1,4 +1,4 @@ -= form_with scope: :node_obsoletion, url: change_requests_path, local: false, class: 'mb-5' do |f| += form_with scope: :node_obsoletion, url: change_requests_path, data: {turbo: true}, class: 'mb-5' do |f| = hidden_field_tag 'concept_id', @concept_id = hidden_field_tag 'concept_label', @concept_label = hidden_field_tag 'github_id', @user.githubId @@ -11,4 +11,5 @@ = f.text_area :comment, rows: 5, class: 'form-control' %div.form-text Optionally enter a comment describing the reason for obsoletion = submit_tag 'Submit', id: 'node_obsoletion_button', class: 'btn btn-primary' - = tag.button 'Cancel', type: 'button', id: 'cancel_kgcl_proposal', class: 'btn btn-primary' + = tag.button('Cancel', type: 'button', + 'data-action': 'click->change-requests#clearProposalForm', class: 'btn btn-primary') diff --git a/app/views/change_requests/_node_rename.html.haml b/app/views/change_requests/_node_rename.html.haml index ba1da7251..7be776f9b 100644 --- a/app/views/change_requests/_node_rename.html.haml +++ b/app/views/change_requests/_node_rename.html.haml @@ -1,5 +1,5 @@ = tag.p("Proposal: rename '#{@concept_label}'", class: 'lead') -= form_with scope: :node_rename, url: change_requests_path, local: false, class: 'mb-5' do |f| += form_with scope: :node_rename, url: change_requests_path, data: {turbo: true}, class: 'mb-5' do |f| = hidden_field_tag 'concept_id', @concept_id = hidden_field_tag 'concept_label', @concept_label = hidden_field_tag 'github_id', @user.githubId @@ -18,4 +18,5 @@ = tag.div('Optionally enter a comment giving a reason for the rename', class: 'form-text', id: 'nodeRenameCommentHelpBlock') = submit_tag 'Submit', id: 'node_rename_button', class: 'btn btn-primary' - = tag.button 'Cancel', type: 'button', id: 'cancel_kgcl_proposal', class: 'btn btn-primary' + = tag.button('Cancel', type: 'button', + 'data-action': 'click->change-requests#clearProposalForm', class: 'btn btn-primary') diff --git a/app/views/change_requests/create.js.erb b/app/views/change_requests/create.js.erb deleted file mode 100644 index ce26058fd..000000000 --- a/app/views/change_requests/create.js.erb +++ /dev/null @@ -1,3 +0,0 @@ -jQuery("#details_content #change-request-notice").html('<%= j render partial: "notice" %>'); - -document.getElementById('addProposalFormDiv').innerHTML = ''; \ No newline at end of file diff --git a/app/views/change_requests/create.turbo_stream.haml b/app/views/change_requests/create.turbo_stream.haml new file mode 100644 index 000000000..fd7669d80 --- /dev/null +++ b/app/views/change_requests/create.turbo_stream.haml @@ -0,0 +1,4 @@ += turbo_stream.update 'change-request-notice' do + = render partial: 'notice' + += turbo_stream.update 'addProposalFormDiv' diff --git a/app/views/change_requests/node_obsoletion.js.erb b/app/views/change_requests/node_obsoletion.js.erb deleted file mode 100644 index 4e0fdc21e..000000000 --- a/app/views/change_requests/node_obsoletion.js.erb +++ /dev/null @@ -1,10 +0,0 @@ -let forms = document.getElementById('addProposalFormDiv').getElementsByTagName('form'); -if (forms.length === 0) { - document.getElementById('addProposalFormDiv') - .insertAdjacentHTML('afterbegin', '<%= j render 'change_requests/node_obsoletion' %>'); -} - -let button = document.getElementById('cancel_kgcl_proposal'); -button.addEventListener('click', () => { - document.getElementById('addProposalFormDiv').innerHTML = ''; -}); diff --git a/app/views/change_requests/node_obsoletion.turbo_stream.haml b/app/views/change_requests/node_obsoletion.turbo_stream.haml new file mode 100644 index 000000000..47d4c62e9 --- /dev/null +++ b/app/views/change_requests/node_obsoletion.turbo_stream.haml @@ -0,0 +1,2 @@ += turbo_stream.update 'addProposalFormDiv' do + = render partial: 'node_obsoletion' \ No newline at end of file diff --git a/app/views/change_requests/node_rename.js.erb b/app/views/change_requests/node_rename.js.erb deleted file mode 100644 index dd8e1700a..000000000 --- a/app/views/change_requests/node_rename.js.erb +++ /dev/null @@ -1,10 +0,0 @@ -let forms = document.getElementById('addProposalFormDiv').getElementsByTagName('form'); -if (forms.length === 0) { - document.getElementById('addProposalFormDiv') - .insertAdjacentHTML('afterbegin', '<%= j render 'change_requests/node_rename' %>'); -} - -let button = document.getElementById('cancel_kgcl_proposal'); -button.addEventListener('click', () => { - document.getElementById('addProposalFormDiv').innerHTML = ''; -}); diff --git a/app/views/change_requests/node_rename.turbo_stream.haml b/app/views/change_requests/node_rename.turbo_stream.haml new file mode 100644 index 000000000..f2ddab6c4 --- /dev/null +++ b/app/views/change_requests/node_rename.turbo_stream.haml @@ -0,0 +1,2 @@ += turbo_stream.update 'addProposalFormDiv' do + = render partial: 'node_rename' \ No newline at end of file diff --git a/app/views/concepts/_details.html.haml b/app/views/concepts/_details.html.haml index 4bc965768..207be3fe9 100644 --- a/app/views/concepts/_details.html.haml +++ b/app/views/concepts/_details.html.haml @@ -14,12 +14,13 @@ = link_to('Obsolete class', change_requests_node_obsoletion_path(concept_id: @concept.id, concept_label: @concept.prefLabel, ont_acronym: @ontology.acronym), - class: 'dropdown-item', remote: 'true') + class: 'dropdown-item', 'data-turbo': 'true', 'data-turbo-stream': 'true') = link_to('Rename class', change_requests_node_rename_path(concept_id: @concept.id, concept_label: @concept.prefLabel, ont_acronym: @ontology.acronym), - class: 'dropdown-item', remote: 'true') - %div#addProposalFormDiv + class: 'dropdown-item', 'data-turbo': 'true', 'data-turbo-stream': 'true') + %div{'data-controller': 'change-requests'} + %div{id: 'addProposalFormDiv', 'data-change-requests-target': 'addProposalForm'} %table.minimal.concept_details{cellpadding: "0", cellspacing: "0", width: "100%"} %tr From 7bca691057760e9b6169edbd94189d33d3bb6cb2 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Thu, 7 Nov 2024 14:36:01 -0800 Subject: [PATCH 5/6] Fix an issue with login page rendering --- app/controllers/change_requests_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/change_requests_controller.rb b/app/controllers/change_requests_controller.rb index 33833e11b..8b687213a 100644 --- a/app/controllers/change_requests_controller.rb +++ b/app/controllers/change_requests_controller.rb @@ -49,11 +49,12 @@ def generate_curie(ont_acronym, concept_id) def require_login return unless session[:user].blank? - # TODO: Can this implementation be improved? For discussion: - # https://stackoverflow.com/a/18681807 - # https://stackoverflow.com/a/10607511 - # https://stackoverflow.com/a/51275445 - render js: "window.location.href='#{login_index_path}'" + # TODO: remove format.js handling after the create_synonym and remove_synonym actions are converted + # from Rails UJS to Turbo Streams. + respond_to do |format| + format.turbo_stream { redirect_to login_index_path } + format.js { render js: "window.location.href='#{login_index_path}'", status: :found } + end end def set_common_instance_variables From 244a22275d2dfa46863790dcf6b86d1b140d3e01 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Thu, 7 Nov 2024 17:50:51 -0800 Subject: [PATCH 6/6] Restore create.js.erb --- app/controllers/change_requests_controller.rb | 7 ++++++- app/views/change_requests/create.js.erb | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 app/views/change_requests/create.js.erb diff --git a/app/controllers/change_requests_controller.rb b/app/controllers/change_requests_controller.rb index 8b687213a..49439ea37 100644 --- a/app/controllers/change_requests_controller.rb +++ b/app/controllers/change_requests_controller.rb @@ -27,7 +27,12 @@ def create @issue = IssueCreatorService.call(params) flash.now.notice = helpers.change_request_success_message if @issue['id'].present? - respond_to :turbo_stream + # TODO: remove format.js from this block, and the create.js.erb file after the create_synonym and + # remove_synonym actions are converted from Rails UJS to Turbo Streams. + respond_to do |format| + format.js + format.turbo_stream + end end private diff --git a/app/views/change_requests/create.js.erb b/app/views/change_requests/create.js.erb new file mode 100644 index 000000000..d1cba95db --- /dev/null +++ b/app/views/change_requests/create.js.erb @@ -0,0 +1,2 @@ +document.getElementById('change-request-notice').innerHTML = '<%= j render partial: "notice" %>' +document.getElementById('addProposalFormDiv').innerHTML = ''; \ No newline at end of file