-
Notifications
You must be signed in to change notification settings - Fork 6
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
Thread notes #104
Thread notes #104
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
"class": "mb-3 pt-0 w-full" | ||
} | ||
) do %> | ||
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", "data-action": "change->messageDrafts#update", disabled: [email protected]?, class:"mb-3 px-3 py-4 placeholder-slate-300 text-slate-í00 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"], placeholder: "Text", "data-action": "change->messageDrafts#update", rows: 10, disabled: [email protected]?, class:"px-3 py-4 placeholder-slate-300 text-slate-í00 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %> | ||
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", "data-action": "change->messageDrafts#update", disabled: [email protected]?, 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"], placeholder: "Text", "data-action": "change->messageDrafts#update", rows: 10, disabled: [email protected]?, 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 %> | ||
<% else %> | ||
<div class="w-full"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
class MessageThreadComponent < ViewComponent::Base | ||
def initialize(message_thread:, thread_tags_with_deletable_flag:, thread_messages:, notice:) | ||
def initialize(message_thread:, thread_tags_with_deletable_flag:, thread_messages:, message_thread_note:, notice:) | ||
@message_thread = message_thread | ||
@thread_tags_with_deletable_flag = thread_tags_with_deletable_flag | ||
@thread_messages = thread_messages | ||
@message_thread_note = message_thread_note | ||
@notice = notice | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<div data-controller="dropdown"> | ||
<div id="dropdown-button" class="flex flex-col justify-start items-between flex-grow-0 flex-shrink-0 relative overflow-hidden p-2 rounded-md bg-white border border-gray-200"> | ||
<div role="button" tabindex="0" data-dropdown-target="button" data-action="click->dropdown#toggle" class="flex justify-between"> | ||
<button type="button" class="m-1.5 flex justify-between grow items-center gap-2 p-1.5" id="thread-note-menu-button" aria-expanded="false" aria-haspopup="true"> | ||
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" class="flex-grow-0 flex-shrink-0 w-8 h-8 relative" preserveAspectRatio="xMidYMid meet"> | ||
<path d="M14.6654 6.66666H7.9987C7.29145 6.66666 6.61318 6.94761 6.11308 7.44771C5.61298 7.9478 5.33203 8.62608 5.33203 9.33333V24C5.33203 24.7072 5.61298 25.3855 6.11308 25.8856C6.61318 26.3857 7.29145 26.6667 7.9987 26.6667H22.6654C23.3726 26.6667 24.0509 26.3857 24.551 25.8856C25.0511 25.3855 25.332 24.7072 25.332 24V17.3333M23.4467 4.78133C23.6927 4.52663 23.9869 4.32348 24.3123 4.18372C24.6376 4.04396 24.9875 3.9704 25.3416 3.96732C25.6957 3.96425 26.0469 4.03172 26.3746 4.1658C26.7023 4.29988 27 4.49789 27.2504 4.74827C27.5008 4.99865 27.6988 5.29639 27.8329 5.62412C27.967 5.95184 28.0344 6.30298 28.0314 6.65706C28.0283 7.01114 27.9547 7.36106 27.815 7.6864C27.6752 8.01175 27.4721 8.306 27.2174 8.55199L15.7694 20H11.9987V16.2293L23.4467 4.78133Z" stroke="#111827" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> | ||
</svg> | ||
<div class="flex justify-start items-start flex-grow-0 flex-shrink-0 relative gap-2"> | ||
<p class="flex-grow-0 flex-shrink-0 text-base font-bold text-left text-gray-900">Poznámky</p> | ||
</div> | ||
<div class="flex justify-start items-start grow relative gap-2"> | ||
<p class="self-stretch flex-grow align-middle text-base text-right text-gray-900"><%= @formatted_last_updated_at %></p> | ||
</div> | ||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="flex-grow-0 flex-shrink-0 w-6 h-6 relative" preserveAspectRatio="xMidYMid meet"> | ||
<path d="M19 9L12 16L5 9" stroke="#9CA3AF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> | ||
</svg> | ||
</button> | ||
</div> | ||
<div data-dropdown-target="menu" | ||
data-transition-enter="transition ease-out duration-200" | ||
data-transition-enter-from="opacity-0 translate-y-1" | ||
data-transition-enter-to="opacity-100 translate-y-0" | ||
data-transition-leave="transition ease-in duration-150" | ||
data-transition-leave-from="opacity-100 translate-y-0" | ||
data-transition-leave-to="opacity-0 translate-y-1" | ||
class="hidden"> | ||
<%= form_with model:[@message_thread, @message_thread_note], class: "flex flex-col justify-start items-start flex-grow-0 flex-shrink-0 overflow-hidden gap-2 py-1 px-2 rounded-md bg-white" do |form| %> | ||
<%= form.text_area :note, placeholder: 'Zadajte svoje poznámky k vláknu', rows:3, 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" %> | ||
<div class="flex flex-col justify-start items-end self-stretch flex-grow-0 flex-shrink-0 gap-2 px-3"> | ||
<%= form.button class: "flex justify-center items-center h-11 relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-blue-600" do %> | ||
<div class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-white">Uložiť</div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class MessageThreadNoteComponent < ViewComponent::Base | ||
def initialize(message_thread_note) | ||
@message_thread_note = message_thread_note | ||
@message_thread = @message_thread_note.message_thread | ||
end | ||
|
||
def before_render | ||
return unless @message_thread_note.last_updated_at | ||
|
||
@formatted_last_updated_at = l @message_thread_note.last_updated_at, format: :long | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Toto je best practice? nemali by taketo formatovacie veci byt vo view? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neviem, ci je, resp. asi nie je. Zdalo sa mi to ako prilis komplikovany vyraz na to, aby som ho nechal vo viewe, najprv bol totiz tam. Este mozme pouzit jednu z tych verzii helpera, ktoru diskutujeme v inom vlakne. Si asi vyber. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No praveze taketo sa bezne do view dava |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class MessageThreadNotesController < ApplicationController | ||
before_action :set_message_thread, only: %i[update create] | ||
before_action :set_message_thread_note, only: %i[update] | ||
|
||
def update | ||
authorize @message_thread_note | ||
@message_thread_note.last_updated_at = Time.current | ||
if @message_thread_note.update(message_thread_note_params) | ||
redirect_back_or_to message_threads_path(@message_thread), notice: 'Note was successfully updated' | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def create | ||
@message_thread_note = @message_thread.build_message_thread_note(message_thread_note_params) | ||
@message_thread_note.last_updated_at = Time.current | ||
authorize @message_thread_note | ||
|
||
if @message_thread_note.save | ||
redirect_back_or_to message_threads_path(@message_thread), notice: 'Note was successfully created' | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_message_thread | ||
@message_thread = policy_scope(MessageThread).find(params[:message_thread_id]) | ||
end | ||
|
||
def set_message_thread_note | ||
@message_thread_note = policy_scope(MessageThreadNote).find(params[:id]) | ||
end | ||
|
||
def message_thread_note_params | ||
params.require(:message_thread_note).permit(:note, :last_updated_at) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ def find_or_create_by_uuid!(uuid:) | |
has_many :message_threads_tags, dependent: :destroy | ||
has_many :tag_users, through: :message_threads_tags | ||
has_many :merge_identifiers, class_name: 'MessageThreadMergeIdentifier', dependent: :destroy | ||
has_one :message_thread_note, dependent: :destroy | ||
|
||
attr_accessor :search_highlight | ||
|
||
|
@@ -50,20 +51,20 @@ def self.merge_threads | |
target_thread = self.first | ||
self.all.each do |thread| | ||
if thread != target_thread | ||
thread.merge_identifiers.update_all(message_thread_id: target_thread.id) | ||
target_thread.last_message_delivered_at = [target_thread.last_message_delivered_at, thread.last_message_delivered_at].max | ||
target_thread.delivered_at = [target_thread.delivered_at, thread.delivered_at].min | ||
thread.messages.each do |message| | ||
message.thread = target_thread | ||
message.save! | ||
end | ||
thread.tags.each do |tag| | ||
target_thread.tags.push(tag) unless target_thread.tags.include?(tag) | ||
end | ||
|
||
thread.reload | ||
thread.destroy! | ||
thread.merge_identifiers.update_all(message_thread_id: target_thread.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. zase kuzli linter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, este par krat mi to spravi, a vypnem ho. Zatial mam ale stale rad tie jeho obcasne navrhy na zlepsenia, co prinasa |
||
target_thread.last_message_delivered_at = [target_thread.last_message_delivered_at, thread.last_message_delivered_at].max | ||
target_thread.delivered_at = [target_thread.delivered_at, thread.delivered_at].min | ||
thread.messages.each do |message| | ||
message.thread = target_thread | ||
message.save! | ||
end | ||
thread.tags.each do |tag| | ||
target_thread.tags.push(tag) unless target_thread.tags.include?(tag) | ||
end | ||
|
||
thread.reload | ||
thread.destroy! | ||
end | ||
end | ||
target_thread.save! | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# == Schema Information | ||
# | ||
# Table name: message_threads | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
# | ||
# id :integer not null, primary key | ||
# title :string not null | ||
# original_title :string not null | ||
# delivered_at :datetime not null | ||
# last_message_delivered_at :datetime not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
|
||
class MessageThreadNote < ApplicationRecord | ||
belongs_to :message_thread | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class MessageThreadNotePolicy < ApplicationPolicy | ||
attr_reader :user, :message_thread_note | ||
|
||
def initialize(user, message_thread_note) | ||
@user = user | ||
@message_thread_note = message_thread_note | ||
end | ||
|
||
class Scope < Scope | ||
def resolve | ||
scope.joins(:message_thread).where(message_thread: Pundit.policy_scope(@user, MessageThread)) | ||
end | ||
end | ||
|
||
def update? | ||
true | ||
end | ||
|
||
def create? | ||
true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= render MessageThreadComponent.new(message_thread: @message_thread, thread_tags_with_deletable_flag: @thread_tags_with_deletable_flag, thread_messages: @thread_messages, notice: @notice) %> | ||
<%= render MessageThreadComponent.new(message_thread: @message_thread, thread_tags_with_deletable_flag: @thread_tags_with_deletable_flag, thread_messages: @thread_messages, message_thread_note: @message_thread_note, notice: @notice) %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateMessageThreadNotes < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :message_thread_notes do |t| | ||
t.references :message_thread, null: false, foreign_key: true | ||
t.text :note | ||
t.datetime :last_updated_at, null: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pokial nemame usecase na specialny last_updated_at tak pouzivajme ten defaultny. |
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toto vies vytiahnut z
@message_thread
cize netreba explicitne posielat. sice to odpali select ale N+1 query problem nehrozi takze nevidim problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, cize ked nejde cez to iterovat, alebo nepouzivame ako kolekciu, tak si to neposielame. To je asi dobre pravidlo.