Class: Knjtasks

Inherits:
Object
  • Object
show all
Defined in:
lib/knjtasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Knjtasks

Returns a new instance of Knjtasks.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/knjtasks.rb', line 4

def initialize(args = {})
  @args = args
  
  if @args[:hayabusa]
    @db = @args[:hayabusa].db
  elsif @args[:db]
    @db = @args[:db]
  else
    raise "Could not figure out database."
  end
  
  require "rubygems"
  require "#{@args[:hayabusa_path]}hayabusa"
  require "#{@args[:knjrbfw_path]}knjrbfw"
  
  require "#{@args[:knjrbfw_path]}knj/autoload"
  
  
  check_args = [:knjjs_url, :email_admin, :email_robot]
  check_args.each do |key|
    raise "No '#{key}' given in arguments." if !@args.has_key?(key)
  end
  
  require "#{File.dirname(__FILE__)}/../files/database_schema.rb"
  Knj::Db::Revision.new.init_db("schema" => $schema, "db" => @db)
  
  @ob = Knj::Objects.new(
    :datarow => true,
    :db => @db,
    :class_path => "#{File.dirname(__FILE__)}/../models",
    :module => Knjtasks,
    :require_all => true
  )
  
  @ob.events.connect(:no_html, &self.method(:no_html))
  @ob.events.connect(:no_date, &self.method(:no_date))
  
  if @args[:hayabusa]
    @hayabusa = @args[:hayabusa]
  else
    @hayabusa = Hayabusa.new(
      :debug => @args[:debug],
      :autorestart => false,
      :autoload => false,
      :verbose => false,
      :title => @args[:title],
      :port => @args[:port],
      :host => @args[:host],
      :default_page => "index.rhtml",
      :doc_root => "#{File.dirname(__FILE__)}/../www",
      :hostname => false,
      :error_report_emails => [@args[:email_admin]],
      :error_report_from => @args[:email_robot],
      :locales_root => "#{File.dirname(__FILE__)}/../locales",
      :locales_gettext_funcs => true,
      :locale_default => "en_GB",
      :knjrbfw_path => @args[:knjrbfw_path],
      :db => @db,
      :smtp_args => @args[:smtp_args],
      :httpsession_db_args => @args[:db_args]
    )
  end
  
  @hayabusa.define_magic_var(:_site, self)
  @hayabusa.define_magic_var(:_ob, @ob)
  @hayabusa.thread_init
  
  if @args.has_key?(:mail_args)
    require "#{File.dirname(__FILE__)}/../threads/thread_mail_task_comments.rb"
    @thread_mail_task_comments = Knjtasks::Thread_mail_task_comments.new(
      :knjtasks => self,
      :ob => @ob,
      :appsrv => @hayabusa,
      :args => @args
    )
    
    if @args[:debug]
      time = 5
    else
      time = 60
    end
    
    @hayabusa.timeout(:time => time, &self.method(:mail_task_comments_run))
  end
  
  @class_translations = {
    :User => _("user"),
    :Project => _("project"),
    :Task => _("task")
  }
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



2
3
4
# File 'lib/knjtasks.rb', line 2

def args
  @args
end

#dbObject (readonly)

Returns the value of attribute db.



2
3
4
# File 'lib/knjtasks.rb', line 2

def db
  @db
end

#hayabusaObject (readonly)

Returns the value of attribute hayabusa.



2
3
4
# File 'lib/knjtasks.rb', line 2

def hayabusa
  @hayabusa
end

#obObject (readonly)

Returns the value of attribute ob.



2
3
4
# File 'lib/knjtasks.rb', line 2

def ob
  @ob
end

Instance Method Details

#boxbObject



146
147
148
# File 'lib/knjtasks.rb', line 146

def boxb
  return "</td></tr></table>"
end

#boxt(title, width = "100%") ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/knjtasks.rb', line 136

def boxt(title, width = "100%")
  width = "#{width}px" if width.is_a?(Fixnum) or width.is_a?(Integer)
  
  html = ""
  html += "<table class=\"box\" style=\"width: #{width};\" cellspacing=\"0\" cellpadding=\"0\">"
  html += "<tr><td class=\"box_header_spacer\">&nbsp;</td><td class=\"box_header\">#{title}</td></tr>"
  html += "<tr><td colspan=\"2\" class=\"box_content\">"
  return html
end

#has_rank?(rank_str) ⇒ Boolean

Returns:

  • (Boolean)


168
169
170
171
# File 'lib/knjtasks.rb', line 168

def has_rank?(rank_str)
  return false if !self.user
  return self.user.has_rank?(rank_str)
end

#header(title) ⇒ Object



132
133
134
# File 'lib/knjtasks.rb', line 132

def header(title)
  return "<h1>#{title}</h1>"
end

#joinObject



110
111
112
# File 'lib/knjtasks.rb', line 110

def join
  @hayabusa.join
end

#load_requestObject



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/knjtasks.rb', line 118

def load_request
  @hayabusa.header("Content-Type", "text/html; charset=utf-8")
  
  #This will make the new Ruby-tasks-system compatible with mails sent from the old PHP-tasks-system.
  _get["show"] = "task_show" if _get["show"] == "tasks_show"
  _get["show"] = "user_login" if _get["show"] == "users_login"
  
  if _get.has_key?("l")
    _session[:locale] = _get["l"]
    _site.user[:locale] = _get["l"] if _site.user
    _hb.redirect(_meta["REQUEST_URI"].gsub(/&l=([A-z_]+)/, ""))
  end
end

#mail_task_comments_runObject



106
107
108
# File 'lib/knjtasks.rb', line 106

def mail_task_comments_run
  @thread_mail_task_comments.run
end

#no_date(event, date) ⇒ Object



102
103
104
# File 'lib/knjtasks.rb', line 102

def no_date(event, date)
  return "[#{_("no date")}]"
end

#no_html(event, classname) ⇒ Object



96
97
98
99
100
# File 'lib/knjtasks.rb', line 96

def no_html(event, classname)
  class_trans = @class_translations[classname]
  class_trans = classname.to_s.downcase if !class_trans
  return "[#{sprintf(_("no %s"), class_trans)}]"
end

#startObject



114
115
116
# File 'lib/knjtasks.rb', line 114

def start
  @hayabusa.start
end

#userObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/knjtasks.rb', line 150

def user
  begin
    if _session[:user_id].to_i > 0
      user = @ob.get(:User, _session[:user_id])
      if !user.active?
        _session.delete(:user_id)
        return false
      end
      
      return user
    end
  rescue
    return false
  end
  
  return false
end