tdf#107752 admin console: indicating whether a document is modified.

Change-Id: I6055a601c1dd3b5e9700ef75d7c07d7e0b13d663
This commit is contained in:
Aditya Dewan
2017-05-12 19:29:01 +05:30
committed by Pranav Kant
parent c05aec945d
commit 9db39ce741
9 changed files with 61 additions and 6 deletions

View File

@ -18,6 +18,7 @@ l10nstrings.strDocument = _('Document');
l10nstrings.strNumberOfViews = _('Number of views');
l10nstrings.strElapsedTime = _('Elapsed time');
l10nstrings.strIdleTime = _('Idle time');
l10nstrings.strModified = _('Modified');
l10nstrings.strKill = _('Kill');
l10nstrings.strGraphs = _('Graphs');
l10nstrings.strSave = _('Save');

View File

@ -90,6 +90,7 @@
<th><script>document.write(l10nstrings.strMemoryConsumed)</script></th>
<th><script>document.write(l10nstrings.strElapsedTime)</script></th>
<th><script>document.write(l10nstrings.strIdleTime)</script></th>
<th><script>document.write(l10nstrings.strModified)</script></th>
</tr>
</thead>
<tbody id="doclist">

View File

@ -23,7 +23,7 @@ var AdminSocketOverview = AdminSocketBase.extend({
this.base.call(this);
this.socket.send('documents');
this.socket.send('subscribe adddoc rmdoc resetidle propchange');
this.socket.send('subscribe adddoc rmdoc resetidle propchange modifications');
this._getBasicStats();
var socketOverview = this;
@ -101,7 +101,8 @@ var AdminSocketOverview = AdminSocketBase.extend({
sMem = docProps['memory'];
sDocTime = docProps['elapsedTime'];
sDocIdle = docProps['idleTime'];
userListJson = docProps['views']
modified = docProps['modified'];
userListJson = docProps['views'];
$doc = $('#doc' + sPid);
$rowContainer = $(document.createElement('tr')).attr('id', 'doc' + sPid);
@ -137,6 +138,11 @@ var AdminSocketOverview = AdminSocketBase.extend({
.val(parseInt(sDocIdle))
.text(Util.humanizeSecs(sDocIdle));
$rowContainer.append($docIdle);
$mod = $(document.createElement('td')).attr('id', 'mod' + sPid)
.text(modified);
$rowContainer.append($mod);
$('#doclist').append($rowContainer);
}
}
@ -187,6 +193,10 @@ var AdminSocketOverview = AdminSocketBase.extend({
.text(Util.humanizeSecs(0));
$rowContainer.append($docIdle);
$mod = $(document.createElement('td')).attr('id', 'mod' + sPid)
.text('');
$rowContainer.append($mod);
$('#doclist').append($rowContainer);
$a = $(document.getElementById('active_docs_count'));
@ -255,6 +265,15 @@ var AdminSocketOverview = AdminSocketBase.extend({
}
}
}
else if (textMsg.startsWith('modifications')) {
textMsg = textMsg.substring('modifications'.length);
docProps = textMsg.trim().split(' ');
sPid = docProps[0];
value = docProps[1];
$mod = $(document.getElementById('mod' + sPid));
$mod.text(value);
}
},
onSocketClose: function() {

View File

@ -350,6 +350,11 @@ void Admin::pollingThread()
}
}
void Admin::modificationAlert(const std::string& dockey, Poco::Process::PID pid, bool value){
addCallback([this, dockey, pid, value]
{ _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)
{
addCallback([this, docKey, pid, filename, sessionId, userName]

View File

@ -71,6 +71,7 @@ public:
unsigned getTotalMemoryUsage();
void modificationAlert(const std::string& dockey, Poco::Process::PID pid, bool value);
/// Update the Admin Model.
void update(const std::string& message);

View File

@ -373,6 +373,24 @@ void AdminModel::notify(const std::string& message)
}
}
void AdminModel::modificationAlert(const std::string& docKey, Poco::Process::PID pid, bool value)
{
assertCorrectThread();
auto doc = _documents.find(docKey);
if(doc != _documents.end())
{
doc->second.setModified(value);
}
std::ostringstream oss;
oss << "modifications "
<< pid << ' '
<< (value?"Yes":"No");
notify(oss.str());
}
void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
const std::string& filename, const std::string& sessionId,
const std::string& userName)
@ -532,6 +550,7 @@ std::string AdminModel::getDocuments() const
<< "\"memory\"" << ':' << it.second.getMemoryDirty() << ','
<< "\"elapsedTime\"" << ':' << it.second.getElapsedTime() << ','
<< "\"idleTime\"" << ':' << it.second.getIdleTime() << ','
<< "\"modified\"" << ':' << '"' << (it.second.getModifiedStatus() ? "Yes" : "No") << '"' << ','
<< "\"views\"" << ':' << '[';
viewers = it.second.getViews();
std::string separator;

View File

@ -85,9 +85,13 @@ public:
const std::string getHistory() const;
void takeSnapshot();
void setModified(bool value) { _isModified = value; }
bool getModifiedStatus() const { return _isModified; }
std::string to_string() const;
private:
bool _isModified;
const std::string _docKey;
const Poco::Process::PID _pid;
/// SessionId mapping to View object
@ -175,6 +179,8 @@ public:
void unsubscribe(int sessionId, const std::string& command);
void modificationAlert(const std::string& docKey, Poco::Process::PID pid, bool value);
void clearMemStats() { _memStats.clear(); }
void clearCpuStats() { _cpuStats.clear(); }

View File

@ -605,8 +605,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
StorageBase::SaveResult storageSaveResult = _storage->saveLocalFileToStorage(accessToken);
if (storageSaveResult == StorageBase::SaveResult::OK)
{
_isModified = false;
_tileCache->setUnsavedChanges(false);
setModified(false);
_lastFileModifiedTime = newFileModifiedTime;
_tileCache->saveLastModified(_lastFileModifiedTime);
_lastSaveTime = std::chrono::steady_clock::now();
@ -1238,8 +1237,13 @@ void DocumentBroker::destroyIfLastEditor(const std::string& id)
void DocumentBroker::setModified(const bool value)
{
if(_isModified != value)
{
_isModified = value;
Admin::instance().modificationAlert(_docKey, getPid(), value);
}
_tileCache->setUnsavedChanges(value);
_isModified = value;
}
bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string& message)

View File

@ -241,7 +241,6 @@ public:
bool saveToStorage(const std::string& sesionId, bool success, const std::string& result = "");
bool isModified() const { return _isModified; }
void setModified(const bool value);
/// Save the document if the document is modified.
/// @param force when true, will force saving if there
/// has been any recent activity after the last save.