From 8766e9ae4a308bb301d8dace2e16dba9ae2ce86d Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 25 Nov 2017 18:38:29 -0500 Subject: [PATCH] cleanup of status code --- public/javascripts/status.js | 49 ------------------------------------ public/javascripts/sync.js | 2 -- routes/api/status.js | 36 -------------------------- routes/routes.js | 2 -- 4 files changed, 89 deletions(-) delete mode 100644 public/javascripts/status.js delete mode 100644 routes/api/status.js diff --git a/public/javascripts/status.js b/public/javascripts/status.js deleted file mode 100644 index 4ca558a8c..000000000 --- a/public/javascripts/status.js +++ /dev/null @@ -1,49 +0,0 @@ -"use strict"; - -const status = (function() { - const changesToPushCountEl = $("#changesToPushCount"); - - async function checkStatus() { - const resp = await $.ajax({ - url: baseApiUrl + 'status', - type: 'POST', - contentType: "application/json", - data: JSON.stringify({ - treeLoadTime: noteTree.getTreeLoadTime(), - currentNoteId: noteEditor.getCurrentNoteId(), - currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime() - }), - statusCode: { - 401: () => { - // if the user got logged out then we should display the page - // here we do that by reloading which will force the redirect if the user is really logged out - window.location.reload(true); - }, - 409: () => { - // 409 means we need to migrate database, reload will take care of it - window.location.reload(true); - } - } - }); - - // if (resp.changedTree) { - // console.log("Reloading tree because of background changes"); - // - // noteTree.reload(); - // } - // - // if (resp.changedCurrentNote) { - // showMessage('Reloading note because background change'); - // - // noteEditor.reload(); - // } - - //changesToPushCountEl.html(resp.changesToPushCount); - } - - //setInterval(checkStatus, 5 * 1000); - - return { - checkStatus - }; -})(); \ No newline at end of file diff --git a/public/javascripts/sync.js b/public/javascripts/sync.js index 0bc32696b..38aa7f6ad 100644 --- a/public/javascripts/sync.js +++ b/public/javascripts/sync.js @@ -6,8 +6,6 @@ function syncNow() { type: 'POST', success: result => { if (result.success) { - status.checkStatus(); - showMessage("Sync finished successfully."); } else { diff --git a/routes/api/status.js b/routes/api/status.js deleted file mode 100644 index d70c5edba..000000000 --- a/routes/api/status.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; - -const express = require('express'); -const router = express.Router(); -const sql = require('../../services/sql'); -const options = require('../../services/options'); -const auth = require('../../services/auth'); -const sync = require('../../services/sync'); -const source_id = require('../../services/source_id'); - -router.post('', auth.checkApiAuth, async (req, res, next) => { - const treeLoadTime = req.body.treeLoadTime; - const currentNoteId = req.body.currentNoteId; - const currentNoteLoadTime = req.body.currentNoteLoadTime; - - const noteTreeChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE entity_name = 'notes_tree' AND source_id != ? " + - "AND sync_date >= ?", [source_id.currentSourceId, treeLoadTime]); - - const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE source_id != ? " + - "AND sync_date >= ? AND entity_name = 'notes' AND entity_id = ?", [source_id.currentSourceId, currentNoteLoadTime, currentNoteId]); - - let changesToPushCount = 0; - - if (sync.isSyncSetup) { - const lastSyncedPush = await options.getOption('last_synced_push'); - changesToPushCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]); - } - - res.send({ - 'changedTree': noteTreeChangesCount > 0, - 'changedCurrentNote': currentNoteChangesCount > 0, - 'changesToPushCount': changesToPushCount - }); -}); - -module.exports = router; \ No newline at end of file diff --git a/routes/routes.js b/routes/routes.js index 88c31eb33..2801a32b0 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -7,7 +7,6 @@ const migrationRoute = require('./migration'); const treeApiRoute = require('./api/tree'); const notesApiRoute = require('./api/notes'); const notesMoveApiRoute = require('./api/notes_move'); -const statusApiRoute = require('./api/status'); const noteHistoryApiRoute = require('./api/note_history'); const recentChangesApiRoute = require('./api/recent_changes'); const settingsApiRoute = require('./api/settings'); @@ -28,7 +27,6 @@ function register(app) { app.use('/api/tree', treeApiRoute); app.use('/api/notes', notesApiRoute); app.use('/api/notes', notesMoveApiRoute); - app.use('/api/status', statusApiRoute); app.use('/api/notes-history', noteHistoryApiRoute); app.use('/api/recent-changes', recentChangesApiRoute); app.use('/api/settings', settingsApiRoute);