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

Make learning materials page CRUD using the Rails Admin gem #87

Open
wants to merge 11 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ gem 'image_processing', '~> 1.2'
gem 'jbuilder' # Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jsbundling-rails' # Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem 'mini_magick', '~> 4.12'
# Motor Admin allows you to deploy a no-code admin panel for your application in less than a minute
gem 'motor-admin', '~> 0.4.7'
gem 'pg', '~> 1.1' # Use postgresql as the database for Active Record
gem 'premailer-rails', '~> 1.12' # This gem is a drop in solution for styling HTML emails with CSS
gem 'puma', '~> 5.0' # Use the Puma web server [https://github.com/puma/puma]
Expand Down Expand Up @@ -66,7 +64,11 @@ group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem 'capybara'
gem 'faker', '~> 3.1'
gem 'rspec-rails', '~> 6.1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i myself prefer Rspec too, if we are going with Rspec, then we need to remove minitest, or make it clear which one we should be using on the project! @JudahSan @banta should we keep Rspec over Minitest?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw i'm aware that replacing minitest with rspec will also mean updating the github action to actually run the tests and move any minitest already written

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to your opinions on this @banta and @JudahSan

gem 'selenium-webdriver'
gem 'simplecov', require: false # Code coverage analysis tool for ruby
gem 'webdrivers'
end

gem 'rails_admin', '~> 3.1'
gem 'sassc-rails'
70 changes: 53 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ GEM
globalid (>= 0.3.6)
activemodel (7.0.3)
activesupport (= 7.0.3)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (7.0.3)
activemodel (= 7.0.3)
activesupport (= 7.0.3)
Expand All @@ -75,11 +79,7 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
ar_lazy_preload (1.1.2)
rails (>= 5.2)
ast (2.4.2)
audited (5.3.2)
activerecord (>= 5.0, < 7.1)
aws-eventstream (1.2.0)
aws-partitions (1.721.0)
aws-sdk-core (3.170.0)
Expand Down Expand Up @@ -149,19 +149,15 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.5.1)
digest (3.1.0)
docile (1.4.0)
dockerfile-rails (1.2.5)
rails
erubi (1.10.0)
et-orbi (1.2.7)
tzinfo
faker (3.1.0)
i18n (>= 1.8.11, < 2)
ffi (1.15.5)
fugit (1.8.1)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
globalid (1.0.0)
activesupport (>= 5.0)
htmlentities (4.3.4)
Expand All @@ -180,6 +176,18 @@ GEM
jsbundling-rails (1.0.2)
railties (>= 6.0.0)
json (2.6.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
Expand All @@ -195,13 +203,8 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.2)
minitest (5.15.0)
motor-admin (0.4.7)
ar_lazy_preload (~> 1.0)
audited (~> 5.0)
cancancan (~> 3.0)
fugit (~> 1.0)
rails (>= 5.2)
msgpack (1.5.2)
nested_form (0.3.2)
net-imap (0.2.3)
digest
net-protocol
Expand Down Expand Up @@ -242,7 +245,6 @@ GEM
public_suffix (4.0.7)
puma (5.6.4)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.6.0)
rack (2.2.3.1)
rack-test (1.1.0)
Expand All @@ -266,6 +268,12 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
rails_admin (3.1.2)
activemodel-serializers-xml (>= 1.0)
kaminari (>= 0.14, < 2.0)
nested_form (~> 0.3)
rails (>= 6.0, < 8)
turbo-rails (~> 1.0)
railties (7.0.3)
actionpack (= 7.0.3)
activesupport (= 7.0.3)
Expand All @@ -283,6 +291,23 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.51.0)
json (~> 2.3)
parallel (~> 1.10)
Expand All @@ -307,6 +332,14 @@ GEM
ffi (~> 1.12)
ruby_http_client (3.5.5)
rubyzip (2.3.2)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.2.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
Expand Down Expand Up @@ -346,6 +379,7 @@ GEM
railties (>= 6.0.0)
strscan (3.0.3)
thor (1.2.1)
tilt (2.3.0)
timeout (0.3.0)
turbo-rails (1.1.1)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -401,15 +435,17 @@ DEPENDENCIES
jsbundling-rails
letter_opener
mini_magick (~> 4.12)
motor-admin (~> 0.4.7)
pg (~> 1.1)
premailer-rails (~> 1.12)
puma (~> 5.0)
rails (~> 7.0.3)
rails_admin (~> 3.1)
redis (~> 4.0)
rspec-rails (~> 6.1)
rubocop (~> 1.51.0)
rubocop-performance (~> 1.18)
rubocop-rails (~> 2.19.1)
sassc-rails
selenium-webdriver
sendgrid-actionmailer (~> 3.2)
simple_form (~> 5.1)
Expand Down
Binary file added app/assets/images/learningmaterialsthumbnail.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 24 additions & 15 deletions app/assets/stylesheets/mailgun_mails.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
font-size: 14px;
}

/* Add CSS variable for repetitive colors */

:root {
--red: #D0021B;
--lightblue: #348eda;
--orange: #ff9f00;
--lightgreen: #68B90F;
}

img {
max-width: 100%;
}
Expand Down Expand Up @@ -136,15 +145,15 @@ p li, ul li, ol li {
LINKS & BUTTONS
------------------------------------- */
a {
color: #348eda;
color: var(--lightblue);
text-decoration: underline;
}

.btn-primary {
text-decoration: none;
color: #FFF;
background-color: #348eda;
border: solid #348eda;
background-color: var(--lightblue);
border: solid var(--lightblue);
border-width: 10px 20px;
line-height: 2em;
/* 2em * 14px = 28px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
Expand All @@ -160,9 +169,9 @@ a {
.btn-warning {
text-decoration: none;
color: #FFF;
background-color: #ff9f00;
border: solid #ff9f00;
border-color: #ff9f00;
background-color: var(--orange);
border: solid var(--orange);
border-color: var(--orange);
border-width: 10px 20px;
line-height: 2em;
/* 2em * 14px = 28px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
Expand All @@ -178,9 +187,9 @@ a {
.btn-success {
text-decoration: none;
color: #FFF;
background-color: #68B90F;
border: solid #68B90F;
border-color: #68B90F;
background-color: var(--lightgreen);
border: solid var(--lightgreen);
border-color: var(--lightgreen);
border-width: 10px 20px;
line-height: 2em;
/* 2em * 14px = 28px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
Expand All @@ -196,9 +205,9 @@ a {
.btn-danger {
text-decoration: none;
color: #FFF;
background-color: #D0021B;
border: solid #D0021B;
border-color: #D0021B;
background-color: var(--red);
border: solid var(--red);
border-color: var(--red);
border-width: 10px 20px;
line-height: 2em;
/* 2em * 14px = 28px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
Expand Down Expand Up @@ -257,13 +266,13 @@ a {
font-size: 16px;
}
.alert.alert-warning {
background-color: #FF9F00;
background-color: var(--orange);
}
.alert.alert-bad {
background-color: #D0021B;
background-color: var(--red);
}
.alert.alert-good {
background-color: #68B90F;
background-color: var(--lightgreen);
}

/* -------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/learning_materials_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
Nemwel-Boniface marked this conversation as resolved.
Show resolved Hide resolved

class LearningMaterialsController < ApplicationController
skip_before_action :authenticate_user!, only: %i[index]

def index
@learning_materials = LearningMaterial.includes(:thumbnail_blob).all
@learning_materials_with_thumbnails = @learning_materials.select do |learning_material|
learning_material.thumbnail.attached?
end
@random_learning_materials = @learning_materials_with_thumbnails.sample(2)
@learning_materials_with_or_without_thumbnails = @learning_materials - @random_learning_materials
end
end
4 changes: 4 additions & 0 deletions app/helpers/learning_materials_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module LearningMaterialsHelper
end
15 changes: 15 additions & 0 deletions app/models/learning_material.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class LearningMaterial < ApplicationRecord
# Associations
belongs_to :user
has_one_attached :thumbnail

# Enum
enum tag: { beginners: 0, intermediates: 1, experts: 2 }

# Validations
validates :tag, :learning_material_title, :learning_material_description, :learning_material_link, presence: true
validates :learning_material_link,
format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), message: :invalid_url }
end
16 changes: 0 additions & 16 deletions app/models/motor/ability.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class User < ApplicationRecord
# Associations
has_many :users_chapters, dependent: :nullify
has_many :chapters, through: :users_chapters
has_many :learning_materials, dependent: :nullify

# Callbacks
before_create :set_defaults # Set model defaults before create
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<li><%= link_to 'Chapters', chapters_path %></li>

<li><%= link_to 'Learning materials', landing_learn_path %></li>
<li><%= link_to 'Learning materials', learning_materials_path %></li>

<% if FeatureFlag.find_by(name: 'projects').try(:enabled) %>
<li><%= link_to 'Projects', '#' %></li>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<li><a href="#">Projects</a></li>
<% end %>

<li><%= link_to 'Learning Materials', landing_learn_path %></li>
<li><%= link_to 'Learning Materials', learning_materials_path %></li>

<% if user_signed_in? %>
<li><%= button_to "Sign out", destroy_user_session_path, method: :delete %></li>
Expand Down Expand Up @@ -85,7 +85,7 @@
</a>
<% end %>

<%= link_to 'Learning Materials', landing_learn_path,
<%= link_to 'Learning Materials', learning_materials_path,
class: 'text-sm font-small text-gray-500 hover:text-red-600' %>
</nav>
<% if user_signed_in? %>
Expand Down
Loading
Loading