Add frontend logic for learning goals
This commit is contained in:
parent
2c06694b4c
commit
484d10385a
|
@ -1,4 +1,4 @@
|
|||
form#blog_post_form {
|
||||
form#blog_post_form, form#learning_goal_form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 55em;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
.learning_goal {
|
||||
margin: 1em auto;
|
||||
padding: .5em;
|
||||
background-color: var(--inset-background-color);
|
||||
border: 1px solid var(--border-color);
|
||||
|
||||
> .created_at {
|
||||
text-align: right;
|
||||
font-size: .8em;
|
||||
}
|
||||
}
|
||||
|
||||
ul#learning_goals {
|
||||
list-style-type: none;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class LearningGoalsController < ApplicationController
|
||||
skip_before_action :require_login, only: [:index, :show]
|
||||
before_action :set_learning_goal, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@learning_goals = LearningGoal.all
|
||||
.order(created_at: :desc)
|
||||
.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@learning_goal = LearningGoal.new
|
||||
end
|
||||
|
||||
def create
|
||||
@learning_goal = LearningGoal.new(learning_goal_params)
|
||||
@learning_goal.user = helpers.current_user
|
||||
|
||||
if @learning_goal.save
|
||||
redirect_to @learning_goal, notice: t(".created")
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def show ; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @learning_goal.update(learning_goal_params)
|
||||
redirect_to @learning_goal, notice: t(".updated")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @learning_goal.destroy
|
||||
redirect_to learning_goals_path, notice: t(".deleted")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def learning_goal_params
|
||||
params.require(:learning_goal).permit(
|
||||
:title,
|
||||
:starts_on,
|
||||
:ends_on,
|
||||
:description,
|
||||
:retrospective,
|
||||
:completed,
|
||||
:user,
|
||||
)
|
||||
end
|
||||
|
||||
def set_learning_goal
|
||||
@learning_goal = LearningGoal.find(params[:id])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
module LearningGoalsHelper
|
||||
def learning_goal_completed_text(learning_goal)
|
||||
learning_goal.completed ? t(".completed") : t(".not_completed")
|
||||
end
|
||||
end
|
|
@ -1,7 +1,8 @@
|
|||
class LearningGoal < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
has_rich_text :description, :retrospective
|
||||
has_rich_text :description
|
||||
has_rich_text :retrospective
|
||||
|
||||
validates :title, presence: true
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div id="@blog_post_<%= @blog_post.id %>" class="blog_post">
|
||||
<div id="blog_post_<%= @blog_post.id %>" class="blog_post">
|
||||
<h2><%= @blog_post.title %></h2>
|
||||
<p><%= @blog_post.content %></p>
|
||||
<div class="created_at">
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<%= form_with model: @learning_goal, id: "learning_goal_form" do |f| %>
|
||||
<h2><%= title %></h2>
|
||||
|
||||
<%= f.text_field :title, placeholder: t(".title") %>
|
||||
|
||||
<%= f.rich_text_area :description %>
|
||||
|
||||
<%= f.label :starts_on %>
|
||||
<%= f.date_field :starts_on %>
|
||||
|
||||
<%= f.label :ends_on %>
|
||||
<%= f.date_field :ends_on %>
|
||||
|
||||
<%= f.rich_text_area :retrospective %>
|
||||
|
||||
<%= f.label :completed %>
|
||||
<%= f.check_box :completed %>
|
||||
|
||||
<%= f.submit button_text %>
|
||||
<% end %>
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<% @title = t(".edit") %>
|
||||
|
||||
<%= render partial: "form",
|
||||
locals: {
|
||||
user: @user,
|
||||
button_text: t(".edit"),
|
||||
title: t(".edit"),
|
||||
} %>
|
||||
|
||||
<%= link_to t(".delete"), @learning_goal, data: { turbo_method: :delete, turbo_confirm: t(".confirm") } %>
|
|
@ -0,0 +1,14 @@
|
|||
<h2><%= t(".learning_goals") %></h2>
|
||||
|
||||
<%= link_to t(".new"), new_learning_goal_path if logged_in? %>
|
||||
|
||||
<% if @learning_goals.empty? %>
|
||||
<p><%= t(".empty") %></p>
|
||||
<% else %>
|
||||
<ul id="learning_goals">
|
||||
<% @learning_goals.each do |learning_goal| %>
|
||||
<li><%= link_to learning_goal.title, learning_goal %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= paginate @learning_goals %>
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
<% @title = t(".create") %>
|
||||
|
||||
<%= render partial: "form",
|
||||
locals: {
|
||||
user: @user,
|
||||
button_text: t(".create"),
|
||||
title: t(".create"),
|
||||
} %>
|
|
@ -0,0 +1,11 @@
|
|||
<div id="learning_goal_<%= @learning_goal.id %>" class="learning_goal">
|
||||
<h2><%= @learning_goal.title %></h2>
|
||||
<p><%= @learning_goal.starts_on %>-<%= @learning_goal.ends_on %></p>
|
||||
<h3><%= t(".description") %></h3>
|
||||
<p><%= @learning_goal.description %></p>
|
||||
<% if @learning_goal.completed? %>
|
||||
<h3><%= t(".retrospective") %></h3>
|
||||
<p><%= @learning_goal.retrospective %></p>
|
||||
<% end %>
|
||||
<%= link_to t(".edit"), edit_learning_goal_path(@learning_goal) if @learning_goal.user == current_user %>
|
||||
</div>
|
|
@ -0,0 +1,5 @@
|
|||
en:
|
||||
learning_goals:
|
||||
created: Successfully created learning goal
|
||||
updated: Successfully updated learning goal
|
||||
deleted: Successfully deleted learning goal
|
|
@ -0,0 +1,20 @@
|
|||
en:
|
||||
learning_goals:
|
||||
index:
|
||||
learning_goals: Learning Goals
|
||||
empty: You have no learning goals yet.
|
||||
new: New learning goal
|
||||
new:
|
||||
create: Create learning goal
|
||||
edit:
|
||||
edit: Edit learning goal
|
||||
delete: Delete learning goal
|
||||
confirm: Are you sure you want to delete this learning goal?
|
||||
form:
|
||||
title: Title
|
||||
show:
|
||||
completed: Learning goal is complete
|
||||
not_completed: Learning goal is incomplete
|
||||
edit: Edit
|
||||
description: Description
|
||||
retrospective: Retrospective
|
|
@ -13,6 +13,7 @@ Rails.application.routes.draw do
|
|||
get "confirm_email", to: "email_confirmations#confirm"
|
||||
|
||||
resources :blog_posts
|
||||
resources :learning_goals
|
||||
resources :microposts
|
||||
resources :tags, only: [:index, :show]
|
||||
resources :diary_entries, except: [:destroy]
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class LearningGoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue