Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation #308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Gemfile
@@ -1,6 +1,11 @@
source "https://rubygems.org"

ruby "3.2.3"
# Temporary fix: Could not instal ruby 3.2.3
# Using ruby 3.3.0
ruby ">=3.2.3"

# Added devise for User model and authentication
gem 'devise'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.2"
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Expand Up @@ -78,6 +78,7 @@ GEM
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.6)
bindex (0.8.1)
bootsnap (1.17.1)
Expand All @@ -99,6 +100,12 @@ GEM
debug (1.9.1)
irb (~> 1.10)
reline (>= 0.3.8)
devise (4.9.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
drb (2.2.0)
ruby2_keywords
erubi (1.12.0)
Expand Down Expand Up @@ -153,6 +160,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
Expand Down Expand Up @@ -202,6 +210,9 @@ GEM
regexp_parser (2.9.0)
reline (0.4.2)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand Down Expand Up @@ -233,6 +244,8 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -262,6 +275,7 @@ DEPENDENCIES
bootsnap
capybara
debug
devise
importmap-rails
jbuilder
puma (>= 5.0)
Expand Down
28 changes: 28 additions & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -13,3 +13,31 @@
*= require_tree .
*= require_self
*/

nav {
display: flex;
justify-content: space-between;
align-items: center;
height: 1in;
padding: 0 20px; /* Add padding for better spacing, adjust as needed */

/* Optional: If you want a background color for the nav bar */
background-color: #f0f0f0; /* Adjust color as needed */
}

#hiddenLink {
/* Styling for the Article Encyclopedia link */
text-decoration: none;
}

.nav-button {
/* Styling for all other nav buttons */
margin: 0 10px; /* Add margin for better spacing, adjust as needed */
text-decoration: none;
}

.larger-button {
/* Styling for the larger Article Encyclopedia link */
font-size: 1.2em; /* Adjust font size as needed */
text-decoration: none;
}
59 changes: 59 additions & 0 deletions app/assets/stylesheets/article_search.css
@@ -0,0 +1,59 @@
body {
font-family: 'Arial', sans-serif;
background-color: #f8f8f8; /* Set background color */
color: #333; /* Set text color */
margin: 0;
padding: 20px;
}

h1 {
font-size: 24px;
margin-bottom: 20px;
}

form {
margin-bottom: 20px;
}

input[type="text"] {
width: 100%;
padding: 10px;
font-size: 16px;
margin-bottom: 10px;
box-sizing: border-box;
}

input[type="submit"] {
background-color: #007bff; /* Set button background color */
color: #fff; /* Set button text color */
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
}

input[type="submit"]:hover {
background-color: #0056b3; /* Change button color on hover */
}

#search-results {
margin-top: 20px;
}

#search-results p {
margin-bottom: 10px;
}

#search-results a {
color: #007bff; /* Set link color */
text-decoration: none;
}

#search-results a:hover {
text-decoration: underline;
}

#no-articles-found {
color: #888; /* Set color for the message when no articles are found */
}

29 changes: 29 additions & 0 deletions app/assets/stylesheets/home.css
@@ -0,0 +1,29 @@
body {
font-family: 'Arial', sans-serif;
background-color: #f8f8f8; /* Set background color */
color: #333; /* Set text color */
margin: 0;
padding: 20px;
}

h1 {
font-size: 36px;
color: #007bff; /* Set heading color */
margin-bottom: 20px;
}

p {
font-size: 18px;
line-height: 1.6;
margin-bottom: 20px;
}

a {
color: #007bff; /* Set link color */
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

63 changes: 63 additions & 0 deletions app/controllers/articles_controller.rb
@@ -0,0 +1,63 @@
class ArticlesController < ApplicationController
before_action :authenticate_user!, only: [:article_repository]

def index
@articles = Article.all
end

def show
@article = Article.find(params[:id])
end

def new
@article = Article.new
end

def edit
@article = Article.find(params[:id])
end

def create
@article = Article.new(article_params)
if @article.save
redirect_to @article, notice: 'Article was successfully created.'
else
render :new, status: :unprocessable_entity
end
end

def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to article_url(@article), notice: "Article was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end

def destroy
@article = Article.find(params[:id])
@article.destroy!
redirect_to article_repository_path, notice: "Article was successfully destroyed."
end

def article_repository
@user_articles = current_user.articles
end

def article_search
@search_query = params[:query]
begin
@search_results = Article.search(@search_query)
rescue ActiveRecord::RecordNotFound
flash[:alert] = "No articles found"
@search_results = []
end
end

private
# Only allow a list of trusted parameters through.
def article_params
params.require(:article).permit(:user_id, :title, :content, :author, :date)
end
end
4 changes: 4 additions & 0 deletions app/controllers/pages_controller.rb
@@ -0,0 +1,4 @@
class PagesController < ApplicationController
def home
end
end
2 changes: 2 additions & 0 deletions app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
module ArticlesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/pages_helper.rb
@@ -0,0 +1,2 @@
module PagesHelper
end
8 changes: 8 additions & 0 deletions app/models/article.rb
@@ -0,0 +1,8 @@
class Article < ApplicationRecord
belongs_to :user

def self.search(query)
where("title LIKE ? OR content LIKE ? OR author LIKE ? OR date LIKE ?",
"%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%")
end
end
7 changes: 7 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,7 @@
class User < ApplicationRecord
has_many :articles
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
23 changes: 23 additions & 0 deletions app/views/articles/_article.html.erb
@@ -0,0 +1,23 @@
<div id="<%= dom_id article %>">

<p>
<strong>Title:</strong>
<%= article.title %>
</p>

<p>
<strong>Content:</strong>
<%= article.content %>
</p>

<p>
<strong>Author:</strong>
<%= article.author %>
</p>

<p>
<strong>Date:</strong>
<%= article.date %>
</p>

</div>
39 changes: 39 additions & 0 deletions app/views/articles/_form.html.erb
@@ -0,0 +1,39 @@
<%= form_with(model: article) do |form| %>
<% if article.errors.any? %>
<div style="color: red">
<h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

<ul>
<% article.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<%= form.hidden_field :user_id, value: current_user.id %>

<div>
<%= form.label :title, style: "display: block" %>
<%= form.text_field :title %>
</div>

<div>
<%= form.label :content, style: "display: block" %>
<%= form.text_area :content %>
</div>

<div>
<%= form.label :author, style: "display: block" %>
<%= form.text_field :author %>
</div>

<div>
<%= form.label :date, style: "display: block" %>
<%= form.date_field :date %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
23 changes: 23 additions & 0 deletions app/views/articles/article_repository.html.erb
@@ -0,0 +1,23 @@
<h1>My Articles</h1>

<% if @user_articles.any? %>
<div id="articles">
<% @user_articles.each do |article| %>
<p>
<strong>Title:</strong>
<%= article.title %>
</p>

<p>
<strong>Content:</strong>
<%= article.content %>
</p>

<p>
<%= link_to "Show this article", article %>
</p>
<% end %>
</div>
<% else %>
<p>Article repository is empty. No previous articles written.</p>
<% end %>
25 changes: 25 additions & 0 deletions app/views/articles/article_search.html.erb
@@ -0,0 +1,25 @@
<h1>Article Search</h1>

<%= form_with(url: article_search_path, method: :get) do |form| %>
<%= form.text_field :query, placeholder: 'Search articles...' %>
<%= form.submit 'Search' %>
<% end %>

<%= form_with(url: article_search_path, method: :get) do |form| %>
<%= form.submit 'Clear Search', name: 'clear_search' %>
<% end %>

<% if params[:query].present? %>
<div id="search-results">
<% if @search_results.any? %>
<% @search_results.each do |article| %>
<%= render article %>
<p>
<%= link_to "Show this article", article %>
</p>
<% end %>
<% else %>
<p>No articles found.</p>
<% end %>
</div>
<% end %>