1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ReactNativeClient/lib/services/report.js

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 20:09:47 +02:00
class ReportService {
2017-07-16 18:06:05 +02:00
async syncStatus(syncTarget) {
2017-07-13 20:09:47 +02: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 18:06:05 +02:00
synced: await ItemClass.syncedCount(syncTarget),
2017-07-13 20:09:47 +02:00
};
output.items[d.className] = o;
itemCount += o.total;
syncedCount += o.synced;
}
2017-07-16 00:47:11 +02:00
let conflictedCount = await Note.conflictedCount();
2017-07-13 20:09:47 +02:00
output.total = {
2017-07-16 00:47:11 +02:00
total: itemCount - conflictedCount,
2017-07-13 20:09:47 +02:00
synced: syncedCount,
};
output.toDelete = {
2017-07-19 21:15:55 +02:00
total: await BaseItem.deletedItemCount(syncTarget),
2017-07-13 20:09:47 +02:00
};
2017-07-15 17:35:40 +02:00
output.conflicted = {
total: await Note.conflictedCount(),
};
output.items['Note'].total -= output.conflicted.total;
2017-07-13 20:09:47 +02:00
return output;
}
2017-07-16 18:06:05 +02:00
async status(syncTarget) {
let r = await this.syncStatus(syncTarget);
2017-07-13 20:09:47 +02: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 17:35:40 +02: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 20:09:47 +02:00
sections.push(section);
section = {};
section.title = _('Folders');
section.body = [];
2017-07-14 20:02:45 +02:00
let folders = await Folder.all({
order: { by: 'title', dir: 'ASC' },
2017-07-14 20:02:45 +02:00
caseInsensitive: true,
});
2017-07-13 20:09:47 +02: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;
}
}
export { ReportService }