From 3368617fb364eb6be8f866ae10d243bf5d022285 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 21 Nov 2023 11:57:29 +0000 Subject: [PATCH] Add microposts to projects --- app/assets/stylesheets/application.css.sass | 1 + app/assets/stylesheets/projects.sass | 10 +++++ app/assets/stylesheets/projects.scss | 3 -- app/models/project.rb | 9 ++++ app/views/profiles/_follow_form.html.haml | 2 +- app/views/profiles/show.html.haml | 2 +- app/views/projects/index.html.haml | 49 +++++++++------------ app/views/projects/show.html.haml | 25 ++++++----- 8 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 app/assets/stylesheets/projects.sass delete mode 100644 app/assets/stylesheets/projects.scss diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 9f551a3a..13500f80 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -259,3 +259,4 @@ textarea @import profiles @import tokens @import microposts +@import projects diff --git a/app/assets/stylesheets/projects.sass b/app/assets/stylesheets/projects.sass new file mode 100644 index 00000000..e0dca1ee --- /dev/null +++ b/app/assets/stylesheets/projects.sass @@ -0,0 +1,10 @@ +.projects-index + .project + text-align: center + &:hover h1 + text-shadow: 0px 0px 9px #e1b027 + h1 + text-shadow: -1px 1px #e1b027, 1px -1px #00ddff + transition: .15s text-shadow + p + margin-top: 0 diff --git a/app/assets/stylesheets/projects.scss b/app/assets/stylesheets/projects.scss deleted file mode 100644 index 90634780..00000000 --- a/app/assets/stylesheets/projects.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Projects controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/models/project.rb b/app/models/project.rb index 9b38b914..6d9d4040 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,3 +1,12 @@ class Project < ActiveRecord::Base belongs_to :user + has_many :microposts, as: :micropostable + has_many :passive_relationships, class_name: "Relationship", + foreign_key: "followed_id", + dependent: :destroy + has_many :followers, through: :passive_relationships, source: :follower + + def display_name + title + end end diff --git a/app/views/profiles/_follow_form.html.haml b/app/views/profiles/_follow_form.html.haml index a6d94448..942af0cd 100644 --- a/app/views/profiles/_follow_form.html.haml +++ b/app/views/profiles/_follow_form.html.haml @@ -2,4 +2,4 @@ - if current_user.following?(@profile) = render 'unfollow' - else - = render 'follow' + = render 'shared/follow' diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml index f4b6960a..2c79ad13 100644 --- a/app/views/profiles/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -3,7 +3,7 @@ = @profile.name - if policy(@profile).edit? = link_to 'Edit', edit_profile_path(@profile) - = render 'follow_form' if current_user.signed_in? + = render 'shared/follow_form' if current_user.signed_in? %p = @profile.summary diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index cccb6118..b3177a25 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -1,31 +1,22 @@ -%h1 Listing projects +.contain + %h1 Listing projects --# - if policy(Project).new? -= link_to '+ Add New Project', new_project_path + -# - if policy(Project).new? + %div{style: "align-self: start;"} + = link_to '+ Add New Project', new_project_path -%table - %thead - %tr - %th Title - %th Description - %th Owner - %th - %th - %th - - %tbody - - @projects.each do |project| - %tr - %td= link_to project.title, project - %td= project.description - %td= project.user - -# %td= link_to 'Show', project - %td - - if policy(project).edit? - %td= link_to 'Edit', edit_project_path(project) - - else - %td - - if policy(project).destroy? - %td= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } - - else - %td +.projects-index + - @projects.each do |project| + = link_to project, class: "project" do + %h1= project.title + %p= project.description + -# .social-links + - project.social_links.each do |social_link| + = social_link.to_icon.html_safe + -# %p= project.about + -# %span #{project.followers.count} Followers + -#    + -# %span #{project.microposts.count} Posts + - if policy(project).destroy? + = link_to 'Edit', edit_project_path(project) + = link_to 'Delete', project, method: :delete, data: { confirm: 'Are you sure?' } diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index e812287b..1c08c9ab 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -1,13 +1,16 @@ -- if policy(@project).edit? - = link_to 'Edit', edit_project_path(@project) +.contain + %h1 + = @project.title + - if policy(@project).edit? + = link_to 'Edit', edit_project_path(@project) + = render 'shared/follow_form' if current_user.signed_in? -%p - %b Title: - = @project.title -%p - %b Description: - = @project.description -%p - %b Owner: - = @project.user + .description + = @project.description +- if @project.microposts.any? + %section.microposts + %h3 Posts #{@project.microposts.count} + %ol.microposts + = render @project.microposts + = will_paginate @project.microposts.paginate(page: params[:page])