diff --git a/app/controllers/admin/tiny_urls_controller.rb b/app/controllers/admin/tiny_urls_controller.rb new file mode 100644 index 0000000..43df4c3 --- /dev/null +++ b/app/controllers/admin/tiny_urls_controller.rb @@ -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 diff --git a/app/controllers/tiny_urls_controller.rb b/app/controllers/tiny_urls_controller.rb index 9c01144..0dfc313 100644 --- a/app/controllers/tiny_urls_controller.rb +++ b/app/controllers/tiny_urls_controller.rb @@ -2,84 +2,12 @@ class TinyUrlsController < ApplicationController 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 @tiny_url = TinyUrl.find(params[:id]) -@tiny_url.nbr_views = @tiny_url.nbr_views.to_i + 1 -@tiny_url.save + @tiny_url.nbr_views = @tiny_url.nbr_views.to_i + 1 + @tiny_url.save redirect_to @tiny_url.url, :status => 301 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 diff --git a/app/views/admin/admins/_index_block.haml b/app/views/admin/admins/_index_block.haml index 6953fd7..c4cf4d7 100644 --- a/app/views/admin/admins/_index_block.haml +++ b/app/views/admin/admins/_index_block.haml @@ -1,7 +1,7 @@ -%table.stat_table.table.table-striped.table-hover +%table.table.table-striped.table-hover %tr %th{:style => "width:30px"} diff --git a/app/views/admin/admins/show.html.haml b/app/views/admin/admins/show.html.haml deleted file mode 100644 index 3a2a8f2..0000000 --- a/app/views/admin/admins/show.html.haml +++ /dev/null @@ -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 - Login: - =h @user.login - - %p - - Email: - =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 - - - - - diff --git a/app/views/admin/tiny_urls/_form.html.haml b/app/views/admin/tiny_urls/_form.html.haml new file mode 100644 index 0000000..2e5f83e --- /dev/null +++ b/app/views/admin/tiny_urls/_form.html.haml @@ -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" + \ No newline at end of file diff --git a/app/views/admin/tiny_urls/edit.html.haml b/app/views/admin/tiny_urls/edit.html.haml new file mode 100644 index 0000000..69b493e --- /dev/null +++ b/app/views/admin/tiny_urls/edit.html.haml @@ -0,0 +1,3 @@ +%h1 Modifier l'url + += render 'form' diff --git a/app/views/tiny_urls/index.html.haml b/app/views/admin/tiny_urls/index.html.haml similarity index 62% rename from app/views/tiny_urls/index.html.haml rename to app/views/admin/tiny_urls/index.html.haml index d4b26c2..350a18b 100644 --- a/app/views/tiny_urls/index.html.haml +++ b/app/views/admin/tiny_urls/index.html.haml @@ -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 %table.stat_table.table.table-striped.table-hover @@ -15,6 +15,6 @@ %td= tiny_url.url %td= tiny_url.nbr_views %td - = link_to i(:trash), 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(:trash), [:admin, tiny_url], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cette url ? Le lien deviendra mort.' } + = link_to i(:pencil), edit_admin_tiny_url_path(tiny_url) diff --git a/app/views/tiny_urls/new.html.haml b/app/views/admin/tiny_urls/new.html.haml similarity index 53% rename from app/views/tiny_urls/new.html.haml rename to app/views/admin/tiny_urls/new.html.haml index 2f807c2..197e0b1 100644 --- a/app/views/tiny_urls/new.html.haml +++ b/app/views/admin/tiny_urls/new.html.haml @@ -2,5 +2,3 @@ = render 'form' -= link_to 'Back', tiny_urls_path - diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 1695a54..d0f1719 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -53,7 +53,7 @@ %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 diff --git a/app/views/tiny_urls/_form.html.erb b/app/views/tiny_urls/_form.html.erb deleted file mode 100644 index 9b5b1e8..0000000 --- a/app/views/tiny_urls/_form.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%= form_for(@tiny_url) do |f| %> - <% if @tiny_url.errors.any? %> -
-

<%= pluralize(@tiny_url.errors.count, "error") %> prohibited this tiny_url from being saved:

- - -
- <% end %> - -
- <%= f.label :url %>
- <%= f.text_field :url %> -
- -
- <%= f.submit %> -
-<% end %> diff --git a/app/views/tiny_urls/edit.html.haml b/app/views/tiny_urls/edit.html.haml deleted file mode 100644 index 91a5f21..0000000 --- a/app/views/tiny_urls/edit.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -%h1 Modifier l'url - -= render 'form' - -= link_to 'Show', @tiny_url -= link_to 'Back', tiny_urls_path diff --git a/app/views/tiny_urls/show.html.erb b/app/views/tiny_urls/show.html.erb deleted file mode 100644 index a16768a..0000000 --- a/app/views/tiny_urls/show.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -

<%= notice %>

- -

- Url: - <%= @tiny_url.url %> -

- -

- Slug: - <%= @tiny_url.slug %> -

- -

- Start at: - <%= @tiny_url.start_at %> -

- -

- Stop at: - <%= @tiny_url.stop_at %> -

- -

- Nbr views: - <%= @tiny_url.nbr_views %> -

- - -<%= link_to 'Edit', edit_tiny_url_path(@tiny_url) %> | -<%= link_to 'Back', tiny_urls_path %> diff --git a/config/routes.rb b/config/routes.rb index 90f7630..2950c98 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Survey::Application.routes.draw do resources :admins resources :survey_types resources :petitions + resources :tiny_urls end