Class: Intranet::Pictures::Responder

Inherits:
AbstractResponder
  • Object
show all
Includes:
Core::HamlWrapper
Defined in:
lib/intranet/pictures/responder.rb

Overview

The responder for the Pictures monitor module of the Intranet.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, defaults, in_menu = true) ⇒ Responder

Initializes a new Pictures responder instance.

Parameters:

  • provider (#title, #list_pictures, #group_thumbnail, #group_brief, #picture)

    The pictures provider.

  • defaults (Hash{group_by:String, sort_by:String, sort_order:String})

    The default grouping and sort order, if none is specified in the URL. All keys except group_by may be omitted.

  • in_menu (Boolean) (defaults to: true)

    Whether the module instance should be displayed in the main navigation menu or not.

See Also:



43
44
45
46
47
# File 'lib/intranet/pictures/responder.rb', line 43

def initialize(provider, defaults, in_menu = true)
  @provider = provider
  @defaults = defaults
  @in_menu = in_menu
end

Class Method Details

.module_homepageString

Returns the homepage URL of the module.

Returns:

  • (String)

    The homepage URL of the module.



29
30
31
# File 'lib/intranet/pictures/responder.rb', line 29

def self.module_homepage
  HOMEPAGE_URL
end

.module_nameString

Returns the name of the module.

Returns:

  • (String)

    The name of the module.



17
18
19
# File 'lib/intranet/pictures/responder.rb', line 17

def self.module_name
  NAME
end

.module_versionString

Returns the version of the module, according to semantic versionning.

Returns:

  • (String)

    The version of the module.



23
24
25
# File 'lib/intranet/pictures/responder.rb', line 23

def self.module_version
  VERSION
end

Instance Method Details

#generate_page(path, query) ⇒ Integer, String

Generates the HTML content associated to the given path and query. Relevant queries are as follows:

  • If path is /browse.html, key/value pairs may be used to restrict the displayed images to those satisfying all the pairs. Moreover, sort_by (followed by a key), sort_order (followed by either asc or desc) and group_by may be used to alter the way images are displayed.
  • If path is /api/group_thumbnail or /api/group_brief, query must contain only a single key/value pair designating the pictures group.
  • If path is /api/pictures, key/value pairs may be used to restrict the displayed images to those satisfying all the pairs. Moreover, sort_by (followed by a key), and sort_order (followed by either asc or desc) may be used to alter the order in which images are returned.
  • If path is api/picture, key/value pairs must be used to select a single image from the gallery.

When path is /api/pictures, the selected pictures are returned in JSON format (REST API) with the following structure: [ { "id": "...", "height": 480, "width": 640, "title": "...", "datetime": "...", ... }, { ... } ]

Parameters:

  • path (String)

    The requested URI, relative to that module root URI.

  • query (Hash<String,String>)

    The URI variable/value pairs, if any.

Returns:

  • (Integer, String, String)

    The HTTP return code, the MIME type and the answer body.



88
89
90
91
92
93
94
95
# File 'lib/intranet/pictures/responder.rb', line 88

def generate_page(path, query)
  case path
  when %r{^/index\.html$} then serve_home(query)
  when %r{^/api/} then serve_api(path.gsub(%r{^/api}, ''), query)
  when %r{^/i18n\.js$} then serve_i18n_js
  else super
  end
end

#in_menu?Boolean

Specifies if the responder instance should be displayed in the main navigation menu or not.

Returns:

  • (Boolean)

    True if the responder instance should be added to the main navigation menu, False otherwise.



52
53
54
# File 'lib/intranet/pictures/responder.rb', line 52

def in_menu?
  @in_menu
end

#resources_dirString

Specifies the absolute path to the resources directory for that module.

Returns:

  • (String)

    The absolute path to the resources directory for the module.



58
59
60
# File 'lib/intranet/pictures/responder.rb', line 58

def resources_dir
  File.absolute_path(File.join('..', 'resources'), __dir__)
end

#titleString

The title of the Pictures module, as displayed on the web page.

Returns:

  • (String)

    The title of the Pictures web page.



99
100
101
# File 'lib/intranet/pictures/responder.rb', line 99

def title
  I18n.t('pictures.menu')
end