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

Simple-Twitter Assignment #195

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d9bd87a
project init
Ryan814 Jul 29, 2018
cba35a9
create tweet model
Ryan814 Jul 29, 2018
243c00e
add index action & view for public users
Ryan814 Jul 29, 2018
89b56b8
add tweet index action and view for admin
Ryan814 Jul 29, 2018
ffc3ab3
create user model using devise
Ryan814 Jul 29, 2018
b2c496d
add login process and update view with login messages
Ryan814 Jul 29, 2018
62c762e
set up admin authenticate
Ryan814 Jul 29, 2018
69e1515
add gem carrierwave for uploader image
Ryan814 Jul 30, 2018
e83c34d
create avatar_uploader model for user's avatar
Ryan814 Jul 30, 2018
691f92c
set user model mount_uploader for carrierwave
Ryan814 Jul 30, 2018
5864672
add tweet destroy action and index page for admin
Ryan814 Jul 30, 2018
43ca945
add gem rest-client for uinames
Ryan814 Jul 30, 2018
0e5b66c
connect user and tweet model
Ryan814 Jul 30, 2018
6b9ae22
create fake user and tweet data
Ryan814 Jul 30, 2018
c70c093
add pagination using Kaminari gem
Ryan814 Jul 30, 2018
f076e58
install bootstrap-sass and jquery-rails
Ryan814 Jul 30, 2018
bf72a78
change navbar
Ryan814 Jul 30, 2018
6837a3d
use Alert components for flash and use Dismissible alerts
Ryan814 Jul 30, 2018
a8b0ee4
rails generate kaminari:views bootstrap3
Ryan814 Jul 30, 2018
e42cced
admin can view all tweets and users
Ryan814 Jul 31, 2018
2c65fb9
move authenticate_user! to application_controller.rb
Ryan814 Jul 31, 2018
151a315
add Admin::BaseController and move authenticate_admin here
Ryan814 Jul 31, 2018
7eaf6f5
setup all routes for public
Ryan814 Jul 31, 2018
3ab727a
rails generate reply model
Ryan814 Jul 31, 2018
8a24456
rails generate model followship
Ryan814 Jul 31, 2018
ee533d8
rails generate model like
Ryan814 Jul 31, 2018
7b10c88
setup model connect
Ryan814 Jul 31, 2018
3d2379f
create and styled index page for public
Ryan814 Aug 1, 2018
7a59e8f
user can edit profile
Ryan814 Aug 2, 2018
44658a1
user cand edit their profile
Ryan814 Aug 4, 2018
7e2cbf9
user can follow & unfollow other user
Ryan814 Aug 5, 2018
bcd411a
user can reply tweet and check all replies
Ryan814 Aug 7, 2018
a5268ea
user can tweet from index page
Ryan814 Aug 8, 2018
00442cf
user can like & unlie other user's tweet
Ryan814 Aug 8, 2018
2f79654
user can view all folloing user
Ryan814 Aug 8, 2018
15c81a5
create followers action in users controller
Ryan814 Aug 9, 2018
ac3d491
create likes action in users controller
Ryan814 Aug 9, 2018
7a44c8a
create fake reply followship like action
Ryan814 Aug 9, 2018
44290ac
admin can view all tweet's replies & user profile
Ryan814 Aug 12, 2018
255a869
admin can view user's detail data
Ryan814 Aug 12, 2018
be39718
user can click their image link to edit profile
Ryan814 Aug 12, 2018
4bc67cf
Simple-twitter Assignment
Ryan814 Aug 14, 2018
9d5cdd5
add pg, update Gemfile.lock, change production db to pg
Ryan814 Aug 14, 2018
3f1bd8b
move sqlite3 to test
Ryan814 Aug 14, 2018
df8faa0
setting carrierwave upload to AWS S3
Ryan814 Aug 14, 2018
961c507
fix setting AWS S3
Ryan814 Aug 14, 2018
922e9fb
fix
Ryan814 Aug 14, 2018
6fa13fb
count followers
Ryan814 Aug 15, 2018
99b293c
to fit the assignment's require
Ryan814 Aug 15, 2018
9f57629
to fit assignment's require
Ryan814 Aug 15, 2018
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
35 changes: 23 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

# user authentication
gem 'devise'
# file uploader
gem 'carrierwave'
# resize image size
# gem 'mini_magick'

gem 'ffaker'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'rails', '~> 5.1.6'

# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
Expand All @@ -34,13 +25,28 @@ gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

#for User
gem 'devise'
#for image
gem 'carrierwave'
#for fake data
gem 'ffaker'
# Use uinames
gem 'rest-client'

gem 'kaminari'
gem 'bootstrap-sass', '~> 3.3.7'
gem 'jquery-rails'

gem 'fog-aws'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand All @@ -51,6 +57,7 @@ group :development, :test do
gem 'factory_bot_rails'
gem 'shoulda-matchers', '~> 3.1'
gem 'rails-controller-testing'
gem 'sqlite3'
end

group :development do
Expand All @@ -62,5 +69,9 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :production do
gem 'pg', '~> 0.20'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
87 changes: 60 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ GEM
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
arel (8.0.0)
autoprefixer-rails (8.5.0)
execjs
bcrypt (3.1.12)
bcrypt (3.1.12-java)
bcrypt (3.1.12-x64-mingw32)
bcrypt (3.1.12-x86-mingw32)
bindex (0.5.0)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.3)
byebug (10.0.2)
capybara (2.18.0)
Expand All @@ -69,7 +71,6 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
concurrent-ruby (1.0.5-java)
crass (1.0.4)
devise (4.4.3)
bcrypt (~> 3.0)
Expand All @@ -78,7 +79,10 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.3)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
erubi (1.7.1)
excon (0.62.0)
execjs (2.7.0)
factory_bot (4.10.0)
activesupport (>= 3.0.0)
Expand All @@ -87,16 +91,49 @@ GEM
railties (>= 3.0.0)
ffaker (2.10.0)
ffi (1.9.25)
ffi (1.9.25-java)
ffi (1.9.25-x64-mingw32)
ffi (1.9.25-x86-mingw32)
fog-aws (3.0.0)
fog-core (~> 2.1)
fog-json (~> 1.1)
fog-xml (~> 0.1)
ipaddress (~> 0.8)
fog-core (2.1.0)
builder
excon (~> 0.58)
formatador (~> 0.2)
mime-types
fog-json (1.2.0)
fog-core
multi_json (~> 1.10)
fog-xml (0.1.3)
fog-core
nokogiri (>= 1.5.11, < 2.0.0)
formatador (0.2.5)
globalid (0.4.1)
activesupport (>= 4.2.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.0.1)
concurrent-ruby (~> 1.0)
ipaddress (0.8.3)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -114,19 +151,14 @@ GEM
mini_portile2 (2.3.0)
minitest (5.11.3)
multi_json (1.13.1)
netrc (0.11.0)
nio4r (2.3.1)
nio4r (2.3.1-java)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
nokogiri (1.8.4-java)
nokogiri (1.8.4-x64-mingw32)
mini_portile2 (~> 2.3.0)
nokogiri (1.8.4-x86-mingw32)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
pg (0.21.0)
public_suffix (3.0.2)
puma (3.12.0)
puma (3.12.0-java)
rack (2.0.5)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down Expand Up @@ -164,6 +196,10 @@ GEM
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
Expand Down Expand Up @@ -212,22 +248,19 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
sqlite3 (1.3.13-x64-mingw32)
sqlite3 (1.3.13-x86-mingw32)
sqlite3 (1.3.13-x86-mswin32-60)
thor (0.20.0)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
tilt (2.0.8)
turbolinks (5.1.1)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
tzinfo-data (1.2018.5)
tzinfo (>= 1.0.0)
uglifier (4.1.17)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
warden (1.2.7)
rack (>= 1.0)
web-console (3.6.2)
Expand All @@ -237,32 +270,32 @@ GEM
railties (>= 5.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-driver (0.6.5-java)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
xpath (3.1.0)
nokogiri (~> 1.8)

PLATFORMS
java
ruby
x64-mingw32
x86-mingw32
x86-mswin32

DEPENDENCIES
bootstrap-sass (~> 3.3.7)
byebug
capybara (~> 2.13)
carrierwave
coffee-rails (~> 4.2)
devise
factory_bot_rails
ffaker
fog-aws
jbuilder (~> 2.5)
jquery-rails
kaminari
listen (>= 3.0.5, < 3.2)
pg (~> 0.20)
puma (~> 3.7)
rails (~> 5.1.4)
rails (~> 5.1.6)
rails-controller-testing
rest-client
rspec-rails (~> 3.7)
sass-rails (~> 5.0)
selenium-webdriver
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
//= require rails-ujs
//= require turbolinks
//= require_tree .

//= require jquery
//= require bootstrap-sprockets
4 changes: 4 additions & 0 deletions app/assets/stylesheets/admin/tweets.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<<<<<<< HEAD
// Place all the styles related to the admin/tweets controller here.
=======
// Place all the styles related to the admin::tweets controller here.
>>>>>>> be397184eefc7ef5727e1b450016174fa9246195
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/admin/users.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<<<<<<< HEAD
// Place all the styles related to the admin/users controller here.
=======
// Place all the styles related to the admin::users controller here.
>>>>>>> be397184eefc7ef5727e1b450016174fa9246195
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self

*/

@import "bootstrap-sprockets";
@import "bootstrap";
@import "style";
30 changes: 30 additions & 0 deletions app/assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body {
margin-top: 70px;
}

.tweet-item {
border: 1px solid #ddd;
border-radius: 4px;
padding: 10px;
margin-bottom: 20px;
}

.popu-item {
border: 1px solid #ddd;
border-radius: 4px;
padding: 10px;
margin-bottom: 20px;
}

.user-item {
border: 1px solid #ddd;
border-radius: 4px;
padding: 10px;
margin: 20px ;
height: 250px;
}

.follow-button {
margin-top: 10px;
text-align: right;
}
12 changes: 12 additions & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
class Admin::BaseController < ApplicationController
before_action :authenticate_admin

private

def authenticate_admin
unless current_user.admin?
flash[:alert] = "非工作人員請勿進入!"
redirect_to root_path
end
end

end


13 changes: 13 additions & 0 deletions app/controllers/admin/tweets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
class Admin::TweetsController < Admin::BaseController

def index
@tweets = Tweet.order(created_at: :desc).page(params[:page]).per(10)
end

def destroy
@tweet = Tweet.find(params[:id])

if current_user.admin?
@tweet.destroy
redirect_to admin_root_path
flash[:alert] = "推文已刪除"
else
redirect_to admin_root_path
flash[:alert] = "非禮勿刪"
end
end

end
4 changes: 4 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class Admin::UsersController < Admin::BaseController
before_action :authenticate_admin

def index
@users = User.order(tweets_count: :desc).page(params[:page]).per(10)
end

end
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :authenticate_user!

# 請參考 Devise 文件自訂表單後通過 Strong Parameters 的方法
# https://github.com/plataformatec/devise#strong-parameters
# 注意有 sign_up 和 account_update 兩種參數要處理

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
devise_parameter_sanitizer.permit(:acount_update, keys: [:name])
end

end
Loading