Skip to content

Commit

Permalink
Merge pull request #251 from mumuki/feature-improve-categories-page
Browse files Browse the repository at this point in the history
Feature improve categories page
  • Loading branch information
flbulgarelli committed Jul 10, 2015
2 parents b6a890c + 716f2c4 commit 5fb59cc
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 22 deletions.
3 changes: 2 additions & 1 deletion app/admin/category.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ActiveAdmin.register Category do

permit_params :name, :description, :locale, :image_url
permit_params :name, :position, :description, :locale, :image_url

filter :name
filter :description
Expand All @@ -11,6 +11,7 @@
index do
column(:id)
column(:name)
column(:position)
column(:description)
column(:locale)
column(:image_url)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CategoriesController < ApplicationController
def index
@categories = Category.at_locale
@categories = Category.at_locale.order(:position)
end
end
12 changes: 11 additions & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
class Category < ActiveRecord::Base

include WithLocale
include WithMarkup

has_many :paths

validates_presence_of :name, :description, :image_url

markup_on :description

def single_path?
paths.size == 1
end

def single_path
paths.first
end
end
20 changes: 12 additions & 8 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
<hr>

<p>
<%= it.description %>
<%= it.description_html %>
</p>

<p>
<strong><%= t :category_languages_availability %> </strong>
</p>
<% it.paths.each do |path| %>
<a href="<%= guide_path(path.first_guide) %>" class="btn btn-success">
<%= image_tag path.language.image_url, height: 32 %> <%= path.language.name %>
</a>
<% if it.single_path? %>
<%= link_to t(:start_practicing), it.single_path.first_guide, class: 'btn btn-success'%>
<% else %>
<p>
<strong><%= t :category_languages_availability %> </strong>
</p>
<% it.paths.each do |path| %>
<a href="<%= guide_path(path.first_guide) %>" class="btn btn-success">
<%= image_tag path.language.image_url, height: 32 %> <%= path.language.name %>
</a>
<% end %>
<% end %>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ es:
cancel: Cancelar
categories_index_title: ¿Qué te gustaría aprender?
category: Categoría
category_languages_availability: Disponible en los siguientes lenguajes
category_languages_availability: ¡Elegí el lenguaje que querés usar!
collaborators_refreshed: Lista de collaboradores actualizada
comma_or_tab_separated: Separados por tab o coma!
continue_practicing: ¡Seguí practicando!
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20150708212022_add_position_to_category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPositionToCategory < ActiveRecord::Migration
def change
add_column :categories, :position, :integer, default: 0, null: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeCategoryDescriptionToText < ActiveRecord::Migration
def change
change_column :categories, :description, :text
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150701212609) do
ActiveRecord::Schema.define(version: 20150708212836) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -59,11 +59,12 @@

create_table "categories", force: true do |t|
t.string "name"
t.string "description"
t.text "description"
t.string "locale"
t.string "image_url"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "position", default: 0, null: false
end

create_table "collaborators", force: true do |t|
Expand Down
40 changes: 32 additions & 8 deletions spec/features/standard_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,51 @@
feature 'Standard Flow' do
let(:haskell) { create(:haskell) }
let!(:exercises) {
create(:exercise, title: 'Succ', guide: guide, position: 1, description: 'Description of foo')
create(:exercise, title: 'Succ', guide: guide, position: 1, description: 'Description of foo')
}
let!(:category) { create(:category, name: 'Functional Programming') }
let!(:path) { create(:path, category: category, language: haskell) }
let!(:guide) { create(:guide, name: 'getting-started', description: 'An awesome guide',
language: haskell, position: 1, path: path) }

scenario 'do a guide for first time, starting from home' do

before do
visit '/'
end

context 'single path' do
scenario 'do a guide for first time, starting from home' do
within('.jumbotron') do
click_on 'Start Practicing!'
end

within('.category-panel') do
click_on 'Start Practicing!'
end

within('.jumbotron') do
click_on 'Start Practicing!'
expect(page).to have_text('Succ')
end
end

within('.category-panel') do
click_on 'haskell'
end
context 'multiple paths' do
let(:js) { create(:language, name: 'js') }
let!(:path_js) { create(:path, category: category, language: js) }
let!(:guide_js) { create(:guide, name: 'getting-started-js', description: 'An awesome JS guide',
language: js, position: 1, path: path_js) }

scenario 'do a guide for first time, starting from home' do
within('.jumbotron') do
click_on 'Start Practicing!'
end

click_on 'Start Practicing!'
within('.category-panel') do
click_on 'haskell'
end

expect(page).to have_text('Succ')
click_on 'Start Practicing!'
expect(page).to have_text('Succ')
end
end


Expand Down

0 comments on commit 5fb59cc

Please sign in to comment.