WHOLIST: add the possibility to filter the wholist for a user.
authorWilfried Goesgens <dothebart@citadel.org>
Thu, 12 Jul 2012 14:00:24 +0000 (16:00 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Thu, 12 Jul 2012 14:00:24 +0000 (16:00 +0200)
  - add a parameter to the Iterator to specify the filter string
  - set this parameter to 0 in all current templates

webcit/static/t/who/iconbar.html
webcit/static/t/who/summary.html
webcit/who.c

index 8ec85b68b5d946f8d167f6fa6b3b14ad202a0a3b..cb436d97105344c54fe9cea006fb0c533b415135 100644 (file)
@@ -1 +1 @@
-<?ITERATE("WHOLIST", ="who_iconbar_section")>
+<?ITERATE("WHOLIST", ="who_iconbar_section", 0)>
index 6a31492cdaf340aa719610e9233653581d02e522..5a9908503dcb0092a80aa402c130720fe460cd67 100644 (file)
@@ -5,5 +5,5 @@
   <th><?_("User name")></th>
   <th><?_("Room")></th>
 </tr>
-<?ITERATE("WHOLIST", ="who_summary_section")>
+<?ITERATE("WHOLIST", ="who_summary_section", 0)>
 </table>
index 1c2984584ada5534ebe22ed4f95780ef461cb351..66667e758fa6de6f1e02a4682a06711f1c892491 100644 (file)
@@ -37,7 +37,7 @@ int CompareUserStruct(const void *VUser1, const void *VUser2)
 }
 
 
-int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
+int GetWholistSection(HashList *List, time_t now, StrBuf *Buf, const char *FilterName, long FNLen)
 {
        wcsession *WCC = WC;
        UserStateStruct *User, *OldUser;
@@ -82,28 +82,41 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
                        User->IdleSince = (now - User->LastActive) / 60;
                        User->SessionCount = 1;
 
-                       if (GetHash(List, 
-                                   ChrPtr(User->UserName), 
-                                   StrLength(User->UserName), 
-                                   &VOldUser)) {
-                               OldUser = VOldUser;
-                               OldUser->SessionCount++;
-                               if (!User->Idle) {
-                                       if (User->Session == WCC->ctdl_pid) 
-                                               OldUser->Session = User->Session;
-
-                                       OldUser->Idle = User->Idle;
-                                       OldUser->LastActive = User->LastActive;
+                       if (FilterName == NULL) {
+                               if (GetHash(List, 
+                                           SKEY(User->UserName), 
+                                           &VOldUser)) {
+                                       OldUser = VOldUser;
+                                       OldUser->SessionCount++;
+                                       if (!User->Idle) {
+                                               if (User->Session == WCC->ctdl_pid) 
+                                                       OldUser->Session = User->Session;
+                                               
+                                               OldUser->Idle = User->Idle;
+                                               OldUser->LastActive = User->LastActive;
+                                       }
+                                       DestroyUserStruct(User);
+                               }
+                               else
+                                       Put(List, 
+                                           SKEY(User->UserName), 
+                                           User, DestroyUserStruct);
+                       }
+                       else {
+                               if (strcmp(FilterName, ChrPtr(User->UserName)) == 0)
+                               {
+                                       Put(List, 
+                                           SKEY(User->UserName), 
+                                           User, DestroyUserStruct);
+                               }
+                               else 
+                               {
+                                       DestroyUserStruct(User);
                                }
-                               DestroyUserStruct(User);
                        }
-                       else
-                               Put(List, 
-                                   ChrPtr(User->UserName), 
-                                   StrLength(User->UserName), 
-                                   User, DestroyUserStruct);
                }
-               SortByPayload(List, CompareUserStruct);
+               if (FilterName == NULL)
+                       SortByPayload(List, CompareUserStruct);
                return 1;
        }
        else {
@@ -160,6 +173,10 @@ void _terminate_session(void) {
 HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP)
 
 {
+       const char *ch = NULL;
+       int HashUniq = 1;
+       long len;
+       StrBuf *FilterNameStr = NULL;
        StrBuf *Buf;
        HashList *List;
         time_t now;
@@ -175,10 +192,17 @@ HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP)
        else {
                now = time(NULL);
        }
+       if (HaveTemplateTokenString(NULL, TP, 2, &ch, &len))
+       {
+               FilterNameStr = NewStrBuf();
+               GetTemplateTokenString(FilterNameStr, TP, 2, &ch, &len);
+               HashUniq = 0;
+       }
 
-       List = NewHash(1, NULL);
-       GetWholistSection(List, now, Buf);
+       List = NewHash(HashUniq, NULL);
+       GetWholistSection(List, now, Buf, ch, len);
        FreeStrBuf(&Buf);
+       FreeStrBuf(&FilterNameStr);
        return List;
 }
 
@@ -279,7 +303,7 @@ InitModule_WHO
        WebcitAddUrlHandler(HKEY("terminate_session"), "", 0, _terminate_session, 0);
        WebcitAddUrlHandler(HKEY("edit_me"), "", 0, edit_me, 0);
 
-       RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
+       RegisterIterator("WHOLIST", 1, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
 
        RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, NULL, CTX_WHO);
        RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, NULL, CTX_WHO);