Skip to content

Commit

Permalink
Locked draft behavior hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 3, 2023
1 parent 3a5fec4 commit ddcc1ac
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 22 deletions.
48 changes: 26 additions & 22 deletions app/components/message_draft_body_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@

<div class="flex flex-col justify-stretch items-start relative gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<% if @message.custom_visualization? %>
<%
message_title_id = dom_id(@message, :title)
message_text_id = dom_id(@message, :text)
<% message_title_id = dom_id(@message, :title)
message_text_id = dom_id(@message, :text)
%>
<%= content_tag(:div,
{
"data-controller": "message-drafts",
"data-message-drafts-message-draft-path": message_draft_path(@message.id),
"data-message-drafts-authenticity-token": form_authenticity_token,
"data-message-drafts-title-id": message_title_id,
"data-message-drafts-text-id": message_text_id,
"class": "mb-3 pt-0 w-full"
}
) do %>
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", "data-action": "change->message-drafts#update", disabled: !@message.editable?, class: "mb-3 px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full" %>
<%= text_area_tag message_text_id, @message.metadata["message_body"], autofocus: @is_last, placeholder: "Text", "data-action": "change->message-drafts#update", rows: 10, disabled: !@message.editable?, class: "px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
{
"data-controller": "message-drafts",
"data-message-drafts-message-draft-path": message_draft_path(@message.id),
"data-message-drafts-authenticity-token": form_authenticity_token,
"data-message-drafts-title-id": message_title_id,
"data-message-drafts-text-id": message_text_id,
"class": "mb-3 pt-0 w-full"
}) do %>
<% if @message.editable? %>
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", "data-action": "change->message-drafts#update", class: "mb-3 px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full" %>
<%= text_area_tag message_text_id, @message.metadata["message_body"], autofocus: @is_last, placeholder: "Text", "data-action": "change->message-drafts#update", rows: 10, class: "px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
<% else %>
<%= link_to enable_edit_message_draft_path(@message), data: { turbo_frame: "modal" } do %>
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", readonly: true, class: "mb-3 px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full" %>
<%= text_area_tag message_text_id, @message.metadata["message_body"], autofocus: @is_last, readonly: true, placeholder: "Text", rows: 10, class: "px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
<% end %>
<% end %>
<% end %>
<% else %>
<div class="w-full">
Expand All @@ -61,14 +66,13 @@
<div class="gap-2 p-2 border-t-0 border-r-0 border-b-0 border-l-0 border-gray-200">
<% if @message.not_yet_submitted? && @message.form&.signable? %>
<%= content_tag(:div,
{
"data-controller": "autogram",
"data-autogram-object-id": @message.form.id,
"data-autogram-message-id": @message.id,
"data-autogram-object-path": message_message_object_path(@message.id, @message.form.id),
"data-autogram-authenticity-token": form_authenticity_token
}
) do %>
{
"data-controller": "autogram",
"data-autogram-object-id": @message.form.id,
"data-autogram-message-id": @message.id,
"data-autogram-object-path": message_message_object_path(@message.id, @message.form.id),
"data-autogram-authenticity-token": form_authenticity_token
}) do %>
<button data-action="click->autogram#signSingleFile" class="flex justify-strech items-start self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-3.5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
Podpísať
</button>
Expand Down
16 changes: 16 additions & 0 deletions app/components/message_draft_enable_edit_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= render Common::ModalComponent.new do |modal| %>
<% modal.with_header do %>
Draft nie je možné upravovať
<% end %>
<% modal.with_modal_content do %>
<% if @message.reason_for_readonly == :form_signed %>
<%= t "message_draft.form_signed" %>
<% elsif @message.reason_for_readonly == :form_submitted %>
<%= t "message_draft.form_submitted" %>
<% else %>
<%= t "message_draft.read_only_agenda" %>
<% end %>
<%= render Common::ModalActionsComponent.new do |actions| %>
<% end %>
<% end %>
<% end %>
5 changes: 5 additions & 0 deletions app/components/message_draft_enable_edit_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class MessageDraftEnableEditComponent < ViewComponent::Base
def initialize(message)
@message = message
end
end
4 changes: 4 additions & 0 deletions app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def destroy
redirect_to redirect_path, notice: "Draft bol zahodený"
end

def enable_edit
authorize @message
end

private

def load_message_drafts
Expand Down
6 changes: 6 additions & 0 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def editable?
metadata["posp_id"] == GENERAL_AGENDA_POSP_ID && !form&.is_signed? && not_yet_submitted?
end

def reason_for_readonly
return :read_only_agenda unless metadata["posp_id"] == GENERAL_AGENDA_POSP_ID
return :form_submitted if submitted? || being_submitted?
return :form_signed if form.is_signed?
end

def custom_visualization?
metadata["posp_id"] == GENERAL_AGENDA_POSP_ID
end
Expand Down
4 changes: 4 additions & 0 deletions app/policies/message_draft_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ def submit_all?
def destroy?
create?
end

def enable_edit?
create?
end
end
3 changes: 3 additions & 0 deletions app/views/message_drafts/enable_edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= tag.turbo_frame id: "modal" do %>
<%= render MessageDraftEnableEditComponent.new(@message) %>
<% end %>
4 changes: 4 additions & 0 deletions config/locales/sk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,7 @@ sk:
tag_editing_in_message_threads:
one: "Úprava štítkov v jednom vlákne"
other: "Úprava štítkov v %{count} vláknach"
message_draft:
form_signed: "Draft už bol podpísaný. Podpísaný draft nie je možné ďalej upravovať. V prípade potreby pripravte novú správu a odošlite ju."
form_submitted: "Správa už bola odoslaná. Odoslanú správu nie je možné ďalej upravovať. V prípade potreby pripravte novú správu a odošlite ju."
read_only_agenda: "Správu nie je možné ďalej upravovať. V prípade potreby pripravte novú správu a odošlite ju."
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

resources :message_drafts do
member do
get 'enable_edit'
post 'submit'
end

Expand Down

0 comments on commit ddcc1ac

Please sign in to comment.