diff --git a/app/assets/stylesheets/blog_posts.css b/app/assets/stylesheets/blog_posts.css index ecb1bef..2ae143a 100644 --- a/app/assets/stylesheets/blog_posts.css +++ b/app/assets/stylesheets/blog_posts.css @@ -1,4 +1,4 @@ -form#blog_post_form { +form#blog_post_form, form#learning_goal_form { display: flex; flex-direction: column; max-width: 55em; diff --git a/app/assets/stylesheets/learning_goals.css b/app/assets/stylesheets/learning_goals.css new file mode 100644 index 0000000..b6d428d --- /dev/null +++ b/app/assets/stylesheets/learning_goals.css @@ -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; +} diff --git a/app/controllers/learning_goals_controller.rb b/app/controllers/learning_goals_controller.rb new file mode 100644 index 0000000..5d8d981 --- /dev/null +++ b/app/controllers/learning_goals_controller.rb @@ -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 diff --git a/app/helpers/learning_goals_helper.rb b/app/helpers/learning_goals_helper.rb new file mode 100644 index 0000000..d36c8ac --- /dev/null +++ b/app/helpers/learning_goals_helper.rb @@ -0,0 +1,5 @@ +module LearningGoalsHelper + def learning_goal_completed_text(learning_goal) + learning_goal.completed ? t(".completed") : t(".not_completed") + end +end diff --git a/app/models/learning_goal.rb b/app/models/learning_goal.rb index 6aae83c..879fdf3 100644 --- a/app/models/learning_goal.rb +++ b/app/models/learning_goal.rb @@ -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 diff --git a/app/views/blog_posts/show.html.erb b/app/views/blog_posts/show.html.erb index 44e9ff0..7346df1 100644 --- a/app/views/blog_posts/show.html.erb +++ b/app/views/blog_posts/show.html.erb @@ -1,4 +1,4 @@ -
<%= @blog_post.content %>
<%= t(".empty") %>
+<% else %> +<%= @learning_goal.starts_on %>-<%= @learning_goal.ends_on %>
+<%= @learning_goal.description %>
+ <% if @learning_goal.completed? %> +<%= @learning_goal.retrospective %>
+ <% end %> + <%= link_to t(".edit"), edit_learning_goal_path(@learning_goal) if @learning_goal.user == current_user %> +