Skip to content
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
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ gem 'bootstrap', '~> 4.1.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
gem 'will_paginate'
gem 'will_paginate-bootstrap'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

Expand Down
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ GEM
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
pg (1.1.3)
popper_js (1.14.3)
public_suffix (3.0.3)
puma (3.12.0)
Expand Down Expand Up @@ -180,7 +181,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
Expand All @@ -199,6 +199,9 @@ GEM
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will_paginate (3.1.6)
will_paginate-bootstrap (1.0.1)
will_paginate (>= 3.0.3)
xpath (3.2.0)
nokogiri (~> 1.8)

Expand All @@ -216,20 +219,22 @@ DEPENDENCIES
jbuilder (~> 2.5)
jquery-rails
listen (>= 3.0.5, < 3.2)
pg
puma (~> 3.11)
rails (~> 5.2.1)
sass-rails (~> 5.0)
selenium-webdriver
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
will_paginate
will_paginate-bootstrap

RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.6
1.17.1
6 changes: 6 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery3
//= require popper
//= require bootstrap
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
*= require_tree .
*= require_self
*/
@import "bootstrap";
@import "bootstrap";
6 changes: 6 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def create
end
end

def destroy
User.find(session[:user_id])
session[:user_id] = nil
redirect_to :root
end

private
def user_params
params.require(:user).permit(:name, :password)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class TasksController < ApplicationController

def index
@task = Task.new
@tasks = current_user.tasks.q(params[:q])
@tasks = current_user.tasks.q(params[:q]).paginate(:page => params[:page], :per_page => 10)
end

def create
Expand Down
54 changes: 31 additions & 23 deletions app/views/tasks/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<%= form_for @task, remote: true do |f| %>
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Title</span>
</div>
<%= f.text_field :title, value: @task.title, class: 'form-control', 'aria-label' => 'Small', 'aria-describedby' => 'inputGroup-sizing-sm'%>
<%= @task.errors[:title].first %>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Description</label>
<%= f.text_area :description, value: @task.description, id: 'exampleFormControlTextarea1', class: 'form-control', rows: 3 %>
<%= @task.errors[:description].first %>
</div>
<%= f.date_field :expire_at, value: @task.expire_at %>
<%= @task.errors[:expire_at].first %>
<%= f.button :OK %>
<% end %>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<%= form_for @task, remote: true do |f| %>
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Title</span>
</div>
<%= f.text_field :title, value: @task.title, class: 'form-control', 'aria-label' => 'Small', 'aria-describedby' => 'inputGroup-sizing-sm'%>
<%= @task.errors[:title].first %>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Description</label>
<%= f.text_area :description, value: @task.description, id: 'exampleFormControlTextarea1', class: 'form-control', rows: 3 %>
<%= @task.errors[:description].first %>
</div>
<%= f.date_field :expire_at, value: @task.expire_at %>
<%= @task.errors[:expire_at].first %>
<%= f.button :OK, class: 'btn btn-outline-primary' %>
<% end %>

<% if notice %>
<div class="error-container alert alert-danger" role="alert">
<% notice.each do |error_message| %>
<p><%= "Field #{error_message.first} #{error_message[1].first}" %></p>
<% end %>
<% if notice %>
<div class="error-container alert alert-danger" role="alert">
<% notice.each do |error_message| %>
<p><%= "Field #{error_message.first} #{error_message[1].first}" %></p>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
26 changes: 17 additions & 9 deletions app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<section class="creat-task-section">
<h1>New Task</h1>
<nav class="navbar navbar-expand-sm bg-dark justify-content-end">

<form class="form-inline">
<%= form_tag tasks_path, method: :get, remote: true do |f| %>
<%= text_field_tag :q, params[:q], placeholder: 'Search', class: 'form-control mr-sm-2' %>
<% end %>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Create new task
</button>
<%= link_to "Log out", logout_path, method: "delete", class: 'btn btn-outline-danger' %>
</form>


</nav>

<section class="creat-task-section">
<%= render 'form' %>
</section>

<section class="tasks-container">
<h2>Tasks</h2>

<%= form_tag tasks_path, method: :get, remote: true do |f| %>
<%= text_field_tag :q, params[:q], placeholder: 'Search', class: 'search' %>
<% end %>


<ul class="tasks-list">
<%= render partial: 'task', collection: @tasks %>
</ul>
<%= will_paginate @tasks %>
<%-# js_will_paginate -%>
</section>


23 changes: 7 additions & 16 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
username: sandri4
password: 3699

development:
<<: *default
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
database: lesson4_development
test:
<<: *default
database: db/test.sqlite3

database: lesson4_test
production:
<<: *default
database: db/production.sqlite3
database: lesson4_production
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
post 'users/login', to: 'users#create'
get 'users/registration', to: 'users#registration'
get 'index', to: 'welcome#index'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
root 'tasks#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resource :session
Expand Down
6 changes: 5 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

ActiveRecord::Schema.define(version: 2018_11_12_173713) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "tasks", force: :cascade do |t|
t.string "title"
t.string "description"
t.integer "status", default: 0
t.datetime "expire_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.bigint "user_id"
t.index ["user_id"], name: "index_tasks_on_user_id"
end

Expand All @@ -30,4 +33,5 @@
t.datetime "updated_at", null: false
end

add_foreign_key "tasks", "users"
end