Skip to content

Commit 443dce1

Browse files
authored
Merge pull request #598 from cedarcode/search-by-code
Search by code
2 parents 51dbbc8 + 453ae1f commit 443dce1

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

app/controllers/subjects_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def all
1818
Subject
1919
.where("lower(unaccent(name)) LIKE lower(unaccent(?))", "%#{params[:search].strip}%")
2020
.or(Subject.where("lower(unaccent(short_name)) LIKE lower(unaccent(?))", "%#{params[:search].strip}%"))
21+
.or(Subject.where("lower(code) LIKE lower(?)", "%#{params[:search].strip}%"))
2122
end
2223

2324
@subjects = TreePreloader.new(subjects).preload

app/javascript/controllers/search_controller.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default class extends Controller {
55

66
toggle() {
77
this.appBarTarget.classList.toggle("d-none")
8+
this.searchInputTarget.value = ""
89
this.searchbarTarget.classList.toggle("d-none")
910
if (!this.searchbarTarget.classList.contains("d-none")) {
1011
this.searchInputTarget.focus()

app/views/layouts/application.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<%= form_with(url: all_subjects_path, method: :get, local: true) do |f| %>
7575
<div class="mdc-text-field mdc-text-field--filled mdc-text-field--label-floating mdc-text-field--no-label mdc-text-field--with-trailing-icon">
7676
<span class="mdc-text-field__ripple"></span>
77-
<%= f.text_field :search, value: params[:search], class: "mdc-text-field__input", placeholder: "Buscar", autofocus: true, data: { 'search-target': "searchInput" } %>
77+
<%= f.text_field :search, value: params[:search], class: "mdc-text-field__input", placeholder: "Buscar por nombre o código de la materia", autofocus: true, data: { 'search-target': "searchInput" } %>
7878
<i class="material-icons mdc-text-field__icon mdc-text-field__icon--trailing" data-action="click->search#toggle" tabindex="0" role="button">close</i>
7979
<span class="mdc-line-ripple"></span>
8080
</div>

test/system/subjects_test.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ class SubjectsTest < ApplicationSystemTestCase
55
gal1 = create :subject, :with_exam, name: "GAL 1", credits: 9, code: "1030"
66
create :subject_prerequisite, approvable: gal1.exam, approvable_needed: gal1.course
77

8-
gal2 = create :subject, :with_exam, name: "GAL 2", credits: 10
8+
gal2 = create :subject, :with_exam, name: "GAL 2", credits: 10, code: "1031"
99
create :and_prerequisite, approvable: gal2.course, operands_prerequisites: [
1010
create(:subject_prerequisite, approvable_needed: gal1.course),
1111
create(:subject_prerequisite, approvable_needed: gal1.exam),
1212
]
1313

14-
create :subject, name: "Taller 1", short_name: 'T1', credits: 11
14+
create :subject, name: "Taller 1", short_name: 'T1', credits: 11, code: "1040"
1515

1616
visit all_subjects_path
1717

@@ -44,6 +44,18 @@ class SubjectsTest < ApplicationSystemTestCase
4444
assert_no_text "GAL 2"
4545
assert_text "T1"
4646

47+
fill_in 'search', with: "1030\n"
48+
49+
assert_text "GAL 1"
50+
assert_no_text "GAL 2"
51+
assert_no_text "T1"
52+
53+
fill_in 'search', with: "103\n"
54+
55+
assert_text "GAL 1"
56+
assert_text "GAL 2"
57+
assert_no_text "T1"
58+
4759
fill_in 'search', with: "This subject does not exist\n"
4860

4961
assert_no_text "GAL 1"

0 commit comments

Comments
 (0)