diff --git a/Gemfile b/Gemfile index 7bbf215..456f87d 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,7 @@ end gem 'rails', '~> 5.1.4' gem 'bootstrap-sass' gem 'will_paginate', '~> 3.1.0' +gem 'faker', '1.7.3' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server diff --git a/Gemfile.lock b/Gemfile.lock index ae4dee6..e8cfde3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,6 +74,8 @@ GEM diff-lcs (1.3) erubi (1.7.0) execjs (2.7.0) + faker (1.7.3) + i18n (~> 0.5) ffi (1.9.21) globalid (0.4.1) activesupport (>= 4.2.0) @@ -214,6 +216,7 @@ DEPENDENCIES byebug capybara (~> 2.13) coffee-rails (~> 4.2) + faker (= 1.7.3) jbuilder (~> 2.5) jquery-rails listen (>= 3.0.5, < 3.2) diff --git a/app/assets/stylesheets/repository.scss b/app/assets/stylesheets/repositories.scss similarity index 81% rename from app/assets/stylesheets/repository.scss rename to app/assets/stylesheets/repositories.scss index b598f6d..5e3bf99 100644 --- a/app/assets/stylesheets/repository.scss +++ b/app/assets/stylesheets/repositories.scss @@ -250,4 +250,66 @@ background-color: #fafbfc; padding: 80px 40px 80px 40px; text-align: center; +} + +.repo-new-heading { + margin-top: 30px; + font-size: 24px; +} + +.new-repository { + width: 700px; +} + +.repo-new-heading-comment { + color: #586069; + padding-bottom: 20px; + margin-bottom: 40px; + border-bottom: 1px solid #dfe2e5; +} + +.list-repositories { + font-size: 24px; + li { + list-style: none; + border-bottom: 1px solid #dfe2e5; + padding-bottom: 20px; + padding-top: 10px; + } +} + +.repository-created-at { + font-size: 14px !important; +} + +.new-button { + border-bottom: 1px solid #dfe2e5; + height: 45px; + button { + text-align: center; + width: 60px; + height: 33px !important; + font-weight: 600!important; + vertical-align: middle; + cursor: pointer; + border: 1px solid rgba(27,31,35,0.2); + border-radius: 5px; + -webkit-appearance: none; + -moz-appearance: none; + background-color: #28a745; + background-image: linear-gradient(-180deg, #34d058 0%, #28a745 90%); + a { + color: #fff; + } + } +} + +.new-repo-form { + input { + width: 250px; + height: 30x; + } + .btn { + width: 200px !important; + } } \ No newline at end of file diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index ba78368..e7bc774 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -334,6 +334,9 @@ input { position: inherit; font-size: 12px; } + a { + color: #dfe2e5; + } } .side-bar-loadmore { @@ -366,7 +369,14 @@ input { } .list-li-repos { - padding-left: 10px; + li { + list-style: none; + padding-left: 10px; + font-weight: bold; + padding-top: 5px; + padding-bottom: 5px; + border-bottom: 1px solid #dfe2e5; + } } .user-photo { @@ -435,8 +445,12 @@ input { width: 313px; height: 110px; margin-bottom: 18px; + margin-left: 5px; padding-left: 15px; padding-top: 15px; + li { + list-style: none; + } } .calendar-box { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7193857..bbfe6a9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,19 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception include SessionsHelper + + def show + @user = User.find(params[:id]) + @repositories = current_user.repositories.paginate(page: params[:page]) + end + + private + + def logged_in_user + unless logged_in? + store_location + flash[:danger] = "Please log in." + redirect_to login_url + end + end end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 2a5d4aa..20cc815 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,4 +1,8 @@ class PullRequestsController < ApplicationController def index + @repositories = current_user.repositories.paginate(page: params[:page]) + end + + def show end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb new file mode 100644 index 0000000..83cfc41 --- /dev/null +++ b/app/controllers/repositories_controller.rb @@ -0,0 +1,44 @@ +class RepositoriesController < ApplicationController + before_action :logged_in_user, only: [:create, :destroy] + before_action :correct_user, only: :destroy + + def index + @repositories = current_user.repositories.paginate(page: params[:page]) + end + + def new + @repository = Repository.new + end + + def show + @repository = Repository.find(params[:id]) + end + + def create + @repository = current_user.repositories.build(repository_params) + if @repository.save + flash[:success] = "Repository created" + redirect_to @repository + end + end + + def edit + end + + def destroy + @repository.destroy + flash[:success] = "Repository deleted" + redirect_to request.referrer || root_url + end + + private + + def repository_params + params.require(:repository).permit(:title) + end + + def correct_user + @repository = current_user.repositories.find_by(id: params[:id]) + redirect_to root_url if @repository.nil? + end +end \ No newline at end of file diff --git a/app/controllers/repository_controller.rb b/app/controllers/repository_controller.rb deleted file mode 100644 index 2b5b680..0000000 --- a/app/controllers/repository_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -class RepositoryController < ApplicationController - def new - end - - def show - end - - def create - end - - def edit - end - - def destroy - end -end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 933208a..419f752 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,9 +2,13 @@ class UsersController < ApplicationController before_action :logged_in_user, only: [:edit, :update, :destroy] before_action :correct_user, only: [:edit, :update] + def profile + @repositories = current_user.repositories.paginate(page: params[:page]) + end + def show @user = User.find(params[:id]) - @repositories = @user.repositories.paginate(page: params[:page]) + @repositories = current_user.repositories.paginate(page: params[:page]) end def new @@ -44,20 +48,12 @@ def destroy private - def user_params - params.require(:user).permit(:name, :email, :password, :password_confirmation) - end - - def logged_in_user - unless logged_in? - store_location - flash[:danger] = "Please log in." - redirect_to login_url + def user_params + params.require(:user).permit(:name, :email, :password, :password_confirmation) end - end - def correct_user - @user = User.find(params[:id]) - redirect_to(root_url) unless current_user?(@user) - end + def correct_user + @user = User.find(params[:id]) + redirect_to(root_url) unless current_user?(@user) + end end \ No newline at end of file diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ac74de8..0110103 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -1,2 +1,3 @@ class PullRequest < ApplicationRecord -end + belongs_to :user +end \ No newline at end of file diff --git a/app/models/repository.rb b/app/models/repository.rb index d9d1d5b..65bd135 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -2,4 +2,5 @@ class Repository < ApplicationRecord belongs_to :user default_scope -> { order(created_at: :desc) } validates :user_id, presence: true + validates :title, presence: true, length: { maximum: 100 } end diff --git a/app/views/layouts/_repo_heading.html.erb b/app/views/layouts/_repo_heading.html.erb index f45a0d5..9978d49 100644 --- a/app/views/layouts/_repo_heading.html.erb +++ b/app/views/layouts/_repo_heading.html.erb @@ -1,13 +1,13 @@
- <%= link_to current_user.name %> / <%= link_to "'name of repository'", "#" %> + <%= link_to current_user.name, current_user %> / <%= link_to @repository.title, @repository %>
-

Repo #1

-

Repo #2

-

Repo #3

-

Repo #4

+