Skip to content
Merged
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
15 changes: 15 additions & 0 deletions app/javascript/controllers/topics_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Controller } from "@hotwired/stimulus"
import { useDebounce } from "stimulus-use"

export default class extends Controller {
static targets = [ "form" ]
static debounces = [ "search" ]

connect() {
useDebounce(this, { wait: 300 })
}

search() {
this.formTarget.requestSubmit()
}
}
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/app-dark.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/iconly.css">

<%= javascript_importmap_tags %>

<style>
#app {
display: flex;
Expand Down Expand Up @@ -70,6 +72,7 @@
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/components/dark.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/extensions/perfect-scrollbar/perfect-scrollbar.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/js/app.js"></script>

<div id="app">
<%= render "layouts/sidebar" %>
<div id="main" class='layout-navbar navbar-fixed'>
Expand Down
30 changes: 30 additions & 0 deletions app/views/topics/_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<tbody>
<% @topics.each do |topic| %>
<tr>
<td class="text-bold-500"><%= topic.title %></td>
<td class="text-bold-500"><%= topic.description.present? && topic.description.truncate(25, omission: "...") %></td>
<td class="text-bold-500"><%= topic.uid.truncate(10, omission: "...") %></td>
<td class="text-bold-500"><%= topic.language.name %></td>
<td class="text-bold-500"><%= topic.provider.name %></td>
<td class="text-bold-500"><%= topic.state %></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 %>
<% unless topic.archived? %>
<%= link_to archive_topic_path(topic), method: :put, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-sm" do %>
<i class="bi bi-archive"></i> Archive
<% end %>
<% end %>
<% if Current.user.is_admin? %>
<%= 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 %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
17 changes: 8 additions & 9 deletions app/views/topics/_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,39 @@
<div class="card-content">
<div class="card-body">
<p class="card-text"> Use these params settings to search topics</p>
<%= form_for :search, url: topics_path, method: :get do |f| %>
<%= form_for :search, url: topics_path, method: :get, data: { controller: "topics", topics_target: "form", turbo_frame: "topic-list", turbo_action: "advance" } do |f| %>
<div class="form-body">
<div class="row">
<div class="col-12">
<div class="form-group">
<%= f.label :provider %>
<%= f.select :provider_id, options_from_collection_for_select(providers, :id, :name, params[:provider_id]), { prompt: "Select provider" }, class: "form-select" %>
<%= f.select :provider_id, options_from_collection_for_select(providers, :id, :name, params[:provider_id]), { prompt: "Select provider" }, class: "form-select", data: { action: "change->topics#search" } %>
</div>
<div class="form-group">
<%= f.label :language %>
<%= f.select :language_id, options_from_collection_for_select(languages, :id, :name, params[:provider_id]), { prompt: "Select language" }, class: "form-select" %>
<%= f.select :language_id, options_from_collection_for_select(languages, :id, :name, params[:provider_id]), { prompt: "Select language" }, class: "form-select", data: { action: "change->topics#search" } %>
</div>
<div class="form-group">
<%= f.label :query %>
<%= f.text_field :query, value: params[:query], class: "form-control" %>
<%= f.text_field :query, value: params[:query], class: "form-control", data: { action: "input->topics#search" } %>
</div>
<div class="form-group">
<%= f.label :year %>
<%= f.select :year, options_for_select((Date.today.year-10..Date.today.year).to_a, params[:year]), { prompt: "Select year" }, class: "form-select" %>
<%= f.select :year, options_for_select((Date.today.year-10..Date.today.year).to_a, params[:year]), { prompt: "Select year" }, class: "form-select", data: { action: "change->topics#search" } %>
</div>
<div class="form-group">
<%= f.label :month %>
<%= f.select :month, options_for_select((1..12).to_a, params[:month]), { prompt: "Select month" }, class: "form-select" %>
<%= f.select :month, options_for_select((1..12).to_a, params[:month]), { prompt: "Select month" }, class: "form-select", data: { action: "change->topics#search" } %>
</div>
<div class="form-group">
<%= f.label :state %>
<%= f.select :state, options_for_select(Topic::STATES.index_with(&:itself), params[:state]), { prompt: "Select state" }, class: "form-select" %>
<%= f.select :state, options_for_select(Topic::STATES.index_with(&:itself), params[:state]), { prompt: "Select state" }, class: "form-select", data: { action: "change->topics#search" } %>
</div>
<div class="form-group">
<%= f.label :order %>
<%= f.select :order, options_for_select(Topic::SORTS.reverse.index_with(&:itself), params[:order]), {}, class: "form-select" %>
<%= f.select :order, options_for_select(Topic::SORTS.reverse.index_with(&:itself), params[:order]), {}, class: "form-select", data: { action: "change->topics#search" } %>
</div>
<div class="col-12 d-flex justify-content-end">
<%= f.submit "Search", class: "btn btn-primary me-1 mb-1" %>
<%= link_to "Clear", topics_path, class: "btn btn-light-secondary me-1 mb-1" %>
</div>
</div>
Expand Down
61 changes: 17 additions & 44 deletions app/views/topics/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<section class="section">
<div class="row" id="table-striped">
<div class="col-12 cold-md-12">
<%= render "topics/search", providers: @providers, languages: @languages, params: search_params %>
<%= render "search", providers: @providers, languages: @languages, params: search_params %>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h2 class="card-title">Topics</h2>
Expand All @@ -14,51 +14,24 @@
<div class="card-content">
<div class="card-body">
<p class="card-text"> Some important information or instruction can be placed here.</p>
<div class="table-responsive">
<table class="table table-lg table-striped mb-0">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>UID</th>
<th>Language</th>
<th>Provider</th>
<th>State</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<% @topics.each do |topic| %>
<%= turbo_frame_tag "topic-list" do %>
<div class="table-responsive">
<table class="table table-lg table-striped mb-0">
<thead>
<tr>
<td class="text-bold-500"><%= topic.title %></td>
<td class="text-bold-500"><%= topic.description.truncate(25, omission: "...") unless topic.description.blank? %></td>
<td class="text-bold-500"><%= topic.uid.truncate(10, omission: "...") %></td>
<td class="text-bold-500"><%= topic.language.name %></td>
<td class="text-bold-500"><%= topic.provider.name %></td>
<td class="text-bold-500"><%= topic.state %></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 %>
<% unless topic.archived? %>
<%= link_to archive_topic_path(topic), method: :put, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-sm" do %>
<i class="bi bi-archive"></i> Archive
<% end %>
<% end %>
<% if Current.user.is_admin? %>
<%= 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 %>
<% end %>
</td>
<th>Title</th>
<th>Description</th>
<th>UID</th>
<th>Language</th>
<th>Provider</th>
<th>State</th>
<th class="text-end">Actions</th>
</tr>
<% end %>
</tbody>
</table>
</div>
</thead>
<%= render "list", topics: @topics %>
</table>
</div>
<% end %>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus", to: "@hotwired--stimulus.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin "stimulus-use" # @0.52.3
4 changes: 4 additions & 0 deletions vendor/javascript/@hotwired--stimulus.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions vendor/javascript/stimulus-use.js

Large diffs are not rendered by default.