-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
215d234
commit 8e29e76
Showing
2 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
require 'sinatra' | ||
require 'erb' | ||
require 'date' | ||
require 'sinatra' # Sinatra web server | ||
require 'erb' # Ruby templates | ||
require 'date' # date parser | ||
|
||
class TaskList < Sinatra::Base | ||
task_list = [] | ||
id_counter = 1 | ||
class TaskList < Sinatra::Base # task list class | ||
task_list = [] # set initial task list to empty array | ||
id_counter = 1 # set initial id counter to 1 | ||
|
||
def overdue?(due_date) | ||
Date.parse(due_date) < Date.today | ||
def overdue?(due_date) # check if task is overdue | ||
Date.parse(due_date) < Date.today # parse the date string | ||
end | ||
|
||
get '/' do | ||
@tasks = task_list | ||
erb :index | ||
get '/' do # get task list | ||
@tasks = task_list # set tasks to task list array | ||
erb :index # redirect to index page | ||
end | ||
|
||
post '/add' do | ||
task_list << { id: id_counter, name: params[:task], due_date: params[:due_date] } | ||
id_counter += 1 | ||
redirect '/' | ||
post '/add' do # add task to task list | ||
task_list << { id: id_counter, name: params[:task], due_date: params[:due_date] } # add task to task list | ||
id_counter += 1 # increase id counter by 1 when task is added | ||
redirect '/' # redirect to index page | ||
end | ||
|
||
post '/delete/:id' do | ||
task_list.reject! { |task| task[:id] == params[:id].to_i } | ||
redirect '/' | ||
task_list.reject! { |task| task[:id] == params[:id].to_i } # find task to delete by task id | ||
redirect '/' # redirect to index page | ||
end | ||
end | ||
|
||
TaskList.run! | ||
TaskList.run! # run the task list application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters