Skip to content
Open
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
72 changes: 72 additions & 0 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class TopicsController < ApplicationController
include Authorization

before_action :set_topic, only: %i[ show edit update destroy ]

# GET /topics or /topics.json
def index
@topics = Topic.all
end

# GET /topics/1 or /topics/1.json
def show
end

# GET /topics/new
def new
@topic = Topic.new
end

# GET /topics/1/edit
def edit
end

# POST /topics or /topics.json
def create
@topic = Topic.new(topic_params)

respond_to do |format|
if @topic.save
format.html { redirect_to @topic, notice: "Topic was successfully created." }
format.json { render :show, status: :created, location: @topic }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /topics/1 or /topics/1.json
def update
respond_to do |format|
if @topic.update(topic_params)
format.html { redirect_to @topic, notice: "Topic was successfully updated." }
format.json { render :show, status: :ok, location: @topic }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end
end

# DELETE /topics/1 or /topics/1.json
def destroy
@topic.destroy!

respond_to do |format|
format.html { redirect_to topics_path, status: :see_other, notice: "Topic was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_topic
@topic = Topic.find(params.expect(:id))
end

# Only allow a list of trusted parameters through.
def topic_params
params.expect(topic: [ :title, :description, :uid, :state, :language_id, :provider_id ])
end
end
2 changes: 2 additions & 0 deletions app/helpers/topics_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TopicsHelper
end
2 changes: 2 additions & 0 deletions app/models/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ class Language < ApplicationRecord
validates :name, presence: true
validates :name, uniqueness: true
validates :file_share_folder, presence: true

has_many :topics
end
1 change: 1 addition & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class Provider < ApplicationRecord
validates :name, uniqueness: true

has_many :users
has_many :topics
end
10 changes: 10 additions & 0 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Topic < ApplicationRecord
validates :description, presence: true
validates :title, presence: true
validates :title, uniqueness: true

belongs_to :language
belongs_to :provider

enum :state, [ :active, :archived ]
end
7 changes: 5 additions & 2 deletions app/views/layouts/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
<span>Dashboard</span>
</a>
</li>
<li class="sidebar-item ">
<%= nav_link("Topics", topics_path, "translate") %>
</li>

<li
<%# <li
class="sidebar-item has-sub">
<a href="#" class='sidebar-link'>
<i class="bi bi-folder"></i>
Expand All @@ -43,7 +46,7 @@
<a href="form-element-textarea.html" class="submenu-link">Textarea</a>
</li>
</ul>
</li>
</li> %>
<% if current_user_is_admin? %>
<li class="sidebar-title">Admin Tools</li>
<li class="sidebar-item <%= active_class(:regions) %>">
Expand Down
53 changes: 53 additions & 0 deletions app/views/topics/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<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>
<%= form_with(model: @topic, local: true, class: "form") do |f| %>
<div class="row">
<div class="col-md-12 col-12">
<div class="form-group">
<%= f.label :title %>
<%= f.text_field :title, class: "form-control", placeholder: "Topic" %>
</div>
</div>
<div class="col-md-12 col-12">
<div class="form-group">
<%= f.label :description %>
<%= f.text_area :description, class: "form-control", placeholder: "Description" %>
</div>
</div>
<div class="col-md-12 col-12">
<div class="form-group">
<%= f.label :uid %>
<%= f.text_field :uid, class: "form-control", placeholder: "UID" %>
</div>
</div>
<div class="col-md-12 col-12">
<div class="form-group">
<%= f.label :state %>
<%= f.text_field :state, class: "form-control", placeholder: "State" %>
</div>
</div>
<div class="col-md-12 col-12">
<div class="form-group">
<%= f.label :language %>
<%= f.collection_select(:language_id, Language.all, :id, :name) %>
</div>
</div>
<div class="col-md-12 col-12">
<div class="form-group">
<%= f.label :provider %>
<%= f.collection_select(:provider_id, Provider.all, :id, :name) %>
</div>
</div>
<div class="col-12 d-flex justify-content-end">
<%= submit_button(f) %>
<%= link_to "Cancel", topics_path, class: "btn btn-light-secondary me-1 mb-1" %>
</div>
</div>
<% end %>
</div>
</div>
32 changes: 32 additions & 0 deletions app/views/topics/_topic.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div id="<%= dom_id topic %>">
<p>
<strong>Title:</strong>
<%= topic.title %>
</p>

<p>
<strong>Description:</strong>
<%= topic.description %>
</p>

<p>
<strong>Uid:</strong>
<%= topic.uid %>
</p>

<p>
<strong>State:</strong>
<%= topic.state %>
</p>

<p>
<strong>Language:</strong>
<%= topic.language.name %>
</p>

<p>
<strong>Provider:</strong>
<%= topic.provider.name %>
</p>

</div>
14 changes: 14 additions & 0 deletions app/views/topics/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% content_for :title, "Editing topic" %>

<section id="multiple-column-form">
<div class="row match-height">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3>Edit Topic</h3>
</div>
<%= render "form", topic:@topic %>
</div>
</div>
</div>
</section>
51 changes: 51 additions & 0 deletions app/views/topics/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<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-circle-fill"></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>Provider</th>
<th class="text-end">Topic Actions</th>
</tr>
</thead>
<tbody>
<% @topics.each do |topic| %>
<tr id="<%= dom_id(topic) %>" class="topic-listing">
<td class="text-bold-500"><%= topic.title %></td>
<td><%= topic.provider.name %></td>
<td class="text-end">
<%= show_page_tool_link(topic, "Show Topic Details") %>
<%= link_to edit_topic_path(topic), class: "btn btn-secondary btn-sm" do %>
<i class="bi bi-pencil"></i>
<% end %>
<%= delete_tool_link(topic, "Delete Topic") %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
12 changes: 12 additions & 0 deletions app/views/topics/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<section id="multiple-column-form">
<div class="row match-height">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3>Create New Topic</h3>
</div>
<%= render "form", topic:@topic %>
</div>
</div>
</div>
</section>
26 changes: 26 additions & 0 deletions app/views/topics/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p style="color: green"><%= notice %></p>

<section id="multiple-column-form">
<div class="row match-height">
<div class="col-12">
<div class="card">
<div class="card-header">
<h2>Topics</h2>
<h4><%= @topic.title %></h4>
</div>
<div class="card-content">
<div class="card-body">
<%= render @topic %>

<div>
<%= link_to "Edit this topic", edit_topic_path(@topic) %> |
<%= link_to "Back to topics", topics_path %>

<%= button_to "Destroy this topic", @topic, method: :delete %>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
resources :providers
resources :users
resources :regions
resources :topics
resource :session
resources :passwords, param: :token

Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20250120173825_create_topics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateTopics < ActiveRecord::Migration[8.0]
def change
create_table :topics do |t|
t.string :title
t.text :description
t.string :uid
t.integer :state, default: 0
t.references :language, null: false, foreign_key: true
t.references :provider, null: false, foreign_key: true

t.timestamps
end
end
end
17 changes: 16 additions & 1 deletion db/schema.rb

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

2 changes: 1 addition & 1 deletion spec/factories/languages.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :language do
name { "MyString" }
sequence(:name) { |n| "MyString#{n}" }
file_share_folder { "MyString" }
end
end
10 changes: 10 additions & 0 deletions spec/factories/topics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactoryBot.define do
factory :topic do
sequence(:title) { |n| "MyString#{n}" }
description { "MyText" }
uid { "MyString" }
state { 0 }
language
provider
end
end
Loading
Loading