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, recents = [], home_groups = [], in_menu = true) ⇒ Responder

Initializes a new Pictures responder instance.

Parameters:

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

    The pictures provider.

  • recents (Array<Hash{group_by:String, sort_by:String, sort_order:String, limit:Integer}>) (defaults to: [])

    The description of the recent pictures to be displayed on the module home page. Pictures will first be sorted according to sort_by and sort_order, then grouped by group_by, keeping only the first limit elements, or all if limit is zero. All keys except group_by may be omitted.

  • home_groups (Array<Hash{group_by:String, sort_by:String, sort_order:String, browse_group_by:String, browse_sort_by:String, browse_sort_order:String}>) (defaults to: [])

    The description of the pictures groups to be displayed on the module home page, after the recents. Pictures will first be sorted according to sort_by and sort_order, then grouped by group_by. The obtained groups will be displayed with their thumbnail, (optional) brief text and a link to display images of that group sorted according to browse_sort_by and browse_sort_order and grouped by browse_group_by. All keys except group_by and browse_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:



54
55
56
57
58
59
# File 'lib/intranet/pictures/responder.rb', line 54

def initialize(provider, recents = [], home_groups = [], in_menu = true)
  @provider = provider
  @recents = recents
  @in_menu = in_menu
  @home_groups = home_groups
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.



100
101
102
103
104
105
106
107
108
# File 'lib/intranet/pictures/responder.rb', line 100

def generate_page(path, query)
  case path
  when %r{^/index\.html$}  then serve_home
  when %r{^/browse\.html$} then serve_browse(query)
  when %r{^/api/} then serve_api(path.gsub(%r{^/api}, ''), query)
  when %r{^/i18n\.js$} then serve_i18n_js
  else super(path, query)
  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.



64
65
66
# File 'lib/intranet/pictures/responder.rb', line 64

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.



70
71
72
# File 'lib/intranet/pictures/responder.rb', line 70

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

#titleString

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

Returns:

  • (String)

    The title of the Pictures module web page.



112
113
114
# File 'lib/intranet/pictures/responder.rb', line 112

def title
  @provider.title
end