1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-07 19:30:04 +02:00

90 lines
2.1 KiB
JavaScript
Raw Normal View History

const { time } = require('lib/time-utils');
const { BaseItem } = require('lib/models/base-item.js');
const { Folder } = require('lib/models/folder.js');
const { Note } = require('lib/models/note.js');
const { _ } = require('lib/locale.js');
2017-07-13 18:09:47 +00:00
class ReportService {
2017-07-16 17:06:05 +01:00
async syncStatus(syncTarget) {
2017-07-13 18:09:47 +00:00
let output = {
items: {},
total: {},
};
let itemCount = 0;
let syncedCount = 0;
for (let i = 0; i < BaseItem.syncItemDefinitions_.length; i++) {
let d = BaseItem.syncItemDefinitions_[i];
let ItemClass = BaseItem.getClass(d.className);
let o = {
total: await ItemClass.count(),
2017-07-16 17:06:05 +01:00
synced: await ItemClass.syncedCount(syncTarget),
2017-07-13 18:09:47 +00:00
};
output.items[d.className] = o;
itemCount += o.total;
syncedCount += o.synced;
}
2017-07-15 23:47:11 +01:00
let conflictedCount = await Note.conflictedCount();
2017-07-13 18:09:47 +00:00
output.total = {
2017-07-15 23:47:11 +01:00
total: itemCount - conflictedCount,
2017-07-13 18:09:47 +00:00
synced: syncedCount,
};
output.toDelete = {
2017-07-19 20:15:55 +01:00
total: await BaseItem.deletedItemCount(syncTarget),
2017-07-13 18:09:47 +00:00
};
2017-07-15 16:35:40 +01:00
output.conflicted = {
total: await Note.conflictedCount(),
};
output.items['Note'].total -= output.conflicted.total;
2017-07-13 18:09:47 +00:00
return output;
}
2017-07-16 17:06:05 +01:00
async status(syncTarget) {
let r = await this.syncStatus(syncTarget);
2017-07-13 18:09:47 +00:00
let sections = [];
let section = {};
section.title = _('Sync status (synced items / total items)');
section.body = [];
for (let n in r.items) {
if (!r.items.hasOwnProperty(n)) continue;
section.body.push(_('%s: %d/%d', n, r.items[n].synced, r.items[n].total));
}
2017-07-15 16:35:40 +01:00
section.body.push(_('Total: %d/%d', r.total.synced, r.total.total));
section.body.push('');
section.body.push(_('Conflicted: %d', r.conflicted.total));
section.body.push(_('To delete: %d', r.toDelete.total));
2017-07-13 18:09:47 +00:00
sections.push(section);
section = {};
section.title = _('Folders');
section.body = [];
2017-07-14 18:02:45 +00:00
let folders = await Folder.all({
order: { by: 'title', dir: 'ASC' },
2017-07-14 18:02:45 +00:00
caseInsensitive: true,
});
2017-07-13 18:09:47 +00:00
for (let i = 0; i < folders.length; i++) {
let folder = folders[i];
section.body.push(_('%s: %d notes', folders[i].title, await Folder.noteCount(folders[i].id)));
}
sections.push(section);
return sections;
}
}
2017-11-03 00:13:17 +00:00
module.exports = { ReportService };