Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sj jtm notes badges #613

Merged
merged 10 commits into from
Aug 8, 2016
10 changes: 10 additions & 0 deletions app/assets/stylesheets/dashboard/layout.sass
Expand Up @@ -35,6 +35,16 @@
margin-left: 5px
vertical-align: middle

// Custom styling for badges
// Needs special rule for badges in buttons, in panel headers
.panel > .panel-heading .btn-success .badge
background-color: #fff
color: #5cb85c
margin-left: 3px

//Dropdown badges need extra spacing
.dropdown_badge span.badge
margin-left: 5px

// Custom Reporting Styling
h2.report_title
Expand Down
1 change: 1 addition & 0 deletions app/controllers/dashboard/notes_controller.rb
Expand Up @@ -34,6 +34,7 @@ def new
def create
if note_params[:body].present? # don't create empty notes
@note = Note.create(note_params.merge(identity_id: current_user.id))
@selector = "#{@note.unique_selector}_notes"
end
@notes = @notable.notes
end
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/dashboard/study_level_activities_helper.rb
Expand Up @@ -34,13 +34,13 @@ def sla_cost_display line_item
return "$#{cost}"
end

def sla_options_buttons line_item_id
def sla_options_buttons line_item
options = raw(
content_tag(:li, raw(
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-sunglasses", aria: {hidden: "true"}))+t(:dashboard)[:study_level_activities][:actions][:details], type: 'button', class: 'btn btn-default form-control actions-button otf_details list'))
)+
content_tag(:li, raw(
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-list-alt", aria: {hidden: "true"}))+t(:dashboard)[:study_level_activities][:actions][:notes], type: 'button', class: 'btn btn-default form-control actions-button notes list', data: {notable_id: line_item_id, notable_type: "LineItem"}))
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-list-alt", aria: {hidden: "true"}))+t(:dashboard)[:study_level_activities][:actions][:notes]+raw(content_tag(:span, line_item.notes.count, class: "badge", id: "lineitem_#{line_item.id}_notes")), type: 'button', class: 'btn btn-default form-control actions-button notes list dropdown_badge', data: {notable_id: line_item.id, notable_type: "LineItem"}))
)+
content_tag(:li, raw(
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-usd", aria: {hidden: "true"}))+t(:dashboard)[:study_level_activities][:actions][:admin_rate], type: 'button', class: 'btn btn-default form-control actions-button otf_admin_rate'))
Expand Down Expand Up @@ -75,10 +75,10 @@ def fulfillments_drop_button line_item_id
raw content_tag(:button, 'List', id: "list-#{line_item_id}", type: 'button', class: 'btn btn-success otf_fulfillment_list', title: 'List', type: "button", aria: {label: "List Fulfillments"}, data: {line_item_id: line_item_id})
end

def fulfillment_options_buttons fulfillment_id
def fulfillment_options_buttons fulfillment
options = raw(
content_tag(:li, raw(
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-list-alt", aria: {hidden: "true"}))+t(:dashboard)[:fulfillments][:actions][:notes], type: 'button', class: 'btn btn-default form-control actions-button notes list', data: {notable_id: fulfillment_id, notable_type: "Fulfillment"}))
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-list-alt", aria: {hidden: "true"}))+t(:dashboard)[:fulfillments][:actions][:notes]+raw(content_tag(:span, fulfillment.notes.count, class: "badge", id: "fulfillment_#{fulfillment.id}_notes")), type: 'button', class: 'btn btn-default form-control actions-button notes list dropdown_badge', data: {notable_id: fulfillment.id, notable_type: "Fulfillment"}))
)+
content_tag(:li, raw(
content_tag(:button, raw(content_tag(:span, '', class: "glyphicon glyphicon-edit", aria: {hidden: "true"}))+t(:dashboard)[:fulfillments][:actions][:edit], type: 'button', class: 'btn btn-default form-control actions-button otf_fulfillment_edit'))
Expand Down
10 changes: 7 additions & 3 deletions app/models/note.rb
Expand Up @@ -27,15 +27,19 @@ class Note < ActiveRecord::Base
attr_accessible :body, :identity_id, :notable_type, :notable_id

validates_presence_of :body, :identity_id


def unique_selector
"#{notable_type.downcase}_#{notable_id}"
end

### audit reporting methods ###

def audit_label audit
subject = appointment.calendar.subject
subject_label = subject.respond_to?(:audit_label) ? subject.audit_label(audit) : "Subject #{subject.id}"
return "Note for #{subject_label} on #{appointment.visit_group.name}"
end

def audit_excluded_fields
{'create' => ['identity_id', 'appointment_id']}
end
Expand Down
Expand Up @@ -4,4 +4,4 @@ json.id fulfillment.id
json.fulfillment_date format_date(fulfillment.date)
json.quantity fulfillment.time
json.quantity_type fulfillment.timeframe
json.options fulfillment_options_buttons(fulfillment.id)
json.options fulfillment_options_buttons(fulfillment)
Expand Up @@ -8,5 +8,5 @@ json.quantity_type line_item.service.current_effective_pricing_map.quantity_type
json.cost sla_cost_display(line_item)
json.date_started format_date(line_item.in_process_date)
json.date_completed format_date(line_item.complete_date)
json.options sla_options_buttons(line_item.id)
json.options sla_options_buttons(line_item)
json.fulfillments_button fulfillments_drop_button(line_item.id)
3 changes: 2 additions & 1 deletion app/views/dashboard/notes/create.js.coffee
Expand Up @@ -20,8 +20,9 @@
if $(".modal-content").length > 0
# dashboard notes modals
$("#modal_place").html("<%= escape_javascript(render(partial: 'index', locals: { notes: @notes, notable_id: @notable_id, notable_type: @notable_type })) %>")
$("span#<%= @selector %>").html("<%= escape_javascript(@notes.count.to_s) %>")
else
#sparc proper service request notes in step 3
$("#request_notes_table").html("<%= escape_javascript(render(partial: '/notes/request_notes', locals: { notes: @notes, thead_class: 'orange-provider' } )) %>")
$('.new_request_note_button').show()
$('#note_form').hide()
$('#note_form').hide()
4 changes: 3 additions & 1 deletion app/views/dashboard/protocols/_summary.html.haml
Expand Up @@ -3,8 +3,10 @@
%h4.panel-title.pull-left
= protocol_type + t(:dashboard)[:protocols][:summary][:header]
.pull-right
%button.btn.btn-sm.btn-default.notes.list{ data: { notable_type: "Protocol", notable_id: protocol.id } }
%button.btn.btn-sm.btn-success.notes.list{ data: { notable_type: "Protocol", notable_id: protocol.id } }
= protocol_type + t(:dashboard)[:protocols][:summary][:notes]
%span.badge{id: "protocol_#{protocol.id}_notes"}
= protocol.notes.count
%button.btn.btn-sm.btn-info.view-protocol-details-button{ data: { protocol_id: protocol.id } }
= t(:dashboard)[:protocols][:summary][:view_details1] + protocol_type + t(:dashboard)[:protocols][:summary][:view_details2]
= edit_protocol_button_display(protocol, permission_to_edit)
Expand Down
Expand Up @@ -22,8 +22,10 @@
%h4.panel-title.pull-left
= protocol_panel_header_line(service_request)
.pull-right
%button.btn.btn-sm.btn-default.notes.list{ data: {notable_type: "ServiceRequest", notable_id: service_request.id } }
%button.btn.btn-sm.btn-success.notes.list{ data: {notable_type: "ServiceRequest", notable_id: service_request.id } }
= t(:models)[:note][:plural]
%span.badge{id: "servicerequest_#{service_request.id}_notes"}
= service_request.notes.count
- if permission_to_edit
%button.btn.btn-warning.btn-sm.edit-service-request{ class: permission_to_edit ? '' : 'disabled', type: 'button', data: { permission: permission_to_edit.to_s, url: modify_request_button_url(service_request) } }
= t(:dashboard)[:service_requests][:modify_request]
Expand Down
6 changes: 4 additions & 2 deletions app/views/dashboard/sub_service_requests/_header.html.haml
Expand Up @@ -25,8 +25,10 @@
%h4.panel-title.pull-left
= "#{sub_service_request.protocol.short_title} > #{sub_service_request.organization.name} (#{sub_service_request.protocol.id}-#{sub_service_request.ssr_id})"
.pull-right
%button.btn.btn-sm.btn-default.notes.list{data: { notable_type: "SubServiceRequest", notable_id: sub_service_request.id }}
%button.btn.btn-sm.btn-success.notes.list{data: { notable_type: "SubServiceRequest", notable_id: sub_service_request.id }}
= t(:models)[:note][:plural]
%span.badge{id: "subservicerequest_#{sub_service_request.id}_notes"}
= sub_service_request.notes.count
.clearfix

%table.table.table-bordered.table-condensed
Expand Down Expand Up @@ -54,4 +56,4 @@
%td.effective_cost
= number_to_currency(effective_current_total(sub_service_request))
%td.display_cost
= number_to_currency(user_display_total(sub_service_request))
= number_to_currency(user_display_total(sub_service_request))
4 changes: 3 additions & 1 deletion app/views/dashboard/subsidies/_approved_subsidy.html.haml
Expand Up @@ -24,8 +24,10 @@
%h4.panel-title.pull-left
= t(:dashboard)[:subsidies][:subsidy_information][:approved][:header]
.pull-right
%button.btn.btn-sm.btn-default.notes.list{data: { notable_type: "Subsidy", notable_id: subsidy.id }}
%button.btn.btn-sm.btn-success.notes.list{data: { notable_type: "Subsidy", notable_id: subsidy.id }}
= t(:models)[:note][:plural]
%span.badge{id: "subsidy_#{subsidy.id}_notes"}
= subsidy.notes.count
.clearfix
%table.table.table-condensed#approved_subsidy_table
%thead
Expand Down
7 changes: 4 additions & 3 deletions spec/controllers/dashboard/notes/post_create_spec.rb
Expand Up @@ -44,10 +44,11 @@ def notes; end # instance of notable types have Notes
@notable_obj = findable_stub(MyNotableType) do
MyNotableType.new(2)
end

@note = build_stubbed(:note)
allow(@notable_obj).to receive(:notes).and_return("all my notes")

allow(Note).to receive(:create).
and_return("my new note")
allow(Note).to receive(:create).and_return(@note)

log_in_dashboard_identity(obj: @logged_in_user)
xhr :get, :create, note: { identity_id: "-1", notable_type: "MyNotableType",
Expand All @@ -64,7 +65,7 @@ def notes; end # instance of notable types have Notes
end

it "should assign @note to the newly created Note" do
expect(assigns(:note)).to eq("my new note")
expect(assigns(:note)).to eq(@note)
end

it "should assign @notes to notable object's Notes" do
Expand Down
33 changes: 33 additions & 0 deletions spec/factories/note.rb
@@ -0,0 +1,33 @@
# Copyright © 2011 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

FactoryGirl.define do

factory :note do
body { Faker::Lorem.sentence(1) }
notable_type { "Protocol" }

trait :without_validations do
to_create { |instance| instance.save(validate: false) }
end

factory :note_without_validations, traits: [:without_validations]
end
end
Expand Up @@ -14,6 +14,7 @@
allow(logged_in_user).to receive(:unread_notification_count).
with(sub_service_request.id).and_return("12345")
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -36,6 +37,7 @@
allow(logged_in_user).to receive(:unread_notification_count).
with(sub_service_request.id).and_return("12345")
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -59,6 +61,7 @@
allow(logged_in_user).to receive(:unread_notification_count).
with(sub_service_request).and_return("12345")
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand Down Expand Up @@ -86,6 +89,7 @@
allow(logged_in_user).to receive_messages(unread_notification_count: 12345,
clinical_provider_rights?: true)
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -107,6 +111,7 @@
allow(logged_in_user).to receive_messages(unread_notification_count: 12345,
clinical_provider_rights?: false)
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -127,6 +132,7 @@
logged_in_user = build_stubbed(:identity)
allow(logged_in_user).to receive_messages(unread_notification_count: 12345)
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -146,6 +152,7 @@
logged_in_user = build_stubbed(:identity)
allow(logged_in_user).to receive_messages(unread_notification_count: 12345)
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -162,6 +169,7 @@
allow(logged_in_user).to receive(:unread_notification_count).
with(sub_service_request).and_return("12345")
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand All @@ -176,6 +184,7 @@
allow(logged_in_user).to receive(:unread_notification_count).
with(sub_service_request).and_return("12345")
stub_current_user(logged_in_user)
allow(sub_service_request).to receive(:notes).and_return(["1"])

render "dashboard/sub_service_requests/header", sub_service_request: sub_service_request

Expand Down