Module: RestFtpDaemon::ViewsHelper

Defined in:
lib/rest-ftp-daemon/helpers/views.rb

Instance Method Summary collapse

Instance Method Details

#dashboard_feature(name, enabled, message_on = "enabled", message_of = "disabled") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 4

def dashboard_feature name, enabled, message_on = "enabled", message_of = "disabled"
  # Build classes
  class_status = enabled ? 'enabled' : 'disabled'
  classes = "btn btn-default feature-#{class_status}"

  # Build title
  title_status = enabled ? message_on : message_of
  title = "#{name}: #{title_status}"

  return sprintf(
    '<div class="%s" title="%s"><img src="/images/feature_%s.png" height="14" alt="%s"/></div>',
    classes,
    title,
    name,
    title
    )
end

#dashboard_job_url(job) ⇒ Object



22
23
24
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 22

def dashboard_job_url job
  "#{MOUNT_JOBS}/#{job.id}" if job.respond_to? :id
end

#datetime_short(datetime) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 79

def datetime_short datetime
  # return param.class
  return "-" if datetime.nil?
  return "?" unless datetime.respond_to? :to_date
  return datetime.to_datetime.strftime("%H:%M:%S") if datetime.to_date == Time.now.to_date
  datetime.to_datetime.strftime("%d/%m %H:%M:%S")
end

#formatted_duration(duration) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 87

def formatted_duration duration
  out = []

  hours = duration / (60 * 60)
  minutes = (duration / 60) % 60
  seconds = duration % 60

  out << "#{hours}h" if hours > 0
  out << "#{minutes}mn" if (minutes > 0) || (hours > 0)
  out << "#{seconds}s"

  out.join(" ")
end

#job_runs_style(runs) ⇒ Object



26
27
28
29
30
31
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 26

def job_runs_style runs
  return  "label-outline"   if runs <= 0
  return  "label-info"      if runs == 1
  return  "label-warning"   if runs == 2
  return  "label-danger"    if runs > 2
end

#job_style(job) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 48

def job_style job
  case job.type
  when JOB_TYPE_TRANSFER
    icon_klass = "transfer"
  when JOB_TYPE_VIDEO
    icon_klass = "facetime-video"
  when JOB_TYPE_DUMMY
    icon_klass = "question-sign"
  else
    icon_klass = "label-default"
  end
end

#job_type(job) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 70

def job_type job
  sprintf(
      '<span class="glyphicon glyphicon-%s" alt="%s"></span>&nbsp;%s',
      job_style(job),
      job.type,
      job.type
      )
end

#location_label(uri) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 61

def location_label uri
  sprintf(
    '<div class="transfer-type label label-%s" title="%s">%s</div>',
    location_style(uri),
    uri.to_s,
    uri.class.name.split('::').last
    )
end

#location_style(uri) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 33

def location_style uri
  case uri
  when URI::FILE
    "info"
  when URI::FTP
    "warning"
  when URI::FTPES, URI::FTPS, URI::SFTP
    "success"
  when URI::S3
    "primary"
  else
    "default"
  end
end

#remove_credentials(path) ⇒ Object



101
102
103
104
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 101

def remove_credentials path
  return unless path.is_a? String
  path.sub(/([a-z]+:\/\/[^\/]+):[^\/]+\@/, '\1@')
end

#text_or_empty(text) ⇒ Object



116
117
118
119
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 116

def text_or_empty text
  return "-" if text.nil? || text.empty?
  text
end

#token_highlight(path) ⇒ Object



111
112
113
114
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 111

def token_highlight path
  return unless path.is_a? String
  path.gsub(/\[([^\[]+)\]/, token_to_label('\1'))
end

#token_to_label(name, url = '') ⇒ Object



106
107
108
109
# File 'lib/rest-ftp-daemon/helpers/views.rb', line 106

def token_to_label name, url = ''
  clean_url = remove_credentials url
  sprintf '<span class="token" title="%s">%s</span>', clean_url, name
end