-
Notifications
You must be signed in to change notification settings - Fork 6
Create topics #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create topics #44
Changes from all commits
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,57 @@ | ||
| class TopicsController < ApplicationController | ||
| before_action :set_topic, only: %i[show edit update destroy] | ||
|
|
||
| def index | ||
| @topics = Topic.all | ||
| end | ||
|
|
||
| def show | ||
| end | ||
|
|
||
| def new | ||
| @topic = Topic.new | ||
| end | ||
|
|
||
| def edit | ||
| end | ||
|
|
||
| def create | ||
| @topic = Topic.new(topic_params) | ||
|
|
||
| respond_to do |format| | ||
| if @topic.save | ||
| format.html { redirect_to @topic, notice: "Topic was successfully created." } | ||
| else | ||
| format.html { render :new, status: :unprocessable_entity } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def update | ||
| respond_to do |format| | ||
| if @topic.update(topic_params) | ||
| format.html { redirect_to @topic, notice: "Topic was successfully updated." } | ||
| else | ||
| format.html { render :edit, status: :unprocessable_entity } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| @topic.destroy! | ||
|
|
||
| respond_to do |format| | ||
| format.html { redirect_to topics_path, status: :see_other, notice: "Topic was successfully destroyed." } | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_topic | ||
| @topic = Topic.find(params[:id]) | ||
| end | ||
|
|
||
| def topic_params | ||
| params.require(:topic).permit(:title, :description, :language_id, :provider_id, :archived) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class Topic < ApplicationRecord | ||
| belongs_to :language | ||
| belongs_to :provider | ||
| has_many :taggings | ||
| has_many :training_resources | ||
|
|
||
| validates :title, presence: true | ||
| validates :language_id, presence: true | ||
| validates :provider_id, presence: true | ||
|
|
||
| scope :archived, -> { where(archived: true) } | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||
| <%= form_with(model: topic) do |form| %> | ||||||
| <% if topic.errors.any? %> | ||||||
| <div style="color: red"> | ||||||
| <h2><%= pluralize(topic.errors.count, "error") %> prohibited this topic from being saved:</h2> | ||||||
|
|
||||||
| <ul> | ||||||
| <% topic.errors.each do |error| %> | ||||||
| <li><%= error.full_message %></li> | ||||||
| <% end %> | ||||||
| </ul> | ||||||
| </div> | ||||||
| <% end %> | ||||||
|
|
||||||
| <div class="row"> | ||||||
| <div class="col-md-4"> | ||||||
| <div class="form-group"> | ||||||
| <%= form.label :title, style: "display: block" %> | ||||||
| <%= form.text_field :title, id: "basicInput", class: "form-control", autofocus: true %> | ||||||
| </div> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="col-md-4"> | ||||||
| <div class="form-group"> | ||||||
| <%= form.label :description, style: "display: block" %> | ||||||
| <%= form.text_area :description, id: "basicInput", class: "form-control" %> | ||||||
| </div> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="col-md-4"> | ||||||
| <div class="form-group"> | ||||||
| <%= form.label :language_id, style: "display: block" %> | ||||||
| <%= form.collection_select :language_id, Language.all, :id, :name, {}, { id: "basicInput", class: "form-control" } %> | ||||||
| </div> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="col-md-4"> | ||||||
| <div class="form-group"> | ||||||
| <%= form.label :provider_id, style: "display: block" %> | ||||||
| <%= form.collection_select :provider_id, Provider.all, :id, :name, {}, { id: "basicInput", class: "form-control" } %> | ||||||
| </div> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="col-md-4"> | ||||||
| <div class="form-group"> | ||||||
| <%= form.label :archived, "Archived", for: "checkbox1", style: "display: block" %> | ||||||
| <%= form.check_box :archived, { id: "checkbox1", class: "form-check-input", checked: false } %> | ||||||
| </div> | ||||||
| </div> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="mt-4"> | ||||||
| <div class="col-12 d-flex justify-content-end"> | ||||||
| <%= form.submit "Create Topic", class: "btn btn-primary me-1 mb-1" %> | ||||||
|
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. Since this is also used for the #edit action, maybe changing the wording to "Save" would be better to apply both for #create and #edit.
Suggested change
|
||||||
| <%= link_to "Cancel", topics_path, class: "btn btn-light-secondary me-1 mb-1" %> | ||||||
| </div> | ||||||
| </div> | ||||||
| <% end %> | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <% content_for :title, "Editing topic" %> | ||
|
|
||
| <h1>Editing topic</h1> | ||
|
|
||
| <%= render "form", topic: @topic %> | ||
|
|
||
| <div class="mt-4"> | ||
| <%= link_to "Show this topic", @topic %> | | ||
| <%= link_to "Back to topics", topics_path %> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <% content_for :title, "Topics" %> | ||
|
|
||
| <section class="section"> | ||
| <div class="row" id="table-striped"> | ||
| <div class="col-12 cold-md-12"> | ||
| <div class="card"> | ||
| <div class="card-header d-flex justify-content-between align-items-center"> | ||
| <h2>Topics</h2> | ||
| <%= link_to new_topic_path, class: "btn btn-primary" do %> | ||
| <i class="bi bi-plus"></i> Add New Topic | ||
| <% end %> | ||
| </div> | ||
| <div class="card-content"> | ||
| <div class="card-body"> | ||
| <p class="card-text"> | ||
| Lorem ipsum dolor sit amet, <code>consectetur adipiscing</code> elit. Sed do eiusmod tempor incididunt ut | ||
| labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
| ex ea commodo consequat. Duis aute irure dolor in <code>reprehenderit</code> in voluptate velit esse cillum dolore eu fugiat nulla | ||
| pariatur. Excepteur sint <code>occaecat cupidatat</code> non proident, sunt in culpa qui officia deserunt mollit anim id est | ||
| laborum. | ||
| </p> | ||
| <!-- table striped --> | ||
| <div class="table-responsive"> | ||
| <table class="table table-lg table-striped mb-0"> | ||
| <thead> | ||
| <tr> | ||
| <th>Title</th> | ||
| <th>Description</th> | ||
| <th>Language</th> | ||
| <th>Provider</th> | ||
| <th>Archived</th> | ||
| <th class="text-end">Topic Actions</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <% @topics.each do |topic| %> | ||
| <tr> | ||
| <td class="text-bold-500"><%= topic.title %></td> | ||
| <td><%= topic.description %></td> | ||
| <td><%= topic.language.name %></td> | ||
| <td><%= topic.provider.name %></td> | ||
| <td><%= topic.archived ? "Yes" : "No" %></td> | ||
| <td class="text-end"> | ||
| <%= link_to topic, class: "btn btn-primary btn-sm" do %> | ||
| <i class="bi bi-search"></i> View | ||
| <% end %> | ||
| <%= link_to edit_topic_path(topic), class: "btn btn-secondary btn-sm" do %> | ||
| <i class="bi bi-pencil"></i> Edit | ||
| <% end %> | ||
| <%= link_to topic, method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-sm" do %> | ||
| <i class="bi bi-trash"></i> Delete | ||
| <% end %> | ||
| </td> | ||
| </tr> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <% content_for :title, "New Topic" %> | ||
|
|
||
| <section id="multiple-column-form"> | ||
| <div class="row match-height"> | ||
| <div class="col-12"> | ||
| <div class="card"> | ||
| <div class="card-header"> | ||
| <h4>Create New Topic</h4> | ||
| </div> | ||
| <div class="card-content"> | ||
| <div class="card-body"> | ||
| <p>Topics should ... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut | ||
| labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
| ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla | ||
| pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est | ||
| laborum.</p> | ||
| <%= render "form", topic: @topic %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <% content_for :title, @topic.title %> | ||
|
|
||
| <h1><%= @topic.title %></h1> | ||
|
|
||
| <p> | ||
| <strong>Description:</strong> | ||
| <%= @topic.description %> | ||
| </p> | ||
|
|
||
| <p> | ||
| <strong>Language:</strong> | ||
| <%= @topic.language.name %> | ||
| </p> | ||
|
|
||
| <p> | ||
| <strong>Provider:</strong> | ||
| <%= @topic.provider.name %> | ||
| </p> | ||
|
|
||
| <p> | ||
| <strong>Archived:</strong> | ||
| <%= @topic.archived ? "Yes" : "No" %> | ||
| </p> | ||
|
|
||
| <div class="mt-4"> | ||
| <%= link_to "Edit this topic", edit_topic_path(@topic) %> | | ||
| <%= link_to "Back to topics", topics_path %> | ||
| </div> | ||
|
|
||
| <div> | ||
| <%= button_to "Destroy this topic", @topic, method: :delete, class: "btn btn-danger mt-4" %> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class CreateTopics < ActiveRecord::Migration[8.0] | ||
| def change | ||
| create_table :topics do |t| | ||
| t.string :title, null: false | ||
| t.text :description | ||
| t.references :language, null: false, foreign_key: true | ||
| t.references :provider, null: false, foreign_key: true | ||
| t.boolean :archived, default: false | ||
|
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. On the wiki, Danny had mentioned using enumerables for states like "active" and "archived". Do we want to do this or should we go with a boolean? |
||
| t.timestamps | ||
| end | ||
| end | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| FactoryBot.define do | ||
| factory :topic do | ||
| title { "Default Title" } | ||
| description { "Default Description" } | ||
| archived { false } | ||
| association :language | ||
| association :provider | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we have a few "id: "basicInput"" in the app, sometimes within the same page, but I don't think we actually need them? I think we got them when we copy/pasted code from Mazer and forgot to remove it.