lib/taskr/views.rb in taskr-0.3.0 vs lib/taskr/views.rb in taskr-0.4.0
- old
+ new
@@ -22,15 +22,15 @@
include Taskr::Models
CONTENT_TYPE = 'text/xml'
def tasks_list
- @tasks.to_xml(:root => 'tasks')#, :include => [:task_actions])
+ @tasks.to_xml(:root => 'tasks', :include => [:task_actions])
end
def view_task
- @task.to_xml(:root => 'task')#, :include => [:task_actions])
+ @task.to_xml(:root => 'task', :include => [:task_actions])
end
end
module HTML
include Taskr::Controllers
@@ -50,10 +50,11 @@
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 = []
@@ -71,20 +72,111 @@
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
+ 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
+
+ button(:type => 'submit') {"Save"}
+ end
+ end
+ end
+
def new_task
html_scaffold do
script(:type => 'text/javascript') do
%{
function show_action_parameters(num) {
@@ -156,10 +248,13 @@
button(: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
button(:type => 'submit', :value => 'run') {"Run Now!"}
end
+ form(:method => 'put', :style => 'display: inline', :action => R(@task, 'reload')) do
+ button(:type => 'submit', :value => 'reload') {"Reload!"}
+ end
br
a(:href => R(Tasks, :list)) {"Back to Task List"}
h1 "Task #{@task.id}"
table do
@@ -220,11 +315,44 @@
th "Created On:"
td @task.created_on
end
end
- iframe(:src => R(LogEntries, :list, :task_id => @task.id), :style => 'width: 100%; margin-top: 20px;')
+ 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
def scheduler_status
s = Taskr.scheduler
@@ -246,20 +374,24 @@
li a
end
end
end
- def action_parameters_form
+ def action_parameters_form(action = @action)
@num ||= 0
- p {em @action.description}
+ p {em action.description}
- @action.parameters.each do |param|
+ action.parameters.each do |param|
p do
label param
br
- input :type => 'text', :name => "action[#{@num}][#{param}]", :size => 50
+ 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
def action_form
@@ -284,9 +416,15 @@
end
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'
\ No newline at end of file