Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ gem "faraday"
gem "faraday-follow_redirects"
gem "resend"

gem "lightning_ui_kit"
gem "lightning_ui_kit", github: "k0va1/lightning_ui_kit", branch: "master"
# gem "lightning_ui_kit", path: "../lightning_ui_kit"

group :development, :test do
gem "brakeman"
Expand Down
24 changes: 15 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
GIT
remote: https://github.com/k0va1/lightning_ui_kit.git
revision: 07fd9ae39c2aba63f198466ff10d471447be0781
branch: master
specs:
lightning_ui_kit (0.3.4)
heroicons
rails (>= 8.0.0)
tailwind_merge
view_component

GIT
remote: https://github.com/kodehealth/activejob-uniqueness.git
revision: 548d8a49e72335af066810f9d7e1f51eebac8558
Expand Down Expand Up @@ -172,11 +183,6 @@ GEM
railties (>= 6.0.0)
json (2.18.1)
language_server-protocol (3.17.0.5)
lightning_ui_kit (0.3.3)
heroicons
rails (>= 8.0.0)
tailwind_merge
view_component
lint_roller (1.1.0)
logger (1.7.0)
loofah (2.25.0)
Expand Down Expand Up @@ -390,7 +396,7 @@ GEM
stringio (3.2.0)
strong_migrations (2.5.2)
activerecord (>= 7.1)
tailwind_merge (1.3.3)
tailwind_merge (1.4.0)
sin_lru_redux (~> 2.5)
thor (1.5.0)
timeout (0.6.0)
Expand Down Expand Up @@ -456,7 +462,7 @@ DEPENDENCIES
faraday-follow_redirects
feedjira
jsbundling-rails
lightning_ui_kit
lightning_ui_kit!
minitest-mock (~> 5.27)
mocha (~> 3.0)
pagy
Expand Down Expand Up @@ -537,7 +543,7 @@ CHECKSUMS
jsbundling-rails (1.3.1) sha256=0fa03f6d051c694cbf55a022d8be53399879f2c4cf38b2968f86379c62b1c2ca
json (2.18.1) sha256=fe112755501b8d0466b5ada6cf50c8c3f41e897fa128ac5d263ec09eedc9f986
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
lightning_ui_kit (0.3.3) sha256=c52bdad3219c05f3f40719591cd01da85ddd5518a0150a908df337ca0008e9a8
lightning_ui_kit (0.3.4)
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
loofah (2.25.0) sha256=df5ed7ac3bac6a4ec802df3877ee5cc86d027299f8952e6243b3dac446b060e6
Expand Down Expand Up @@ -627,7 +633,7 @@ CHECKSUMS
stimulus-rails (1.3.4) sha256=765676ffa1f33af64ce026d26b48e8ffb2e0b94e0f50e9119e11d6107d67cb06
stringio (3.2.0) sha256=c37cb2e58b4ffbd33fe5cd948c05934af997b36e0b6ca6fdf43afa234cf222e1
strong_migrations (2.5.2) sha256=06faff4782b24c8a0a4b1a5a1613d809339ff26c5ac135fde75a932a5c9b454e
tailwind_merge (1.3.3) sha256=9073fa69add5e9266609dee759bee333cdfa7bc0704fc577812e50c70b62291b
tailwind_merge (1.4.0) sha256=58009e3f4410dcb7ea6156e15b875e405f0e428f961cda5ee19359fe037933da
thor (1.5.0) sha256=e3a9e55fe857e44859ce104a84675ab6e8cd59c650a49106a05f55f136425e73
timeout (0.6.0) sha256=6d722ad619f96ee383a0c557ec6eb8c4ecb08af3af62098a0be5057bf00de1af
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/admin/article_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module Admin
class ArticleSearchesController < BaseController
def index
if params[:id].present?
article = Article.includes(:blog).find(params[:id])
render json: {id: article.id, title: article.title, url: article.url, summary: article.summary}
article = Article.includes(:blog).find_by(id: params[:id])
return render json: {error: "not found"}, status: :not_found unless article
render json: {id: article.id, title: article.title, url: article.url, description: article.summary}
elsif params[:q].present?
articles = Article.includes(:blog).search_by_title(params[:q]).recent(20)
render json: articles.map { |a|
Expand Down
10 changes: 3 additions & 7 deletions app/controllers/admin/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
module Admin
class ArticlesController < BaseController
before_action :set_article, only: [:show, :edit, :update, :destroy]
include PeriodFilterable

PERIOD_FILTERS = {
"last_week" => 1.week,
"last_2_weeks" => 2.weeks,
"last_month" => 1.month
}.freeze
before_action :set_article, only: [:show, :edit, :update, :destroy]

def index
scope = Article.includes(:blog)
scope = Article.includes(:blog).by_publish_date
scope = scope.where(blog_id: params[:blog_id]) if params[:blog_id].present?

@period = params[:period]
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def index
@total_issues = NewsletterIssue.count
@sent_issues = NewsletterIssue.sent.count
@total_clicks = Click.count
@total_ruby_gems = RubyGem.count
@unprocessed_ruby_gems = RubyGem.unprocessed.count
@total_github_repos = GithubRepo.count
@unprocessed_github_repos = GithubRepo.unprocessed.count
@total_reddit_posts = RedditPost.count
@unprocessed_reddit_posts = RedditPost.unprocessed.count
@recent_issues = NewsletterIssue.order(created_at: :desc).limit(5)
@recent_articles = Article.includes(:blog).order(published_at: :desc).limit(5)
end
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/admin/gem_searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Admin
class GemSearchesController < BaseController
def index
if params[:id].present?
gem = RubyGem.find_by(id: params[:id])
return render json: {error: "not found"}, status: :not_found unless gem
render json: {id: gem.id, title: gem.name, url: gem.project_url, description: gem.info}
elsif params[:q].present?
gems = RubyGem.search_by_name(params[:q]).recent(20)
render json: gems.map { |g|
{value: g.id, label: "#{g.name} (#{g.version})"}
}
else
render json: []
end
end
end
end
20 changes: 20 additions & 0 deletions app/controllers/admin/github_repo_searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Admin
class GithubRepoSearchesController < BaseController
include ActionView::Helpers::NumberHelper

def index
if params[:id].present?
repo = GithubRepo.find_by(id: params[:id])
return render json: {error: "not found"}, status: :not_found unless repo
render json: {id: repo.id, title: repo.full_name, url: repo.url, description: repo.description}
elsif params[:q].present?
repos = GithubRepo.search_by_name(params[:q]).recent(20)
render json: repos.map { |r|
{value: r.id, label: "#{r.full_name} (#{number_with_delimiter(r.stars)} stars)"}
}
else
render json: []
end
end
end
end
62 changes: 62 additions & 0 deletions app/controllers/admin/github_repos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Admin
class GithubReposController < BaseController
include PeriodFilterable

before_action :set_github_repo, only: [:show, :edit, :update, :destroy]

def index
scope = GithubRepo.by_push_date

@period = params[:period]
scope = scope.where("repo_pushed_at >= ?", PERIOD_FILTERS[@period].ago) if PERIOD_FILTERS.key?(@period)

@search = params[:search]
scope = scope.search_by_name(@search) if @search.present?

@pagy, @github_repos = pagy(scope)
end

def show
end

def new
@github_repo = GithubRepo.new
end

def create
@github_repo = GithubRepo.new(github_repo_params)

if @github_repo.save
redirect_to admin_github_repo_path(@github_repo), notice: "GitHub repo created."
else
render :new, status: :unprocessable_content
end
end

def edit
end

def update
if @github_repo.update(github_repo_params)
redirect_to admin_github_repo_path(@github_repo), notice: "GitHub repo updated."
else
render :edit, status: :unprocessable_content
end
end

def destroy
@github_repo.destroy
redirect_to admin_github_repos_path, notice: "GitHub repo deleted."
end

private

def set_github_repo
@github_repo = GithubRepo.find(params[:id])
end

def github_repo_params
params.require(:github_repo).permit(:full_name, :name, :description, :url, :stars, :forks, :language, :owner_name, :owner_avatar_url, :repo_created_at, :repo_pushed_at, :processed, :featured_in_issue, topics: [])
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/newsletter_issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def newsletter_issue_params
:issue_number, :subject, :sent_at, :subscriber_count, :total_clicks, :total_unique_clicks,
newsletter_sections_attributes: [
:id, :title, :position, :_destroy,
newsletter_items_attributes: [:id, :title, :description, :url, :position, :article_id, :_destroy]
newsletter_items_attributes: [:id, :title, :description, :url, :position, :linkable_type, :linkable_id, :_destroy]
]
)
end
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/admin/reddit_post_searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Admin
class RedditPostSearchesController < BaseController
def index
if params[:id].present?
post = RedditPost.find_by(id: params[:id])
return render json: {error: "not found"}, status: :not_found unless post
render json: {id: post.id, title: post.title, url: post.url, description: "r/#{post.subreddit} by #{post.author}"}
elsif params[:q].present?
posts = RedditPost.search_by_title(params[:q]).recent(20)
render json: posts.map { |p|
{value: p.id, label: "#{p.title} (r/#{p.subreddit})"}
}
else
render json: []
end
end
end
end
63 changes: 63 additions & 0 deletions app/controllers/admin/reddit_posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Admin
class RedditPostsController < BaseController
include PeriodFilterable

before_action :set_reddit_post, only: [:show, :edit, :update, :destroy]

def index
scope = RedditPost.by_post_date
scope = scope.from_subreddit(params[:subreddit]) if params[:subreddit].present?

@period = params[:period]
scope = scope.where("posted_at >= ?", PERIOD_FILTERS[@period].ago) if PERIOD_FILTERS.key?(@period)

@search = params[:search]
scope = scope.search_by_title(@search) if @search.present?

@pagy, @reddit_posts = pagy(scope)
end

def show
end

def new
@reddit_post = RedditPost.new
end

def create
@reddit_post = RedditPost.new(reddit_post_params)

if @reddit_post.save
redirect_to admin_reddit_post_path(@reddit_post), notice: "Reddit post created."
else
render :new, status: :unprocessable_content
end
end

def edit
end

def update
if @reddit_post.update(reddit_post_params)
redirect_to admin_reddit_post_path(@reddit_post), notice: "Reddit post updated."
else
render :edit, status: :unprocessable_content
end
end

def destroy
@reddit_post.destroy
redirect_to admin_reddit_posts_path, notice: "Reddit post deleted."
end

private

def set_reddit_post
@reddit_post = RedditPost.find(params[:id])
end

def reddit_post_params
params.require(:reddit_post).permit(:reddit_id, :title, :url, :external_url, :score, :author, :subreddit, :num_comments, :posted_at, :processed, :featured_in_issue)
end
end
end
63 changes: 63 additions & 0 deletions app/controllers/admin/ruby_gems_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Admin
class RubyGemsController < BaseController
include PeriodFilterable

before_action :set_ruby_gem, only: [:show, :edit, :update, :destroy]

def index
scope = RubyGem.by_version_date
scope = scope.where(activity_type: params[:activity_type]) if params[:activity_type].present?

@period = params[:period]
scope = scope.where("version_created_at >= ?", PERIOD_FILTERS[@period].ago) if PERIOD_FILTERS.key?(@period)

@search = params[:search]
scope = scope.search_by_name(@search) if @search.present?

@pagy, @ruby_gems = pagy(scope)
end

def show
end

def new
@ruby_gem = RubyGem.new
end

def create
@ruby_gem = RubyGem.new(ruby_gem_params)

if @ruby_gem.save
redirect_to admin_ruby_gem_path(@ruby_gem), notice: "Gem created."
else
render :new, status: :unprocessable_content
end
end

def edit
end

def update
if @ruby_gem.update(ruby_gem_params)
redirect_to admin_ruby_gem_path(@ruby_gem), notice: "Gem updated."
else
render :edit, status: :unprocessable_content
end
end

def destroy
@ruby_gem.destroy
redirect_to admin_ruby_gems_path, notice: "Gem deleted."
end

private

def set_ruby_gem
@ruby_gem = RubyGem.find(params[:id])
end

def ruby_gem_params
params.require(:ruby_gem).permit(:name, :version, :authors, :info, :downloads, :project_url, :homepage_url, :source_code_url, :version_created_at, :activity_type, :processed, :featured_in_issue)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ArticlesController < ApplicationController
def index
@articles = Article.includes(:blog).recent(15)
@articles = Article.includes(:blog).by_publish_date.recent(15)
end
end
11 changes: 11 additions & 0 deletions app/controllers/concerns/admin/period_filterable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Admin
module PeriodFilterable
extend ActiveSupport::Concern

PERIOD_FILTERS = {
"last_week" => 1.week,
"last_2_weeks" => 2.weeks,
"last_month" => 1.month
}.freeze
end
end
Loading