Skip to content

Commit

Permalink
fixed change status button + keep notes in item for completed request
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Deli authored and Dennis Deli committed Feb 11, 2025
1 parent 041799e commit 25f8ace
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,20 @@ def change_status
@item.audit_comment = "#{@item.title} status changed to #{@item.status}"

@item.save(validate: false)

@notes_by_item = {}
@notes_by_item[@item.id] = Audited::Audit.where(
auditable_id: @request.id,
auditable_type: "Request",
associated_id: @item.id,
associated_type: "Item",
action: "note"
)

@notes = @notes_by_item || {}

respond_to do |format|
format.html { redirect_to @request, noitce: "Item status changed to #{status}" }
format.html { redirect_to @request, notice: "Item status changed to #{status}" }
format.js
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def initialize(user, params)
# can get back to login
can :back_to_login, :requestor

can :add_note, Item do |i|
i.request.status == Request::COMPLETED || i.request.status == Request::ACTIVE
end

### CANNOTS
cannot [:update, :destroy, :assign], Request do |r|
r.status == Request::CANCELLED || r.status == Request::COMPLETED
Expand Down
4 changes: 2 additions & 2 deletions app/views/items/_item_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@
<span class="btn btn-sm gray-bg">Removed</span>
<% end %>

<% if can?(:change_status, item) && item.status != Item::STATUS_DELETED%>
<% if can?(:add_note, item) && item.status != Item::STATUS_DELETED%>
<br/><br/>
<%= render partial: 'requests/item_history_log_modal_', locals: { item: item } %>
<!-- Adding a link with text -->
<div style="display: inline-flex; align-items: center;">
<%= link_to 'Add a Note / History Log', '#', data: { toggle: 'modal', target: "#item_history_popup_#{item.id}", remote: true }, class: 'btn btn-xs btn-default' %>

<% if @notes[item.id].any? %>
<% if @notes&.dig(item.id)&.any? %>
<span id="notes-icon-<%= item.id %>" style="font-size: 1.5rem; margin-left: 3px;">⚠️</span>
<% else %>
<span id="notes-icon-<%= item.id %>" style="font-size: 1.5rem; margin-left: 3px;"></span>
Expand Down

0 comments on commit 25f8ace

Please sign in to comment.