#!/usr/bin/env ruby require 'rubygems' gem 'ramaze', '= 2009.03' require 'ramaze' require 'ramaze/setup' module Tickets VERSION = "0.1.0.3" end # load config conf_path = File.expand_path("~/.tickets.conf") load conf_path if File.exist?(conf_path) # update config module Tickets module Config DB_PATH = File.expand_path("~/.tickets.db") unless defined?(DB_PATH) PORT = 7007 unless defined?(PORT) SHAKE_INTERVAL = 24 unless defined?(SHAKE_INTERVAL) # hours SHAKE_DISTANCE = 8 unless defined?(SHAKE_DISTANCE) # pixels BOARD_WIDTH = 600 unless defined?(BOARD_WIDTH) # pixels BOARD_HEIGHT = 600 unless defined?(BOARD_HEIGHT) # pixels end end # connect database $LOAD_PATH.unshift(File.expand_path("../", File.dirname(__FILE__))) require 'model/ticket' # controllers class MainController < Ramaze::Controller def index Ticket.shake! if Ticket.needs_shaking? end def track @tickets = Ticket.filter(:deleted => true).reverse_order(:id) end end class ConfigController < Ramaze::Controller map '/config' deny_layout :all def board_size "(xy . (#{Tickets::Config::BOARD_WIDTH} . #{Tickets::Config::BOARD_HEIGHT}))" end end class TicktesController < Ramaze::Controller map '/tickets' deny_layout :all def create ticket = Ticket.new ticket.save "(id . #{ticket.id})" end def list tickets = Ticket.filter(:deleted => false).all '(' + tickets.map{|ticket| "(#{ticket.id} #{ticket.title.inspect} #{ticket.emergency} #{ticket.importance})" }.join(' ') + ')' end def move raise "must be via POST" unless request.post? ticket = Ticket.find(:id => request["id"]) raise "ticket not found" unless ticket ticket.update(:emergency => request["x"], :importance => request["y"]) "#t" end def rename raise "must be via POST" unless request.post? ticket = Ticket.find(:id => request["id"]) raise "ticket not found" unless ticket ticket.update(:title => request["title"]) "#t" end def delete raise "must be via POST" unless request.post? ticket = Ticket.find(:id => request["id"]) raise "ticket not found" unless ticket ticket.update(:deleted => true) "#t" end end Dir.chdir(File.expand_path("..", File.dirname(__FILE__))) Ramaze.setup do option.port = Tickets::Config::PORT end Ramaze.start