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 9 files changed, 91 insertions(+), 99 deletions(-)
New commits: commit bc7fa9a8120a5fb94ff032785186f4453416ab3a Author: Aditya Dewan <iit2015...@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 <pran...@collabora.co.uk> Tested-by: pranavk <pran...@collabora.co.uk> diff --git a/loleaflet/admin.strings.js b/loleaflet/admin.strings.js index 26f232ba..21db2e5d 100644 --- a/loleaflet/admin.strings.js +++ b/loleaflet/admin.strings.js @@ -11,7 +11,7 @@ l10nstrings.strAnalytics = _('Analytics'); l10nstrings.strHistory = _('History'); 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 62be8e56..ddcf3e46 100644 --- a/loleaflet/dist/admin/admin.html +++ b/loleaflet/dist/admin/admin.html @@ -125,7 +125,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 95d62235..82fb2f5f 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,9 +136,6 @@ tr:hover .dropdown-menu{ .selected-view-opt{ background-color: #f5f5f5; } -.doc_list_label{ - cursor: pointer; -} /* * Graph view buttons diff --git a/loleaflet/src/admin/AdminSocketOverview.js b/loleaflet/src/admin/AdminSocketOverview.js index a0726e60..858d5f75 100644 --- a/loleaflet/src/admin/AdminSocketOverview.js +++ b/loleaflet/src/admin/AdminSocketOverview.js @@ -82,18 +82,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) { @@ -142,50 +130,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); @@ -235,7 +227,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) { @@ -246,7 +239,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); @@ -299,46 +292,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') || @@ -380,24 +378,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 deeaecc0..04a20ad5 100644 --- a/wsd/Admin.cpp +++ b/wsd/Admin.cpp @@ -415,10 +415,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 18acab4a..d5b62cb8 100644 --- a/wsd/Admin.hpp +++ b/wsd/Admin.hpp @@ -77,7 +77,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 26097fd0..440de191 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."); @@ -464,17 +464,19 @@ 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.takeSnapshot(); - 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); @@ -484,7 +486,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. @@ -656,6 +659,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 e9eed373..b217c2be 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; }; @@ -80,7 +83,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); @@ -231,7 +234,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 3be3375c..9af4ba4a 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -906,7 +906,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);
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits