Changeset 7768


Ignore:
Timestamp:
Feb 7, 2020, 11:17:23 AM (22 months ago)
Author:
Nicklas Nordborg
Message:

References #2202: Include information from parent items in list pages

Implemented lazy-loading of data from the parent item colums. The column definition will generate a proxy html tag (ParentItemColumn.getProxyTag()) that a JavaScript (lazy-parent-items.js) can detect and initiate a lazy loading action via AJAX.

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemAnnotationColumn.java

    r7767 r7768  
    2222  private final Filter<AnnotationSnapshot> atFilter;
    2323 
    24   ParentItemAnnotationColumn(String id, Filter<Annotatable> filter, ParentItemHelper helper, AnnotationType at)
     24  ParentItemAnnotationColumn(int index, String id, Filter<Annotatable> filter, ParentItemHelper helper, AnnotationType at)
    2525  {
    26     super(id, filter, helper);
     26    super(index, id, filter, helper);
    2727    this.at = at;
    2828    this.atFilter = new AnnotationTypeFilter(at);
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumn.java

    r7767 r7768  
    3838  */
    3939  @SuppressWarnings({ "unchecked", "rawtypes" })
    40   public static ParentItemColumn create(DbControl dc, String expr, ParentItemHelper helper)
     40  public static ParentItemColumn create(DbControl dc, int index, String expr, ParentItemHelper helper)
    4141  {
    4242    ParentItemColumn col = null;
     
    5050      {
    5151        AnnotationType at = AnnotationType.getById(dc, Values.getInt(tmp[3].substring(1)));
    52         col = new ParentItemAnnotationColumn(expr, parentFilter, helper, at);
     52        col = new ParentItemAnnotationColumn(index, expr, parentFilter, helper, at);
    5353        col.setTitle(at.getName() + " [A]");
    5454        col.setTooltip(subtype.getName() + " › "+at.getName());
    5555        col.setValueType(at.getValueType());
    5656        col.setExportFormatter(FormatterFactory.getTypeFormatter(dc.getSessionControl(), at.getValueType()));
    57         col.setFormatter(new CollectionFormatter(col.getExportFormatter()));
     57        if (!helper.lazy) col.setFormatter(new CollectionFormatter(col.getExportFormatter()));
    5858      }
    5959      else
     
    6565          Metadata m = Metadata.getInstance(parentType.getItemClass());
    6666          property = m.getPropertyPath(path, false);
    67           col = new ParentItemPropertyColumn(expr, parentFilter, helper, property);
     67          col = new ParentItemPropertyColumn(index, expr, parentFilter, helper, property);
    6868          col.setTitle(subtype.getName()+"."+path);
    6969          col.setTooltip(subtype.getName() + " › "+path);
     
    7171        else
    7272        {
    73           col = new ParentItemPropertyColumn(expr, parentFilter, helper, null);
     73          col = new ParentItemPropertyColumn(index, expr, parentFilter, helper, null);
    7474          col.setTitle(subtype.getName());
    7575          col.setTooltip(subtype.getName());
     
    7878        {
    7979          col.setExportFormatter(new NameableFormatter());
    80           col.setFormatter(new CollectionFormatter(new LinkedItemFormatter()));
     80          if (!helper.lazy) col.setFormatter(new CollectionFormatter(new LinkedItemFormatter()));
    8181        }
    8282        else
    8383        {
    8484          col.setExportFormatter(new ToStringFormatter<>());
    85           col.setFormatter(new CollectionFormatter(col.getExportFormatter()));
     85          if (!helper.lazy) col.setFormatter(new CollectionFormatter(col.getExportFormatter()));
    8686        }
    8787      }
     
    9393  }
    9494
     95  private final int index;
    9596  private final Filter<Annotatable> filter;
    9697  private final ParentItemHelper helper;
    9798 
    98   ParentItemColumn(String id, Filter<Annotatable> filter, ParentItemHelper helper)
     99  ParentItemColumn(int index, String id, Filter<Annotatable> filter, ParentItemHelper helper)
    99100  {
     101    this.index = index;
    100102    this.filter = filter;
    101103    this.helper = helper;
     
    115117  public final Object getValue(DbControl dc, Annotatable item)
    116118  {
     119    if (helper.lazy) return getProxyTag(item);
    117120    item = helper.recycle(dc, item);
    118121    return getValue(helper, item);
    119122  }
    120123
     124  /**
     125    Generate a proxy tag that is returned instead of actual data. A
     126    JavaScript in 'lazy-parent-items.js' will scan the table and
     127    inject the actual data in batches.
     128  */
     129  private String getProxyTag(Annotatable item)
     130  {
     131    StringBuilder sb = new StringBuilder();
     132    sb.append("<div");
     133    sb.append(" class=\"lazy-parent not-loaded\"");
     134    sb.append(" id=\"lazy-parent-").append(index).append("-").append(item.getId()).append("\"");
     135    sb.append(" data-item-id=\"").append(item.getId()).append("\"");
     136    sb.append(" data-index=\"").append(index).append("\"");
     137    sb.append("></div>");
     138    return sb.toString();
     139  }
     140 
     141  /**
     142    We finalize this implementation to make sure that the helper
     143    implementation always get a chance to re-cycle transactions.
     144    Subclasses should implement {@link #getValue(ParentItemHelper, Annotatable)}
     145    to return the requested value from the item and use the
     146    DbControl from {@link ParentItemHelper#dc}.
     147  */
     148  @Override
     149  public final Object getExportValue(DbControl dc, Annotatable item)
     150  {
     151    item = helper.recycle(dc, item);
     152    return getValue(helper, item);
     153  }
     154
     155 
    121156  /**
    122157    Alternate implementation for loading data.
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumnActionFactory.java

    r7767 r7768  
    5555    if (allColumns == null || !allColumns.contains("/")) return false;
    5656
     57    jspContext.addScript(jspContext.getRoot() + "/include/scripts/lazy-parent-items.js");
    5758    return super.prepareContext(context);
    5859  }
     
    7576    if (allColumns == null || !allColumns.contains("/")) return null;
    7677   
     78   
     79    boolean lazy = !Boolean.FALSE.equals(jspContext.getAttribute("lazy-loading"));
    7780    DbControl dc = jspContext.getDbControl();
    78     ParentItemHelper helper = new ParentItemHelper(sc);
     81    ParentItemHelper helper = new ParentItemHelper(sc, lazy);
    7982    List<ListColumnAction<Annotatable, Object>> actions = new ArrayList<>();
    8083    for (String col : allColumns.split(","))
     
    8285      if (col.startsWith("/"))
    8386      {
    84         ListColumnAction<Annotatable, Object> action = ParentItemColumn.create(dc, col, helper);
     87        ListColumnAction<Annotatable, Object> action = ParentItemColumn.create(dc, actions.size(), col, helper);
    8588        if (action != null) actions.add(action);
    8689      }
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemHelper.java

    r7767 r7768  
    2424 
    2525  final SessionControl sc;
     26  final boolean lazy;
    2627  // Use the snapshot manager for efficient loading of annotations
    2728  final SnapshotManager manager;
     
    3233  DbControl dc;
    3334 
    34   ParentItemHelper(SessionControl sc)
     35  ParentItemHelper(SessionControl sc, boolean lazy)
    3536  {
    3637    this.sc = sc;
     38    this.lazy = lazy;
    3739    this.manager = new SnapshotManager();
    3840    this.cache = AnnotationUtil.createCache();
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemPropertyColumn.java

    r7767 r7768  
    2222  private final PropertyPath<? super Annotatable, ?> property;
    2323 
    24   ParentItemPropertyColumn(String id, Filter<Annotatable> filter, ParentItemHelper helper, PropertyPath<? super Annotatable, ?> property)
     24  ParentItemPropertyColumn(int index, String id, Filter<Annotatable> filter, ParentItemHelper helper, PropertyPath<? super Annotatable, ?> property)
    2525  {
    26     super(id, filter, helper);
     26    super(index, id, filter, helper);
    2727    this.property = property;
    2828  }
  • trunk/www/include/styles/table.css

    r7604 r7768  
    377377}
    378378
    379 
     379.lazy-parent.not-loaded
     380{
     381  outline: 1px dotted #A0A0A0;
     382    margin: 0 1em;
     383    height: 3px;
     384}
     385
     386
Note: See TracChangeset for help on using the changeset viewer.