[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - 2 commits - loleaflet/admin.strings.js loleaflet/dist loleaflet/src wsd/Admin.cpp wsd/Admin.hpp wsd/AdminModel.cpp wsd/AdminModel.hpp wsd/DocumentBroker.cpp wsd/Storage.cpp

Aditya Dewan iit2015097 at iiita.ac.in
Mon Jul 31 11:10:41 UTC 2017


 loleaflet/admin.strings.js                   |    2 
 loleaflet/dist/admin/admin.html              |    1 
 loleaflet/dist/admin/bootstrap/dashboard.css |    7 -
 loleaflet/src/admin/AdminSocketOverview.js   |  146 ++++++++++++---------------
 wsd/Admin.cpp                                |    7 -
 wsd/Admin.hpp                                |    2 
 wsd/AdminModel.cpp                           |   14 +-
 wsd/AdminModel.hpp                           |    9 +
 wsd/DocumentBroker.cpp                       |    2 
 wsd/Storage.cpp                              |    2 
 10 files changed, 92 insertions(+), 100 deletions(-)

New commits:
commit 7f326a9a2fe06fc8350ca4778e4c30679657068c
Author: Aditya Dewan <iit2015097 at iiita.ac.in>
Date:   Fri Jun 23 18:02:44 2017 +0530

    admin: convert document list to drop down
    
    Change-Id: I23635599b008fb0bfa694b4e73cb8f18f49c8ab7
    Reviewed-on: https://gerrit.libreoffice.org/39170
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/loleaflet/admin.strings.js b/loleaflet/admin.strings.js
index d8a02918..66b51774 100644
--- a/loleaflet/admin.strings.js
+++ b/loleaflet/admin.strings.js
@@ -10,7 +10,7 @@ l10nstrings.strCurrent = _('(current)');
 l10nstrings.strAnalytics = _('Analytics');
 l10nstrings.strDashboard = _('Dashboard');
 l10nstrings.strUsersOnline = _('Users online');
-l10nstrings.strUserName = _('Users Name');
+l10nstrings.strUserName = _('User Name');
 l10nstrings.strDocumentsOpened = _('Documents opened');
 l10nstrings.strDocumentNumber = _('Number of Documents');
 l10nstrings.strMemoryConsumed = _('Memory consumed');
diff --git a/loleaflet/dist/admin/admin.html b/loleaflet/dist/admin/admin.html
index 0b5cde72..dd6ead66 100644
--- a/loleaflet/dist/admin/admin.html
+++ b/loleaflet/dist/admin/admin.html
@@ -116,7 +116,6 @@
               <tr>
                 <th><script>document.write(l10nstrings.strUserName)</script></th>
                 <th><script>document.write(l10nstrings.strDocumentNumber)</script></th>
-                <th><script>document.write(l10nstrings.strDocumentsOpened)</script></th>
               </tr>
             </thead>
             <tbody id="userlist">
diff --git a/loleaflet/dist/admin/bootstrap/dashboard.css b/loleaflet/dist/admin/bootstrap/dashboard.css
index cdf37a82..0e521de1 100644
--- a/loleaflet/dist/admin/bootstrap/dashboard.css
+++ b/loleaflet/dist/admin/bootstrap/dashboard.css
@@ -113,10 +113,10 @@ body {
   position: absolute;
   display: none;
 }
-.userContainer{
+.userContainer, .docContainer{
   position: absolute;
 }
-tr:hover .dropdown-menu{
+tr:hover .userContainer .dropdown-menu, td:hover .docContainer .dropdown-menu{
   display: block;
 }
 
@@ -136,6 +136,3 @@ tr:hover .dropdown-menu{
 .selected-view-opt{
   background-color: #f5f5f5;
 }
-.doc_list_label{
-  cursor: pointer;
-}
\ No newline at end of file
diff --git a/loleaflet/src/admin/AdminSocketOverview.js b/loleaflet/src/admin/AdminSocketOverview.js
index dfb92b64..25ce26f9 100644
--- a/loleaflet/src/admin/AdminSocketOverview.js
+++ b/loleaflet/src/admin/AdminSocketOverview.js
@@ -80,18 +80,6 @@ var AdminSocketOverview = AdminSocketBase.extend({
 			$('#docview').toggle();
 			$('#userview').toggle();
 		});
-
-		$('body').on('click', '#userlist .doc_list_label', function() {
-			if ($(this).text() === '🢃 list') {
-				docName = $($('.docentry', $(this).parent())[0]).text();
-				$user = $(this).parent().parent();
-				docCount = parseInt($('.doc_number', $user).text()) - 1 ;
-				$(this).text('🡺 ' + docName + ' and ' + String(docCount) + ' other docs');
-			}
-			else
-				$(this).text('🢃 list');
-			$('.docentry', $(this).parent()).toggle();
-		});
 	},
 
 	onSocketMessage: function(e) {
@@ -140,50 +128,54 @@ var AdminSocketOverview = AdminSocketBase.extend({
 					$listContainer.append($user);
 
 					sessionid = userListJson[j]['sessionid'];
-					encodedUName = userListJson[j]['userName'].replace(/ /g, '');
-					// this isn't the right way to do this, but we can't also use encode here. what should we do then.
+					UName = userListJson[j]['userName'];
+					encodedUId = encodeURI(userListJson[j]['userId']);
 
-					$userListRow = $('#usr' + encodedUName);
+					$userListRow = $(document.getElementById('usr' + encodedUId));
 
 					if ($userListRow.length == 0) {
 
-						$userListRow = $(document.createElement('tr')).attr('id', 'usr' + encodedUName);
+						$userListRow = $(document.createElement('tr')).attr('id', 'usr' + encodedUId);
 
 						$uName = $(document.createElement('td')).text(userListJson[j]['userName']);
 						$userListRow.append($uName);
 
-						$noOfDocuments = $(document.createElement('td')).addClass('doc_number')
-																	.text('1');
-						$userListRow.append($noOfDocuments);
+						$number = $(document.createElement('div')).addClass('doc_number').attr('id', 'num' + encodedUId).text(1);
+						$noOfDocuments = $(document.createElement('td')).append($number);
+						// Document List
+						$docListContainer = $(document.createElement('div')).addClass('dropdown docContainer');
+						$docDropDown = $(document.createElement('ul')).addClass('dropdown-menu')
+												.attr('id', 'docListContainer_' + encodedUId);
+						$docListHeader = $(document.createElement('li')).addClass('dropdown-header')
+												.text(_('Documents'));
+						$name = $(document.createElement('a')).text(sName);
+						$docentry = $(document.createElement('li')).addClass('docentry')
+												.attr('id', sessionid + '_' + sPid)
+												.append($name);
+						$docDropDown.append($docListHeader);
+						$docDropDown.append($docentry);
+						$docListContainer.append($docDropDown);
+						$noOfDocuments.append($docListContainer);
 
-						$docList = $(document.createElement('td')).addClass('doc_list');
-						$docLabel = $(document.createElement('div')).addClass('doc_list_label');
-						$docentry = $(document.createElement('div')).addClass('docentry')
-																.attr('id', sessionid + '_' + sPid)
-																.text(sName);
-						$docList.append($docLabel);
-						$docList.append($docentry);
-						$userListRow.append($docList);
+						$userListRow.append($noOfDocuments);
 
 						$('#userlist').append($userListRow);
 					}
 					else {
 						userListChildren = $userListRow[0].childNodes;
 
-						docCount = parseInt($(userListChildren[1]).text())
-						$(userListChildren[1]).text(docCount + 1);
-
-						$docLabel = $(userListChildren[2].getElementsByClassName('doc_list_label')[0]);
-						$docLabel.text('🡺 ' + sName + ' and ' + String(docCount) + ' other docs');
+						var $number = $(document.getElementById('num' + encodedUId));
+						docCount = parseInt($number.text())
+						$number.text(docCount + 1);
 
-						$('.docentry', $('userListChildren[2]').hide());
+						$docParent = $(userListChildren[1]);
 
-						$docentry = $(document.createElement('div')).addClass('docentry')
-																.attr('id', sessionid + '_' + sPid)
-																.text(sName);
+						$name = $(document.createElement('a')).text(sName);
+						$docentry = $(document.createElement('li')).addClass('docentry')
+												.attr('id', sessionid + '_' + sPid)
+												.append($name);
 
-						$(userListChildren[2]).append($docentry);
-						$('.docentry', $userListRow).css('display', 'none');
+						$(document.getElementById('docListContainer_' + encodedUId)).append($docentry);
 					}
 				}
 				$userContainer.append($listContainer);
@@ -233,7 +225,8 @@ var AdminSocketOverview = AdminSocketBase.extend({
 			sName = decodeURI(docProps[1]);
 			sessionid = docProps[2];
 			uName = decodeURI(docProps[3]);
-			sMem = docProps[4];
+			encodedUId = encodeURI(docProps[4]);
+			sMem = docProps[5];
 
 			$doc = $('#doc' + sPid);
 			if ($doc.length === 0) {
@@ -244,7 +237,7 @@ var AdminSocketOverview = AdminSocketBase.extend({
 										  .addClass('userContainer dropdown');
 				$listContainer = $(document.createElement('ul')).addClass('dropdown-menu');
 				$listLabel = $(document.createElement('li')).addClass('dropdown-header')
-															.text('Users');
+													.text('Users');
 				$listContainer.append($listLabel);
 				$userContainer.append($listContainer);
 				$pid.append($userContainer);
@@ -297,46 +290,51 @@ var AdminSocketOverview = AdminSocketBase.extend({
 			nTotalViews = parseInt($a.text());
 			$a.text(nTotalViews + 1);
 
+			$userListRow = $(document.getElementById('usr' + encodedUId));
+			if ($userListRow.length === 0) {
 
-			encodedUName = uName.replace(/ /g, '');
-			$user = $('#usr' + encodedUName);
-			if ($user.length === 0) {
-
-				$userListRow = $(document.createElement('tr')).attr('id', 'usr' + encodedUName);
+				$userListRow = $(document.createElement('tr')).attr('id', 'usr' + encodedUId);
 
 				$uName = $(document.createElement('td')).text(uName);
 				$userListRow.append($uName);
 
-				$noOfDocuments = $(document.createElement('td')).addClass('doc_number')
-															.text('1');
-				$userListRow.append($noOfDocuments);
+				$number = $(document.createElement('div')).addClass('doc_number').attr('id', 'num' + encodedUId).text(1);
+				$noOfDocuments = $(document.createElement('td')).append($number);
+
+				// Document List
+				$docListContainer = $(document.createElement('div')).addClass('dropdown docContainer');
+				$docDropDown = $(document.createElement('ul')).addClass('dropdown-menu')
+										.attr('id', 'docListContainer_' + encodedUId);
+				$docListHeader = $(document.createElement('li')).addClass('dropdown-header')
+										.text(_('Documents'));
+				$name = $(document.createElement('a')).text(sName);
+				$docentry = $(document.createElement('li')).addClass('docentry')
+										.attr('id', sessionid + '_' + sPid)
+										.append($name);
+				$docDropDown.append($docListHeader);
+				$docDropDown.append($docentry);
+				$docListContainer.append($docDropDown);
+				$noOfDocuments.append($docListContainer);
 
-				$docList = $(document.createElement('td')).addClass('doc_list');
-				$docLabel = $(document.createElement('div')).addClass('doc_list_label');
-				$docentry = $(document.createElement('div')).addClass('docentry')
-														.attr('id', sessionid + '_' + sPid)
-														.text(sName);
-				$docList.append($docLabel);
-				$docList.append($docentry);
-				$userListRow.append($docList);
+				$userListRow.append($noOfDocuments);
 
 				$('#userlist').append($userListRow);
 			}
 			else {
-				userListChildren = $user[0].childNodes;
+				userListChildren = $userListRow[0].childNodes;
 
-				docCount = parseInt($(userListChildren[1]).text())
-				$(userListChildren[1]).text(docCount + 1);
+				var $number = $(document.getElementById('num' + encodedUId));
+				docCount = parseInt($number.text())
+				$number.text(docCount + 1);
 
-				$docLabel = $(userListChildren[2].getElementsByClassName('doc_list_label')[0]);
-				$docLabel.text('🡺 ' + sName + ' and ' + String(docCount) + ' other docs');
+				$docParent = $(userListChildren[1]);
 
-				$docentry = $(document.createElement('div')).addClass('docentry')
-														.attr('id', sessionid + '_' + sPid)
-														.text(sName);
+				$name = $(document.createElement('a')).text(sName);
+				$docentry = $(document.createElement('li')).addClass('docentry')
+										.attr('id', sessionid + '_' + sPid)
+										.append($name);
 
-				$(userListChildren[2]).append($docentry);
-				$('.docentry', $(userListChildren[2])).hide();
+				$(document.getElementById('docListContainer_' + encodedUId)).append($docentry);
 			}
 		}
 		else if (textMsg.startsWith('total_mem') ||
@@ -374,24 +372,14 @@ var AdminSocketOverview = AdminSocketBase.extend({
 			}
 
 			$docEntry = $('#' + sessionid + '_' + sPid);
-			$user = $docEntry.parent().parent();
-			$nDocs = $('.doc_number', $user);
+			$user = $docEntry.parent().parent().parent();
+			$nDocs = $('.doc_number', $user.parent());
 			docCount = parseInt($nDocs.text());
 			if (docCount == 1) {
-				$user.remove();
-			}
-			else if (docCount == 2) {
-				$('.doc_list_label', $user).text('');
-				$('.docentry', $user).show();
-				$nDocs.text(docCount - 1);
-				$docEntry.remove();
+				$user.parent().remove();
 			}
 			else {
-				$parent = $docEntry.parent()
 				$docEntry.remove();
-				$child = $('.docentry', $parent);
-				$('.doc_list_label', $user).text('🡺 ' + $($child[0]).text() + ' and ' + String(docCount - 2) + ' other docs')
-				$('.docentry', $user).hide();
 				$nDocs.text(docCount - 1);
 			}
 		}
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 5153586d..eb80bce3 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -350,10 +350,11 @@ void Admin::modificationAlert(const std::string& dockey, Poco::Process::PID pid,
                 { _model.modificationAlert(dockey, pid, value); });
 }
 
-void Admin::addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId, const std::string& userName)
+void Admin::addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename,
+        const std::string& sessionId, const std::string& userName, const std::string& userId)
 {
-    addCallback([this, docKey, pid, filename, sessionId, userName]
-                 { _model.addDocument(docKey, pid, filename, sessionId, userName); });
+    addCallback([this, docKey, pid, filename, sessionId, userName, userId]
+                 { _model.addDocument(docKey, pid, filename, sessionId, userName, userId); });
 }
 
 void Admin::rmDoc(const std::string& docKey, const std::string& sessionId)
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index f9d8bb6a..e003d619 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -76,7 +76,7 @@ public:
     void update(const std::string& message);
 
     /// Calls with same pid will increment view count, if pid already exists
-    void addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId, const std::string& userName);
+    void addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId, const std::string& userName, const std::string& userId);
 
     /// Decrement view count till becomes zero after which doc is removed
     void rmDoc(const std::string& docKey, const std::string& sessionId);
diff --git a/wsd/AdminModel.cpp b/wsd/AdminModel.cpp
index dcb8279f..5e1bef3a 100644
--- a/wsd/AdminModel.cpp
+++ b/wsd/AdminModel.cpp
@@ -26,9 +26,9 @@
 #include "Unit.hpp"
 #include "Util.hpp"
 
-void Document::addView(const std::string& sessionId, const std::string& userName)
+void Document::addView(const std::string& sessionId, const std::string& userName, const std::string& userId)
 {
-    const auto ret = _views.emplace(sessionId, View(sessionId, userName));
+    const auto ret = _views.emplace(sessionId, View(sessionId, userName, userId));
     if (!ret.second)
     {
         LOG_WRN("View with SessionID [" << sessionId << "] already exists.");
@@ -294,16 +294,18 @@ void AdminModel::modificationAlert(const std::string& docKey, Poco::Process::PID
 
 void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
                              const std::string& filename, const std::string& sessionId,
-                             const std::string& userName)
+                             const std::string& userName, const std::string& userId)
 {
     assertCorrectThread();
 
     const auto ret = _documents.emplace(docKey, Document(docKey, pid, filename));
-    ret.first->second.addView(sessionId, userName);
+    ret.first->second.addView(sessionId, userName, userId);
     LOG_DBG("Added admin document [" << docKey << "].");
 
     std::string encodedUsername;
     std::string encodedFilename;
+    std::string encodedUserId;
+    Poco::URI::encode(userId, " ", encodedUserId);
     Poco::URI::encode(filename, " ", encodedFilename);
     Poco::URI::encode(userName, " ", encodedUsername);
 
@@ -313,7 +315,8 @@ void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
         << pid << ' '
         << encodedFilename << ' '
         << sessionId << ' '
-        << encodedUsername << ' ';
+        << encodedUsername << ' '
+        << encodedUserId << ' ';
 
     // We have to wait until the kit sends us its PSS.
     // Here we guestimate until we get an update.
@@ -456,6 +459,7 @@ std::string AdminModel::getDocuments() const
                 if(!viewIt.second.isExpired()) {
                     oss << separator << '{'
                         << "\"userName\"" << ':' << '"' << viewIt.second.getUserName() << '"' << ','
+                        << "\"userId\"" << ':' << '"' << viewIt.second.getUserId() << '"' << ','
                         << "\"sessionid\"" << ':' << '"' << viewIt.second.getSessionId() << '"' << '}';
                         separator = ',';
                 }
diff --git a/wsd/AdminModel.hpp b/wsd/AdminModel.hpp
index 5445224b..cdca2243 100644
--- a/wsd/AdminModel.hpp
+++ b/wsd/AdminModel.hpp
@@ -24,21 +24,24 @@
 class View
 {
 public:
-    View(const std::string& sessionId, const std::string& userName) :
+    View(const std::string& sessionId, const std::string& userName, const std::string& userId) :
         _sessionId(sessionId),
         _userName(userName),
+        _userId(userId),
         _start(std::time(nullptr))
     {
     }
 
     void expire() { _end = std::time(nullptr); }
     std::string getUserName() const { return _userName; }
+    std::string getUserId() const { return _userId; }
     std::string getSessionId() const { return _sessionId; }
     bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
 
 private:
     const std::string _sessionId;
     const std::string _userName;
+    const std::string _userId;
     const std::time_t _start;
     std::time_t _end = 0;
 };
@@ -69,7 +72,7 @@ public:
 
     std::time_t getIdleTime() const { return std::time(nullptr) - _lastActivity; }
 
-    void addView(const std::string& sessionId, const std::string& userName);
+    void addView(const std::string& sessionId, const std::string& userName, const std::string& userId);
 
     int expireView(const std::string& sessionId);
 
@@ -190,7 +193,7 @@ public:
 
     void notify(const std::string& message);
 
-    void addDocument(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId, const std::string& userName);
+    void addDocument(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId, const std::string& userName, const std::string& userId);
 
     void removeDocument(const std::string& docKey, const std::string& sessionId);
     void removeDocument(const std::string& docKey);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 18f5bc71..6eaf0d10 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -866,7 +866,7 @@ size_t DocumentBroker::addSessionInternal(const std::shared_ptr<ClientSession>&
     _childProcess->sendTextFrame(aMessage);
 
     // Tell the admin console about this new doc
-    Admin::instance().addDoc(_docKey, getPid(), getFilename(), id, session->getUserName());
+    Admin::instance().addDoc(_docKey, getPid(), getFilename(), id, session->getUserName(), session->getUserId());
 
     // Add and attach the session.
     _sessions.emplace(session->getId(), session);
commit 28bdd8296eb13cb267bd87bb2eb707452a23675e
Author: Aditya Dewan <iit2015097 at iiita.ac.in>
Date:   Sun Jul 2 02:00:14 2017 +0530

    Assign unique editorId to localhost users
    
    Change-Id: I1c8949fa7acca1b11b35b48629cc20a1170d8caa
    Reviewed-on: https://gerrit.libreoffice.org/39442
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 341cef41..a147601b 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -228,7 +228,7 @@ std::unique_ptr<LocalStorage::LocalFileInfo> LocalStorage::getLocalFileInfo()
     _fileInfo = FileInfo({filename, "localhost", lastModified, size});
 
     // Set automatic userid and username
-    return std::unique_ptr<LocalStorage::LocalFileInfo>(new LocalFileInfo({"localhost", std::string("Local Host #") + std::to_string(LastLocalStorageId++)}));
+    return std::unique_ptr<LocalStorage::LocalFileInfo>(new LocalFileInfo({"localhost" + std::to_string(LastLocalStorageId), "Local Host #" + std::to_string(LastLocalStorageId++)}));
 }
 
 std::string LocalStorage::loadStorageFileToLocal(const std::string& /*accessToken*/)


More information about the Libreoffice-commits mailing list