Module: ODDB::View::User::Export

Included in:
Drugs::DivExportCSV, DownloadExportInnerComposite, FachinfoPDFDownloadInnerComposite, OddbDatDownloadInnerComposite, YamlExportInnerComposite
Defined in:
src/view/user/export.rb

Constant Summary

EXPORT_DIR =
File.expand_path(
'../../../data/downloads',
File.dirname(__FILE__))
EXPORT_FILE =
''

Instance Method Summary (collapse)

Instance Method Details

- (Object) checkbox_with_filesize(filename)



63
64
65
66
67
68
69
70
# File 'src/view/user/export.rb', line 63

def checkbox_with_filesize(filename)
  if(display?(filename))
    checkbox = HtmlGrid::InputCheckbox.new("download[#{filename}]", 
      @model, @session, self)
    size = filesize(filename)
    [checkbox, "#{filename} #{size}"]
  end
end

- (Object) convert_filesize(filename)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'src/view/user/export.rb', line 43

def convert_filesize(filename)
  kilo = (2**10)
  valid_paths = file_paths(filename).select { |path|
    File.exist?(path)
  }
  sizes = valid_paths.collect { |path|
    File.size(path)
  }
  size = sizes.max
  unit = 'Bytes'
  if(size > kilo)
    size = size / kilo
    unit = "KB"
  end
  if(size > kilo)
    size = size / kilo
    unit = "MB"
  end
  sprintf('( ~ %i %s)', size, unit)
end

- (Object) datadesc(filename)



12
13
14
15
16
17
18
19
20
21
# File 'src/view/user/export.rb', line 12

def datadesc(filename)
  if(display?(filename))
    link = HtmlGrid::Link.new(:data_description, 
      @model, @session, self)
    path = File.join('datadesc', "#{filename}.txt")
    link.href = @lookandfeel.resource_global(:downloads, path)
    link.css_class = 'small'
    link
  end
end

- (Boolean) display?(name)

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'src/view/user/export.rb', line 22

def display?(name)
  res = file_paths(name).any? { |path|
    File.exists?(path) && File.size(path) > 0
  }
  res
end

- (Object) example(filename)



28
29
30
31
32
33
34
# File 'src/view/user/export.rb', line 28

def example(filename)
  link = HtmlGrid::Link.new(:example_download, 
                            @model, @session, self)
  link.href = @lookandfeel.resource_global(:examples, filename)
  link.css_class = 'small'
  link
end


35
36
37
38
39
40
41
42
# File 'src/view/user/export.rb', line 35

def export_link(key, filename)
  link = HtmlGrid::Link.new(key, @model, @session, self)
  args = {'filename'=>filename}
  link.href = @lookandfeel._event_url(:download, args)
  link.label = true
  link.set_attribute('class', 'list')
  link
end

- (Object) file_path(filename)



103
104
105
# File 'src/view/user/export.rb', line 103

def file_path(filename)
  File.expand_path(filename, self::class::EXPORT_DIR)
end

- (Object) file_paths(filename)



106
107
108
109
110
111
112
113
# File 'src/view/user/export.rb', line 106

def file_paths(filename)
  if uncompressed?(filename)
    return [File.expand_path(filename, self::class::EXPORT_DIR)]
  end
  ['.zip', '.gz', '.tar.gz'].collect { |suffix|
    File.expand_path(filename + suffix, self::class::EXPORT_DIR)
  }
end

- (Object) filesize(filename)



114
115
116
117
118
# File 'src/view/user/export.rb', line 114

def filesize(filename)
  if(display?(filename))
    convert_filesize(filename)
  end
end

- (Object) once(filename)



71
72
73
74
75
76
77
78
79
80
# File 'src/view/user/export.rb', line 71

def once(filename)
  if(display?(filename))
    price = State::User::DownloadExport.price(filename)
     = HtmlGrid::Input.new("months[#{filename}]", 
      @model, @session, self)
    .set_attribute('type', 'hidden')
    .value = '1'
    [@lookandfeel.format_price(price.to_i * 100, 'EUR'), ]
  end
end

- (Object) once_or_year(filename)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'src/view/user/export.rb', line 81

def once_or_year(filename)
  if(display?(filename))
    name = "months[#{filename}]"
    months = @session.user_input('months') || {}
    checked = months[filename] || '1'
    radio1 = HtmlGrid::InputRadio.new(name, @model, @session, self)
    price = State::User::DownloadExport.price(filename)
    price1 = @lookandfeel.format_price(price.to_i * 100, 'EUR')
    radio1.value = '1'
    if(checked == '1')
      radio1.set_attribute('checked', true)
    end
    radio2 = HtmlGrid::InputRadio.new(name, @model, @session, self)
    radio2.value = '12'
    if(checked == '12')
      radio2.set_attribute('checked', true)
    end
    price = State::User::DownloadExport.subscription_price(filename)
    price2 = @lookandfeel.format_price(price.to_i * 100, 'EUR')
    [radio1, nil, price1, nil, radio2, nil, price2]
  end
end

- (Boolean) uncompressed?(filename)

Returns:

  • (Boolean)


119
120
121
# File 'src/view/user/export.rb', line 119

def uncompressed?(filename)
  DOWNLOAD_UNCOMPRESSED.include?(filename)
end