From 03ec40662796f664983d890ec1d7022b11dabc7c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 5 Dec 2017 19:21:01 +0000 Subject: [PATCH] All: Filter to sync target and refactored so that same code can be used by all clients --- ElectronClient/app/gui/StatusScreen.jsx | 35 ++--------------------- ReactNativeClient/lib/models/base-item.js | 4 +-- ReactNativeClient/lib/services/report.js | 34 ++++++++++++++++------ 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/ElectronClient/app/gui/StatusScreen.jsx b/ElectronClient/app/gui/StatusScreen.jsx index 266f0fafa..148d994da 100644 --- a/ElectronClient/app/gui/StatusScreen.jsx +++ b/ElectronClient/app/gui/StatusScreen.jsx @@ -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({row.item.title}{row.syncInfo.sync_disabled_reason}); - } - - sectionsHtml.push( -
- {titleHtml} - - - - {trsHtml} - -
{_('Name')}{_('Reason')}
-
- ); - } - 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 (
diff --git a/ReactNativeClient/lib/models/base-item.js b/ReactNativeClient/lib/models/base-item.js index 82017012e..1066a0eaa 100644 --- a/ReactNativeClient/lib/models/base-item.js +++ b/ReactNativeClient/lib/models/base-item.js @@ -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); diff --git a/ReactNativeClient/lib/services/report.js b/ReactNativeClient/lib/services/report.js index 0b189b651..815ec2129 100644 --- a/ReactNativeClient/lib/services/report.js +++ b/ReactNativeClient/lib/services/report.js @@ -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,16 +151,19 @@ class ReportService { sections.push(section); - 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); - section.body.push(_('On %s: %s', time.formatMsToLocal(alarm.trigger_time), note.title)); - } - sections.push(section); + if (alarms.length) { + section = { title: _('Coming alarms'), body: [] }; + + for (let i = 0; i < alarms.length; i++) { + const alarm = alarms[i]; + const note = await Note.load(alarm.note_id); + section.body.push(_('On %s: %s', time.formatMsToLocal(alarm.trigger_time), note.title)); + } + + sections.push(section); + } return sections; }