Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions app/controllers/topics_controller.rb
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
12 changes: 12 additions & 0 deletions app/models/topic.rb
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
1 change: 0 additions & 1 deletion app/views/languages/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<% content_for :title, "New language" %>

<section id="basic-vertical-layouts">
<div class="row match-height">
<div class="col-md-6 col-12">
Expand Down
15 changes: 11 additions & 4 deletions app/views/layouts/_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div id="sidebar">
<div class="sidebar-wrapper active">
<div class="sidebar-header position-relative">
Expand Down Expand Up @@ -42,11 +41,19 @@

<div class="sidebar-menu">
<ul class="menu">

<li class="sidebar-item">
<a href="application-chat.html" class="sidebar-link">
<i class="bi bi-grid-fill"></i>
<span>Dashboard</span>
</a>
</li>

<li class="sidebar-title">Administration</li>

<li class="sidebar-item">
<%= link_to regions_path, class: "sidebar-link" do %>
<i class="bi bi-hospital-fill"></i>
<i class="bi bi-globe"></i>
<span>Regions</span>
<% end %>
</li>
Expand All @@ -59,10 +66,10 @@
</li>

<li class="sidebar-item">
<a href="ui-file-uploader.html" class="sidebar-link">
<%= link_to topics_path, class: "sidebar-link" do %>
<i class="bi bi-tags-fill"></i>
<span>Topics</span>
</a>
<% end %>
</li>

<li class="sidebar-item">
Expand Down
57 changes: 57 additions & 0 deletions app/views/topics/_form.html.erb
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 %>
Copy link
Collaborator

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.

</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" %>
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
<%= form.submit "Create Topic", class: "btn btn-primary me-1 mb-1" %>
<%= form.submit "Save Topic", class: "btn btn-primary me-1 mb-1" %>

<%= link_to "Cancel", topics_path, class: "btn btn-light-secondary me-1 mb-1" %>
</div>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/topics/edit.html.erb
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>
63 changes: 63 additions & 0 deletions app/views/topics/index.html.erb
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>
23 changes: 23 additions & 0 deletions app/views/topics/new.html.erb
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>
32 changes: 32 additions & 0 deletions app/views/topics/show.html.erb
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>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
resource :session
resources :topics
root "home#index"
get "home/index", as: :home
resources :languages, only: %i[index show new create edit update]
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20250204133409_create_topics.rb
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
30 changes: 22 additions & 8 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions spec/factories/topics.rb
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
Loading