Changeset 6568


Ignore:
Timestamp:
Oct 21, 2014, 1:07:45 PM (9 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1840: Filter annotations on the Annotations tab based on subtype of item

Location:
trunk/www/common/annotations
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/common/annotations/list.js

    r6255 r6568  
    3333    Events.addEventHandler(element, 'click', list.editAnnotation);
    3434  }
     35 
     36  list.initListPage = function()
     37  {
     38    if (Doc.element('annotations'))
     39    {
     40      var allWithValues = Data.int('annotations-stat', 'all-with-values');
     41      var allOfCategory = Data.int('annotations-stat', 'all-of-category');
     42      Events.addEventHandler('view_all', 'click', list.setViewFilter);
     43      Events.addEventHandler('view_values', 'click', list.setViewFilter);
     44      Events.addEventHandler('view_category', 'click', list.setViewFilter);
     45      Doc.element('allWithValues').innerHTML = allWithValues;
     46      if (Doc.element('allOfCategory'))
     47      {
     48        Doc.element('allOfCategory').innerHTML = allOfCategory;
     49      }
     50      if (allWithValues == 0 && allOfCategory == 0)
     51      {
     52        Doc.element('view_all').checked = true;
     53      }
     54      list.setViewFilter();
     55    }
     56  }
     57 
    3558  if (Doc.getPageId() == 'list-annotations')
    3659  {
    3760    Doc.addElementInitializer(list.initEditLink);
     61    Doc.onLoad(list.initListPage);
    3862  }
    3963
     
    6690  }
    6791 
     92  list.setViewFilter = function()
     93  {
     94    var frm = document.forms['annotations'];
     95    var filter = Forms.getCheckedRadio(frm.view).value;
     96    Doc.element('annotations-data').className = 'data ' + filter;
     97  }
     98 
    6899  return list;
    69100}();
  • trunk/www/common/annotations/list_annotations.jsp

    r6384 r6568  
    3838  import="net.sf.basedb.core.Subtypable"
    3939  import="net.sf.basedb.core.ItemSubtype"
     40  import="net.sf.basedb.core.BioPlate"
     41  import="net.sf.basedb.core.BioPlateType"
    4042  import="net.sf.basedb.core.ItemQuery"
    4143  import="net.sf.basedb.core.ItemResultList"
     
    4345  import="net.sf.basedb.core.query.Orders"
    4446  import="net.sf.basedb.core.query.Hql"
     47  import="net.sf.basedb.core.query.Restrictions"
     48  import="net.sf.basedb.core.query.Expressions"
    4549  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
    4650  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
     
    140144    annotationTypes.removeAll(protocolParameters);
    141145  }
     146  // Load the current subtype
     147  // NOTE! User may have selected a different subtype in the form than what is
     148  // currently saved so if a subtype_id is sent in the request we use that
     149  String selectedCategoryName = null;
     150  try
     151  {
     152    ItemSubtype subtype = null;
     153    if (item instanceof Subtypable)
     154    {
     155      subtype = ((Subtypable)item).getItemSubtype();
     156    }
     157    else if (item instanceof BioPlate)
     158    {
     159      BioPlateType bpt = ((BioPlate)item).getBioPlateType();
     160      subtype = bpt.getItemSubtype();
     161      if (subtype == null) selectedCategoryName = bpt.getName();
     162    }
     163    if (subtype != null) selectedCategoryName = subtype.getName();
     164  }
     165  catch (PermissionDeniedException ex)
     166  {}
     167  Set<AnnotationType> annotationTypesInCategory = new HashSet<AnnotationType>();
     168  if (selectedCategoryName != null)
     169  {
     170    ItemQuery<AnnotationType> query = AnnotationType.getQuery(item.getType());
     171    query.join(Hql.innerJoin("categories", "ct"));
     172    query.restrict(Restrictions.eq(Hql.property("ct", "name"), Expressions.string(selectedCategoryName)));
     173    annotationTypesInCategory.addAll(query.list(dc));
     174  }
    142175  %>
    143176  <base:page type="iframe" id="list-annotations">
    144   <base:head scripts="~list.js" styles="table.css" />
     177  <base:head scripts="~list.js" styles="table.css">
     178  <style>
     179    #annotations-data.all
     180    {}
     181   
     182    #annotations-data.values .novalues
     183    {
     184      display: none;
     185    }
     186   
     187    #annotations-data.category .nocategory
     188    {
     189      display: none;
     190    }
     191  </style>
     192  </base:head>
    145193  <base:body>
    146194    <%
     
    157205      >
    158206      <%
     207      int allWithValues = 0;
     208      int allOfCategory = 0;
    159209      if (annotationTypes.size() == 0)
    160210      {
     
    185235            title="Description"
    186236          />
    187           <tbl:data>
     237          <div class="panelgroup topborder leftborder rightborder">
     238            <tbl:panel style="height: auto; padding: 2px;">
     239              <b>View:</b>
     240              <%
     241              if (selectedCategoryName != null)
     242              {
     243                %>
     244                <label><input type="radio" name="view" id="view_category" value="category" checked>All of <i><%=HTML.encodeTags(selectedCategoryName)%></i> category</label> (<span id="allOfCategory">?</span>)
     245                <%
     246              }
     247              %>
     248              <label><input type="radio" name="view" id="view_values" value="values" <%=selectedCategoryName == null ? "checked" : ""%>>All with values</label> (<span id="allWithValues">?</span>)
     249              <label><input type="radio" name="view" id="view_all" value="all">All annotations</label> (<%=annotationTypes.size()%>)
     250            </tbl:panel>
     251          </div>
     252          <tbl:data id="annotations-data">
    188253            <tbl:headers>
    189254              <tbl:headerrow>
     
    206271              if (values != null || !at.isRemoved())
    207272              {
    208               %>
    209                 <tbl:row>
     273                String rowClass = "";
     274                if (values == null || values.size() == 0)
     275                {
     276                  rowClass += " novalues";
     277                }
     278                else
     279                {
     280                  allWithValues++;
     281                }
     282                if (!annotationTypesInCategory.contains(at))
     283                {
     284                  rowClass += " nocategory";
     285                }
     286                else
     287                {
     288                  allOfCategory++;
     289                }
     290                %>
     291                <tbl:row subclass="<%=rowClass%>">
    210292                  <tbl:cell column="annotation"><base:icon
    211293                    image="deleted.png"
     
    237319      }
    238320      %>
     321      <div id="annotations-stat" class="datacontainer"
     322        data-all-with-values="<%=allWithValues %>"
     323        data-all-of-category="<%=allOfCategory%>"
     324      ></div>
     325     
    239326    </base:section>
    240327
Note: See TracChangeset for help on using the changeset viewer.