mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Filter to sync target and refactored so that same code can be used by all clients
This commit is contained in:
parent
c703521b6c
commit
03ec406627
@ -7,7 +7,6 @@ const { Header } = require('./Header.min.js');
|
||||
const { themeStyle } = require('../theme.js');
|
||||
const { _ } = require('lib/locale.js');
|
||||
const { ReportService } = require('lib/services/report.js');
|
||||
const { BaseItem } = require('lib/models/base-item.js');
|
||||
|
||||
class StatusScreenComponent extends React.Component {
|
||||
|
||||
@ -15,7 +14,6 @@ class StatusScreenComponent extends React.Component {
|
||||
super();
|
||||
this.state = {
|
||||
report: [],
|
||||
disabledItems: [],
|
||||
};
|
||||
}
|
||||
|
||||
@ -26,11 +24,7 @@ class StatusScreenComponent extends React.Component {
|
||||
async resfreshScreen() {
|
||||
const service = new ReportService();
|
||||
const report = await service.status(Setting.value('sync.target'));
|
||||
const disabledItems = await BaseItem.syncDisabledItems();
|
||||
this.setState({
|
||||
report: report,
|
||||
disabledItems: disabledItems,
|
||||
});
|
||||
this.setState({ report: report });
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -70,7 +64,7 @@ class StatusScreenComponent extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
function renderBodyHtml(report, disabledItems) {
|
||||
function renderBodyHtml(report) {
|
||||
let output = [];
|
||||
let baseStyle = {
|
||||
paddingLeft: 6,
|
||||
@ -84,27 +78,6 @@ class StatusScreenComponent extends React.Component {
|
||||
|
||||
let sectionsHtml = [];
|
||||
|
||||
if (disabledItems.length) {
|
||||
const titleHtml = [renderSectionTitleHtml('disabled_sync_items', _('Items that cannot be synchronised'))];
|
||||
const trsHtml = [];
|
||||
for (let i = 0; i < disabledItems.length; i++) {
|
||||
const row = disabledItems[i];
|
||||
trsHtml.push(<tr key={'item_' + i}><td style={theme.textStyle}>{row.item.title}</td><td style={theme.textStyle}>{row.syncInfo.sync_disabled_reason}</td></tr>);
|
||||
}
|
||||
|
||||
sectionsHtml.push(
|
||||
<div key={'disabled_sync_items'}>
|
||||
{titleHtml}
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th style={theme.textStyle}>{_('Name')}</th><th style={theme.textStyle}>{_('Reason')}</th></tr>
|
||||
{trsHtml}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
for (let i = 0; i < report.length; i++) {
|
||||
let section = report[i];
|
||||
if (!section.body.length) continue;
|
||||
@ -118,9 +91,7 @@ class StatusScreenComponent extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
console.info(this.state.disabledItems);
|
||||
|
||||
let body = renderBodyHtml(this.state.report, this.state.disabledItems);
|
||||
let body = renderBodyHtml(this.state.report);
|
||||
|
||||
return (
|
||||
<div style={style}>
|
||||
|
@ -383,8 +383,8 @@ class BaseItem extends BaseModel {
|
||||
throw new Error('Invalid type: ' + type);
|
||||
}
|
||||
|
||||
static async syncDisabledItems() {
|
||||
const rows = await this.db().selectAll('SELECT * FROM sync_items WHERE sync_disabled = 1');
|
||||
static async syncDisabledItems(syncTargetId) {
|
||||
const rows = await this.db().selectAll('SELECT * FROM sync_items WHERE sync_disabled = 1 AND sync_target = ?', [syncTargetId]);
|
||||
let output = [];
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const item = await this.loadItem(rows[i].item_type, rows[i].item_id);
|
||||
|
@ -109,8 +109,21 @@ class ReportService {
|
||||
async status(syncTarget) {
|
||||
let r = await this.syncStatus(syncTarget);
|
||||
let sections = [];
|
||||
let section = null;
|
||||
|
||||
let section = { title: _('Sync status (synced items / total items)'), body: [] };
|
||||
const disabledItems = await BaseItem.syncDisabledItems(syncTarget);
|
||||
|
||||
if (disabledItems.length) {
|
||||
section = { title: _('Items that cannot be synchronised'), body: [] };
|
||||
|
||||
for (let i = 0; i < disabledItems.length; i++) {
|
||||
const row = disabledItems[i];
|
||||
section.body.push(_('"%s": "%s"', row.item.title, row.syncInfo.sync_disabled_reason));
|
||||
}
|
||||
sections.push(section);
|
||||
}
|
||||
|
||||
section = { title: _('Sync status (synced items / total items)'), body: [] };
|
||||
|
||||
for (let n in r.items) {
|
||||
if (!r.items.hasOwnProperty(n)) continue;
|
||||
@ -138,9 +151,11 @@ class ReportService {
|
||||
|
||||
sections.push(section);
|
||||
|
||||
const alarms = await Alarm.allDue();
|
||||
|
||||
if (alarms.length) {
|
||||
section = { title: _('Coming alarms'), body: [] };
|
||||
|
||||
const alarms = await Alarm.allDue();
|
||||
for (let i = 0; i < alarms.length; i++) {
|
||||
const alarm = alarms[i];
|
||||
const note = await Note.load(alarm.note_id);
|
||||
@ -148,6 +163,7 @@ class ReportService {
|
||||
}
|
||||
|
||||
sections.push(section);
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user