Skip to content

Commit

Permalink
Merge pull request #344 from ncbo/feature/kgcl-issue-attribution/323
Browse files Browse the repository at this point in the history
Enhance ontology change request attribution and begin UJS replacement
  • Loading branch information
jvendetti authored Nov 8, 2024
2 parents a8753d9 + 244a222 commit 156d1b8
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 170 deletions.
26 changes: 17 additions & 9 deletions app/controllers/change_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +27,12 @@ def create
@issue = IssueCreatorService.call(params)
flash.now.notice = helpers.change_request_success_message if @issue['id'].present?

respond_to :js
# 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
Expand All @@ -49,17 +54,20 @@ 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
@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
10 changes: 10 additions & 0 deletions app/javascript/controllers/change_requests_controller.js
Original file line number Diff line number Diff line change
@@ -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 = '';
}
}
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import { application } from "./application"

import ChangeRequestsController from "./change_requests_controller"
application.register("change-requests", ChangeRequestsController)

import LanguageChangeController from "./language_change_controller"
application.register("language-change", LanguageChangeController)

Expand Down
56 changes: 56 additions & 0 deletions app/lib/kgcl/renderers/issue_content.rb
Original file line number Diff line number Diff line change
@@ -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
37 changes: 7 additions & 30 deletions app/lib/kgcl/renderers/new_synonym_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,11 @@ 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
Expand All @@ -56,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
Expand Down
37 changes: 7 additions & 30 deletions app/lib/kgcl/renderers/node_obsoletion_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +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 username
@params[:username]
def title_template
'node_obsoletion_title.erb'
end

def body_template
'node_obsoletion_body.erb'
end
end
end
Expand Down
33 changes: 7 additions & 26 deletions app/lib/kgcl/renderers/node_rename_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,11 @@ 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
Expand All @@ -45,8 +22,12 @@ 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
Expand Down
33 changes: 7 additions & 26 deletions app/lib/kgcl/renderers/remove_synonym_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,11 @@ 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
Expand All @@ -47,8 +24,12 @@ 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
Expand Down
9 changes: 9 additions & 0 deletions app/lib/kgcl/templates/footer.erb
Original file line number Diff line number Diff line change
@@ -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 %>
5 changes: 2 additions & 3 deletions app/lib/kgcl/templates/new_synonym_body.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

---

Comment: <%= comment %>

This request comes from BioPortal user: <%= username %>
<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %>
<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %>
5 changes: 2 additions & 3 deletions app/lib/kgcl/templates/node_obsoletion_body.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

---

Comment: <%= comment %>

This request comes from BioPortal user: <%= username %>
<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %>
<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %>
5 changes: 2 additions & 3 deletions app/lib/kgcl/templates/node_rename_body.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

---

Comment: <%= comment %>

This request comes from BioPortal user: <%= username %>
<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %>
<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %>
5 changes: 2 additions & 3 deletions app/lib/kgcl/templates/remove_synonym_body.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

---

Comment: <%= comment %>

This request comes from BioPortal user: <%= username %>
<% footer_template = File.read("#{Rails.root}/app/lib/kgcl/templates/footer.erb") %>
<%= ERB.new(footer_template, trim_mode: '<>', eoutvar: 'footer').result(binding) %>
Loading

0 comments on commit 156d1b8

Please sign in to comment.