mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-12 18:34:22 +01:00
Initial import
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@1 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
commit
ec3ee77797
83 changed files with 3361 additions and 0 deletions
18
tracks/app/controllers/application.rb
Normal file
18
tracks/app/controllers/application.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# The filters added to this controller will be run for all controllers in the application.
|
||||
# Likewise will all the methods added be available for all controllers.
|
||||
|
||||
require_dependency "login_system"
|
||||
require_dependency "redcloth"
|
||||
require 'date'
|
||||
|
||||
$delete_img = "<img src=\"/images/delete.png\" width=\"10\" height=\"10\" />"
|
||||
$edit_img = "<img src=\"/images/edit.png\" width=\"10\" height=\"10\" />"
|
||||
$notes_img = "<img src=\"/images/notes.png\" width=\"10\" height=\"10\" />"
|
||||
$done_img = "<img src=\"/images/done.png\" width=\"16\" height=\"16\" />"
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
helper :application
|
||||
include LoginSystem
|
||||
|
||||
end
|
||||
94
tracks/app/controllers/context_controller.rb
Normal file
94
tracks/app/controllers/context_controller.rb
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
class ContextController < ApplicationController
|
||||
|
||||
|
||||
helper :context
|
||||
model :project
|
||||
scaffold :context
|
||||
before_filter :login_required
|
||||
|
||||
layout "standard"
|
||||
|
||||
|
||||
# Main method for listing contexts
|
||||
# Set page title, and collect existing contexts in @contexts
|
||||
#
|
||||
def list
|
||||
@page_title = "List Contexts"
|
||||
@contexts = Context.find_all
|
||||
end
|
||||
|
||||
|
||||
# Called by a form button
|
||||
# Parameters from form fields should be passed to create new context
|
||||
#
|
||||
def add_context
|
||||
context = Context.new
|
||||
context.name = @params["new_context"]["name"]
|
||||
|
||||
if context.save
|
||||
flash["confirmation"] = "Succesfully created context"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't add new context"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Filter the contexts to show just the one passed in the URL
|
||||
# e.g. <home>/context/show/<context_id> shows just <context_id>.
|
||||
#
|
||||
def show
|
||||
@context = Context.find(@params["id"])
|
||||
@places = Context.find_all
|
||||
@projects = Project.find_all
|
||||
@page_title = "Context: #{@context.name.capitalize}"
|
||||
@not_done = Todo.find_all( "context_id=#{@context.id} AND done=0", "created DESC" )
|
||||
end
|
||||
|
||||
|
||||
# Called by a form button
|
||||
# Parameters from form fields are passed to create new action
|
||||
# in the selected context.
|
||||
def add_item
|
||||
item = Todo.new
|
||||
item.attributes = @params["new_item"]
|
||||
|
||||
# Convert the date format entered (as set in config/settings.yml)
|
||||
# to the mysql format YYYY-MM-DD
|
||||
if @params["new_item"]["due"] != ""
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(@params["new_item"]["due"], "#{date_fmt}")
|
||||
item.due = formatted_date.strftime("%Y-%m-%d")
|
||||
else
|
||||
item.due = "0000-00-00"
|
||||
end
|
||||
|
||||
back_to = item.context_id
|
||||
|
||||
if item.save
|
||||
flash["confirmation"] = "Succesfully added action to context"
|
||||
redirect_to( :controller => "context", :action => "show", :id => "#{back_to}" )
|
||||
else
|
||||
flash["warning"] = "Could not add action to context"
|
||||
redirect_to( :controller => "context", :action => "show", :id => "#{back_to}" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Fairly self-explanatory; deletes the context
|
||||
# If the context contains actions, you'll get a warning dialogue.
|
||||
# If you choose to go ahead, any actions in the context will also be deleted.
|
||||
def destroy
|
||||
context = Context.find(@params['id'])
|
||||
if context.destroy
|
||||
flash["confirmation"] = "Succesfully deleted context"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't delete context"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
33
tracks/app/controllers/feed_controller.rb
Normal file
33
tracks/app/controllers/feed_controller.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Produces an feeds of the next actions, both RSS and plain text
|
||||
#
|
||||
class FeedController < ApplicationController
|
||||
|
||||
helper :feed
|
||||
model :todo, :context, :project
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
# Builds an RSS feed for the latest 15 items
|
||||
# This is fairly basic: it lists the action description as the title
|
||||
# and the item context as the description
|
||||
#
|
||||
def na_feed
|
||||
@not_done = Todo.find_all( "done=0", "created DESC" )
|
||||
@headers["Content-Type"] = "text/xml; charset=utf-8"
|
||||
end
|
||||
|
||||
# Builds a plain text page listing all the next actions,
|
||||
# sorted by context. Showing notes doesn' make much sense here
|
||||
# so they are omitted. You can use this with GeekTool to get your next actions
|
||||
# on the desktop:
|
||||
# curl http://url_for_the_app/feed/na_text
|
||||
#
|
||||
def na_text
|
||||
@places = Context.find_all
|
||||
@projects = Project.find_all
|
||||
@not_done = Todo.find_all( "done=0", "context_id ASC" )
|
||||
@headers["Content-Type"] = "text/plain; charset=utf-8"
|
||||
end
|
||||
|
||||
end
|
||||
49
tracks/app/controllers/login_controller.rb
Normal file
49
tracks/app/controllers/login_controller.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
class LoginController < ApplicationController
|
||||
model :user
|
||||
layout 'scaffold'
|
||||
|
||||
def login
|
||||
case @request.method
|
||||
when :post
|
||||
if @session['user'] = User.authenticate(@params['user_login'], @params['user_password'])
|
||||
|
||||
flash['notice'] = "Login successful"
|
||||
redirect_back_or_default :controller => "todo", :action => "list"
|
||||
else
|
||||
@login = @params['user_login']
|
||||
@message = "Login unsuccessful"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def signup
|
||||
case @request.method
|
||||
when :post
|
||||
@user = User.new(@params['user'])
|
||||
|
||||
if @user.save
|
||||
@session['user'] = User.authenticate(@user.login, @params['user']['password'])
|
||||
flash['notice'] = "Signup successful"
|
||||
redirect_back_or_default :controller => "todo", :action => "list"
|
||||
end
|
||||
when :get
|
||||
@user = User.new
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
if @params['id']
|
||||
@user = User.find(@params['id'])
|
||||
@user.destroy
|
||||
end
|
||||
redirect_back_or_default :controller => "todo", :action => "list"
|
||||
end
|
||||
|
||||
def logout
|
||||
@session['user'] = nil
|
||||
end
|
||||
|
||||
def welcome
|
||||
end
|
||||
|
||||
end
|
||||
107
tracks/app/controllers/project_controller.rb
Normal file
107
tracks/app/controllers/project_controller.rb
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
class ProjectController < ApplicationController
|
||||
|
||||
helper :project
|
||||
model :context
|
||||
model :todo
|
||||
scaffold :project
|
||||
|
||||
before_filter :login_required
|
||||
layout "standard"
|
||||
|
||||
# Main method for listing projects
|
||||
# Set page title, and collect existing projects in @projects
|
||||
#
|
||||
def list
|
||||
@page_title = "List Projects"
|
||||
@projects = Project.find_all
|
||||
end
|
||||
|
||||
|
||||
# Filter the projects to show just the one passed in the URL
|
||||
# e.g. <home>/project/show/<project_id> shows just <project_id>.
|
||||
#
|
||||
def show
|
||||
@project = Project.find(@params["id"])
|
||||
@places = Context.find_all
|
||||
@page_title = "Project: #{@project.name}"
|
||||
@not_done = Todo.find_all( "project_id=#{@project.id} AND done=0", "created DESC" )
|
||||
end
|
||||
|
||||
|
||||
# Called by a form button
|
||||
# Parameters from form fields should be passed to create new project
|
||||
#
|
||||
def add_project
|
||||
project = Project.new
|
||||
project.name = @params["new_project"]["name"]
|
||||
|
||||
if project.save
|
||||
flash["confirmation"] = "Succesfully added project"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't add project"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Called by a form button
|
||||
# Parameters from form fields should be passed to create new item
|
||||
#
|
||||
def add_item
|
||||
item = Todo.new
|
||||
item.attributes = @params["new_item"]
|
||||
|
||||
# Convert the date format entered (as set in config/settings.yml)
|
||||
# to the mysql format YYYY-MM-DD
|
||||
if @params["new_item"]["due"] != ""
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(@params["new_item"]["due"], "#{date_fmt}")
|
||||
item.due = formatted_date.strftime("%Y-%m-%d")
|
||||
else
|
||||
item.due = "0000-00-00"
|
||||
end
|
||||
|
||||
back_to = item.project_id
|
||||
|
||||
if item.save
|
||||
flash["confirmation"] = "Successfully added next action to project"
|
||||
redirect_to( :controller => "project", :action => "show", :id => "#{back_to}" )
|
||||
else
|
||||
flash["warning"] = "Couldn't add next action to project"
|
||||
redirect_to( :controller => "project", :action => "show", :id => "#{back_to}" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
project = Project.find( @params['id'] )
|
||||
if project.destroy
|
||||
flash["confirmation"] = "Succesfully deleted project"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't delete project"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Toggles the 'done' status of the action
|
||||
def toggle_check
|
||||
item = Todo.find( @params['id'] )
|
||||
|
||||
case item.done
|
||||
when 0: item.done = 1; item.completed = Time.now()
|
||||
when 1: item.done = 0; item.completed = nil
|
||||
end
|
||||
|
||||
if item.save
|
||||
flash["confirmation"] = "Marked next action as completed"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't mark next action as completed"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
111
tracks/app/controllers/todo_controller.rb
Normal file
111
tracks/app/controllers/todo_controller.rb
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
class TodoController < ApplicationController
|
||||
|
||||
helper :todo
|
||||
model :context
|
||||
model :project
|
||||
|
||||
scaffold :todo
|
||||
before_filter :login_required
|
||||
layout "standard"
|
||||
|
||||
# Main method for listing tasks
|
||||
# Set page title, and fill variables with contexts and done and not-done tasks
|
||||
#
|
||||
def list
|
||||
@page_title = "List tasks"
|
||||
@places = Context.find_all
|
||||
@projects = Project.find_all
|
||||
@not_done = Todo.find_all( "done=0", "completed DESC" )
|
||||
@done = Todo.find_all( "done=1", "completed DESC", 5 )
|
||||
end
|
||||
|
||||
|
||||
# List the completed tasks, sorted by completion date
|
||||
#
|
||||
def completed
|
||||
@page_title = "Completed tasks"
|
||||
@done = Todo.find_all( "done=1", "completed DESC" )
|
||||
end
|
||||
|
||||
|
||||
# Called by a form button
|
||||
# Parameters from form fields should be passed to create new item
|
||||
#
|
||||
def add_item
|
||||
item = Todo.new
|
||||
item.attributes = @params["new_item"]
|
||||
|
||||
# Convert the date format entered (as set in config/settings.yml)
|
||||
# to the mysql format YYYY-MM-DD
|
||||
if @params["new_item"]["due"] != ""
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(@params["new_item"]["due"], "#{date_fmt}")
|
||||
item.due = formatted_date.strftime("%Y-%m-%d")
|
||||
else
|
||||
item.due = "0000-00-00"
|
||||
end
|
||||
|
||||
if item.save
|
||||
flash["confirmation"] = "Next action was successfully added"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't add the action"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@item = Todo.find(@params['id'])
|
||||
@belongs = @item.project_id
|
||||
@page_title = "Edit task: #{@item.description}"
|
||||
@places = Context.find_all
|
||||
@projects = Project.find_all
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@item = Todo.find(@params['item']['id'])
|
||||
@item.attributes = @params['item']
|
||||
if @item.save
|
||||
flash["confirmation"] = 'Next action was successfully updated'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
flash["warning"] = 'Next action could not be updated'
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
item = Todo.find(@params['id'])
|
||||
if item.destroy
|
||||
flash["confirmation"] = "Next action was successfully deleted"
|
||||
redirect_to :action => "list"
|
||||
else
|
||||
flash["warning"] = "Couldn't delete next action"
|
||||
redirect_to :action => "list"
|
||||
end
|
||||
end
|
||||
|
||||
# Toggles the 'done' status of the action
|
||||
#
|
||||
def toggle_check
|
||||
item = Todo.find(@params['id'])
|
||||
|
||||
case item.done
|
||||
when 0: item.done = 1; item.completed = Time.now()
|
||||
when 1: item.done = 0; item.completed = nil
|
||||
end
|
||||
|
||||
if item.save
|
||||
flash["confirmation"] = "Next action marked as completed"
|
||||
redirect_to( :action => "list" )
|
||||
else
|
||||
flash["warning"] = "Couldn't mark action as completed"
|
||||
redirect_to( :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue