This repository was archived by the owner on Nov 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 69
Adding Impact Stories #415
Open
fosterv2
wants to merge
11
commits into
main
Choose a base branch
from
impact-stories
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3ff95d0
Generate files for impact_stories model. Added all necessary views an…
fosterv2 0b9959a
formatted all the views correctly.
fosterv2 fc9d6ee
Enabled emailing impact stories on the show page.
fosterv2 80580bf
Add impact story model, request, and feature specs
fosterv2 cab0733
Remove emailing framework
fosterv2 dfd3e43
Fix indentation in all files
fosterv2 a5a3225
Add schema information to impact_story.rb and change enumerator in co…
fosterv2 feff48d
Use rubocop to fix layout and style
fosterv2 4d785eb
Fix rubocop offence
fosterv2 7e30f6d
Delete unnecessary files, add constraints and validations, and add mo…
fosterv2 d58631f
Fix rubocop offense
fosterv2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,45 @@ | ||
| class ImpactStoriesController < ApplicationController | ||
| before_action :authenticate_user! | ||
|
|
||
| def index | ||
| @impact_stories = current_partner.impact_stories.sort_by(&:created_at).reverse | ||
| end | ||
|
|
||
| def show | ||
| @impact_story = current_partner.impact_stories.find(params[:id]) | ||
| end | ||
|
|
||
| def new | ||
| @impact_story = current_partner.impact_stories.new | ||
| end | ||
|
|
||
| def create | ||
| @impact_story = current_partner.impact_stories.new(impact_story_params) | ||
|
|
||
| if @impact_story.save | ||
| redirect_to @impact_story, notice: "Impact Story was successfully created." | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
| def edit | ||
| @impact_story = current_partner.impact_stories.find(params[:id]) | ||
| end | ||
|
|
||
| def update | ||
| @impact_story = current_partner.impact_stories.find(params[:id]) | ||
|
|
||
| if @impact_story.update(impact_story_params) | ||
| redirect_to @impact_story, notice: "Impact Story was successfully updated." | ||
| else | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def impact_story_params | ||
| params.require(:impact_story).permit(:title, :content) | ||
| end | ||
| end |
This file contains hidden or 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,21 @@ | ||
| # == Schema Information | ||
| # | ||
| # Table name: impact_stories | ||
| # | ||
| # id :bigint(8) not null, primary key | ||
| # partner_id :bigint(8) | ||
| # title :string not null | ||
| # content :text not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # | ||
|
|
||
| class ImpactStory < ApplicationRecord | ||
| belongs_to :partner | ||
|
|
||
| validates :title, :content, presence: true | ||
|
|
||
| def blurb(limit) | ||
| content.truncate(limit, separator: ' ') | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,28 @@ | ||
| <section class="content"> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <!-- left column --> | ||
| <div class="col-md-12"> | ||
| <!-- jquery validation --> | ||
| <div class="card card-primary"> | ||
| <!-- /.card-header --> | ||
| <!-- form start --> | ||
| <div class="card-body"> | ||
| <%= simple_form_for impact_story, html: {role: 'form', class: 'form-horizontal'} do |f| %> | ||
| <%= f.input :title, label: "Story Title", class: "form-control", wrapper: :input_group %> | ||
|
|
||
| <%= f.text_area :content, label: "Story Content", class: "form-control", wrapper: :input_group %> | ||
|
|
||
| <div class="card-footer"> | ||
| <%= f.submit(class: 'btn btn-primary') %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| <!-- /.card --> | ||
| </div> | ||
| <p>We're working on adding image upload. Watch this space for updates!</p> | ||
| </div> | ||
| </div> | ||
| <!-- /.row --> | ||
| </div><!-- /.container-fluid --> | ||
| </section> |
This file contains hidden or 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,21 @@ | ||
| <table class="table table-striped"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col">Story Title</th> | ||
| <th scope="col">Date Created</th> | ||
| <th scope="col">Content</th> | ||
| <th scope="col" colspan="2"> | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <% @impact_stories.each do |story| %> | ||
| <tr> | ||
| <td><%= story.title %></td> | ||
| <td><%= story.created_at.strftime("%B %-d %Y") %></td> | ||
| <td><%= story.blurb(40) %></td> | ||
| <td><%= link_to 'View Story', story, class: "btn btn-sm btn-info pull-right" %></td> | ||
| <td><%= link_to 'Edit Story Details', edit_impact_story_path(story), class: "btn btn-sm btn-success pull-right" %></td> | ||
| <% end %> | ||
| </tbody> | ||
| </table> |
This file contains hidden or 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,27 @@ | ||
| <section class="content-header"> | ||
| <div class="container-fluid"> | ||
| <div class="row mb-2"> | ||
| <div class="col-sm-6"> | ||
| <% content_for :title, "Impact Story - #{current_partner.name}" %> | ||
| <h1><i class="fa fa-user-plus"></i> | ||
| Edit Impact Story | ||
| <small>for <%= current_partner.name %></small> | ||
| </h1> | ||
| </div> | ||
| <div class="col-sm-6"> | ||
| <ol class="breadcrumb float-sm-right"> | ||
| <li class="breadcrumb-item"><%= link_to(dashboard_path) do %> | ||
| <i class="fa fa-home fa-lg"></i> Home | ||
| <% end %> | ||
| </li> | ||
| <li class="breadcrumb-item"><a href="<%= impact_stories_path %>">All Impact Stories</a></li> | ||
| <li class="breadcrumb-item"> | ||
| <a href="<%= impact_story_path(@impact_story) %>">The <%= "#{@impact_story.title}" %> Story</a></li> | ||
| <li class="breadcrumb-item"><a href="#">Edit</a></li> | ||
| </ol> | ||
| </div> | ||
| </div> | ||
| </div><!-- /.container-fluid --> | ||
| </section> | ||
|
|
||
| <%= render 'form', impact_story: @impact_story %> |
This file contains hidden or 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,64 @@ | ||
| <!-- Content Header (Page header) --> | ||
| <section class="content-header"> | ||
| <div class="container-fluid"> | ||
| <div class="row mb-2"> | ||
| <div class="col-sm-6"> | ||
| <% content_for :title, "Impact Stories - #{current_partner.name}" %> | ||
| <h1><i class="fa fa-users"></i> | ||
| Impact Stories | ||
| <small>for <%= current_partner.name %></small> | ||
| </h1> | ||
| </div> | ||
| <div class="col-sm-6"> | ||
| <ol class="breadcrumb float-sm-right"> | ||
| <li class="breadcrumb-item"><%= link_to(dashboard_path) do %> | ||
| <i class="fa fa-dashboard"></i> Home | ||
| <% end %> | ||
| </li> | ||
| <li class="breadcrumb-item"><a href="#">Impact Stories</a></li> | ||
| </ol> | ||
| </div> | ||
| </div> | ||
| </div><!-- /.container-fluid --> | ||
| </section> | ||
|
|
||
| <section class="content"> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <!-- left column --> | ||
| <div class="col-md-12"> | ||
| <!-- jquery validation --> | ||
| <div class="card"> | ||
| <div class="card-footer"> | ||
| <span class="float-right"> | ||
| <%= link_to 'Add New Impact Story', new_impact_story_path, class: "btn btn-info" %> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <!-- /.card --> | ||
| </div> | ||
| <!--/.col (left) --> | ||
| </div> | ||
| <!-- /.row --> | ||
| </div><!-- /.container-fluid --> | ||
| </section> | ||
| <section class="content"> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <div class="col-md-12"> | ||
| <!-- Default box --> | ||
| <div class="card"> | ||
| <div class="card-body"> | ||
| <div id="filterrific_results"> | ||
| <%= render( | ||
| partial: 'impact_stories/list', | ||
| locals: {impact_stories: @impact_stories} | ||
| ) %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <!-- /.card --> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> |
This file contains hidden or 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,25 @@ | ||
| <section class="content-header"> | ||
| <div class="container-fluid"> | ||
| <div class="row mb-2"> | ||
| <div class="col-sm-6"> | ||
| <% content_for :title, "Impact Story - #{current_partner.name}" %> | ||
| <h1><i class="fa fa-user-plus"></i> | ||
| New Impact Story | ||
| <small>for <%= current_partner.name %></small> | ||
| </h1> | ||
| </div> | ||
| <div class="col-sm-6"> | ||
| <ol class="breadcrumb float-sm-right"> | ||
| <li class="breadcrumb-item"><%= link_to(dashboard_path) do %> | ||
| <i class="fa fa-home fa-lg"></i> Home | ||
| <% end %> | ||
| </li> | ||
| <li class="breadcrumb-item"><a href="<%= impact_stories_path %>">All Impact Stories</a></li> | ||
| <li class="breadcrumb-item"><a href="#">New Impact Story</a></li> | ||
| </ol> | ||
| </div> | ||
| </div> | ||
| </div><!-- /.container-fluid --> | ||
| </section> | ||
|
|
||
| <%= render 'form', impact_story: @impact_story %> |
This file contains hidden or 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,49 @@ | ||
| <section class="content-header"> | ||
| <div class="container-fluid"> | ||
| <div class="row mb-2"> | ||
| <div class="col-sm-6"> | ||
| <% content_for :title, "Impact Stories - #{current_partner.name}" %> | ||
| <h1><i class="fa fa-users"></i> | ||
| Impact Story Details | ||
| <small>for <%= current_partner.name %></small> | ||
| </h1> | ||
| </div> | ||
| <div class="col-sm-6"> | ||
| <ol class="breadcrumb float-sm-right"> | ||
| <li class="breadcrumb-item"><%= link_to(dashboard_path) do %> | ||
| <i class="fa fa-home fa-lg"></i> Home | ||
| <% end %> | ||
| </li> | ||
| <li class="breadcrumb-item"><a href="<%= impact_stories_path %>">All Impact Stories</a></li> | ||
| <li class="breadcrumb-item"><a href="#">The <%= "#{@impact_story.title}" %> Story</a></li> | ||
| </ol> | ||
| </div> | ||
| </div> | ||
| </div><!-- /.container-fluid --> | ||
| </section> | ||
|
|
||
| <section class="content"> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <div class="col-md-12"> | ||
| <div class="card mb-4"> | ||
| <h5 class="card-header bg-primary text-white">Story Information | ||
| </h5> | ||
| <div class="card-body"> | ||
| <dl> | ||
| <dt>Story Title:</dt> | ||
| <dd><%= @impact_story.title %></dd> | ||
|
|
||
| <dt>Story Content:</dt> | ||
| <dd><%= simple_format(h(@impact_story.content)) %></dd> | ||
| </dl> | ||
| </div> | ||
| <div class="card-footer"> | ||
| <%= link_to 'Edit This Story', edit_impact_story_path(@impact_story), class: "btn btn-sm btn-primary" %> | ||
| <%= link_to 'Back to All Stories', impact_stories_path, class: "btn btn-sm btn-info pull-right" %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> |
This file contains hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
| class CreateImpactStories < ActiveRecord::Migration[6.0] | ||
| def change | ||
| create_table :impact_stories do |t| | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add some database constraints to prevent it at the DB level from having incorrect data. I usually think about the database first when it comes to adding new models. Without these constraints, you could pass invalid data through if you bypass the callbacks using something like |
||
| t.string :title, null: false | ||
| t.text :content, null: false | ||
| t.references :partner, index: true, foreign_key: true | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,19 @@ | ||
| # == Schema Information | ||
| # | ||
| # Table name: impact_stories | ||
| # | ||
| # id :bigint(8) not null, primary key | ||
| # partner_id :bigint(8) | ||
| # title :string not null | ||
| # content :text not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # | ||
|
|
||
| FactoryBot.define do | ||
| factory :impact_story do | ||
| title { Faker::Lorem.word } | ||
| content { Faker::Lorem.paragraph } | ||
| partner | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.