-
-
Notifications
You must be signed in to change notification settings - Fork 69
Adding Impact Stories #415
base: main
Are you sure you want to change the base?
Changes from 9 commits
3ff95d0
0b9959a
fc9d6ee
80580bf
cab0733
dfd3e43
a5a3225
feff48d
4d785eb
7e30f6d
d58631f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Place all the styles related to the ImpactStories controller here. | ||
| // They will automatically be included in application.css. | ||
| // You can use Sass (SCSS) here: https://sass-lang.com/ | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| module ImpactStoriesHelper | ||
| end | ||
fosterv2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 :integer | ||
| # title :string | ||
| # content :text | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # | ||
|
|
||
| class ImpactStory < ApplicationRecord | ||
| belongs_to :partner | ||
|
|
||
fosterv2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def blurb(limit) | ||
| if content.length > limit then "#{content[0, limit]}…" else content end | ||
fosterv2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
| 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <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"> | ||
| <%# link_to 'Export Results To CSV', families_path(nil, format: :csv), class: "btn btn-info pull-right" %> | ||
fosterv2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </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(30) %></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> | ||
| 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 %> |
| 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> |
| 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 %> |
| 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> |
| 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 | ||
fosterv2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| t.text :content | ||
fosterv2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| t.integer :partner_id | ||
|
||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| FactoryBot.define do | ||
| factory :impact_story do | ||
| title { "MyTitle" } | ||
| content { "MyText" } | ||
| partner | ||
| end | ||
fosterv2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.