From 1c05473e83c92155d25522b9f8dcea95f9d8ed02 Mon Sep 17 00:00:00 2001 From: Alexandre Arias <apa13@inf.ufpr.br> Date: Tue, 18 Aug 2015 13:20:01 -0300 Subject: [PATCH] fix orientdb connection to highlights management Signed-off-by: Alexandre Arias <apa13@inf.ufpr.br> --- .../management/highlights_controller.rb | 13 +++++-- .../orient_db/highlight_repository.rb | 7 ++-- .../highlights/_form_delete.html.erb | 34 +++++++++++-------- config/routes.rb | 2 +- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/app/controllers/management/highlights_controller.rb b/app/controllers/management/highlights_controller.rb index 967c8b29..355bbb98 100644 --- a/app/controllers/management/highlights_controller.rb +++ b/app/controllers/management/highlights_controller.rb @@ -24,14 +24,21 @@ class Management::HighlightsController < ManagementController def create render :action => 'new' - @name = params[:name] - @url = params[:url] db = OrientDb::HighlightRepository.new - db.insert_data(@name,@url) + db.insert_data(params[:name],params[:url]) + end + + def destroy + params[:name].each do |name| + db = OrientDb::HighlightRepository.new + db.destroy_data(name) + end + redirect_to management_highlights_index_path end + end diff --git a/app/repositories/orient_db/highlight_repository.rb b/app/repositories/orient_db/highlight_repository.rb index 2fde0931..870479c7 100644 --- a/app/repositories/orient_db/highlight_repository.rb +++ b/app/repositories/orient_db/highlight_repository.rb @@ -17,9 +17,10 @@ module OrientDb return nil end - def remove_data - - #return @connection.command "DELETE FROM Highlight (name)" + def destroy_data(name) + return @connection.command "DELETE VERTEX Highlight where name = '#{name}'" + rescue + return nil end end diff --git a/app/views/management/highlights/_form_delete.html.erb b/app/views/management/highlights/_form_delete.html.erb index 13bebe30..74f2c97f 100644 --- a/app/views/management/highlights/_form_delete.html.erb +++ b/app/views/management/highlights/_form_delete.html.erb @@ -6,24 +6,28 @@ <class="ls-title-2"><h3>Remover destaque</h3><br> - <fieldset> + + <%= form_tag(:action => "destroy", :method => "get") do %> + <fieldset> <!-- Exemplo com Radio button --> -<div class="ls-label col-md-5"> - <p>Escolha os destaques a remover:</p> - <% @highlights.each do |highlight| %> - <label class="ls-label-text"> - <input type="radio" name="plataforms"> - <%= highlight['name'] %> - </label> - <%end%> -</div> -</fieldset> + <div class="ls-label col-md-5"> + <p>Escolha os destaques a remover:</p> + <% @highlights.each do |highlight| %> + <label class="ls-label-text"> + <input type="checkbox" name="name[]" value= <%= highlight['name'] %>> + <%= highlight['name'] %> + </label> + <%end%> + </div> + </fieldset> + + <div class="ls-actions-btn"> + <%= submit_tag "Salvar", class: "ls-btn" %> + <%= link_to "Cancelar", management_highlights_index_path, class: "ls-btn-danger" %> + </div> + <%end%> </div> -<div class="ls-actions-btn"> - <button class="ls-btn">Remover</button> - <%= link_to "Cancelar", management_highlights_index_path, class: "ls-btn-danger" %> -</div> </body> diff --git a/config/routes.rb b/config/routes.rb index 4cf78d0b..bf222848 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,7 @@ Rails.application.routes.draw do namespace :management do root 'welcome#index' post 'highlights/create' - + post 'highlights/destroy' end root 'welcome#index' -- GitLab