Module: Taskr::Views::HTML
- Includes:
- Controllers
- Defined in:
- lib/taskr/views.rb
Constant Summary collapse
- CONTENT_TYPE =
'text/html'
Instance Method Summary collapse
- #action_form ⇒ Object
- #action_list ⇒ Object
- #action_parameters_form(action = @action) ⇒ Object
- #edit_task ⇒ Object
- #log_entries_list ⇒ Object
- #new_task ⇒ Object
- #scheduler_status ⇒ Object
- #tasks_list ⇒ Object
- #view_task ⇒ Object
Instance Method Details
#action_form ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/taskr/views.rb', line 397 def action_form @num ||= 0 p do label 'action_class_name' br select(:name => "action[#{@num}][action_class_name]", :id => "action_class_name_#{@num}", :class => "action_class_name", :onchange => "show_action_parameters(#{@num})") do option(:value => "") @actions.each do |a| a.to_s =~ /Taskr::Actions::([^:]*?)$/ option(:value => $~[1]) {$~[1]} end end end div(:id => "parameters_#{@num}") end |
#action_list ⇒ Object
370 371 372 373 374 375 376 377 |
# File 'lib/taskr/views.rb', line 370 def action_list h1 "Actions" ul do @actions.each do |a| li a end end end |
#action_parameters_form(action = @action) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/taskr/views.rb', line 379 def action_parameters_form(action = @action) @num ||= 0 p {em action.description} action.parameters.each do |param| p do label param br unless action.is_a?(Taskr::Models::TaskAction) # Setting up a new task input :type => 'text', :name => "action[#{@num}][#{param}]", :size => 50 else # Editing an existing task input :type => 'text', :name => "action[action_id_#{action.id}][#{param.name}]", :size => 50, :value => param.value end end end end |
#edit_task ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/taskr/views.rb', line 88 def edit_task html_scaffold do script(:type => 'text/javascript') do %{ function show_action_parameters(num) { new Ajax.Updater('parameters_'+num, '#{R(Actions)}', { method: 'get', parameters: { id: $F('action_class_name_'+num), action: 'parameters_form', num: num } }); } } end a(:href => R(Tasks, :list)) {"Back to Task List"} form :method => 'put', :action => R(@task, 'update') do h1 "Edit Task \"#{@task.name}\"" p do label 'name' br input :type => 'text', :name => 'name', :value => @task.name, :size => 40 end p do label 'schedule' br select(:name => 'schedule_method') do ['every','at','in','cron'].each do |method| if @task.schedule_method == method option(:value => method, :selected => 'selected') {method} else option(:value => method) {method} end end end input :type => 'text', :name => 'schedule_when', :value => @task.schedule_when, :size => 30 end p do label 'description/memo' br textarea(:name => 'memo', :cols => '60', :rows => '4'){@task.memo} end p do label "Actions:" @task.task_actions.each do |action| div {action_parameters_form(action)} end # div do # if @task.task_actions.length > 1 # ol(:style => 'padding-left: 20px') do # @task.task_actions.each do |ta| # html_task_action_li(ta) # end # end # else # html_task_action_li(@task.task_actions.first) # end # end end p do a(:id => 'add_action', :href => '#'){'Add another action'} end script(:type => 'text/javascript') do %{ Event.observe('add_action', 'click', function() { new Ajax.Updater('add_action', '#{R(Actions, :new)}', { method: 'get', parameters: { num: $$('select.action_class_name').size() }, insertion: Insertion.Before }); return false; }) } end (:type => 'submit') {"Save"} end end end |
#log_entries_list ⇒ Object
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/taskr/views.rb', line 419 def log_entries_list h2 "Log" p(:style => 'margin: 0px') do em(:style => "font-weight: normal; font-size: 9pt"){"Entries since #{@since}<br />"} unless @since.blank? em(:style => "font-weight: normal; font-size: 9pt"){"With levels #{@level.join(", ")}<br />"} unless @level.blank? end table do @log_entries.each do |entry| case entry.level.downcase.intern when :error bg_color = '#faa' when :warn bg_color = '#ffa' when :info bg_color = '#aaf' when :debug bg_color = '#eee' else bg_color = '#fff; '+entry.level.inspect end tr do td(:style => "vertical-align: top; font-size: 9pt; white-space: nowrap; background: #{bg_color}") do entry. end td(:style => "vertical-align: top; font-size: 9pt; background-color: #{bg_color}; font-size: 9pt; font-family: monospace") do entry.data.gsub(/<\/?(html|body)>/, '').gsub(/\n/, "<br />") end end end end end |
#new_task ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/taskr/views.rb', line 178 def new_task html_scaffold do script(:type => 'text/javascript') do %{ function show_action_parameters(num) { new Ajax.Updater('parameters_'+num, '#{R(Actions)}', { method: 'get', parameters: { id: $F('action_class_name_'+num), action: 'parameters_form', num: num } }); } } end form :method => 'post', :action => self/"/tasks?format=#{@format}" do h1 "New Task" input :type => 'hidden', :name => '_method', :value => 'post' p do label 'name' br input :type => 'text', :name => 'name', :size => 40 end p do label 'schedule' br select(:name => 'schedule_method') do ['every','at','in','cron'].each do |method| option(:value => method) {method} end end input :type => 'text', :name => 'schedule_when', :size => 30 end p do label 'description/memo' br textarea(:name => 'memo', :cols => '60', :rows => '4'){""} end action_form p do a(:id => 'add_action', :href => '#'){'Add another action'} end script(:type => 'text/javascript') do %{ Event.observe('add_action', 'click', function() { new Ajax.Updater('add_action', '#{R(Actions, :new)}', { method: 'get', parameters: { num: $$('select.action_class_name').size() }, insertion: Insertion.Before }); return false; }) } end (:type => 'submit') {"submit"} end end end |
#scheduler_status ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/taskr/views.rb', line 357 def scheduler_status s = Taskr.scheduler h3(:style => "margin-bottom: 8px;") {"Scheduler Status"} strong "Running?" span(:style => 'margin-right: 10px') {s.instance_variable_get(:@stopped) ? "NO" : "Yes"} strong "Precision:" span(:style => 'margin-right: 10px') {"#{s.instance_variable_get(:@precision)}s"} strong "Pending Jobs:" span(:style => 'margin-right: 10px') {s.instance_variable_get(:@pending_jobs).size} strong "Thread Status:" span(:style => 'margin-right: 10px') {s.instance_variable_get(:@scheduler_thread).status} end |
#tasks_list ⇒ Object
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 |
# File 'lib/taskr/views.rb', line 40 def tasks_list html_scaffold do h1 {"Tasks"} p{a(:href => R(Taskr::Controllers::Tasks, 'new')) {"Schedule New Task"}} table do thead do tr do th "Name" th "Schedule" th "Last Triggered" th "Job ID" th "Created On" th "Created By" th "" end end tbody do @tasks.each do |t| tr_css = [] tr_css << "error" if t.last_triggered_error tr_css << "expired" if t.next_trigger_time != :unknown && t.next_trigger_time < Time.now tr(:class => tr_css.join(" ")) do td {a(:href => R(t)) {strong{t.name}}} td "#{t.schedule_method} #{t.schedule_when}" td do if t.last_triggered "#{distance_of_time_in_words(t.last_triggered, Time.now, true)} ago" else em "Not yet triggered" end end td(:class => "job-id") {t.scheduler_job_id} td t.created_on td t.created_by td {a(:href => R(t, 'edit')) {"Edit"}} end end end end br div {scheduler_status} end end |
#view_task ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/taskr/views.rb', line 245 def view_task html_scaffold do form(:method => 'delete', :style => 'display: inline', :action => R(@task)) do (:type => 'submit', :value => 'delete', :onclick => 'return confirm("Are you sure you want to unschedule and delete this task?")') {"Delete"} end form(:method => 'put', :style => 'display: inline', :action => R(@task, 'run')) do (:type => 'submit', :value => 'run') {"Run Now!"} end form(:method => 'put', :style => 'display: inline', :action => R(@task, 'reload')) do (:type => 'submit', :value => 'reload') {"Reload!"} end br a(:href => R(Tasks, :list)) {"Back to Task List"} h1 "Task #{@task.id}" table do tr do th "Name:" td @task.name end tr do th "Schedule:" td "#{@task.schedule_method} #{@task.schedule_when}" end tr do th "Description/Memo:" td "#{@task.memo}" end tr do th "Job ID:" td @task.scheduler_job_id end tr do th "Triggered:" td do if @task.last_triggered span "#{distance_of_time_in_words(@task.last_triggered, Time.now, true)} ago" span(:style => 'font-size: 8pt; color: #bbb'){"(#{@task.last_triggered})"} else em "Not yet triggered" end end end if @task.last_triggered_error th "Error:" td(:style => 'color: #e00;') do strong "#{@task.last_triggered_error[:type]}" br pre @task.last_triggered_error[:message] end end tr do th "Actions:" td do if @task.task_actions.length > 1 ol(:style => 'padding-left: 20px') do @task.task_actions.each do |ta| html_task_action_li(ta) end end else html_task_action_li(@task.task_actions.first) end end end tr do th "Created By:" td @task.created_by end tr do th "Created On:" td @task.created_on end end script %{ function clickbold(el) { $$('#logfilter a').each(function(a){a.style.fontWeight = 'normal'}) el.style.fontWeight = 'bold' } } p(:style => "margin-top: 20px; border-top: 1px dotted black; padding-top: 10px", :id => 'logfilter') do strong "Show: " a(:href => R(LogEntries, :list, :task_id => @task.id, :since => (Time.now - 1.day).to_formatted_s(:db)), :target => 'log', :onclick => "clickbold(this)", :style => 'font-weight: bold') {"Last 24 Hours"} text "|" a(:href => R(LogEntries, :list, :task_id => @task.id, :since => (Time.now - 2.days).to_formatted_s(:db)), :target => 'log', :onclick => "clickbold(this)") {"48 Hours"} text "|" a(:href => R(LogEntries, :list, :task_id => @task.id), :target => 'log', :onclick => "clickbold(this)") {"All"} br strong "Level: " a(:href => R(LogEntries, :list, :task_id => @task.id, :level => 'DEBUG'), :target => 'log', :onclick => "clickbold(this)") {"DEBUG"} text "|" a(:href => R(LogEntries, :list, :task_id => @task.id, :level => 'INFO'), :target => 'log', :onclick => "clickbold(this)") {"INFO"} text "|" a(:href => R(LogEntries, :list, :task_id => @task.id, :level => 'WARN'), :target => 'log', :onclick => "clickbold(this)") {"WARN"} text "|" a(:href => R(LogEntries, :list, :task_id => @task.id, :level => 'ERROR'), :target => 'log', :onclick => "clickbold(this)") {"ERROR"} end iframe(:src => R(LogEntries, :list, :task_id => @task.id, :since => (Time.now - 1.day).to_formatted_s(:db)), :style => 'width: 100%; height: 300px', :name => 'log') end end |