Difference between revisions of "Views.pl"

From EPrints Documentation
Jump to: navigation, search
(Option avaible for the views config)
m (Sections: fixed typo)
 
(58 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== Option avaible for the views config ==
+
[[Category:Browse Views]]
 +
{{dirs}}
 +
{{cfgd}}
 +
 
 +
'''views.pl''' contains configuration for rendering ''views''.  Conceptually a ''view'' is a browsable list of eprints split into ''menus'' and a ''list''.
 +
 
 +
<div align="center">
 +
{| cellpadding="0" cellspacing="0" border="0"
 +
|-
 +
| style="border-color:black; border-style:solid; border-width:1px 1px 0 1px; margin:0; padding:0; text-align:center; font-size:10px" |Menu1
 +
| &nbsp;
 +
| &nbsp;
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
| style="border-color:black; border-style:solid; border-width:0 1px; text-align: left; margin:0; padding:0; font-size:10px"| &nbsp; Item1_1 ------
 +
| style="font-size:10px"|--->
 +
| style="border-color:black; border-style:solid; border-width:1px 1px 0 1px; margin:0; padding:0; text-align:center; font-size:10px"|Menu2
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
|style="border-color:black; border-style:solid; border-width:0 1px; text-align: left; font-size:10px"| &nbsp; Item1_2
 +
| &nbsp;
 +
|style="border-color:black; border-style:solid; border-width:0 1px; text-align: left; margin:0; padding:0; font-size:10px"| &nbsp; Item2_1 -----
 +
|style="font-size:10px"|--->
 +
|style="border-color:black; border-style:solid; border-width:1px 1px 0 1px; margin:0; padding:0; text-align:center; font-size:10px"| &nbsp; &nbsp; LIST &nbsp; &nbsp;
 +
|-
 +
|style="border-color:black; border-style:solid; border-width:0 1px 1px 1px; margin:0; padding:0; text-align:left; font-size:10px"| &nbsp; ....
 +
| &nbsp;
 +
|style="border-color:black; border-style:solid; border-width:0 1px; text-align: left; margin:0; padding:0; font-size:10px"| &nbsp; Item2_2
 +
|&nbsp;
 +
|style="border-color:black; border-style:solid; border-width:0 1px 1px 1px; margin:0; padding:0; text-align:left; font-size:10px"| &nbsp; ....
 +
|-
 +
| &nbsp;
 +
| &nbsp;
 +
|style="border-color:black; border-style:solid; border-width:0 1px 1px 1px; margin:0; padding:0; text-align:left; font-size:10px"| &nbsp; ....
 +
| &nbsp;
 +
|&nbsp;
 +
|}
 +
</div>
 +
In a ''menu'' values of one (or more) fields are listed, and a link points to the collection of all items with that particular value in that field.
 +
 
 +
The ''list'' contains the final list of eprints with field values as determined by the menus above it.
 +
 
 +
 
 +
== Options available for the views config ==
 
This link is an [http://wiki.eprints.org/w/Adding_new_views 'How to' about views] with examples.
 
This link is an [http://wiki.eprints.org/w/Adding_new_views 'How to' about views] with examples.
  
Line 5: Line 50:
  
 
   $c->{browse_views} = [
 
   $c->{browse_views} = [
     { <first browse definition> },
+
     { <first view definition> },
     { <second browse definition> },
+
     { <second view definition> },
 
     ...
 
     ...
     { <last browse definition> },
+
     { <last view definition> },
 
   ];
 
   ];
  
(be careful about commas and semicolons). The order of the view determine the order in which they appear in the http://repoid/view/ page.
+
(be careful about commas and semicolons). The order of the view definitions determines the order in which these will appear in the <nowiki>http://repoid/view/</nowiki> page.
  
Each browse definition is a collection of attributes, given as
+
Each view definition is a collection of attributes, given as
  
     attribute_id => value,
+
     attribute1 => value1,
 +
    attribute2 => value2,
 +
    ...
  
(again, the ''value'' should end by a comma). The ''value'' can be a ''string'' enclosed by quotation marks (") or by apostrophes ('); an ''array'' which starts by a square bracket [ followed by the elements of the array (separated by commas) and closed by ]; or a ''hash'' which is a list of attribute&endash;value pairs enclosed into curly brackets. Thus the browse view definition is an array of hashes.
+
(again, the ''value'' should end by a comma). The ''value'' can be
 +
*''integer''
 +
*''string'' enclosed by quotation marks (") or by apostrophes (')
 +
*''array'' which starts by a square bracket [ followed by the elements of the array (separated by commas) and closed by ] or  
 +
*''hash'' which is a list of "attribute => value" pairs enclosed by curly brackets { and }.
 +
Thus the browse_views definition is an array of hashes.
  
===Basic attributes===
+
Attributes marked by <sup style="font-weight:bold; font-size:10px">(V)</sup> are ''view'' attributes and are in the view definition; attributes marked by <sup style="font-weight:bold; font-size:10px">(M)</sup> are ''menu'' attributes and should be used only in [[#Menu options|menu definitions]].
  
====id (mandatory)====
+
==Basic options==
  
This is the ID by which you will refer to this view. For example, this is the value of the ''browse_link'' attribute in [[eprint_fields.pl]].
+
Options in the first category are ''view'' options.
  
====fields (deprecated)====
+
{| border="1" cellpadding="4" cellspacing="0"
 +
|- valign="top"
 +
| id <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
| (mandatory) String, this is the ID by which you will refer to this view, and also the name of the top directory in <nowiki>http://repoid/view/</nowiki>. This is the value of the ''browse_link'' attribute in [[eprint_fields.pl]]. Example:
  
This attribute describes the field(s) by which the view is built. It has been replaced by the more general [[#menus|menus]] attribute.
+
    id => 'divisions',
 +
|- valign="top"
 +
|fields <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|(deprecated) This attribute describes the field(s) by which the view is built. It has been replaced by the more general [[#Menu options|menus]] attribute.
 +
|- valign="top"
 +
|hideempty <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
allow_null <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
new_column_at <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
render_menu <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|These define the default values of the same attributes in all [[#Menu options|menus]]. I.e, if not defined otherwise there, they take this as the default value in this view. "Hideempty" is also used when rendering the [[#View list options|view]] list.
 +
|- valign="top"
 +
|menus <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|An array of ''[[#Menu options|menu descriptions]]''. Each ''menu'' is a refinement of the previous ones, and last menu points to the [[#View list options|view list(s)]]. In each menu, as minimum, you should give the field(s) which are used to define entries at that level. The menus definition looks like
 +
  menus => [
 +
    { <first menu definition> },
 +
    { <second level menu> },
 +
    { <last level> },
 +
  ],
 +
You must have at least one menu level.
 +
|- valign="top"
 +
|template <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|Define an alternate template for all pages in this view. The template page should be a proper xml file in the <tt>repoid/cfg/lang/<langid>/templates/</tt> directory. The best way is to copy the default.xml file and edit it according to taste.
 +
  template => 'view_template',
 +
|- valign="top"
 +
|nolink <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|When this is set to 1 by adding
 +
  nolink => 1,
 +
then this view won't appear in the outmost <nowiki>http://repoid/view/</nowiki> browse page.
 +
|- valign="top"
 +
| max_menu_age&nbsp;<sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
| Defaults to 86400 (one day in seconds). If the menus in this view has been generated more than that many seconds ago, it is regenerated.
 +
|- valign="top"
 +
| max_items <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|Defaults to 2000.  If the items list is larger increase the number enough to accomodate the number of items needed to be displayed.
 +
  max_items => 3000,
 +
|}
 +
 
 +
 
 +
===View list options===
 +
These are the options which determine how the last list page in the menu chain should look like. They must be entered at the outmost ''view'' level.
 +
{| border="1" cellpadding="4" cellspacing="0"
 +
|- valign="top"
 +
|order <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|This defines how the items in the view list (at the lowest level) are ordered. The format is 'foo/-bar'. This means that the list will be sorted by 'foo' and then any equal 'foo' values will be reverse sorted by 'bar'. More than 2 fields can be specified. Example:
 +
  order => "-date/title",
 +
|- valign="top"
 +
|hideup <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|Don't show the "up one level" link in the list page. You ''must'' set this attribute for each menu separately, it is not inherited.
 +
|- valign="top"
 +
|hideempty <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|Do not list the empty (undefined) entry in the list. This property inherits to the menus.
 +
|- valign="top"
 +
|nocount <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|If set, the "Number of items" line at the top of the page is omitted.
 +
|- valign="top"
 +
|notimestamp <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|If set, the "This list was generated on" line at the bottom of the list is omitted.
 +
|- valign="top"
 +
|variations <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|An array of strings describing different rendering of the items at the ''list''. For datails see [[#Variations|variations]]. Example:
 +
    variation => [ "creators_name;first_letter",
 +
        "type", "DEFAULT", ],
 +
|- valign="top"
 +
|layout <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|Possible values are
 +
*paragraph (default)
 +
*orderedlist
 +
*unorderedlist
 +
Determines how items in the list (or sublist) is rendered. In the first case each item is a paragraph by itself. In the other cases items are rendered as an ordered (unordered) list.
 +
|- valign="top"
 +
|citation <sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|The citation style defined in archives/<REPOID>/cfg/citations/eprint/ which is used to render each item. Example:
 +
  citation => 'screen',
 +
|- valign="top"
 +
|max_list_age&nbsp;<sup style="font-weight:bold; font-size:10px;">(V)</sup>
 +
|Defaults to 86400 (one day in seconds). If the lists in this view were generated more than than many seconds ago, it is regenerated.
 +
|}
  
====nolink====
 
  
When this is set to 1 by adding
+
===Variations===
  
  nolink => 1,
+
Variations, if defined, determine how the final list is rendered. ''Variations'' is an array of strings, for example,
  
then this view won't appear in the outmost eprints.org/view/ browse directory.
+
[ "creators_name;first_letter",
 +
  "type",
 +
  "DEFAULT",
 +
]
  
====max_menu_age====
+
For each string in the list, a different rendering is produced, and you can switch from one to the other. The variation "DEFAULT" is the default one, it is always a good practice to include it in the list. If no variation is given, "DEFAULT" is used.
  
Defaults to 86400 (one day in seconds). If the menus in this view has been generated more than that many seconds before, it is regenerated.
+
A ''variation definition'' consists of a field name, followed by zero, one or more ''options'' after a semicolon. Options are separated by commas. An ''option'' is either a single attribute, or an attribute, an equal sign, and the value of the attribute. For example,
 +
    "creators_name;truncate=4,hideup"
 +
sets the attribute value "truncate" to 4, and "hideup" to 1 (or true).
  
====max_list_age====
+
The following options are available. These options are ''part of the string'' defining the variation, and ''should not be entered'' as attributes.
  
Defaults to 86400 (one day in seconds). If the list in this menu was generated more than than many seconds before, it is regenerated.
+
{| border="1" cellpadding="4" cellspacing="0"
 +
|- valign="top"
 +
|reverse
 +
|Reverses the order in which the groupings are shown.  Default is the ordervalue for that field (usually alphanumeric).  Useful for dates as you may want the highest values first.
 +
|- valign="top"
 +
|filename
 +
|Changes the filename of the view variation.  The default is the name of the metadata field used, so if two variations use the same metadata field with different options, this is needed.
 +
filename=different_filename
 +
|- valign="top"
 +
|first_value
 +
|If a field is multiple, only use the first value.  Otherwise each item will appear once for each value.
 +
|- valign="top"
 +
|first_initial
 +
|If using a name, truncate the given name to the first initial.  This will make items like "Les Carr" and "Leslie Carr" appear together.  Note it will also make "John Smith" and "Jake Smith" appear together too, showing that you really never can win.
 +
|- valign="top"
 +
|first_letter
 +
|The same as 'truncate=1'
 +
|- valign="top"
 +
|truncate
 +
|Use the first X characters of a value to group by.  truncate=4 may be useful for dates as it will group by the first four digits (the year) only.
 +
truncate=4
 +
|- valign="top"
 +
|tags
 +
|Useful for fields like keywords where values may be separated by commas or semi-colons.  The value is split on these two characters ( , and ; ) and a heading is created for each.
 +
|- valign="top"
 +
|cloud
 +
|Creates a tag cloud.  Sets jump to 'plain', cloudmax to 200, cloudmin to 80 and no_separator, then resizes the jump-to links according to frequency of use.
 +
|- valign="top"
 +
|cloudmax
 +
|The % size of the largest tag in a tag cloud.
 +
|- valign="top"
 +
|cloudmin
 +
|The % size of the smallest tag in a tag cloud.
 +
|- valign="top"
 +
|jump
 +
|Possible values are 'plain', 'default', and 'none'. Example:
 +
  jump=plain
 +
When set to 'plain' turns off the 'jump to' text before the list of subheading navigation links. When 'none', then the 'jump' part is not rendered.
 +
|- valign="top"
 +
|no_seperator (sic)
 +
|Turns of the separator between each subheading navigation link (by default a vertical bar symbol).
 +
|- valign="top"
 +
|string
 +
|Uses values 'as is'.  No ordervalues, no phrases.
 +
|- valign="top"
 +
|hideup (since 3.1.1)
 +
|Defaults to "0". If set to "1" this hides the "up to parent" link (often you want to hide this on .include files)
 +
|- valign="top"
 +
|render_fn
 +
|Name of a function to render this groupings list of items. For an example, see views_render_items_example.pl
 +
|}
  
====allow_null, new_column_at, hideempty, render_menu====
 
  
These define the default values of the same attributes in all [[#menus|menus]]. I.e, if not defined otherwise, they take this as the default value.
+
===Menu options===
  
====order====
+
These options can only be used in the '''menu definitions'''.
  
====menus====
+
{|border="1" cellpadding="4" cellspacing="0"
 +
|- valign="top"
 +
|fields  <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|Obligatory, an array of field identifiers. Items in all fields are merged together. For example, to define a list of those those who are either authors or editors or both, use the definition
  
An array of ''menu descriptions'' (see below). Each ''menu'' is a refinement of the previous ones. In each menu, as minimum, you should give the fields which are used to define the menu. Thus a ''menus'' definition looks like
+
    fields => [ "creators_id", "editors_id" ],
  
  menus => [
+
Even if there is a single field, you must use square brackets, such as
    { <first menu definition> },
 
    { <second menu definition which is the refinement of the first> },
 
    { <third level menu definition> },
 
  ],
 
  
If there is only one menu definition, then the browse will be ''flat'', otherwise you'll get links to the next level.
+
    fields => [ "subjects" ],
  
===Options in ''menus''===
+
<div style="color: #662211; background-color:#ddffdc; border:1px solid black; padding:3px;">'''Important!''' All fields must have the same type - i.e. you cannot mix titles and authors, say.</div>
  
====fields====
+
You can also add extra rendering info to the field name, without the "render_" prefix. For example, to make a date have resolution year, you would write
  
====allow_null====
+
    fields => [ "date;res=year" ],
  
If the ''fields'' value is undefined, the entry does not show up in the generated view. To allow these undefined values to be there as well, set
+
or, ordering authors by their ''given'' names rather than by their family names:
  
  allow_null => 1,
+
    fields => [ "creators_name;order=gf" ],
  
Be beware: the title of the undefined entries will be the ugly UNDEFINED. You can redefine this to something else in the system.xml file.
+
You can add ";quiet" to the field name to force non-existing values to appear as empty space rather than the ugly "UNDEFINED" (see the allow_null property below). You can find the available rendering properties of different fields in the [[Metadata]] section.
 +
|- valign="top"
 +
|allow_null <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|The ''undefined'' value among the possible values of the fields does not show up in the generated view. To allow the undefined value to appear as well, set
  
====hideempty====
+
  allow_null => 1,
  
If a category is empty, don't show it as an entry. Default value: show all entries, even if they contain no entries.  
+
Beware: the title of the undefined entries will be the ugly UNDEFINED. You might consider to use the ";quiet" rendering option for field names.
 +
|- valign="top"
 +
|hideempty <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|If a category is empty, don't show it as an entry. Default value: show all entries, even if they contain no entries. Used only in menus, not at the lower level (list).
 
Example:
 
Example:
  
 
     hideempty => 1,
 
     hideempty => 1,
 +
|- valign="top"
 +
|reverse_order <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|If set, then the ordering of items in this menu is reversed. Example:
 +
 +
    reverse_order => 1,
 +
|- valign="top"
 +
|mode <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|Possible values: ''[[#Sections|sections]]'' and ''default'' (default). When defined as ''sections'' then grouping can be defined by the following data:
 +
* ''grouping_function'' (group by first character if not defined)
 +
* ''group_sorting_function'' (how to sort members of a group)
 +
* ''group_range_function''
 +
* ''open_first_section'' the front page should show the first section
 +
See [[#Sections|below]].
 +
|- valign="top"
 +
|hideup <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|When set to 1, don't show the "move one level up" link at the top of the page.
 +
|- valign="top"
 +
|render_menu <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|The configuration parameter which renders this menu. This should be a string, and also you should define a routine with the same name. For example if you write
 +
    render_menu => 'render_view_menu_3col_boxes',
 +
then this menu will be rendered by the routine which is defined in [[views_render_menu_example.pl]] as
 +
  $c->{render_view_menu_3col_boxes} = sub
 +
  {
 +
      ...
 +
  }
 +
See there for hints how to tweak your own routine.
 +
|- valign="top"
 +
|new_column_at <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|Used in menus (not lists) and in default mode. This is an array of integers representing the number of items in a view list before another column is added.  For example:
 +
 +
[ 11 ]
  
===Standard===
+
The menu is rendered as a single column data if there are less than 11 entries, then there would be 2 columns.
  
====heading_level====
+
[ 11, 21 ]
  
====include====
+
This would have one column if there were ten or less values, two columns if there are twenty or less, and three columns for all other cases.
  
====subheadings====
+
[ 0, 0 ]
  
===Extra feature===
+
This would always have three columns.
  
====citation====
+
[ 2, 3 ]
  
====nocount====
+
This would have one column for a single data, two columns for two, and three columns for three or more data.
  
====nohtml====
+
Add one to the number of integers in the array and you get the maximum number of columns. The entries are evenly distributed in the columns.
 +
|}
  
====noindex====
 
  
====nolink====
+
===Sections===
  
 +
When a menu is using "sections", then items on the menu are grouped together. The exact method is defined by defining values for several options. These options go to the ''menus section'' as well.
  
===New features===
+
{|border="1" cellpadding="4" cellspacing="0"
 +
|-valign="top"
 +
|grouping_function <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|This function determines how grouping is done. The following predefined functions can be used:
 +
*"EPrints::Update::Views::group_by_a_to_z"
 +
*"EPrints::Update::Views::group_by_first_character" (default)
 +
*"EPrints::Update::Views::group_by_2_characters"
 +
*"EPrints::Update::Views::group_by_3_characters"
 +
*"EPrints::Update::Views::group_by_4_characters"
 +
*"EPrints::Update::Views::group_by_5_characters"
 +
with the usual meaning. If you use 'group_by_a_to_z', all entries not starting with a letter will be discarded.
 +
|-valign="top"
 +
|group_sorting_function <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|A custom function which sorts the group identifiers. The only available function
 +
*"EPrints::Update::Views::default_sort"
 +
sorts alphabetically.
 +
|-valign="top"
 +
|group_range_function <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|Splits the groups (as determined by the grouping function) into sections so that a group never splits. Groups are rendered separately, but a section is kept on a single page. Available grouping functions are
 +
*"Eprints::Update::Views::no_ranges" (default)
 +
*"EPrints::Update::Views::cluster_ranges_<range>"
 +
where <range> is one of 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, and 200.
 +
|-valign="top"
 +
|open_first_section <sup style="font-weight:bold; font-size:10px;">(M)</sup>
 +
|if set, the first section is included in the front page.
 +
|}
  
====render_menu====
+
==Phrases==
  
The name of a config element which defines a function with an alternate way to render the menu page for a view. For an example, try looking in lib/defaultcfg/cfg.d/views_render_menu_example.pl
+
Views can have their own titles and other phrases. If they do not exist, then a default one is used (usually containing the view's id). For examples, see the views.xml file.
  
====new_column_at====
+
{|border="1" cellpadding="3" cellspacing="0"
 +
|-valign="top"
 +
|viewname_eprint_<viewid>
 +
|the name of the browse pages
 +
|-valign="top"
 +
|viewintro_<viewid>
 +
|The phrase to replace the text "Please select a value to browse from the list below." in the top level menu
 +
|-valign="top"
 +
|viewintro_<viewid>/<value>
 +
|Intro phrase on the next level
 +
|-valign="top"
 +
|viewtitle_eprint_<viewid>_menu_<level>
 +
|Title of browse page at level <level>, which is 1, 2, ... In the phrase you can use the pins "value1", "value2", etc. where the number can be one less than the present level; the value of the pin is the actual value of the previous levels. See the example below.
 +
|-valign="top"
 +
|viewgroup_eprint_<viewid>_<filename>
 +
|Used as a pin value for the title on the list pages, when [[#Variations|variations]] are used. <Filename> is the filename defined as the option of the variation, or, if it is not defined, then it is the fieldname at the beginning.
 +
|-valign="top"
 +
|viewtitle_eprint_<viewid>_list
 +
|Title of the list pages of the view. You can use the same pins as before ("value1", "value2", etc.). If the list was generated by a [[#Variations|variation]] then the "grouping" pin is also available.
 +
|}
  
This is an array of integers representing the number of items in a view list before another column is addedFor example:
+
The following example shows how to define these values.
 +
  <epp:phrase id="viewname_eprint_divisions">Divisions</epp:phrase>
 +
<epp:phrase id="viewtitle_eprint_divisions_menu_1">
 +
    Browse by Division and Year</epp:phrase>
 +
<epp:phrase id="viewtitle_eprint_divisions_menu_2">
 +
    Browse by Year where Division is
 +
    <epc:pin name="value1" /> </epp:phrase>
  
[ 10 ]
+
==Other==
  
This would have one column of values until there were 11, then there would be 2 columns.
+
{|border="1" cellpadding="4" cellspacing="0"
 +
|heading_level
 +
| ?
 +
|-
 +
|include
 +
| ?
 +
|-
 +
|subheadings
 +
| ?
 +
|-
 +
|nohtml
 +
| ?
 +
|-
 +
|noindex
 +
| ?
 +
|}
  
  [ 10, 10 ]
+
=Example=
 +
==EPrints 3.2 example==
 +
===cfg/cfg.d/views.pl===
 +
  { id        => "target", # The 'name' for this view
 +
    allow_null => 0,
 +
    hide_empty => 1,
 +
    menus      => [
 +
      { fields => ["broker_reponame"], # The field(s) to use - in this case the 'reponame' sub-element of the 'broker' field
 +
        new_column_at      => [0],    # force 2 columns, even if the
 +
                                      # second is blank
 +
        mode              => "sections",
 +
        open_first_section => 1,
 +
        group_range_function  => "EPrints::Update::Views::cluster_ranges_30",
 +
        group_sorting_function => "EPrints::Update::Views::default_sort",
 +
      },
 +
    ],
 +
    order => "-date/title",
 +
    citation => 'router',    # This defines the file in cfg/citations/eprint/
 +
    layout  => 'router',    # This is used in Views.pm to determine how to
 +
                            # join individual citations together...
 +
  },
  
This would have one column if there were ten or less values, two columns if there were between eleven and twenty (ten + ten) values, and three columns for all other cases.
+
This creates a view, which will be 2-columns wide.
 +
Two important definitions here are:
 +
* '''citation''' defines the citation file used to create the block of html for each record to be displayed, and
 +
* '''layout''' indicates how those blocks are joined together.
  
[ 0, 0 ]
+
====Layout====
 +
'''Layout''' can be one of:
 +
* paragraph (the default)
 +
puts &lt;p> elements round each citation
 +
 
 +
* orderedlist
 +
makes an ordered list (1,2,3,4 or whatever the CSS defines)
 +
 
 +
* unorderedlist
 +
makes an unordered list
 +
 
 +
* ''anything else''
 +
just puts a newline (in the page source) after each citation
 +
 
 +
====citation====
 +
In our example, we're using a home-made citation layout
 +
 
 +
The citation file is in <code>/cfg/citations/eprint/</code>
  
This would always have three columns.
+
In the above view, we have defined the citation format to be '''router''', therefore we need a file called '''router.xml''' in the citations directory.
  
Add one to the number of integers in the array and you get the maximum number of columns.  The value of each integer defines the point at which that column becomes full, and more values cause an 'overflow' into the next column.
+
Remember this format is used for each record, so needs to be complete in it's own right - and if you want records to line up vertically, you need to plan that in advance.
  
====variations====
 
  
 +
    &lt;?xml version="1.0" ?>
 +
    &lt;!--
 +
  Full citation for an eprint.
 +
    -->
 +
    &lt;cite:citation xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://eprints.org/ep3/control" xmlns:cite="http://eprints.org/ep3/citation" >
 +
    &lt;table class='ep_rt_citation'>;
 +
    &lt;tr>&lt;td colspan='2'>
 +
    &lt;choose>
 +
      &lt;when test="type = 'book' and is_set( creators )">
 +
        &lt;span class='strong'>&lt;print expr="creators_name"/></span>
 +
      &lt;/when>
 +
      .... more code ....
 +
    &lt;/choose>
 +
    &lt;/td>&lt;td style="width:8em">
 +
    &lt;if test="date">&lt;span class='right strong'>(&lt;print expr="date" opts="res=year"/>)&lt;/span>&lt;/if>
 +
    &lt;/td>&lt;/tr>
 +
    &lt;tr>&lt;td style="width:50%">
 +
      &lt;cite:linkhere>&lt;xhtml:em>&lt;print expr="title" opts="magicstop"/>&lt;/xhtml:em>&lt;/cite:linkhere>
 +
    &lt;/td>
 +
    &lt;choose>
 +
    .... more code
 +
    &lt;when test="type = 'article'">
 +
    &lt;td>
 +
      &lt;if test="publication">&lt;print expr="publication"/>
 +
        &lt;if test="volume">, &lt;print expr="volume"/>&lt;/if>
 +
        &lt;if test="number"> (&lt;print expr="number"/>)&lt;/if>
 +
        .&lt;/if>
 +
      &lt;if test="pagerange"> &lt;print expr="pagerange"/>.&lt;/if>
 +
      &lt;/td>&lt;td>
 +
      &lt;if test="issn"><span class='right'> ISSN <print expr="issn"/></span></if>
 +
      &lt;/td>
 +
    &lt;/when>
 +
    .... more code
 +
  &lt;/choose>
 +
  &lt;/tr>
 +
  &lt;if test=" ! type.one_of( 'patent','thesis' )">
 +
    &lt;if test="ispublished.one_of('unpub', 'submitted', 'inpress')">
 +
    &lt;tr>&lt;td colspan='2'>
 +
    (&lt;print expr="ispublished"/>)
 +
    &lt;/td>&lt;/tr>
 +
    &lt;/if>
 +
  &lt;/if>
 +
  &lt;/table>
 +
  &lt;/cite:citation>
  
The following options are available:
+
This creates a table for each record, and CSS is used to manage the size & position of the various elements
  
{| border="1" cellpadding="4" cellspacing="0"
+
===cfg/cfg.d/eprint_render.pl===
|reverse
+
When viewing a record, the main abstract view page can also be altered
|Reverses the order in which the groupings are shown. Default is the ordervalue for that field (usually alphanumeric).  Useful for dates as you may want the highest values first.
 
|-
 
|filename
 
|Changes the filename of the view variation.  The default is the name of the metadata field used, so if two variations use the same metadata field with different options, this is needed.
 
  
filename=different_filename
+
In <code>cfg/cfg.d/eprint_render.pl</code>, towards the bottom of the subroutine <code>$c->{eprint_render}</code> is the following line:
|-
 
|first_value
 
|If a field is multiple, only use the first value. Otherwise each item will appear once for each value.
 
|-
 
|first_initial
 
|If using a name, truncate the given name to the first initial.  This will make items like "Les Carr" and "Leslie Carr" appear together.  Note it will also make "John Smith" and "Jake Smith" appear together too, showing that you really never can win.
 
|-
 
|first_letter
 
|The same as 'truncate=1'
 
|-
 
|truncate
 
|Use the first X characters of a value to group by.  truncate=4 may be useful for dates as it will group by the first four digits (the year) only.
 
  
truncate=4
+
  my $page = $eprint->render_citation( "router_page", %fragments, flags=>$flags );
|-
 
|tags
 
|Useful for fields like keywords where values may be separated by commas or semi-colons.  The value is split on these two characters ( , and ; ) and a heading is created for each.
 
|-
 
|cloud
 
|Creates a tag cloud.  Sets jump to 'plain', cloudmax to 200, cloudmin to 80 and no_separator, then resizes the jump-to links according to frequency of use.
 
|-
 
|cloudmax
 
|The % size of the largest tag in a tag cloud.
 
|-
 
|cloudmin
 
|The % size of the smallest tag in a tag cloud.
 
|-
 
|jump
 
|
 
  jump=plain
 
  
Turns of the 'jump to' text before the list of subheading navigation links.
+
Here, '''router_page''' is the name of the citation file for creating the abstract page..... '''router_page.xml''' in this case
|-
 
|no_seperator (sic)
 
|Turns of the separator between each subheading navigation link (by default a vertical bar symbol).
 
|-
 
|string
 
|Uses values 'as is'. No ordervalues, no phrases.
 
|-
 
|hideup (since 3.1.1)
 
|Defaults to "0". If set to "1" this hides the "up to parent" link (often you want to hide this on .include files)
 
|-
 
|render_fn
 
|Name of a function to render this groupings list of items. For an example, see views_render_items_example.pl
 
|}
 

Latest revision as of 16:45, 2 July 2024

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


Back to cfg.d

views.pl contains configuration for rendering views. Conceptually a view is a browsable list of eprints split into menus and a list.

Menu1        
  Item1_1 ------ ---> Menu2    
  Item1_2     Item2_1 ----- --->     LIST    
  ....     Item2_2     ....
      ....    

In a menu values of one (or more) fields are listed, and a link points to the collection of all items with that particular value in that field.

The list contains the final list of eprints with field values as determined by the menus above it.


Options available for the views config

This link is an 'How to' about views with examples.

The general form of views definition is

 $c->{browse_views} = [
   { <first view definition> },
   { <second view definition> },
   ...
   { <last view definition> },
 ];

(be careful about commas and semicolons). The order of the view definitions determines the order in which these will appear in the http://repoid/view/ page.

Each view definition is a collection of attributes, given as

   attribute1 => value1,
   attribute2 => value2,
   ...

(again, the value should end by a comma). The value can be

  • integer
  • string enclosed by quotation marks (") or by apostrophes (')
  • array which starts by a square bracket [ followed by the elements of the array (separated by commas) and closed by ] or
  • hash which is a list of "attribute => value" pairs enclosed by curly brackets { and }.

Thus the browse_views definition is an array of hashes.

Attributes marked by (V) are view attributes and are in the view definition; attributes marked by (M) are menu attributes and should be used only in menu definitions.

Basic options

Options in the first category are view options.

id (V) (mandatory) String, this is the ID by which you will refer to this view, and also the name of the top directory in http://repoid/view/. This is the value of the browse_link attribute in eprint_fields.pl. Example:
   id => 'divisions',
fields (V) (deprecated) This attribute describes the field(s) by which the view is built. It has been replaced by the more general menus attribute.
hideempty (V)

allow_null (V) new_column_at (V) render_menu (V)

These define the default values of the same attributes in all menus. I.e, if not defined otherwise there, they take this as the default value in this view. "Hideempty" is also used when rendering the view list.
menus (V) An array of menu descriptions. Each menu is a refinement of the previous ones, and last menu points to the view list(s). In each menu, as minimum, you should give the field(s) which are used to define entries at that level. The menus definition looks like
 menus => [
    { <first menu definition> },
    { <second level menu> },
    { <last level> },
 ],

You must have at least one menu level.

template (V) Define an alternate template for all pages in this view. The template page should be a proper xml file in the repoid/cfg/lang/<langid>/templates/ directory. The best way is to copy the default.xml file and edit it according to taste.
 template => 'view_template',
nolink (V) When this is set to 1 by adding
 nolink => 1,

then this view won't appear in the outmost http://repoid/view/ browse page.

max_menu_age (V) Defaults to 86400 (one day in seconds). If the menus in this view has been generated more than that many seconds ago, it is regenerated.
max_items (V) Defaults to 2000. If the items list is larger increase the number enough to accomodate the number of items needed to be displayed.
 max_items => 3000,


View list options

These are the options which determine how the last list page in the menu chain should look like. They must be entered at the outmost view level.

order (V) This defines how the items in the view list (at the lowest level) are ordered. The format is 'foo/-bar'. This means that the list will be sorted by 'foo' and then any equal 'foo' values will be reverse sorted by 'bar'. More than 2 fields can be specified. Example:
 order => "-date/title",
hideup (V) Don't show the "up one level" link in the list page. You must set this attribute for each menu separately, it is not inherited.
hideempty (V) Do not list the empty (undefined) entry in the list. This property inherits to the menus.
nocount (V) If set, the "Number of items" line at the top of the page is omitted.
notimestamp (V) If set, the "This list was generated on" line at the bottom of the list is omitted.
variations (V) An array of strings describing different rendering of the items at the list. For datails see variations. Example:
   variation => [ "creators_name;first_letter", 
       "type", "DEFAULT", ],
layout (V) Possible values are
  • paragraph (default)
  • orderedlist
  • unorderedlist

Determines how items in the list (or sublist) is rendered. In the first case each item is a paragraph by itself. In the other cases items are rendered as an ordered (unordered) list.

citation (V) The citation style defined in archives/<REPOID>/cfg/citations/eprint/ which is used to render each item. Example:
 citation => 'screen',
max_list_age (V) Defaults to 86400 (one day in seconds). If the lists in this view were generated more than than many seconds ago, it is regenerated.


Variations

Variations, if defined, determine how the final list is rendered. Variations is an array of strings, for example,

[ "creators_name;first_letter",
  "type",
  "DEFAULT",
]

For each string in the list, a different rendering is produced, and you can switch from one to the other. The variation "DEFAULT" is the default one, it is always a good practice to include it in the list. If no variation is given, "DEFAULT" is used.

A variation definition consists of a field name, followed by zero, one or more options after a semicolon. Options are separated by commas. An option is either a single attribute, or an attribute, an equal sign, and the value of the attribute. For example,

   "creators_name;truncate=4,hideup"

sets the attribute value "truncate" to 4, and "hideup" to 1 (or true).

The following options are available. These options are part of the string defining the variation, and should not be entered as attributes.

reverse Reverses the order in which the groupings are shown. Default is the ordervalue for that field (usually alphanumeric). Useful for dates as you may want the highest values first.
filename Changes the filename of the view variation. The default is the name of the metadata field used, so if two variations use the same metadata field with different options, this is needed.
filename=different_filename
first_value If a field is multiple, only use the first value. Otherwise each item will appear once for each value.
first_initial If using a name, truncate the given name to the first initial. This will make items like "Les Carr" and "Leslie Carr" appear together. Note it will also make "John Smith" and "Jake Smith" appear together too, showing that you really never can win.
first_letter The same as 'truncate=1'
truncate Use the first X characters of a value to group by. truncate=4 may be useful for dates as it will group by the first four digits (the year) only.
truncate=4
tags Useful for fields like keywords where values may be separated by commas or semi-colons. The value is split on these two characters ( , and ; ) and a heading is created for each.
cloud Creates a tag cloud. Sets jump to 'plain', cloudmax to 200, cloudmin to 80 and no_separator, then resizes the jump-to links according to frequency of use.
cloudmax The % size of the largest tag in a tag cloud.
cloudmin The % size of the smallest tag in a tag cloud.
jump Possible values are 'plain', 'default', and 'none'. Example:
 jump=plain

When set to 'plain' turns off the 'jump to' text before the list of subheading navigation links. When 'none', then the 'jump' part is not rendered.

no_seperator (sic) Turns of the separator between each subheading navigation link (by default a vertical bar symbol).
string Uses values 'as is'. No ordervalues, no phrases.
hideup (since 3.1.1) Defaults to "0". If set to "1" this hides the "up to parent" link (often you want to hide this on .include files)
render_fn Name of a function to render this groupings list of items. For an example, see views_render_items_example.pl


Menu options

These options can only be used in the menu definitions.

fields (M) Obligatory, an array of field identifiers. Items in all fields are merged together. For example, to define a list of those those who are either authors or editors or both, use the definition
   fields => [ "creators_id", "editors_id" ],

Even if there is a single field, you must use square brackets, such as

   fields => [ "subjects" ],
Important! All fields must have the same type - i.e. you cannot mix titles and authors, say.

You can also add extra rendering info to the field name, without the "render_" prefix. For example, to make a date have resolution year, you would write

   fields => [ "date;res=year" ],

or, ordering authors by their given names rather than by their family names:

   fields => [ "creators_name;order=gf" ],

You can add ";quiet" to the field name to force non-existing values to appear as empty space rather than the ugly "UNDEFINED" (see the allow_null property below). You can find the available rendering properties of different fields in the Metadata section.

allow_null (M) The undefined value among the possible values of the fields does not show up in the generated view. To allow the undefined value to appear as well, set
 allow_null => 1,

Beware: the title of the undefined entries will be the ugly UNDEFINED. You might consider to use the ";quiet" rendering option for field names.

hideempty (M) If a category is empty, don't show it as an entry. Default value: show all entries, even if they contain no entries. Used only in menus, not at the lower level (list).

Example:

   hideempty => 1,
reverse_order (M) If set, then the ordering of items in this menu is reversed. Example:
   reverse_order => 1,
mode (M) Possible values: sections and default (default). When defined as sections then grouping can be defined by the following data:
  • grouping_function (group by first character if not defined)
  • group_sorting_function (how to sort members of a group)
  • group_range_function
  • open_first_section the front page should show the first section

See below.

hideup (M) When set to 1, don't show the "move one level up" link at the top of the page.
render_menu (M) The configuration parameter which renders this menu. This should be a string, and also you should define a routine with the same name. For example if you write
   render_menu => 'render_view_menu_3col_boxes',

then this menu will be rendered by the routine which is defined in views_render_menu_example.pl as

 $c->{render_view_menu_3col_boxes} = sub
 {
      ...
 }

See there for hints how to tweak your own routine.

new_column_at (M) Used in menus (not lists) and in default mode. This is an array of integers representing the number of items in a view list before another column is added. For example:
[ 11 ]

The menu is rendered as a single column data if there are less than 11 entries, then there would be 2 columns.

[ 11, 21 ]

This would have one column if there were ten or less values, two columns if there are twenty or less, and three columns for all other cases.

[ 0, 0 ]

This would always have three columns.

[ 2, 3 ]

This would have one column for a single data, two columns for two, and three columns for three or more data.

Add one to the number of integers in the array and you get the maximum number of columns. The entries are evenly distributed in the columns.


Sections

When a menu is using "sections", then items on the menu are grouped together. The exact method is defined by defining values for several options. These options go to the menus section as well.

grouping_function (M) This function determines how grouping is done. The following predefined functions can be used:
  • "EPrints::Update::Views::group_by_a_to_z"
  • "EPrints::Update::Views::group_by_first_character" (default)
  • "EPrints::Update::Views::group_by_2_characters"
  • "EPrints::Update::Views::group_by_3_characters"
  • "EPrints::Update::Views::group_by_4_characters"
  • "EPrints::Update::Views::group_by_5_characters"

with the usual meaning. If you use 'group_by_a_to_z', all entries not starting with a letter will be discarded.

group_sorting_function (M) A custom function which sorts the group identifiers. The only available function
  • "EPrints::Update::Views::default_sort"

sorts alphabetically.

group_range_function (M) Splits the groups (as determined by the grouping function) into sections so that a group never splits. Groups are rendered separately, but a section is kept on a single page. Available grouping functions are
  • "Eprints::Update::Views::no_ranges" (default)
  • "EPrints::Update::Views::cluster_ranges_<range>"

where <range> is one of 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, and 200.

open_first_section (M) if set, the first section is included in the front page.

Phrases

Views can have their own titles and other phrases. If they do not exist, then a default one is used (usually containing the view's id). For examples, see the views.xml file.

viewname_eprint_<viewid> the name of the browse pages
viewintro_<viewid> The phrase to replace the text "Please select a value to browse from the list below." in the top level menu
viewintro_<viewid>/<value> Intro phrase on the next level
viewtitle_eprint_<viewid>_menu_<level> Title of browse page at level <level>, which is 1, 2, ... In the phrase you can use the pins "value1", "value2", etc. where the number can be one less than the present level; the value of the pin is the actual value of the previous levels. See the example below.
viewgroup_eprint_<viewid>_<filename> Used as a pin value for the title on the list pages, when variations are used. <Filename> is the filename defined as the option of the variation, or, if it is not defined, then it is the fieldname at the beginning.
viewtitle_eprint_<viewid>_list Title of the list pages of the view. You can use the same pins as before ("value1", "value2", etc.). If the list was generated by a variation then the "grouping" pin is also available.

The following example shows how to define these values.

<epp:phrase id="viewname_eprint_divisions">Divisions</epp:phrase>
<epp:phrase id="viewtitle_eprint_divisions_menu_1">
   Browse by Division and Year</epp:phrase>
<epp:phrase id="viewtitle_eprint_divisions_menu_2">
   Browse by Year where Division is
    <epc:pin name="value1" /> </epp:phrase>

Other

heading_level ?
include ?
subheadings ?
nohtml ?
noindex ?

Example

EPrints 3.2 example

cfg/cfg.d/views.pl

 { id         => "target",  # The 'name' for this view
   allow_null => 0,
   hide_empty => 1,
   menus      => [
     { fields => ["broker_reponame"], # The field(s) to use - in this case the 'reponame' sub-element of the 'broker' field
       new_column_at      => [0],    # force 2 columns, even if the
                                     # second is blank
       mode               => "sections",
       open_first_section => 1,
       group_range_function   => "EPrints::Update::Views::cluster_ranges_30",
       group_sorting_function => "EPrints::Update::Views::default_sort",
     },
   ],
   order => "-date/title",
   citation => 'router',    # This defines the file in cfg/citations/eprint/
   layout   => 'router',    # This is used in Views.pm to determine how to
                            # join individual citations together...
 },

This creates a view, which will be 2-columns wide. Two important definitions here are:

  • citation defines the citation file used to create the block of html for each record to be displayed, and
  • layout indicates how those blocks are joined together.

Layout

Layout can be one of:

  • paragraph (the default)

puts <p> elements round each citation

  • orderedlist

makes an ordered list (1,2,3,4 or whatever the CSS defines)

  • unorderedlist

makes an unordered list

  • anything else

just puts a newline (in the page source) after each citation

citation

In our example, we're using a home-made citation layout

The citation file is in /cfg/citations/eprint/

In the above view, we have defined the citation format to be router, therefore we need a file called router.xml in the citations directory.

Remember this format is used for each record, so needs to be complete in it's own right - and if you want records to line up vertically, you need to plan that in advance.


   <?xml version="1.0" ?>
   <!-- 
 	Full citation for an eprint. 
   -->
   <cite:citation xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://eprints.org/ep3/control" xmlns:cite="http://eprints.org/ep3/citation" >
   <table class='ep_rt_citation'>;
   <tr><td colspan='2'>
   <choose>
     <when test="type = 'book' and is_set( creators )">
       <span class='strong'><print expr="creators_name"/>
     </when>
     .... more code ....
   </choose>
   </td><td style="width:8em">
   <if test="date"><span class='right strong'>(<print expr="date" opts="res=year"/>)</span></if>
   </td></tr>
   <tr><td style="width:50%">
     <cite:linkhere><xhtml:em><print expr="title" opts="magicstop"/></xhtml:em></cite:linkhere>
   </td>
   <choose>
    .... more code
   <when test="type = 'article'">
   <td>
     <if test="publication"><print expr="publication"/>
       <if test="volume">, <print expr="volume"/></if>
       <if test="number"> (<print expr="number"/>)</if>
       .</if>
     <if test="pagerange"> <print expr="pagerange"/>.</if>
     </td><td>
     <if test="issn"> ISSN <print expr="issn"/></if>
     </td>
   </when>
   .... more code
 </choose>
 </tr>
 <if test=" ! type.one_of( 'patent','thesis' )">
   <if test="ispublished.one_of('unpub', 'submitted', 'inpress')">
   <tr><td colspan='2'>
    (<print expr="ispublished"/>)
   </td></tr>
   </if>
 </if>
 </table>
 </cite:citation>

This creates a table for each record, and CSS is used to manage the size & position of the various elements

cfg/cfg.d/eprint_render.pl

When viewing a record, the main abstract view page can also be altered

In cfg/cfg.d/eprint_render.pl, towards the bottom of the subroutine $c->{eprint_render} is the following line:

  my $page = $eprint->render_citation( "router_page", %fragments, flags=>$flags );

Here, router_page is the name of the citation file for creating the abstract page..... router_page.xml in this case