Clean tiny urls

This commit is contained in:
Nicolas Bally 2013-06-29 22:33:14 +02:00
parent 1f27ce74f9
commit e31190214f
13 changed files with 72 additions and 171 deletions

View File

@ -0,0 +1,54 @@
# -*- encoding : utf-8 -*-
class Admin::TinyUrlsController < ApplicationController
layout "admin"
before_filter :authenticate_admin!
def index
@tiny_urls = TinyUrl.all
end
def new
@tiny_url = TinyUrl.new
end
def edit
@tiny_url = TinyUrl.find(params[:id])
end
def create
@tiny_url = TinyUrl.new(params[:tiny_url])
if @tiny_url.save
redirect_to admin_tiny_urls_url, notice: 'Url courte crée.'
else
render action: "new"
end
end
def update
@tiny_url = TinyUrl.find(params[:id])
if @tiny_url.update_attributes(params[:tiny_url])
redirect_to admin_tiny_urls_url, notice: 'Url courte modifiée.'
else
render action: "edit"
end
end
def destroy
@tiny_url = TinyUrl.find(params[:id])
@tiny_url.destroy
redirect_to admin_tiny_urls_url, :notice => "Url courte supprimée."
end
end

View File

@ -2,20 +2,7 @@
class TinyUrlsController < ApplicationController class TinyUrlsController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_admin!, except: [:show]
# GET /tiny_urls
# GET /tiny_urls.json
def index
@tiny_urls = TinyUrl.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tiny_urls }
end
end
# GET /tiny_urls/1
# GET /tiny_urls/1.json
def show def show
@tiny_url = TinyUrl.find(params[:id]) @tiny_url = TinyUrl.find(params[:id])
@tiny_url.nbr_views = @tiny_url.nbr_views.to_i + 1 @tiny_url.nbr_views = @tiny_url.nbr_views.to_i + 1
@ -23,63 +10,4 @@ class TinyUrlsController < ApplicationController
redirect_to @tiny_url.url, :status => 301 redirect_to @tiny_url.url, :status => 301
end end
# GET /tiny_urls/new
# GET /tiny_urls/new.json
def new
@tiny_url = TinyUrl.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @tiny_url }
end
end
# GET /tiny_urls/1/edit
def edit
@tiny_url = TinyUrl.find(params[:id])
end
# POST /tiny_urls
# POST /tiny_urls.json
def create
@tiny_url = TinyUrl.new(params[:tiny_url])
respond_to do |format|
if @tiny_url.save
format.html { redirect_to tiny_urls_url, notice: 'Tiny url was successfully created.' }
else
format.html { render action: "new" }
end
end
end
# PUT /tiny_urls/1
# PUT /tiny_urls/1.json
def update
@tiny_url = TinyUrl.find(params[:id])
respond_to do |format|
if @tiny_url.update_attributes(params[:tiny_url])
format.html { redirect_to tiny_urls_url, notice: 'Tiny url was successfully updated.' }
else
format.html { render action: "edit" }
end
end
end
# DELETE /tiny_urls/1
# DELETE /tiny_urls/1.json
def destroy
@tiny_url = TinyUrl.find(params[:id])
@tiny_url.destroy
respond_to do |format|
format.html { redirect_to tiny_urls_url }
format.json { head :no_content }
end
end
end end

View File

@ -1,7 +1,7 @@
%table.stat_table.table.table-striped.table-hover %table.table.table-striped.table-hover
%tr %tr
%th{:style => "width:30px"} %th{:style => "width:30px"}

View File

@ -1,31 +0,0 @@
.header
%h1 Détails de l'utilisateur
.back
= link_to "Retour",admin_users_path
.links
= link_to "Modifier", edit_admin_user_path(@user), :class => "lien"
.shadow_box{:style => "padding:10px;"}
%p
<b>Login:</b>
=h @user.login
%p
<b>Email:</b>
=mail_to @user.email
.shadow_box.padding
%h2 Logs
%table.admin_table
-for log in @user.user_logs.find(:all, :order => "created_at DESC")
%tr
%td=l log.created_at
%td=h log.message

View File

@ -0,0 +1,6 @@
= semantic_form_for([:admin, @tiny_url]) do |f|
=f.inputs do
= f.input :url
= f.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,3 @@
%h1 Modifier l'url
= render 'form'

View File

@ -1,4 +1,4 @@
= link_to i(:plus, :icon => false)+' Ajouter une url courte', new_tiny_url_path, :class => "btn" = link_to i(:plus, :icon => false)+' Ajouter une url courte', new_admin_tiny_url_path, :class => "btn"
%h1 Liste des urls courtes %h1 Liste des urls courtes
%table.stat_table.table.table-striped.table-hover %table.stat_table.table.table-striped.table-hover
@ -15,6 +15,6 @@
%td= tiny_url.url %td= tiny_url.url
%td= tiny_url.nbr_views %td= tiny_url.nbr_views
%td %td
= link_to i(:trash), tiny_url, method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cette url ? Le lien deviendra mort.' } = link_to i(:trash), [:admin, tiny_url], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cette url ? Le lien deviendra mort.' }
= link_to i(:pencil), edit_tiny_url_path(tiny_url) = link_to i(:pencil), edit_admin_tiny_url_path(tiny_url)

View File

@ -2,5 +2,3 @@
= render 'form' = render 'form'
= link_to 'Back', tiny_urls_path

View File

@ -53,7 +53,7 @@
%li=link_to "notes", topics_path %li=link_to "notes", topics_path
%li=link_to "urls courtes", tiny_urls_path %li=link_to "urls courtes", admin_tiny_urls_path
%ul.nav.pull-right %ul.nav.pull-right

View File

@ -1,22 +0,0 @@
<%= form_for(@tiny_url) do |f| %>
<% if @tiny_url.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tiny_url.errors.count, "error") %> prohibited this tiny_url from being saved:</h2>
<ul>
<% @tiny_url.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :url %><br />
<%= f.text_field :url %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -1,6 +0,0 @@
%h1 Modifier l'url
= render 'form'
= link_to 'Show', @tiny_url
= link_to 'Back', tiny_urls_path

View File

@ -1,30 +0,0 @@
<p id="notice"><%= notice %></p>
<p>
<b>Url:</b>
<%= @tiny_url.url %>
</p>
<p>
<b>Slug:</b>
<%= @tiny_url.slug %>
</p>
<p>
<b>Start at:</b>
<%= @tiny_url.start_at %>
</p>
<p>
<b>Stop at:</b>
<%= @tiny_url.stop_at %>
</p>
<p>
<b>Nbr views:</b>
<%= @tiny_url.nbr_views %>
</p>
<%= link_to 'Edit', edit_tiny_url_path(@tiny_url) %> |
<%= link_to 'Back', tiny_urls_path %>

View File

@ -10,6 +10,7 @@ Survey::Application.routes.draw do
resources :admins resources :admins
resources :survey_types resources :survey_types
resources :petitions resources :petitions
resources :tiny_urls
end end