Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #214 from OHS-Hosting-Infrastructure/itams_fake
Browse files Browse the repository at this point in the history
Add fake monitoring link to complaint
  • Loading branch information
jduss4 authored Nov 1, 2021
2 parents 2e0ea08 + 6d1bbf8 commit 34c2780
Show file tree
Hide file tree
Showing 26 changed files with 364 additions and 87 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/complaints.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
background-color: #fff;
border: 2px solid #dfe1e2;
border-radius: 5px;
padding: 0 1rem 1rem;
}

.summary-header {
Expand Down Expand Up @@ -38,6 +39,12 @@
border-bottom: 1px solid #DFE1E2;
}

.ct-monitoring-divider {
border-top: 1px solid #DFE1E2;
padding-top: 1rem;
margin-top: 1rem;
}

.ct-timeline__two-part-container {
display: flex;
align-items: baseline;
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/complaints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def show
@complaint = Complaint.new(
ApiDelegator.use("hses", "issue", {id: params[:id]}).request.data
)
@issue_tta_reports = IssueTtaReport.where(issue_id: params[:id]).order(:start_date).each do |report|
# inject the user's HSES access token to be used by TtaActivityReport
report.access_token = hses_access_token
end
@issue_tta_reports = inject_access_token(IssueTtaReport)
@issue_monitoring_reviews = inject_access_token(IssueMonitoringReview)

@timeline = Timeline.new(@complaint.attributes, @issue_tta_reports)
render layout: "details"
end
Expand All @@ -36,6 +35,13 @@ def check_pa11y_id
end
end

def inject_access_token(model)
model.where(issue_id: params[:id]).order(:start_date).each do |record|
# inject the user's HSES access token to be used by the TTA report or monitoring review
record.access_token = hses_access_token
end
end

def options_index
{user: session[:user], params: params}
end
Expand Down
31 changes: 31 additions & 0 deletions app/controllers/issue_monitoring_reviews_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class IssueMonitoringReviewsController < ApplicationController
include NeedsHsesAccessToken

def create
@issue_monitoring_review = IssueMonitoringReview.new(
issue_id: issue_id,
review_id: review_id,
access_token: hses_access_token
)

respond_to do |format|
if @issue_monitoring_review.save
format.js { render inline: "location.reload(true);" }
else
format.js { render inline: "alert('there was an error linking to a RAN review');" }
# TODO implement when working on error handling
# format.js { render "create_errors" }
end
end
end

private

def issue_id
params[:issue_id_monitoring]
end

def review_id
params[:monitoring_review_id]
end
end
2 changes: 1 addition & 1 deletion app/controllers/issue_tta_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def tta_report_display_id
end

def issue_id
params[:issue_id]
params[:issue_id_tta]
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const openForm = function () {
const form = document.querySelector("#tta-activity-form")
const openForm = function (formId, itemId) {
const form = document.querySelector(formId)
form.classList.remove("display-none")
document.querySelector("#tta-report-display-id").focus()
document.querySelector(itemId).focus()
}

const closeForm = function (containerId = "#tta-activity-form") {
const clearFormValue = function (elementId) {
const input = document.querySelector(elementId)
input.value = ""
}

const closeForm = function (containerId) {
const formContainer = document.querySelector(containerId)
formContainer.classList.add("display-none")

Expand All @@ -14,22 +19,43 @@ const closeForm = function (containerId = "#tta-activity-form") {
errorMessage.innerText = ""
}

// TTA open form

document.querySelector("#js-add-tta-report").addEventListener('click', event => {
event.preventDefault()
openForm()
openForm("#tta-activity-form", "#tta-report-display-id")
})

document.querySelector("#tta-report-icon").addEventListener('click', event => {
openForm()
openForm("#tta-activity-form", "#tta-report-display-id")
})

// ITAMS open form

document.querySelector("#js-add-monitoring-review").addEventListener('click', event => {
event.preventDefault()
openForm("#monitoring-activity-form", "#monitoring-review-id")
})

document.querySelector("#monitoring-review-icon").addEventListener('click', event => {
openForm("#monitoring-activity-form", "#monitoring-review-id")
})

// Close form

document.querySelector("#js-close-tta-form").addEventListener('click', event => {
event.preventDefault()
closeForm()
const input = document.querySelector("#tta-report-display-id")
input.value = ""
closeForm("#tta-activity-form")
clearFormValue("#tta-report-display-id")
})

document.querySelector("#js-close-monitoring-form").addEventListener('click', event => {
event.preventDefault()
closeForm("#monitoring-activity-form")
clearFormValue("#monitoring-review-id")
})


document.querySelectorAll(".js-edit-tta").forEach((el) => {
el.addEventListener('click', event => {
event.preventDefault()
Expand Down Expand Up @@ -67,8 +93,7 @@ document.querySelectorAll(".js-open-unlink-modal").forEach((el) => {

document.querySelectorAll(".ct-close-modal").forEach((el) => {
el.addEventListener('click', event => {
// remove display id from hidden input form
const hiddenInput = document.querySelector("#hidden-tta-display_id")
hiddenInput.value = ""
// remove id from hidden input forms
clearFormValue("#hidden-tta-display_id")
})
})
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
require "fake_api_response_wrapper"

class Api::FakeData::Itams
class Api::FakeData::Monitoring
class Review
include FakeApiResponseWrapper
attr_accessor :id

def initialize(id:)
def initialize(id:, access_token:)
@id = id
end

def request
details_response(
Api::FakeData::Review.new(id: id).data
)
details_response(Api::FakeData::Review.new(id: id).data)
end
end
end
17 changes: 17 additions & 0 deletions app/models/api/monitoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# TODO remove fake api business once this is hooked up
require "fake_api_response_wrapper"

module Api::Monitoring
include FakeApiResponseWrapper
attr_accessor :id

def initialize(id:, access_token:)
@id = id
end

def request
details_response(
Api::FakeData::MonitoringReview.new(id: id).data
)
end
end
15 changes: 15 additions & 0 deletions app/models/issue_monitoring_review.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
class IssueMonitoringReview < ApplicationRecord
before_validation :retrieve_monitoring_review_details
validates :issue_id, :review_id, :start_date, presence: true
validates :review_id, uniqueness: {scope: :issue_id}

attr_accessor :access_token

def monitoring_review
@monitoring_review ||= MonitoringReview.new(review_id, access_token)
end

private

def retrieve_monitoring_review_details
if monitoring_review.valid?
self.start_date = monitoring_review.start_date
end
end
end
33 changes: 33 additions & 0 deletions app/models/monitoring_review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "api_delegator"

class MonitoringReview
attr_accessor :access_token, :id

def initialize(id, access_token)
@id = id
@access_token = access_token
@errors = []
end

def start_date
get_api_data_field :attributes, :reviewStartDate
end

def valid?
review_data.error.nil?
end

private

def api
ApiDelegator.use("monitoring", "review", id: id, access_token: access_token)
end

def get_api_data_field(*path)
review_data.data.dig(*path)
end

def review_data
@review_data ||= api.request
end
end
13 changes: 13 additions & 0 deletions app/views/complaints/_complaints_open_new_linked_item.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="display-flex flex-align-center">
<%= image_pack_tag "media/usa-icons/link.svg",
class: "ct-link-icon",
id: "#{type}-icon",
"aria-hidden": true
%>
<%= button_to label, "##{type}-id", {
class: "usa-link usa-button--unstyled ct-add-report-link",
id: "js-add-#{type}",
role: "button"
}
%>
</div>
3 changes: 3 additions & 0 deletions app/views/complaints/_issue_monitoring_review.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="ct-tta-divider display-flex flex-justify" id="monitoring-activity-show-<%= issue_monitoring_review.id %>">
<div><%= issue_monitoring_review.review_id %></div>
</div>
40 changes: 19 additions & 21 deletions app/views/complaints/_issue_tta_report.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<div>
<div class="ct-tta-divider display-flex flex-justify" id="tta-activity-show-<%= issue_tta_report.id %>">
<div><%= issue_tta_report.tta_report_display_id %></div>
<div>
<%= button_tag image_pack_tag("media/usa-icons/edit.svg", alt: "Edit Display ID"),
class: "ct-link-icon usa-button--unstyled js-edit-tta",
"aria-label": "Edit Display ID",
"data-id": issue_tta_report.id
%>
<%= link_to image_pack_tag("media/usa-icons/link_off.svg", alt: "Unlink Display ID"),
"#unlink-modal",
class: "ct-link-icon usa-button--unstyled js-open-unlink-modal",
"aria-controls": "unlink-modal",
"aria-label": "Unlink Display ID",
"data-open-modal": true,
"data-display-id": issue_tta_report.tta_report_display_id
%>
</div>
</div>
<div class="display-none" id="edit-tta-activity-<%= issue_tta_report.id %>">
<%= render "tta_edit_activity_report", issue_tta_report: issue_tta_report %>
<div class="ct-tta-divider display-flex flex-justify" id="tta-activity-show-<%= issue_tta_report.id %>">
<div><%= issue_tta_report.tta_report_display_id %></div>
<div>
<%= button_tag image_pack_tag("media/usa-icons/edit.svg", alt: "Edit Display ID"),
class: "ct-link-icon usa-button--unstyled js-edit-tta",
"aria-label": "Edit Display ID",
"data-id": issue_tta_report.id
%>
<%= link_to image_pack_tag("media/usa-icons/link_off.svg", alt: "Unlink Display ID"),
"#unlink-modal",
class: "ct-link-icon usa-button--unstyled js-open-unlink-modal",
"aria-controls": "unlink-modal",
"aria-label": "Unlink Display ID",
"data-open-modal": true,
"data-display-id": issue_tta_report.tta_report_display_id
%>
</div>
</div>
<div class="display-none" id="edit-tta-activity-<%= issue_tta_report.id %>">
<%= render "tta_edit_activity_report", issue_tta_report: issue_tta_report %>
</div>
19 changes: 19 additions & 0 deletions app/views/complaints/_monitoring_create_review.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="display-none" id="monitoring-activity-form">
<div class="ct-section-divider">
<div class="display-flex flex-justify margin-bottom-2">
<span> RAN ID</span>
<%= button_to "Cancel", "#js-add-monitoring-review", class: "usa-link usa-button--unstyled", id: "js-close-monitoring-form" %>
</div>
<div>
<%= form_with url: issue_monitoring_reviews_path, local: false, method: "post", class: "usa-search display-flex", id: "monitoring-review-form" do %>
<%= hidden_field_tag(:issue_id_monitoring, @complaint.id) %>
<div class="usa-form-group">
<%= label_tag "monitoring-review-id", "RAN ID", class: "usa-sr-only", id: "monitoring-review-label" %>
<span class="usa-error-message"></span>
<%= text_field_tag :monitoring_review_id, nil, id: "monitoring-review-id", "aria-describedBy": "monitoring-review-label" %>
<%= submit_tag "Link", class: "usa-button usa-search__submit-text", id: "monitoring-review-create-link" %>
</div>
<% end %>
</div>
</div>
</div>
10 changes: 5 additions & 5 deletions app/views/complaints/_tta_create_activity_report.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<div class="ct-section-divider">
<p>
<div class="display-none" id="tta-activity-form">
<div class="ct-section-divider">
<div class="display-flex flex-justify margin-bottom-2">
<span> Activity Report ID</span>
<%= button_to "Cancel", "#js-add-tta-report", class: "usa-link usa-button--unstyled", id: "js-close-tta-form" %>
</div>
<div>
<%= form_with url: issue_tta_reports_path, local: false, method: "post", class: "usa-search display-flex", id: "tta-report-form" do %>
<%= hidden_field_tag(:issue_id, @complaint.id) %>
<%= hidden_field_tag(:issue_id_tta, @complaint.id) %>
<div class="usa-form-group">
<%= label_tag "tta-report-display-id", "TTA report display ID", class: "usa-sr-only", id: "tta-report-label" %>
<span class="usa-error-message"></span>
<%= text_field_tag :tta_report_display_id, nil, id: "tta-report-display-id", "aria-describedBy": "tta-report-label" %>
<%= submit_tag "Link", class: "usa-button usa-search__submit-text" %>
<%= submit_tag "Link", class: "usa-button usa-search__submit-text", id: "tta-report-create-link" %>
</div>
<% end %>
</div>
</p>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/complaints/_tta_edit_activity_report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div>
<%= form_with url: issue_tta_report_path(issue_tta_report), local: false, method: "put", class: "usa-search display-flex" do %>
<%= hidden_field_tag(:issue_id, @complaint.id) %>
<%= hidden_field_tag(:issue_id_tta, @complaint.id) %>
<div class="usa-form-group">
<%= label_tag "tta-edit-report-id", "TTA report display ID", class: "usa-sr-only tta-edit-report-label" %>
<span class="usa-error-message"></span>
Expand Down
Loading

0 comments on commit 34c2780

Please sign in to comment.