Browse Source

fixes the items ordering + add number of items in the tab view

damien 11 years ago
parent
commit
7fe3cb5013

+ 27 - 7
pboard/pboard/model/data.py View File

@@ -12,6 +12,7 @@ order by last_action desc
12 12
 """
13 13
 import os
14 14
 import re
15
+import datetime as datetimeroot
15 16
 from datetime import datetime
16 17
 from hashlib import sha256
17 18
 __all__ = ['User', 'Group', 'Permission']
@@ -143,6 +144,8 @@ class PBNodeType(object):
143 144
   Comment = 'comment'
144 145
 
145 146
 
147
+MINIMUM_DATE = datetimeroot.date(datetimeroot.MINYEAR, 1, 1)
148
+
146 149
 class PBNode(DeclarativeBase):
147 150
 
148 151
   def __init__(self):
@@ -188,14 +191,15 @@ class PBNode(DeclarativeBase):
188 191
 
189 192
   _oParent = relationship('PBNode', remote_side=[node_id], backref='_lAllChildren')
190 193
 
191
-  def getChildrenOfType(self, plNodeTypeList, plSortingCriteria):
194
+  def getChildrenOfType(self, plNodeTypeList, poKeySortingMethod=None, pbDoReverseSorting=False):
192 195
     """return all children nodes of type 'data' or 'node' or 'folder'"""
193 196
     llChildren = []
194 197
     for child in self._lAllChildren:
195 198
       if child.node_type in plNodeTypeList:
196 199
         llChildren.append(child)
200
+    if poKeySortingMethod!=None:
201
+      llChildren = sorted(llChildren, key=poKeySortingMethod, reverse=pbDoReverseSorting)
197 202
     return llChildren
198
-    # return DBSession.query(PBNode).filter(PBNode.parent_id==self.node_id).filter(PBNode.node_type.in_(plNodeTypeList)).order_by(plSortingCriteria).all()
199 203
   
200 204
   def getChildNbOfType(self, plNodeTypeList):
201 205
     """return all children nodes of type 'data' or 'node' or 'folder'"""
@@ -211,20 +215,36 @@ class PBNode(DeclarativeBase):
211 215
 
212 216
   def getChildren(self):
213 217
     """return all children nodes of type 'data' or 'node' or 'folder'"""
214
-    return self.getChildrenOfType([PBNodeType.Node, PBNodeType.Folder, PBNodeType.Data], PBNode.node_order.asc())
218
+    return self.getChildrenOfType([PBNodeType.Node, PBNodeType.Folder, PBNodeType.Data])
215 219
 
216 220
   def getContacts(self):
217 221
     """return all children nodes of type 'data' or 'node' or 'folder'"""
218
-    return self.getChildrenOfType([PBNodeType.Contact], PBNode.data_label.asc())
222
+    return self.getChildrenOfType([PBNodeType.Contact], PBNode.getSortingKeyForContact)
223
+
224
+  def getContactNb(self):
225
+    """return all children nodes of type 'data' or 'node' or 'folder'"""
226
+    return self.getChildNbOfType([PBNodeType.Contact])
227
+
228
+  @classmethod
229
+  def getSortingKeyBasedOnDataDatetime(cls, poDataNode):
230
+    return poDataNode.data_datetime or MINIMUM_DATE
231
+    
232
+  @classmethod
233
+  def getSortingKeyForContact(cls, poDataNode):
234
+    return poDataNode.data_label or ''
235
+
236
+  @classmethod
237
+  def getSortingKeyForComment(cls, poDataNode):
238
+    return poDataNode.data_datetime or ''
219 239
 
220 240
   def getEvents(self):
221
-    return self.getChildrenOfType([PBNodeType.Event], PBNode.data_datetime.desc())
241
+    return self.getChildrenOfType([PBNodeType.Event], PBNode.getSortingKeyBasedOnDataDatetime, True)
222 242
     
223 243
   def getFiles(self):
224
-    return self.getChildrenOfType([PBNodeType.File], PBNode.data_datetime.desc())
244
+    return self.getChildrenOfType([PBNodeType.File])
225 245
 
226 246
   def getComments(self):
227
-    return self.getChildrenOfType([PBNodeType.Comment], PBNode.data_datetime.desc())
247
+    return self.getChildrenOfType([PBNodeType.Comment], PBNode.getSortingKeyBasedOnDataDatetime, True)
228 248
 
229 249
   def getIconClass(self):
230 250
     laIconClass = dict()

+ 4 - 4
pboard/pboard/templates/document.mak View File

@@ -148,10 +148,10 @@ POD :: ${current_node.getTruncatedLabel(40)} [${current_node.getStatus().label}]
148 148
       <div class="tabbable">
149 149
         <ul class="nav nav-tabs">
150 150
             <li class="active"><a href="#tags" data-toggle="tab" title="${_('Tags')}"><i class='icon-g-tags'></i></a></li>
151
-            <li><a href="#events" data-toggle="tab" title="History"><i class="icon-g-history"></i></a></li>
152
-            <li><a href="#contacts" data-toggle="tab" title="Contacts"><i class="icon-g-user""></i> </a></li>
153
-            <li><a href="#comments" data-toggle="tab" title="Comments"><i class="icon-g-conversation"></i> </a></li>
154
-            <li><a href="#files" data-toggle="tab" title="Files"><i class="icon-g-attach"></i> </a></li>
151
+            <li><a href="#events" data-toggle="tab" title="History"><i class="icon-g-history"></i>${POD.ItemNb(current_node.getEvents())}</a></li>
152
+            <li><a href="#contacts" data-toggle="tab" title="Contacts"><i class="icon-g-user""></i>${POD.ItemNb(current_node.getContacts())}</a></li>
153
+            <li><a href="#comments" data-toggle="tab" title="Comments"><i class="icon-g-conversation"></i>${POD.ItemNb(current_node.getComments())}</a></li>
154
+            <li><a href="#files" data-toggle="tab" title="Files"><i class="icon-g-attach"></i>${POD.ItemNb(current_node.getFiles())}</a></li>
155 155
         </ul>
156 156
         <div class="tab-content">
157 157
             ################################

+ 5 - 0
pboard/pboard/templates/master.mak View File

@@ -64,6 +64,11 @@ div.pod-toolbar {
64 64
   top: 0;
65 65
 }
66 66
 
67
+.pod-item-nb-sup-block {
68
+  color: #3a87ad;
69
+  font-weight: bold;
70
+}
71
+
67 72
 h3:Hover div.pod-toolbar {
68 73
   visibility: visible;
69 74
 }

+ 6 - 0
pboard/pboard/templates/pod.mak View File

@@ -17,3 +17,9 @@
17 17
 <%def name='Badge(psLabel, psCssClass="")'>
18 18
   <span class='badge ${psCssClass}'>${psLabel}</span>
19 19
 </%def>
20
+
21
+<%def name='ItemNb(plItemList)'>
22
+  % if len(plItemList)>0:
23
+  <sup class="pod-item-nb-sup-block"> ${len(plItemList)}</sup>
24
+  % endif
25
+</%def>