From f6bb5102c7bf5607fea8d8fc77a0b5c99868591f Mon Sep 17 00:00:00 2001 From: somenickname Date: Wed, 14 Nov 2018 20:57:11 +0200 Subject: [PATCH 1/6] add header and logout link --- app/controllers/application_controller.rb | 4 ++++ app/controllers/sessions_controller.rb | 10 +++++++++- app/views/layouts/_header.html.erb | 9 +++++++++ app/views/layouts/application.html.erb | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/views/layouts/_header.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 05ff14f..59b01d0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,10 @@ def require_user redirect_to new_session_path unless current_user end + def require_guess + redirect_to tasks_path if current_user + end + def current_user @current_user ||= User.find_by(id: session[:user_id]) end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 443a9cd..5512e30 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,4 +1,6 @@ class SessionsController < ApplicationController + before_action :require_guess, except: :destroy + def new @user = User.new end @@ -8,11 +10,17 @@ def create @user ||= User.create(user_params) if @user.valid? && @user.authenticate(user_params[:password]) session[:user_id] = @user.id - redirect_to tasks_path + redirect_to root_path end end + def destroy + session[:user_id] = nil + redirect_to new_session_path + end + private + def user_params params.require(:user).permit(:name, :password) end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb new file mode 100644 index 0000000..cb4aa4c --- /dev/null +++ b/app/views/layouts/_header.html.erb @@ -0,0 +1,9 @@ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cb8067c..4c3be6f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,6 +11,7 @@ + <%= render 'layouts/header' %>
<%= yield %>
From aa0fa9a30b1eb0d82c32e8132a38122593d26fab Mon Sep 17 00:00:00 2001 From: somenickname Date: Thu, 15 Nov 2018 14:15:12 +0200 Subject: [PATCH 2/6] kaminari pagination --- Gemfile | 1 + Gemfile.lock | 13 +++++++++++++ app/controllers/tasks_controller.rb | 2 +- app/models/task.rb | 6 +++++- app/views/tasks/index.html.erb | 26 ++++++++++++++------------ app/views/tasks/index.js.erb | 2 ++ 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 76f9a44..af02a67 100644 --- a/Gemfile +++ b/Gemfile @@ -62,3 +62,4 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock index d59203c..3b07d7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,6 +96,18 @@ GEM 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) @@ -215,6 +227,7 @@ DEPENDENCIES coffee-rails (~> 4.2) jbuilder (~> 2.5) jquery-rails + kaminari listen (>= 3.0.5, < 3.2) puma (~> 3.11) rails (~> 5.2.1) diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index bf173b5..44e5398 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -3,7 +3,7 @@ class TasksController < ApplicationController def index @task = Task.new - @tasks = current_user.tasks.q(params[:q]) + @tasks = current_user.tasks.search(params[:q]).get_page(params[:page].to_i) end def create diff --git a/app/models/task.rb b/app/models/task.rb index 32a20ab..8928a24 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -1,4 +1,6 @@ class Task < ApplicationRecord + DEFAULT_PAGE_SIZE = 10 + belongs_to :user validates :title, presence: true @@ -7,5 +9,7 @@ class Task < ApplicationRecord validates :expire_at, inclusion: { in: (Date.today..Date.today+5.years) } enum status: %i(todo done) - scope :q, ->(q) { where("title LIKE '%#{q}%'") if q } + scope :search, ->(search_query) { where("title LIKE '%#{search_query}%'") if search_query } + + scope :get_page, ->(cur_page, size = DEFAULT_PAGE_SIZE) { page(cur_page).per(size) if cur_page } end diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb index 15095f2..6ac1e6f 100644 --- a/app/views/tasks/index.html.erb +++ b/app/views/tasks/index.html.erb @@ -1,20 +1,22 @@
-

New Task

+

New Task

- <%= render 'form' %> + <%= render 'form' %>
-

Tasks

+

Tasks

- <%= form_tag tasks_path, method: :get, remote: true do |f| %> - <%= text_field_tag :q, params[:q], placeholder: 'Search', class: 'search' %> - <% end %> + <%= form_tag tasks_path, method: :get, remote: true do |f| %> + <%= text_field_tag :q, params[:q], placeholder: 'Search', class: 'search form-control' %> + <% end %> - -
    - <%= render partial: 'task', collection: @tasks %> -
+
+
    + <%= render partial: 'task', collection: @tasks %> +
+
+ <%= paginate(@tasks, remote: true) %> +
+
- - diff --git a/app/views/tasks/index.js.erb b/app/views/tasks/index.js.erb index b922937..5771240 100644 --- a/app/views/tasks/index.js.erb +++ b/app/views/tasks/index.js.erb @@ -1 +1,3 @@ document.querySelector('ul.tasks-list').innerHTML = "<%= j(render @tasks) %>" + +document.querySelector('.tasks-pagination').innerHTML = "<%= j(paginate(@tasks, remote: true)) %>" From 6b295696fceef990c148aaf2929c52f6fe945d92 Mon Sep 17 00:00:00 2001 From: somenickname Date: Thu, 22 Nov 2018 22:06:41 +0200 Subject: [PATCH 3/6] send welcome email --- .gitignore | 2 ++ Gemfile | 1 + Gemfile.lock | 3 +++ app/controllers/sessions_controller.rb | 12 +++++++++--- app/mailers/user_mailer.rb | 9 +++++++++ app/views/sessions/_form.html.erb | 3 +++ app/views/user_mailer/welcome_email.html.erb | 14 ++++++++++++++ app/views/user_mailer/welcome_email.text.erb | 10 ++++++++++ config/environments/development.rb | 14 +++++++++++++- db/migrate/20181120184825_add_email_to_users.rb | 5 +++++ db/schema.rb | 3 ++- 11 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 app/mailers/user_mailer.rb create mode 100644 app/views/user_mailer/welcome_email.html.erb create mode 100644 app/views/user_mailer/welcome_email.text.erb create mode 100644 db/migrate/20181120184825_add_email_to_users.rb diff --git a/.gitignore b/.gitignore index 388fdca..3e13ae4 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +/config/application.yml diff --git a/Gemfile b/Gemfile index f6f2fc8..01bc9a3 100644 --- a/Gemfile +++ b/Gemfile @@ -64,3 +64,4 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'kaminari' +gem "figaro" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 9a018e3..69843f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,6 +84,8 @@ GEM erubi (1.7.1) execjs (2.7.0) ffi (1.9.25) + figaro (1.1.1) + thor (~> 0.14) globalid (0.4.1) activesupport (>= 4.2.0) i18n (1.1.1) @@ -226,6 +228,7 @@ DEPENDENCIES capybara (>= 2.15) chromedriver-helper coffee-rails (~> 4.2) + figaro jbuilder (~> 2.5) jquery-rails kaminari diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index edf9cc1..a4160c1 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -5,8 +5,13 @@ def new end def create - @user = User.find_by(name: user_params[:name]) - @user ||= User.create(user_params) + @existed_user = User.find_by(name: user_params[:name]) + @user = @existed_user ? @existed_user : User.create(user_params) + + if (user_params[:email] && !@existed_user) + UserMailer.welcome_email(@user).deliver_later + end + if @user.valid? && @user.authenticate(user_params[:password]) session[:user_id] = @user.id redirect_to tasks_path @@ -19,7 +24,8 @@ def destroy end private + def user_params - params.require(:user).permit(:name, :password) + params.require(:user).permit(:name, :password, :email) end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb new file mode 100644 index 0000000..a17c53a --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -0,0 +1,9 @@ +class UserMailer < ApplicationMailer + default from: 'notifications@example.com' + + def welcome_email(user) + @user = user + + mail(to: @user.email, subject: "Wellcome, #{@user.name}#") + end +end \ No newline at end of file diff --git a/app/views/sessions/_form.html.erb b/app/views/sessions/_form.html.erb index 24f8901..a88351b 100644 --- a/app/views/sessions/_form.html.erb +++ b/app/views/sessions/_form.html.erb @@ -8,6 +8,9 @@ <%= f.password_field :password, placeholder: 'Username', class: 'form-control' %> <%= @user.errors[:password].first %> +
+ <%= f.email_field :email, placeholder: 'Enter email(optional)', class: 'form-control' %> +
<%= f.submit 'Sign Up', class: 'btn btn-primary' %>
<% end %> diff --git a/app/views/user_mailer/welcome_email.html.erb b/app/views/user_mailer/welcome_email.html.erb new file mode 100644 index 0000000..4137eff --- /dev/null +++ b/app/views/user_mailer/welcome_email.html.erb @@ -0,0 +1,14 @@ + + + + + + +

Welcome, <%= @user.name %>

+

+ You have successfully signed up, + your username is: <%= @user.name %>.
+

+

Thanks for joining and have a great day!

+ + diff --git a/app/views/user_mailer/welcome_email.text.erb b/app/views/user_mailer/welcome_email.text.erb new file mode 100644 index 0000000..4b5c4d1 --- /dev/null +++ b/app/views/user_mailer/welcome_email.text.erb @@ -0,0 +1,10 @@ + +Welcome to example.com, <%= @user.name %> +=============================================== + +You have successfully signed up to example.com, +your username is: <%= @user.name %>. + +To login to the site, just follow this link: <%= @url %>. + +Thanks for joining and have a great day! diff --git a/config/environments/development.rb b/config/environments/development.rb index 1311e3e..40a1ed8 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -31,7 +31,19 @@ config.active_storage.service = :local # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false + config.action_mailer.default_url_options = {host: "localhost:3000"} + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "example.com", + authentication: "plain", + enable_starttls_auto: true, + user_name: ENV["GMAIL_USERNAME"], + password: ENV["gmail_password"] + } + # config.action_mailer.raise_delivery_errors = false + # config.active_job.queue_adapter = :delayed_job config.action_mailer.perform_caching = false diff --git a/db/migrate/20181120184825_add_email_to_users.rb b/db/migrate/20181120184825_add_email_to_users.rb new file mode 100644 index 0000000..cd7fc31 --- /dev/null +++ b/db/migrate/20181120184825_add_email_to_users.rb @@ -0,0 +1,5 @@ +class AddEmailToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ae69849..3359661 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_11_12_173713) do +ActiveRecord::Schema.define(version: 2018_11_20_184825) do create_table "tasks", force: :cascade do |t| t.string "title" @@ -28,6 +28,7 @@ t.string "password_digest" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "email" end end From e6430be77b8b6fcf30b9acecff6b557893697620 Mon Sep 17 00:00:00 2001 From: somenickname Date: Sun, 25 Nov 2018 22:39:27 +0200 Subject: [PATCH 4/6] User co --- app/assets/javascripts/application.js | 3 +- app/assets/stylesheets/application.scss | 3 -- app/controllers/sessions_controller.rb | 26 +++++++++ app/controllers/tasks_controller.rb | 2 +- app/helpers/application_helper.rb | 18 +++++++ app/models/task.rb | 12 +++-- app/models/user.rb | 5 +- app/models/user_connection.rb | 4 ++ app/views/layouts/_header.html.erb | 3 ++ app/views/layouts/application.html.erb | 3 +- app/views/sessions/_share-form.html.erb | 22 ++++++++ app/views/sessions/share.js.erb | 2 + app/views/tasks/_form.html.erb | 54 ++++++++++++++----- config/routes.rb | 6 +-- .../20181124195127_create_user_connections.rb | 8 +++ db/schema.rb | 7 ++- 16 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 app/models/user_connection.rb create mode 100644 app/views/sessions/_share-form.html.erb create mode 100644 app/views/sessions/share.js.erb create mode 100644 db/migrate/20181124195127_create_user_connections.rb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 7631c6d..6f3e766 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,11 +10,12 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // -//= require jquery //= require rails-ujs //= require activestorage //= require turbolinks //= require_tree . +//= require jquery3 +//= require bootstrap function openPopup () { $('.modal').show(500, function () { diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 567f715..be5206b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -33,9 +33,6 @@ body { min-width: 100vw; padding: 100px 0; width: 100%; - z-index: -10; - overflow-x: hidden; - color: white; font-size: 1.3rem; } .hero { diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index a4160c1..953f3be 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,6 @@ class SessionsController < ApplicationController before_action :require_guest, only: [:new, :create] + def new @user = User.new end @@ -18,6 +19,24 @@ def create end end + def find + @user = User.find_by(name: params[:user][:name]) + + return share_error('No such user') unless @user + + if @user.id != current_user.id + current_user.users.push(@user) + flash[:success] = 'Successful shared' + redirect_to root_path + else + share_error('U cant do it with yourself ;)') + end + end + + def share + @user = User.new + end + def destroy session[:user_id] = nil redirect_to new_session_path @@ -25,6 +44,13 @@ def destroy private + def share_error(error) + flash[:error] = error + + @user = User.new + render 'share' + end + def user_params params.require(:user).permit(:name, :password, :email) end diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index fe8a15d..a730c63 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -3,7 +3,7 @@ class TasksController < ApplicationController def index @task = Task.new - @tasks = Task.for_dashboard(params).where(user_id: params[:user_id] || current_user) + @tasks = Task.for_dashboard(params, current_user) end def create diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..bd6f680 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,20 @@ module ApplicationHelper + + def bootstrap_class_for flash_type + { + success: "alert-success", + error: "alert-danger", + alert: "alert-warning", + notice: "alert-info"}.stringify_keys[flash_type.to_s] || flash_type.to_s + end + + def flash_messages(opts = {}) + flash.each do |msg_type, message| + concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)}", role: "alert") do + concat content_tag(:button, 'x', class: "close", data: {dismiss: 'alert'}) + concat message + end) + end + nil + end end diff --git a/app/models/task.rb b/app/models/task.rb index 2a43fea..094f2cd 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -4,12 +4,18 @@ class Task < ApplicationRecord validates :title, presence: true validates :description, presence: true validates_length_of :description, minimum: 5 - validates :expire_at, inclusion: { in: (Date.today..Date.today+5.years) } + validates :expire_at, inclusion: {in: (Date.today..Date.today + 5.years)} enum status: %i[todo done] scope :q, ->(q) { where("title LIKE '%#{q}%'") unless q.blank? } scope :status, ->(status) { where(status: status) unless status.blank? } - scope :expired, ->(val) { where("expire_at #{val == 'Expired' ? '<' : '>'} ?", Time.now) unless val.blank?} - scope :for_dashboard, ->(params) { q(params[:q]).status(params[:status]).expired(params[:expired]).paginate(page: params[:page], per_page: 5) } + scope :expired, ->(val) { where("expire_at #{val == 'Expired' ? '<' : '>'} ?", Time.now) unless val.blank? } + scope :for_dashboard, ->(params, current_user) { users_tasks(params, current_user).q(params[:q]).status(params[:status]).expired(params[:expired]).paginate(page: params[:page], per_page: 5) } + + scope :users_tasks, ->(params, current_user) { + id = current_user.id + friends = UserConnection.find_by_user_b_id(id) + where(user_id: friends ? [id, friends.user_a_id] : id) + } end diff --git a/app/models/user.rb b/app/models/user.rb index 30a97a4..711b2be 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,5 +4,8 @@ class User < ApplicationRecord has_secure_password validations: false - has_many :tasks + has_many :user_connections, :foreign_key => :user_a_id, :dependent => :destroy + has_many :users, :through => :user_connections, :source => :user_b + has_many(:reverse_user_connections, :class_name => :UserConnection, + :foreign_key => :user_b_id, :dependent => :destroy) end diff --git a/app/models/user_connection.rb b/app/models/user_connection.rb new file mode 100644 index 0000000..f5eaf66 --- /dev/null +++ b/app/models/user_connection.rb @@ -0,0 +1,4 @@ +class UserConnection < ApplicationRecord + belongs_to :user_a, :class_name => :User + belongs_to :user_b, :class_name => :User +end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 105fc3e..12da989 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -3,6 +3,9 @@ +

<%= @current_user.name if @current_user %>

<%= button_to('Logout', 'session', method: "delete", remote: true, class: 'btn btn-outline-light', diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 73b9b61..a0a754f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,18 +9,19 @@ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - <% if @current_user %> <%= render 'layouts/header' %> <% end %> +<%= flash_messages %>
<%= yield %>
<%= render 'tasks/popup' %> + diff --git a/app/views/sessions/_share-form.html.erb b/app/views/sessions/_share-form.html.erb new file mode 100644 index 0000000..a569175 --- /dev/null +++ b/app/views/sessions/_share-form.html.erb @@ -0,0 +1,22 @@ + diff --git a/app/views/sessions/share.js.erb b/app/views/sessions/share.js.erb new file mode 100644 index 0000000..2e33434 --- /dev/null +++ b/app/views/sessions/share.js.erb @@ -0,0 +1,2 @@ +$("#modal-window").html("<%= escape_javascript(render 'share-form') %>"); +$('#modal-window').modal('show'); \ No newline at end of file diff --git a/app/views/tasks/_form.html.erb b/app/views/tasks/_form.html.erb index 7b5edcc..bd52112 100644 --- a/app/views/tasks/_form.html.erb +++ b/app/views/tasks/_form.html.erb @@ -1,14 +1,40 @@ -<%= form_for @task, remote: true, class: 'col-lg-6 col-8 mx-auto' do |f| %> -
- <%= f.text_field :title, value: @task.title, class: 'form-control', placeholder: 'Title' %> -

<%= @task.errors[:title].first %>

-
-
- - <%= f.text_area :description, value: @task.description, id: 'exampleFormControlTextarea1', class: 'form-control', rows: 3 %> -

<%= @task.errors[:description].first %>

-
- <%= f.date_field :expire_at, value: @task.expire_at %> -

<%= @task.errors[:expire_at].first %>

- <%= f.button :OK, class: 'save btn btn-primary' %> -<% end %> + diff --git a/config/routes.rb b/config/routes.rb index 06ae911..f7b1187 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,10 +6,8 @@ get 'index', to: 'welcome#index' root 'tasks#index' get 'users/:user_id/tasks', to: 'tasks#index' - namespace 'admin' do - get 'dashbpar' - end - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + get 'sessions/share', to: 'sessions#share' + post 'sessions/share', to: 'sessions#find' resource :session resources :tasks end diff --git a/db/migrate/20181124195127_create_user_connections.rb b/db/migrate/20181124195127_create_user_connections.rb new file mode 100644 index 0000000..ce73c5a --- /dev/null +++ b/db/migrate/20181124195127_create_user_connections.rb @@ -0,0 +1,8 @@ +class CreateUserConnections < ActiveRecord::Migration[5.2] + def change + create_table :user_connections do |t| + t.string :user_a_id + t.integer :user_b_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3359661..f9c04cc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_11_20_184825) do +ActiveRecord::Schema.define(version: 2018_11_24_195127) do create_table "tasks", force: :cascade do |t| t.string "title" @@ -23,6 +23,11 @@ t.index ["user_id"], name: "index_tasks_on_user_id" end + create_table "user_connections", force: :cascade do |t| + t.string "user_a_id" + t.integer "user_b_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.string "password_digest" From 2c0c736c1e92eb4be056c6a330b3c25af8bb89a7 Mon Sep 17 00:00:00 2001 From: somenickname Date: Sun, 25 Nov 2018 23:09:43 +0200 Subject: [PATCH 5/6] refactoring --- app/assets/javascripts/application.js | 11 ----- app/assets/stylesheets/application.scss | 63 ------------------------- app/controllers/tasks_controller.rb | 4 ++ app/views/layouts/_header.html.erb | 10 ++-- app/views/layouts/application.html.erb | 5 +- app/views/tasks/index.html.erb | 28 ++++++----- app/views/tasks/new.js.erb | 2 + config/locales/en.yml | 2 +- 8 files changed, 29 insertions(+), 96 deletions(-) create mode 100644 app/views/tasks/new.js.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6f3e766..2059af0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,17 +17,6 @@ //= require jquery3 //= require bootstrap -function openPopup () { - $('.modal').show(500, function () { - $(this).addClass('active') - }) -} - -function closePopup () { - $('.modal').removeClass('active') - $('.modal').hide(500) -} - function handleCheckbox (event) { if (event.target.id === 'task_status') { var item = event.target.parentNode.parentNode.parentNode diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index be5206b..a3d9908 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -36,7 +36,6 @@ body { font-size: 1.3rem; } .hero { - //background-color: rgba(31, 34, 118, 0.5); .container { text-align: center; button.open { @@ -144,65 +143,3 @@ body { background-color: #343a4069; } } - -.navbar { - .container { - display: flex; - justify-content: space-between; - } - .user-data-container { - display: flex; - align-items: center; - p { - margin: 0 10px 0 0; - font-size: 14px; - } - } -} - -.modal { - justify-content: center; - align-items: center; - transition: background 0.1s ease; - &.active { - display: flex; - background: rgba(0, 0, 0, 0.6); - } - .modal-dialog { - height: 100%; - display: flex; - align-items: center; - } - .modal-content { - position: relative; - display: flex; - flex-direction: column; - align-items: center; - padding: 50px 50px 25px; - .close { - position: absolute; - top: 5px; - right: 5px; - width: 25px; - outline: none; - } - button.save { - margin-top: 20px; - } - } - form.new_task { - display: flex; - width: 100%; - flex-direction: column; - align-items: center; - .input-group, .form-group, .field_with_errors, input { - width: 100%; - } - button { - width: 100px; - } - } - .error { - color: red; - } -} \ No newline at end of file diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index a730c63..5181e39 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -6,6 +6,10 @@ def index @tasks = Task.for_dashboard(params, current_user) end + def new + @task = Task.new + end + def create @task = current_user.tasks.create(task_params) return if @task.invalid? diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 12da989..cca0409 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,15 +1,15 @@ -