Merge remote-tracking branch 'remotes/origin/projects_search' into fixes

# Conflicts:
#	app/views/favorites/projects.html.erb
#	db/schema.rb
This commit is contained in:
Pfingstfrosch 2020-05-31 13:16:56 +02:00
commit 831c78a3ff
8 changed files with 77 additions and 11 deletions

View File

@ -35,7 +35,14 @@ class FavoritesController < ApplicationController
end end
def projects def projects
@favorite_projects = FavoriteProject.where('user_id': current_user.id)
.order(sort_column + " " + sort_direction)
@host = 'https://tiss.tuwien.ac.at'
end
def delete_project
FavoriteProject.find_by(id: params[:id]).destroy
redirect_back(fallback_location: projects)
end end
private private

View File

@ -0,0 +1,5 @@
class FavoriteProject < ApplicationRecord
self.primary_key = 'id'
validates :id, uniqueness: true
end

View File

@ -1,11 +1,34 @@
<%= render(:partial => "nav")%> <%= render(:partial => "nav") %>
<h1>Favorite Projects</h1> <h1>Favorite Projects</h1>
<p>Not implemented yet!</p> <% if !@favorite_projects[0].blank? %>
<div class="table_wrapper">
<%# if !@favorite_theses[0].blank? %> <table>
<tr>
<%# else %> <th><%= sortable "Title", "title" %></th>
<!-- No favorite projects added yet!--> <th><%= sortable "Registration Date", "created_at" %></th>
<%# end %> <th></th>
<th></th>
</tr>
<% for project in @favorite_projects %>
<tr>
<td>
<%= project['title'] %>
</td>
<td>
<%= project['created_at'] %>
</td>
<td>
<%= button_to 'Details', crawlers_projects_crawler_show_detail_url(:id => project['id']) %>
</td>
<td>
<%= button_to 'Delete', {:action => "delete_project", :id => project['id']}, :method => 'delete' %>
</td>
</tr>
<% end %>
</table>
</div>
<% else %>
No favorite projects added yet!
<% end %>

View File

@ -48,7 +48,7 @@ Rails.application.routes.draw do
get 'theses' get 'theses'
delete 'delete_thesis' delete 'delete_thesis'
get 'projects' get 'projects'
delete 'delete_projects' delete 'delete_project'
end end
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

View File

@ -0,0 +1,12 @@
class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
def change
create_table :favorite_projects, id: false do |t|
t.integer :id, null: false
t.integer :user_id, null: false
t.string :title
t.timestamps
end
add_index :favorite_projects, :id, unique: true
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_05_29_142235) do ActiveRecord::Schema.define(version: 2020_05_29_081537) do
create_table "favorite_courses", force: :cascade do |t| create_table "favorite_courses", force: :cascade do |t|
t.string "number", null: false t.string "number", null: false
@ -33,7 +33,8 @@ ActiveRecord::Schema.define(version: 2020_05_29_142235) do
t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true
end end
create_table "favorite_projects", force: :cascade do |t| create_table "favorite_projects", id: false, force: :cascade do |t|
t.integer "id", null: false
t.integer "user_id", null: false t.integer "user_id", null: false
t.string "title" t.string "title"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false

11
test/fixtures/favorite_projects.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@ -0,0 +1,7 @@
require 'test_helper'
class FavoriteProjectTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end