From 21099b2d10cd249884fa15373d05ce85c48d7ad6 Mon Sep 17 00:00:00 2001 From: andreydro Date: Sun, 11 Mar 2018 13:00:01 +0300 Subject: [PATCH] Add-actions-to-repositries-controller --- Gemfile | 1 + Gemfile.lock | 3 + .../{repository.scss => repositories.scss} | 62 ++++++++++ app/assets/stylesheets/users.scss | 16 ++- app/controllers/application_controller.rb | 15 +++ app/controllers/pull_requests_controller.rb | 4 + app/controllers/repositories_controller.rb | 44 +++++++ app/controllers/repository_controller.rb | 16 --- app/controllers/users_controller.rb | 26 ++--- app/models/pull_request.rb | 3 +- app/models/repository.rb | 1 + app/views/layouts/_repo_heading.html.erb | 4 +- app/views/repositories/index.html.erb | 47 ++++++++ app/views/repositories/new.html.erb | 12 ++ app/views/repositories/show.html.erb | 108 ++++++++++++++++++ app/views/repository/new.html.erb | 48 -------- app/views/repository/show.html.erb | 52 --------- app/views/users/profile.html.erb | 47 +++----- app/views/users/show.html.erb | 13 ++- config/routes.rb | 6 +- db/schema.rb | 2 +- db/seeds.rb | 12 +- 22 files changed, 360 insertions(+), 182 deletions(-) rename app/assets/stylesheets/{repository.scss => repositories.scss} (81%) create mode 100644 app/controllers/repositories_controller.rb delete mode 100644 app/controllers/repository_controller.rb create mode 100644 app/views/repositories/index.html.erb create mode 100644 app/views/repositories/new.html.erb create mode 100644 app/views/repositories/show.html.erb delete mode 100644 app/views/repository/new.html.erb delete mode 100644 app/views/repository/show.html.erb 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 %>
    -
  • <%= link_to "Code", repository_path %>
  • +
  • <%= link_to "Code", "#" %>
  • <%= link_to "Issues", issues_path %>
  • <%= link_to "Pull requests", pull_requests_path %>
  • <%= link_to "Projects", "#" %>
  • diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb new file mode 100644 index 0000000..f8a16da --- /dev/null +++ b/app/views/repositories/index.html.erb @@ -0,0 +1,47 @@ +
    +
    +
    +
    +
    +
    + User name +
    +
    + <%= current_user.name %> +
    +
    + Description +
    +
    + <%= current_user.email %> +
    +
    + Organizations +
    +
    +
    + +
    + +
    +
    +
      + <% @repositories.each do |repository| %> +
    • + <%= link_to repository.title, repository %> +
      <%= time_ago_in_words(repository.created_at) %>
      +
    • + <% end %> +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/repositories/new.html.erb b/app/views/repositories/new.html.erb new file mode 100644 index 0000000..9433364 --- /dev/null +++ b/app/views/repositories/new.html.erb @@ -0,0 +1,12 @@ +
    +
    Create a new repository
    +
    A repository contains all the fields for your project, including a revision history
    +
    + <%= form_for(@repository) do |f| %> + <%= f.label 'Repository name' %> + <%= f.text_field :title, class: 'form-control' %> +
    Great repository names are short and memorable
    + <%= f.submit "Create repository", class: "btn btn-primary" %> + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb new file mode 100644 index 0000000..185407e --- /dev/null +++ b/app/views/repositories/show.html.erb @@ -0,0 +1,108 @@ +<%= render partial: 'layouts/repo_heading' %> + +
    User: <%= link_to @repository.user.name, @repository.user %>
    +
    Created repository: "<%= @repository.title %>" <%= time_ago_in_words(@repository.created_at) %> ago.
    + +# repository was just created + +
    +
    + Quick setup - if you've done this kind of thing before +
    or
    +
    + We recommend every repository include a README, LICENSE, and .gitignore +
    +
    +
    + ...or create a new repository on the command line +
    +

    echo "#<%= @repository.title %>" >> README.md

    +

    git init

    +

    git add README.md

    +

    git commit -m "first commit"

    +

    git remote add origin git@gitclub.com:<%= @repository.user.name%>/<%= @repository.title %>.git

    +

    git push -u origin master

    +
    +
    +
    + ...or push an existing repository from command line +
    +

    git remote add origin git@gitclub.com:<%= @repository.user.name%>/<%= @repository.title %>.git

    +

    git push -u origin master

    +
    +
    +
    + ...or import code from another repository +
    + You can initialize this repository with code from Subversion, Mercurial, of TFS project. +
    +
    +
    +
    +
    + + ProTip! + Use the URL for this page when adding GitHub as a remote. +
    +
    +
    + +# repository after first commit + +
    +
    + No description, website, or topics provided + +

    Add topics

    +
    +
    +
      +
    • ? commits
    • +
    • ? branch
    • +
    • ? releases
    • +
    • ? contributor
    • +
    +
    +
    +
    + + + + + + +
    +
    + <%= link_to current_user.name %> "info about last commit" + date of "last" commit +
    +
    +

    + README.md + first commit + 1 day ago +

    +

    + bundler.rb + second commit + 1 day ago +

    +

    + rails.rb + third commit + 1 day ago +

    +
    +
    + README.md +
    +
    + text +
    +
    \ No newline at end of file diff --git a/app/views/repository/new.html.erb b/app/views/repository/new.html.erb deleted file mode 100644 index 3fec4ea..0000000 --- a/app/views/repository/new.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<%= render partial: 'layouts/repo_heading' %> -
    -
    - Quick setup - if you've done this kind of thing before -
    or
    -
    - We recommend every repository include a README, LICENSE, and .gitignore -
    -
    -
    - ...or create a new repository on the command line -
    -

    echo "# repository" >> README.md

    -

    git init

    -

    git add README.md

    -

    git commit -m "first commit"

    -

    git remote add origin git@gitclub.com:user/repository.git

    -

    git push -u origin master

    -
    -
    -
    - ...or push an existing repository from command line -
    -

    git remote add origin git@gitclub.com:user/repository.git

    -

    git push -u origin master

    -
    -
    -
    - ...or import code from another repository -
    - You can initialize this repository with code from Subversion, Mercurial, of TFS project. -
    -
    -
    -
    -
    - - ProTip! - Use the URL for this page when adding GitHub as a remote. -
    -
    -
    \ No newline at end of file diff --git a/app/views/repository/show.html.erb b/app/views/repository/show.html.erb deleted file mode 100644 index 4482109..0000000 --- a/app/views/repository/show.html.erb +++ /dev/null @@ -1,52 +0,0 @@ -<%= render partial: 'layouts/repo_heading' %> -
    -
    - No description, website, or topics provided - -

    Add topics

    -
    -
    -
      -
    • ? commits
    • -
    • ? branch
    • -
    • ? releases
    • -
    • ? contributor
    • -
    -
    -
    -
    - - - - - - -
    -
    - <%= link_to current_user.name %> "info about last commit" - date of "last" commit -
    -
    -

    - README.md - first commit - 1 day ago -

    -

    - bundler.rb - second commit - 1 day ago -

    -

    - rails.rb - third commit - 1 day ago -

    -
    -
    - README.md -
    -
    - text -
    -
    \ No newline at end of file diff --git a/app/views/users/profile.html.erb b/app/views/users/profile.html.erb index 24caff4..efd6a1e 100644 --- a/app/views/users/profile.html.erb +++ b/app/views/users/profile.html.erb @@ -22,8 +22,8 @@
    -
    - <%= link_to "Repo 1", '#' %> -

    Comment

    -

    Language

    -
    -
    - <%= link_to "Repo 2", '#' %> -

    Comment

    -

    Language

    -
    -
    - <%= link_to "Repo 3", '#' %> -

    Comment

    -

    Language

    -
    -
    - <%= link_to "Repo 4", '#' %> -

    Comment

    -

    Language

    -
    -
    - <%= link_to "Repo 5", '#' %> -

    Comment

    -

    Language

    -
    -
    - <%= link_to "Repo 6", '#' %> -

    Comment

    -

    Language

    -
    +
      + <% @repositories.limit(6).each do |repository| %> +
      + +
    • + <%= link_to repository.title, repository %> +
    • +
      +

      Comment

      +

      Language

      +
      + <% end %> +
-

Repo #1

-

Repo #2

-

Repo #3

-

Repo #4

+
    + <% @repositories.limit(6).each do |repository| %> +
  • + <%= link_to repository.title, repository %> +
  • + <% end %> +