Martin Atkins (mart) wrote in fotobilder,
Martin Atkins

core1.s2 proposals: ItemRange

I'm going over my old email to Brad about core1.s2 and I'm going to post it again here, revised to suit the current state of the core later.

First up, changes to ItemRange. Brad put my original ItemRange in core, but he renamed all of the members. I originally made it general enough that it could represent a range of anything, but at the time it was only used for Pages. It was my intention that the same class would be used to represent the navigation between different images within a gallery from the PicturePage. Here, then, is the revised ItemRange class:

class ItemRange
"Represents a range of items which optionally contain items. For example, in a thumbnail gallery 'pages' are items and 'pictures' are subitems."
  var bool all_subitems_displayed "True if the subitems in this range represent the entire set. In this case, all of the URL members are blank.";
  var int num_subitems_displayed "The number of subitems in this range.";
  var int total "The total number of items that are navigatable to.";
  var int current "The currently-active item.";
  var int from_subitem "The index of the first subitem in this range.";
  var int to_subitem "The index of the last subitem in this range.";
  var string url_next "URL for the 'next' link. Blank if non-applicable."; 
  var string url_prev "URL for the 'previous' link. Blank if non-applicable.";
  var string url_first "URL for the 'first' link. Blank if non-applicable.";
  var string url_last "URL for the 'last' link. Blank if non-applicable.";
  function builtin url_of(int n) "Returns the URL to use to link to the nth item";

The names “item” and “subitem” aren't very inspiring, but there's a good reason for using them instead of “page“ and “picture”: On a PicturePage, the images themselves become “items”. Also, in the future, we might have ranges of other things we've not thought of yet. These also make for more intuitive overall variable names: "Page $.pages.current of $" makes a lot more sense than "Page $ of $pages.pages" — too much of the word “page”!

All of the subitem stuff can be used to display text saying “Viewing pictures 5 through 15” and the boolean variable can be used to decide that maybe it's not worth printing out any links at all since none of the links actually go anywhere.

This means that we need a GalleryPicturePage class (discussed before, not implemented yet) with some extra members:

class GalleryPicturePage extends PicturePage
"Page showing a single picture selected from a gallery."
  var ItemRange pictures;
  var GalleryBasic gallery;
  function print_picture_navigation();
  function picture_location() "Returns text like 'Picture X of Y' where X is \$.pictures.current and Y is \$";

Also, we can extend GalleryPage a bit:

class GalleryPage extends Page
"Page class for a viewing a user's gallery."
  var Picture[] pictures
  "The pictures in this gallery which the remote user has access to see.";

  var Gallery gallery
  "The gallery being viewed.";

  var ItemRange pages;
  function print_page_navigation();
  function page_location() "Returns text like 'Page X of Y' where X is \$.pages.current and Y is \$";

Also, a default implementation of the skiplinks:

function itemrange_skiplinks(ItemRange range, string labeltext) {
  "<table width=\"100%\" style=\"text-align: center;\"><tr>\n";
  "<td width=\"12%\">" + linkif($*text_range_first, $range.url_first) + "</td>\n";
  "<td width=\"12%\">" + linkif($*text_range_prev, $range.url_prev) + "</td>\n";
  "<td width=\"12%\">" + linkif($*text_range_next, $range.url_next) + "</td>\n";
  "<td width=\"12%\">" + linkif($*text_range_last, $range.url_last) + "</td>\n";

Implemented as a separate function because I think in most cases styles will use common code for all of these structures, so this'll make overriding easy. $labeltext is to be passed the return value of page_location() or picture_location() from the classes that use ItemRange above.

That's all.


  • 302: lj_dev

    In the interests of consolidating all FotoBilder development-related discussion, we're going to be closing down this community. The same…

  • Development stalled?

    Is the development of Fotobilder held? Stalled? I am asking because there is no activity on the community and there is no link to the Fotobilder…

  • (no subject)

    Does FotoBilder works with Apache2? I installed all the required modules on my debian sarge, and when I restart my apache server, it dies horribly…

  • Post a new comment


    Comments allowed for members only

    Anonymous comments are disabled in this journal

    default userpic