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
77 changes: 41 additions & 36 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.3'
ruby "3.0.3"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
gem "rails", "~> 6.1.3", ">= 6.1.3.1"
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
gem "pg", "~> 1.1"
# Use Puma as the app server
gem 'puma', '~> 5.0'
gem "puma", "~> 5.0"
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
gem "sass-rails", ">= 6"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
gem "webpacker", "~> 5.0"
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
gem "turbolinks", "~> 5"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
gem "jbuilder", "~> 2.7"

gem "devise"
gem 'faker'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
Expand All @@ -26,52 +29,54 @@ gem 'jbuilder', '~> 2.7'
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
gem "bootsnap", ">= 1.4.4", require: false

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]
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
gem "web-console", ">= 4.1.0"
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
gem "rack-mini-profiler", "~> 2.0"
gem "listen", "~> 3.3"
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem "spring"

gem "annotate"
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
gem "capybara", ">= 3.26"
gem "selenium-webdriver"
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
gem "webdrivers"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

# appdev Gems
group :development do
gem 'annotate'
gem 'awesome_print'
gem 'better_errors'
gem 'binding_of_caller'
gem 'bullet'
gem 'htmlbeautifier'
gem 'pry-rails'
gem 'rack-canonical-host'
gem 'rails-erd'
gem 'rollbar'
gem 'rufo'
gem 'standard', require: false
gem 'solargraph'
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
gem 'skylight'
gem 'web_git', github: 'firstdraft/web_git'
gem "annotate"
gem "awesome_print"
gem "better_errors"
gem "binding_of_caller"
gem "bullet"
gem "htmlbeautifier"
gem "pry-rails"
gem "rack-canonical-host"
gem "rails-erd"
gem "rollbar"
gem "rufo"
gem "standard", require: false
gem "solargraph"
gem "rubocop-rails", require: false
gem "rubocop-rspec", require: false
gem "skylight"
gem "web_git", github: "firstdraft/web_git"
end
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ GEM
ast (2.4.2)
awesome_print (1.9.2)
backport (1.2.0)
bcrypt (3.1.18)
benchmark (0.2.0)
better_errors (2.9.1)
coderay (>= 1.0.0)
Expand Down Expand Up @@ -111,10 +112,18 @@ GEM
concurrent-ruby (1.1.10)
crass (1.0.6)
debug_inspector (1.1.0)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.5.0)
diffy (3.4.2)
e2mmap (0.1.0)
erubi (1.11.0)
faker (3.1.0)
i18n (>= 1.8.11, < 2)
ffi (1.15.5)
git (1.12.0)
addressable (~> 2.8)
Expand Down Expand Up @@ -155,6 +164,7 @@ GEM
racc (~> 1.4)
nokogiri (1.13.9-x86_64-darwin)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.22.1)
parser (3.1.1.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -218,6 +228,9 @@ GEM
ffi (~> 1.0)
rchardet (1.8.0)
regexp_parser (2.2.1)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.5)
Expand Down Expand Up @@ -307,6 +320,8 @@ GEM
tzinfo (>= 1.0.0)
unicode-display_width (2.1.0)
uniform_notifier (1.16.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -344,6 +359,8 @@ DEPENDENCIES
bullet
byebug
capybara (>= 3.26)
devise
faker
htmlbeautifier
jbuilder (~> 2.7)
listen (~> 3.3)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end
91 changes: 91 additions & 0 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class TasksController < ApplicationController
before_action :set_task, only: %i[ show edit update destroy move ]

# GET /tasks or /tasks.json
def index
@tasks = Task.all
end

# GET /tasks/1 or /tasks/1.json
def show
end

# GET /tasks/new
def new
@task = Task.new
end

# GET /tasks/1/edit
def edit
respond_to do |format|
format.js
end
end

# POST /tasks or /tasks.json
def create
@task = current_user.tasks.build(task_params)

respond_to do |format|
if @task.save
format.html { redirect_to task_url(@task), notice: "Task was successfully created." }
format.json { render :show, status: :created, location: @task }
format.js
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /tasks/1 or /tasks/1.json
def update
respond_to do |format|
if @task.update(task_params)
format.html { redirect_to task_url(@task), notice: "Task was successfully updated." }
format.json { render :show, status: :ok, location: @task }
format.js
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
end
end

# DELETE /tasks/1 or /tasks/1.json
def destroy
@task.destroy

respond_to do |format|
format.html { redirect_to tasks_url, notice: "Task was successfully destroyed." }
format.json { head :no_content }
format.js
end
end

def move
if @task.not_yet_started?
@task.in_progress!
elsif @task.in_progress?
@task.completed!
else
@task.in_progress!
end

respond_to do |format|
format.html {redirect_to tasks_url, notice: "Task updated"}
format.js
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_task
@task = Task.find(params[:id])
end

# Only allow a list of trusted parameters through.
def task_params
params.require(:task).permit(:status, :content)
end
end
2 changes: 2 additions & 0 deletions app/helpers/tasks_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TasksHelper
end
27 changes: 27 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: tasks
#
# id :bigint not null, primary key
# content :string not null
# status :string default("not_yet_started"), not null
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_tasks_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
class Task < ApplicationRecord
belongs_to :user
validates :content, presence: true

scope :by_updated, -> { order(updated_at: :desc)}

enum status: { not_yet_started: "not_yet_started", in_progress: "in_progress", completed: "completed" }
end
27 changes: 27 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# private :boolean
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_email (email) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
#
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

has_many :tasks, dependent: :destroy
end
26 changes: 22 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>Vanilla Rails</title>
<title>Task List</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= render "shared/cdn_assets" %>

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_pack_tag 'application' %>
</head>

<body>
<%= yield %>
<%= render "shared/navbar" %>

<div class="container">
<div class="row mb-4">
<div class="col-md-6 offset-md-3">
<% if notice.present? %>
<%= render "shared/flash", message: notice, css_class: "success" %>
<% end %>

<% if alert.present? %>
<%= render "shared/flash", message: alert, css_class: "danger" %>
<% end %>
</div>
</div>

<%= yield %>
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions app/views/shared/_cdn_assets.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<meta charset="utf-8">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/js/all.min.js"></script>
7 changes: 7 additions & 0 deletions app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="alert alert-<%= css_class %> alert-dismissible fade show" role="alert">
<%= message %>

<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
Loading