Admin geozones: index, create

Modified Geozone factory and seeds to be more complete
This commit is contained in:
Alberto Miedes Garcés
2016-12-04 20:41:51 +01:00
parent dd406cfeb0
commit 6175990533
11 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
class Admin::GeozonesController < ApplicationController
respond_to :html
load_and_authorize_resource
def index
end
def new
end
def create
@geozone = Geozone.new(geozone_params)
if @geozone.save
redirect_to admin_geozones_path
else
render :new
end
end
private
def geozone_params
params.require(:geozone).permit(:name, :external_code, :census_code)
end
end

View File

@@ -43,6 +43,7 @@ module Abilities
can [:read, :update, :destroy, :summary], SpendingProposal
can [:search, :edit, :update, :create, :index, :destroy], Banner
can [:index, :create], Geozone
end
end
end

View File

@@ -83,6 +83,12 @@
<% end %>
</li>
<li <%= 'class=active' if controller_name == 'geozones' %>>
<%= link_to admin_geozones_path do %>
<span class="icon-settings"></span><%= t('admin.menu.geozones') %>
<% end %>
</li>
<li <%= 'class=active' if controller_name == 'activity' %>>
<%= link_to admin_activity_path do %>
<span class="icon-eye"></span><%= t('admin.menu.activity') %>

View File

@@ -0,0 +1,15 @@
<% if @geozone.errors.any? %>
<div id="error_explanation" data-alert class="callout alert" data-closable>
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
<span aria-hidden="true">&times;</span>
</button>
<strong>
<%= @geozone.errors.count %>
<%= t("admin.geozones.errors.form.error", count: @geozone.errors.count) %>
</strong>
</div>
<% end %>

View File

@@ -0,0 +1,25 @@
<%= form_for [:admin, @geozone] do |f| %>
<%= render 'errors' %>
<div clas="row">
<div class="small-12 medium-6 large-6 column">
<%= f.label :name, t("admin.geozones.geozone.name") %>
<%= f.text_field :name, label: false %>
</div>
<div class="small-12 medium-3 large-3 column">
<%= f.label :external_code, t("admin.geozones.geozone.external_code") %>
<%= f.text_field :external_code, label: false %>
</div>
<div class="small-12 medium-3 large-3 column">
<%= f.label :census_code, t("admin.geozones.geozone.census_code") %>
<%= f.text_field :census_code, label: false %>
</div>
</div>
<div class="row">
<div class="actions small-12 large-3 medium-3 column">
<%= f.submit(class: "button expanded", value: t("admin.geozones.edit.form.submit_button")) %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,24 @@
<%= link_to t("admin.geozones.index.create"),
new_admin_geozone_path, class: "button success float-right" %>
<h2 class="inline-block"><%= t("admin.geozones.index.title") %></h2>
<table>
<thead>
<tr>
<th><%= t("admin.geozones.geozone.name") %></th>
<th><%= t("admin.geozones.geozone.external_code") %></th>
<th><%= t("admin.geozones.geozone.census_code") %></th>
</tr>
</thead>
<tbody>
<% @geozones.each do |geozone| %>
<tr id="<%= dom_id(geozone) %>">
<td><%= geozone.name %></td>
<td><%= geozone.external_code %></td>
<td><%= geozone.census_code %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,13 @@
<div class="geozone-new row">
<div class="small-12 column">
<%= link_to admin_geozones_path, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("admin.geozones.new.back") %>
<% end %>
<h1><%= t("admin.geozones.new.creating") %></h1>
<%= render "form" %>
</div>
</div>

View File

@@ -97,6 +97,7 @@ en:
admin: Admin menu
banner: Manage banners
debate_topics: Debate topics
geozones: Manage geozones
hidden_comments: Hidden comments
hidden_debates: Hidden debates
hidden_proposals: Hidden proposals
@@ -267,6 +268,25 @@ en:
in_evaluation_count: In evaluation
total_count: Total
cost_for_geozone: Cost
geozones:
index:
title: Geozone
create: Create geozone
geozone:
name: Name
external_code: External code
census_code: Census code
errors:
form:
error:
one: "prevented this geozone from being saved"
other: 'prevented this geozone from being saved'
edit:
form:
submit_button: Save changes
new:
back: Volver
creating: Crear distrito
stats:
show:
stats_title: Stats

View File

@@ -95,6 +95,7 @@ es:
admin: Menú de administración
banner: Gestionar banners
debate_topics: Temas de debate
geozones: Gestionar distritos
hidden_comments: Comentarios ocultos
hidden_debates: Debates ocultos
hidden_proposals: Propuestas ocultas
@@ -265,6 +266,25 @@ es:
in_evaluation_count: En evaluación
total_count: Total
cost_for_geozone: Coste total
geozones:
index:
title: Distritos
create: Crear un distrito
geozone:
name: Nombre
external_code: Código externo
census_code: Código del censo
errors:
form:
error:
one: "error impidió guardar el distrito"
other: "errores impidieron guardar el distrito."
edit:
form:
submit_button: Guardar cambios
new:
back: Volver
creating: Crear distrito
stats:
show:
stats_title: Estadísticas

View File

@@ -192,6 +192,8 @@ Rails.application.routes.draw do
namespace :api do
resource :stats, only: :show
end
resources :geozones, only: [:index, :new, :create]
end
namespace :moderation do

View File

@@ -0,0 +1,40 @@
require 'rails_helper'
feature 'Admin geozones' do
background do
login_as(create(:administrator).user)
end
scenario 'Show list of geozones' do
chamberi = create(:geozone, name: 'Chamberí')
retiro = create(:geozone, name: 'Retiro')
visit admin_geozones_path
expect(page).to have_content(chamberi.name)
expect(page).to have_content(retiro.name)
end
scenario 'Create new geozone' do
visit admin_root_path
within('#side_menu') do
click_link "Manage geozones"
end
click_link "Create geozone"
fill_in 'geozone_name', with: 'Fancy District'
fill_in 'geozone_external_code', with: 123
fill_in 'geozone_census_code', with: 44
click_button 'Save changes'
expect(page).to have_content 'Fancy District'
visit admin_geozones_path
expect(page).to have_content 'Fancy District'
end
end