Remove learning goals and their associated todos
/ test (push) Has been cancelled Details

This commit is contained in:
Trevor Vallender 2024-03-05 16:07:05 +00:00
parent 5281d2e972
commit 7b9f27815b
36 changed files with 8 additions and 498 deletions

View File

@ -1,4 +1,4 @@
form#blog_post_form, form#learning_goal_form {
form#blog_post_form {
display: flex;
flex-direction: column;
max-width: 55em;

View File

@ -1,26 +0,0 @@
.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;
}
ul.todos {
list-style-type: none;
}
ul.tags {
list-style-type: none;
> li {
display: inline;
}
}

View File

@ -1,44 +0,0 @@
form#blog_post_form, form#learning_goal_form, form#todo_form {
display: flex;
flex-direction: column;
max-width: 55em;
> h2 {
width: 100%;
}
> trix-toolbar {
max-width: 95%;
}
> trix-editor {
width: 95%;
> ul {
list-style-type: disc;
}
}
input[type=text] {
width: 95%;
}
> input[type=submit] {
width: 95%;
}
}
.blog_post {
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#blog_posts {
list-style-type: none;
}

View File

@ -1,62 +0,0 @@
# 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 ; 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,
tag_ids: [],
)
end
def set_learning_goal
@learning_goal = LearningGoal.find(params[:id])
end
end

View File

@ -1,51 +0,0 @@
class TodosController < ApplicationController
before_action :set_todo, only: [:edit, :update, :destroy]
def new
@todo = Todo.new
end
def create
@todo = Todo.new(todo_params)
if @todo.save
redirect_to @todo.learning_goal, notice: t(".created")
else
render :new, status: :unprocessable_entity
end
end
def edit ; end
def update
if @todo.update(todo_params)
redirect_to @todo.learning_goal, notice: t(".updated")
else
render :edit, status: :unprocessable_entity
end
end
def destroy
learning_goal = @todo.learning_goal
if @todo.destroy
redirect_to learning_goal, notice: t(".deleted")
else
render :edit, status: :unprocessable_entity
end
end
private
def set_todo
@todo = Todo.find(params[:id])
end
def todo_params
params.require(:todo).permit(
:learning_goal_id,
:description,
:done,
:title,
:due,
)
end
end

View File

@ -1,5 +0,0 @@
module LearningGoalsHelper
def learning_goal_completed_text(learning_goal)
learning_goal.completed ? t(".completed") : t(".not_completed")
end
end

View File

@ -1,2 +0,0 @@
module TodosHelper
end

View File

@ -1,21 +0,0 @@
class LearningGoal < ApplicationRecord
belongs_to :user
has_many :todos
has_and_belongs_to_many :tags
accepts_nested_attributes_for :tags
has_rich_text :description
has_rich_text :retrospective
validates :completed, inclusion: { in: [true, false] }
validates :title, presence: true
scope :current, -> { where(starts_on: ..Date.today, ends_on: Date.today..) }
scope :past, -> { where(ends_on: ..Date.today) }
scope :future, -> { where(starts_on: Date.today..) }
def microposts
microposts = Micropost.none
tags.each { |tag| microposts = microposts.or(tag.microposts) }
microposts.uniq
end
end

View File

@ -4,7 +4,6 @@ class Tag < ApplicationRecord
validates :name, presence: true
has_many :microposts_tags
has_many :microposts, through: :microposts_tags
has_and_belongs_to_many :learning_goals
def to_param
name

View File

@ -1,6 +0,0 @@
class Todo < ApplicationRecord
belongs_to :learning_goal
validates :done, inclusion: { in: [true, false] }
has_rich_text :description
has_one :user, through: :learning_goal
end

View File

@ -22,7 +22,6 @@
<li><%= link_to t(".microposts"), microposts_path %></li>
<% if logged_in? %>
<li><%= link_to t(".diary_entries"), diary_entries_path %></li>
<li><%= link_to t(".learning_goals"), learning_goals_path %></li>
<li><%= link_to t(".profile"), user_path(current_user) %></li>
<li><%= link_to t(".log_out"), log_out_path, data: { turbo_method: :delete } %></li>
<% end %>

View File

@ -1,25 +0,0 @@
<%= 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.label :microposts_tag %>
<%= f.collection_check_boxes :tag_ids, Tag.all, :id, :name %>
<%= f.submit button_text %>
<% end %>

View File

@ -1,4 +0,0 @@
<div id="learning_goal_<%= learning_goal.id %>" class="learning_goal">
<h2><%= link_to learning_goal.title, learning_goal %></h2>
<%= learning_goal.description %>
</div>

View File

@ -1,10 +0,0 @@
<% @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") } %>

View File

@ -1,25 +0,0 @@
<h2><%= t(".learning_goals") %></h2>
<%= link_to t(".new"), new_learning_goal_path if logged_in? %>
<%= link_to t(".new_todo"), new_todo_path if logged_in? %>
<h3><%= t(".current") %></h3>
<% if LearningGoal.current.any? %>
<%= render LearningGoal.current %>
<% else %>
<p><%= t(".no_current_goals") %></p>
<% end %>
<h3><%= t(".future") %></h3>
<% if LearningGoal.future.any? %>
<%= render LearningGoal.future %>
<% else %>
<p><%= t(".no_future_goals") %></p>
<% end %>
<h3><%= t(".past") %></h3>
<% if LearningGoal.past.any? %>
<%= render LearningGoal.past %>
<% else %>
<p><%= t(".no_past_goals") %></p>
<% end %>

View File

@ -1,8 +0,0 @@
<% @title = t(".create") %>
<%= render partial: "form",
locals: {
user: @user,
button_text: t(".create"),
title: t(".create"),
} %>

View File

@ -1,28 +0,0 @@
<div id="learning_goal_<%= @learning_goal.id %>" class="learning_goal">
<%= link_to t(".edit"), edit_learning_goal_path(@learning_goal) if @learning_goal.user == current_user %>
<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 %>
<h3><%= t(".todos") %></h3>
<ul class="todos">
<% @learning_goal.todos.each do |todo| %>
<li><%= render todo %></li>
<% end %>
</ul>
<h3><%= t(".tags") %></h3>
<ul class="tags">
<% @learning_goal.tags.each do |tag| %>
<li><%= link_to tag.name, tag %></li>
<% end %>
</ul>
<h3><%= t(".related_microposts") %></h3>
<p><%= render @learning_goal.microposts %></p>
</div>

View File

@ -1,18 +0,0 @@
<%= form_with model: @todo, id: "todo_form" do |f| %>
<h2><%= title %></h2>
<%= f.text_field :title, placeholder: t(".title") %>
<%= f.label :learning_goal %>
<%= f.collection_select :learning_goal_id, LearningGoal.all, :id, :title %>
<%= f.rich_text_area :description %>
<%= f.label :due %>
<%= f.date_field :due %>
<%= f.label :done %>
<%= f.check_box :done %>
<%= f.submit button_text %>
<% end %>

View File

@ -1,10 +0,0 @@
<input type="checkbox" class="todo" disabled
<% if todo.done? %>
checked
<% end %>>
<%= todo.title %>
<% if todo.user == current_user %>
<%= link_to t(".edit"), edit_todo_path(todo) %>
<%= link_to t(".delete"), todo, data: { turbo_method: :delete, turbo_confirm: t(".confirm") } %>
<% end %>
<%= todo.description %>

View File

@ -1,10 +0,0 @@
<% @title = t(".edit") %>
<%= render partial: "form",
locals: {
user: @user,
button_text: t(".edit"),
title: t(".edit"),
} %>
<%= link_to t(".delete"), @todo, data: { turbo_method: :delete, turbo_confirm: t(".confirm") } %>

View File

@ -1,8 +0,0 @@
<% @title = t(".create") %>
<%= render partial: "form",
locals: {
user: @user,
button_text: t(".create"),
title: t(".create"),
} %>

View File

@ -1,5 +0,0 @@
en:
learning_goals:
created: Successfully created learning goal
updated: Successfully updated learning goal
deleted: Successfully deleted learning goal

View File

@ -1,5 +0,0 @@
en:
todos:
created: Successfully created todo
updated: Successfully updated todo
deleted: Successfully deleted todo

View File

@ -10,4 +10,3 @@ en:
blog_posts: Blog
microposts: μposts
diary_entries: Diary
learning_goals: Learning Goals

View File

@ -1,29 +0,0 @@
en:
learning_goals:
index:
learning_goals: Learning Goals
new: New learning goal
new_todo: New todo
current: Current
future: Future
past: Past
no_current_goals: You have no current goals
no_future_goals: You have no future goals
no_past_goals: You have no past goals
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
tags: Tags
todos: Todos
related_microposts: Related μposts

View File

@ -1,14 +0,0 @@
en:
todos:
new:
create: Create todo
edit:
edit: Edit todo
delete: Delete todo
confirm: Are you sure you want to delete this todo?
form:
title: Title
todo:
edit: Edit
delete: Delete
confirm: Are you sure you want to delete this todo?

View File

@ -13,10 +13,8 @@ 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 :todos, only: [:new, :create, :edit, :update, :destroy]
resources :diary_entries, except: [:destroy]
get "up" => "rails/health#show", as: :rails_health_check

View File

@ -0,0 +1,6 @@
class RemoveLearningGoals < ActiveRecord::Migration[7.1]
def change
drop_table :todos
drop_table :learning_goals
end
end

25
db/schema.rb generated
View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_01_26_101316) do
ActiveRecord::Schema[7.1].define(version: 2024_03_05_160037) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -105,17 +105,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_26_101316) do
t.index ["name"], name: "index_feature_flags_on_name", unique: true
end
create_table "learning_goals", force: :cascade do |t|
t.string "title", null: false
t.date "starts_on"
t.date "ends_on"
t.boolean "completed", default: false, null: false
t.bigint "user_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_learning_goals_on_user_id"
end
create_table "learning_goals_tags", id: false, force: :cascade do |t|
t.bigint "learning_goal_id", null: false
t.bigint "tag_id", null: false
@ -148,16 +137,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_26_101316) do
t.datetime "updated_at", null: false
end
create_table "todos", force: :cascade do |t|
t.bigint "learning_goal_id", null: false
t.boolean "done", default: false, null: false
t.string "title", default: "", null: false
t.date "due"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["learning_goal_id"], name: "index_todos_on_learning_goal_id"
end
create_table "users", force: :cascade do |t|
t.string "username", null: false
t.string "password_digest", null: false
@ -177,7 +156,5 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_26_101316) do
add_foreign_key "diary_entries", "users"
add_foreign_key "exercises", "diary_entries"
add_foreign_key "exercises", "exercise_types"
add_foreign_key "learning_goals", "users"
add_foreign_key "microposts", "users"
add_foreign_key "todos", "learning_goals"
end

View File

@ -1,7 +0,0 @@
require "test_helper"
class LearningGoalsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require "test_helper"
class TodosControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -10,7 +10,3 @@ draft_blog_post:
record: draft (BlogPost)
name: content
body: <p>Just some text</p>
learning_goal_one:
record: linux (LearningGoal)
name: content
body: <p>Learning about Linux</p>

View File

@ -1,13 +0,0 @@
sql:
title: SQL
starts_on: 2024-01-06
ends_on: 2024-06-06
completed: false
user: trevor
linux:
title: Linux
starts_on: 2023-03-06
ends_on: 2023-06-06
completed: true
user: trevor

View File

@ -1,10 +0,0 @@
one:
learning_goal: sql
done: false
title: Read SQL for Mere Mortals
due: <%= 3.years.from_now %>
two:
learning_goal: linux
done: true
title: Install Debian

View File

@ -1,4 +0,0 @@
require "test_helper"
class LearningGoalTest < ActiveSupport::TestCase
end

View File

@ -1,7 +0,0 @@
require "test_helper"
class TodoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end