-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff6239c
commit cea44c5
Showing
35 changed files
with
5,684 additions
and
37 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
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 @@ | ||
//= require htmx |
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,70 @@ | ||
class TagsController < ApplicationController | ||
before_action :set_tag, only: %i[ show edit update destroy ] | ||
|
||
# GET /tags or /tags.json | ||
def index | ||
@tags = Tag.all | ||
end | ||
|
||
# GET /tags/1 or /tags/1.json | ||
def show | ||
end | ||
|
||
# GET /tags/new | ||
def new | ||
@tag = Tag.new | ||
end | ||
|
||
# GET /tags/1/edit | ||
def edit | ||
end | ||
|
||
# POST /tags or /tags.json | ||
def create | ||
@tag = Tag.new(tag_params) | ||
|
||
respond_to do |format| | ||
if @tag.save | ||
format.html { redirect_to @tag, notice: "Tag was successfully created." } | ||
format.json { render :show, status: :created, location: @tag } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @tag.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /tags/1 or /tags/1.json | ||
def update | ||
respond_to do |format| | ||
if @tag.update(tag_params) | ||
format.html { redirect_to @tag, notice: "Tag was successfully updated." } | ||
format.json { render :show, status: :ok, location: @tag } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @tag.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /tags/1 or /tags/1.json | ||
def destroy | ||
@tag.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to tags_path, status: :see_other, notice: "Tag was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_tag | ||
@tag = Tag.find(params.expect(:id)) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def tag_params | ||
params.expect(tag: [ :name ]) | ||
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,2 @@ | ||
module TagsHelper | ||
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class Memo < ApplicationRecord | ||
belongs_to :user | ||
has_and_belongs_to_many :tags | ||
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,4 @@ | ||
class MemosTag < ApplicationRecord | ||
belongs_to :memo | ||
belongs_to :tag | ||
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,3 @@ | ||
class Tag < ApplicationRecord | ||
has_and_belongs_to_many :memos | ||
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 |
---|---|---|
@@ -1,29 +1,45 @@ | ||
<%= form_for :memo, :url => url_for(:controller => "memos", :action => "create"), html: { class: "memo_form" } do |form| %> | ||
<div class="card" > | ||
<div class="card-content"> | ||
<div class="content"> | ||
<div class="field"> | ||
<%= form.text_area :body, placeholder: "Memo", class: "textarea" %> | ||
</div> | ||
</div> | ||
<div class="card-content"> | ||
<div class="content"> | ||
<div class="field"> | ||
<%= form.text_area :body, placeholder: "Memo", class: "textarea" %> | ||
</div> | ||
<footer class="card-footer"> | ||
<div class="card-footer-item"> | ||
<div class="file" style="margin-bottom: 0"> | ||
<label class="file-label"> | ||
</div> | ||
</div> | ||
<footer class="card-footer"> | ||
<div class="card-footer-item"> | ||
<div class="file" style="margin-bottom: 0"> | ||
<label class="file-label"> | ||
<%= form.file_field :attachment, accept: "image/png,image/jpg,image/jpeg", class: "file-input" %> | ||
<span class="file-cta"> | ||
<span class="file-icon"> | ||
<i class="fas fa-upload"></i> | ||
</span> | ||
<span class="file-label"> Choose a file… </span> | ||
</span> | ||
</label> | ||
</div> | ||
<%= button_tag type: 'submit', class: "button right is-save" do %> | ||
<i class="fa-regular fa-floppy-disk" aria-hidden="true"></i> | ||
<% end %> | ||
</div> | ||
</footer> | ||
<span class="file-cta" style="background-color: var(--ctp-frappe-green)"> | ||
<i class="fas fa-upload" style="color: black"></i> | ||
</span> | ||
</label> | ||
</div> | ||
<%= button_tag type: 'button', class: "button", style: "background-color: var(--ctp-frappe-mauve); color: black;", onclick: "addTag();" do %> | ||
<i class="fa-regular fa-hashtag" aria-hidden="true"></i> | ||
<% end %> | ||
<%= button_tag type: 'submit', class: "button right is-save" do %> | ||
<i class="fa-regular fa-floppy-disk" aria-hidden="true"></i> | ||
<% end %> | ||
</div> | ||
</footer> | ||
</div> | ||
<div id="addTagModal" class="modal"> | ||
<div class="modal-background"></div> | ||
<div class="modal-content"> | ||
<div class="box"> | ||
<article class="media"> | ||
<%= form.text_field :tagName, placeholder: "Tags", class: "input" %> | ||
</article> | ||
</div> | ||
</div> | ||
<button class="modal-close is-large" aria-label="close"></button> | ||
</div> | ||
<script> | ||
function addTag(elem) { | ||
$("#addTagModal").addClass("is-active"); | ||
} | ||
</script> | ||
<% 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,63 @@ | ||
<% if user_signed_in? %> | ||
<%= csrf_meta_tag %> | ||
<script> | ||
function openModal() { | ||
document.getElementById("modal1") | ||
.classList.add("is-active"); | ||
} | ||
</script> | ||
<div class="memoIndex"> | ||
<%= render "layouts/new" %> | ||
<% @memos.each do |memo| %> | ||
<%= render partial: "layouts/memo", object: memo %> | ||
<% end %> | ||
</div> | ||
<script> | ||
document.body.addEventListener('htmx:configRequest', function(evt) { | ||
event.detail.headers['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content'); | ||
}) | ||
|
||
document.body.addEventListener('htmx:afterSettle', function(evt) { | ||
setupClicks(); | ||
}) | ||
|
||
document.querySelectorAll('.modal-background, .modal-close,.modal-card-head .delete, .modal-card-foot .button').forEach(($el) => {const $modal = $el.closest('.modal');$el.addEventListener('click', () => {$modal.classList.remove("is-active");});}); | ||
|
||
function setupClicks() { | ||
$(".editMemo").on("click", function() { | ||
$(this).parent().find(".saveMemo").show(); | ||
$(this).parent().find(".cancelEdit").show(); | ||
var card = $(this).parents(".card"); | ||
card.children(".viewMemo").hide(); | ||
card.children(".updateMemo").show(); | ||
$(this).hide(); | ||
}); | ||
$(".cancelEdit").on("click", function() { | ||
$(this).parent().find(".saveMemo").hide(); | ||
$(this).parents().find(".editMemo").show(); | ||
var card = $(this).parents(".card"); | ||
card.children(".viewMemo").show(); | ||
card.children(".updateMemo").hide(); | ||
$(this).hide(); | ||
}); | ||
$(".saveMemo").on("clickt", function() { | ||
var card = $(this).parents(".card"); | ||
var url = card.children(".updateMemo").data('url'); | ||
var body = card.find("#editMemoTA").val(); | ||
$.ajax({ | ||
url: url, | ||
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))}, | ||
data: "memo%5Bbody%5D="+encodeURIComponent(body), | ||
dataType: "html", | ||
type: 'PUT', | ||
success: function(result) { | ||
var memoDiv = card.parents("#memo"); | ||
memoDiv.replaceWith(result); | ||
setupClicks(); | ||
} | ||
}); | ||
}); | ||
} | ||
setupClicks(); | ||
</script> | ||
<% 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,22 @@ | ||
<%= form_with(model: tag) do |form| %> | ||
<% if tag.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(tag.errors.count, "error") %> prohibited this tag from being saved:</h2> | ||
|
||
<ul> | ||
<% tag.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div> | ||
<%= form.label :name, style: "display: block" %> | ||
<%= form.text_field :name %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
Oops, something went wrong.