-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4478-notes' into develop
- Loading branch information
Showing
26 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class Admin::NotesController < AdminController | ||
include Admin::TagHelper | ||
include TranslatableParams | ||
|
||
def new | ||
@note = scope.build | ||
@note.build_all_translations | ||
end | ||
|
||
def create | ||
@note = scope.build(note_params) | ||
if @note.save | ||
notice = 'Note successfully created.' | ||
redirect_to admin_note_parent_path(@note), notice: notice | ||
else | ||
@note.build_all_translations | ||
render :new | ||
end | ||
end | ||
|
||
def edit | ||
@note = scope.find(params[:id]) | ||
@note.build_all_translations | ||
end | ||
|
||
def update | ||
@note = scope.find(params[:id]) | ||
if @note.update(note_params) | ||
notice = 'Note successfully updated.' | ||
redirect_to admin_note_parent_path(@note), notice: notice | ||
else | ||
@note.build_all_translations | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@note = Note.find(params[:id]) | ||
@note.destroy | ||
notice = 'Note successfully destroyed.' | ||
redirect_to admin_note_parent_path(@note), notice: notice | ||
end | ||
|
||
private | ||
|
||
def scope | ||
Note.where(params.slice(:notable_tag, :notable_id, :notable_type).permit!) | ||
end | ||
|
||
def note_params | ||
translatable_params( | ||
params.require(:note), | ||
translated_keys: [:locale, :body], | ||
general_keys: [:notable_tag, :notable_id, :notable_type] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Notable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_many :concrete_notes, | ||
class_name: 'Note', | ||
as: :notable, | ||
inverse_of: :notable, | ||
dependent: :destroy | ||
end | ||
|
||
def all_notes | ||
concrete_notes.with_translations + tagged_notes.with_translations | ||
end | ||
|
||
def tagged_notes | ||
Note.where(notable_tag: notable_tags) | ||
end | ||
|
||
private | ||
|
||
def notable_tags | ||
tags.map(&:name_and_value) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# == Schema Information | ||
# Schema version: 20220720085105 | ||
# | ||
# Table name: notes | ||
# | ||
# id :bigint not null, primary key | ||
# notable_type :string | ||
# notable_id :bigint | ||
# notable_tag :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# body :text | ||
# | ||
|
||
class Note < ApplicationRecord | ||
include AdminColumn | ||
|
||
translates :body | ||
include Translatable | ||
|
||
belongs_to :notable, polymorphic: true | ||
|
||
validates :body, presence: true | ||
validates :notable_or_notable_tag, presence: true | ||
|
||
private | ||
|
||
def notable_or_notable_tag | ||
notable || notable_tag | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<%= foi_error_messages_for :note %> | ||
|
||
<div class="well"> | ||
<% if @note.notable %> | ||
Applies to <%= both_links(@note.notable) %> | ||
<%= f.hidden_field :notable_id %> | ||
<%= f.hidden_field :notable_type %> | ||
<% else %> | ||
Applies to objects tagged with <%= render_tag @note.notable_tag %> | ||
<%= f.hidden_field :notable_tag %> | ||
<% end %> | ||
</div> | ||
|
||
<div id="div-locales"> | ||
<ul class="locales nav nav-tabs"> | ||
<% @note.ordered_translations.each do |translation| %> | ||
<li> | ||
<a href="#div-locale-<%= translation.locale.to_s %>" data-toggle="tab" > | ||
<%= locale_name(translation.locale.to_s) || translation.locale.to_s %> | ||
</a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
<div class="tab-content"> | ||
<% @note.ordered_translations.each do |translation| %> | ||
<% if AlaveteliLocalization.default_locale?(translation.locale) %> | ||
<%= fields_for('note', @note) do |t| %> | ||
<%= render partial: 'locale_fields', locals: { t: t, locale: translation.locale } %> | ||
<% end %> | ||
<% else %> | ||
<%= f.fields_for(:translations, translation, child_index: translation.locale) do |t| %> | ||
<%= render partial: 'locale_fields', locals: { t: t, locale: translation.locale } %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="tab-pane" id="div-locale-<%= locale %>"> | ||
<div class="control-group"> | ||
<%= t.hidden_field :locale, :value => locale %> | ||
|
||
<%= t.label :body, class: 'control-label' %> | ||
<div class="controls"> | ||
<% if AlaveteliLocalization.default_locale?(locale) && t.object.errors[:body].any? %> | ||
<span class="fieldWithErrors"> | ||
<% end %> | ||
<%= t.text_area :body, class: 'span6', rows: 10 %> | ||
<% if AlaveteliLocalization.default_locale?(locale) && t.object.errors[:body].any? %> | ||
</span> | ||
<%end %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="accordion-group"> | ||
<div class="accordion-heading accordion-toggle row"> | ||
<span class="item-title span6"> | ||
<%= link_to chevron_right, "##{dom_id(note)}", data: { toggle: 'collapse', parent: 'notes' } %> | ||
<%= link_to(note.body, edit_admin_note_path(note), title: 'view full details') %> | ||
</span> | ||
|
||
<span class="item-metadata span6"> | ||
<%= render_tag note.notable_tag if note.notable_tag %> | ||
</span> | ||
</div> | ||
<%= tag.div id: dom_id(note), class: 'item-detail accordion-body collapse row' do %> | ||
<% note.for_admin_column do |name, value, type| %> | ||
<div> | ||
<span class="span6"> | ||
<b><%= name %></b> | ||
</span> | ||
<span class="span6"> | ||
<%= admin_value(value) %> | ||
</span> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="row"> | ||
<% if notes.size > 0 %> | ||
<table class="table table-condensed table-hover span12 censor-rule-list"> | ||
<tr> | ||
<th>ID</th> | ||
<th>Notable ID</th> | ||
<th>Notable type</th> | ||
<th>Notable tag</th> | ||
<th>Actions</th> | ||
</tr> | ||
|
||
<% notes.each do |note| %> | ||
<tr class="<%= cycle('odd', 'even') %>"> | ||
<td class="id"><%= h note.id %></td> | ||
<td class="notable_id"><%= h note.notable_id %></td> | ||
<td class="notable_type"><%= h note.notable_type %></td> | ||
<td class="notable_tag"><%= h note.notable_tag %></td> | ||
<td><%= link_to "Edit", edit_admin_note_path(note) %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<% else %> | ||
<p class="span12">None yet.</p> | ||
<% end %> | ||
</div> | ||
|
||
<div class="row"> | ||
<p class="span12"> | ||
<%= link_to "New note", new_admin_note_path(notable_type: notable.class, notable_id: notable), class: "btn btn-info" %> | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="row"> | ||
<div class="span12"> | ||
<div class="page-header"> | ||
<h1><%= @title = 'Edit note' %></h1> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<%= form_for [:admin, @note], class: 'form form-horizontal' do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<div class="form-actions"> | ||
<%= submit_tag 'Save', class: 'btn btn-success' %> | ||
</div> | ||
<% end %> | ||
|
||
<%= form_tag [:admin, @note], class: 'form form-inline', method: 'delete' do %> | ||
<%= submit_tag 'Destroy note', | ||
class: 'btn btn-danger', | ||
data: { confirm: 'Are you sure? This is irreversible.' } %> | ||
(this is permanent!) | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="row"> | ||
<div class="span12"> | ||
<div class="page-header"> | ||
<h1><%= @title = 'New note' %></h1> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<%= form_for [:admin, @note], class: 'form form-horizontal' do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<div class="form-actions"> | ||
<%= submit_tag 'Create', class: 'btn btn-success' %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h2>Notes</h2> | ||
|
||
<div class="btn-toolbar"> | ||
<div class="btn-group"> | ||
<%= link_to 'New note', new_admin_note_path(notable_tag: @tag), class: 'btn' %> | ||
</div> | ||
</div> | ||
|
||
<% if @notes.empty? %> | ||
<p>No notes.</p> | ||
<% else %> | ||
<%= render partial: 'tagging', collection: @notes %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.