From 2bd4ed9e17fbd380bc2f45f902038bb749177c93 Mon Sep 17 00:00:00 2001 From: gine Date: Wed, 19 Apr 2017 17:42:11 +0200 Subject: [PATCH] Fix Loader senza rete #36 --- www/js/query.js | 20 +++++++++++--------- www/js/update.js | 6 +++--- www/js/util.js | 5 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/www/js/query.js b/www/js/query.js index ede4327..773e275 100644 --- a/www/js/query.js +++ b/www/js/query.js @@ -1,6 +1,5 @@ function myJsonCategory(Qcategory, div, addTagCategory) { - $.mobile.loading('show'); - FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts WHERE category = ? ORDER BY date COLLATE NOCASE DESC;", [Qcategory], function (resultSet) { + FONTE.dbHandler.executeSql("SELECT DISTINCT * FROM xm24_posts WHERE category = ? ORDER BY date COLLATE NOCASE DESC;", [Qcategory], function (resultSet) { var items = []; for (var i = 0; i < resultSet.rows.length; i++) { var val = JSON.parse(resultSet.rows.item(i).post); @@ -83,7 +82,10 @@ var drawListPost = function(div, resultSet, position) { } else if(position == 'prepend'){ ul.prependTo(div); } - $.mobile.loading('hide'); + + setTimeout(function () { + $.mobile.loading('hide'); + }, 1000); }; var appendPostList = function(div, resultSet, categories, fallback) { @@ -144,7 +146,7 @@ var getCategoryWhere = function(categories) { var POST = POST || {}; POST.sql = { - init: "SELECT * FROM xm24_posts JOIN xm24_cats_to_posts USING(id) WHERE ", + init: "SELECT DISTINCT * FROM xm24_posts JOIN xm24_cats_to_posts USING(id) WHERE ", end : "ORDER BY date COLLATE NOCASE DESC LIMIT ?" }; @@ -195,7 +197,7 @@ function myJsonLastPage(div) { var firstTime = storage.getItem('db_lastnews_firsttime'); if (firstTime != 'yes') { if (lastnewsDate) { - FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts WHERE date > ? ORDER BY date COLLATE NOCASE DESC LIMIT 40;", [lastnewsDate], function (resultSet) { + FONTE.dbHandler.executeSql("SELECT DISTINCT * FROM xm24_posts WHERE date > ? ORDER BY date COLLATE NOCASE DESC LIMIT 40;", [lastnewsDate], function (resultSet) { var items = []; $(div).empty(); if (resultSet.rows.length > 0) { @@ -232,7 +234,7 @@ function myJsonLastPage(div) { function myJsonCategoryPaginated(Qcategory, div, pageNumber) { $.mobile.loading('show'); - FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts WHERE category = ? ORDER BY date COLLATE NOCASE DESC;", [Qcategory], function (resultSet) { + FONTE.dbHandler.executeSql("SELECT DISTINCT * FROM xm24_posts WHERE category = ? ORDER BY date COLLATE NOCASE DESC;", [Qcategory], function (resultSet) { var items = []; $(div).empty(); for (var i = 0; i < resultSet.rows.length; i++) { @@ -313,7 +315,7 @@ function myJsonPost(Qid, div_title, div_content, _class) { table = EVENTS.table.single; } - FONTE.dbHandler.executeSql("SELECT * FROM " + table + " WHERE id = ?;", [Qid], function(resultSet) { + FONTE.dbHandler.executeSql("SELECT DISTINCT * FROM " + table + " WHERE id = ?;", [Qid], function(resultSet) { if(!_class){ drawPost(div_title, div_content, resultSet); } else { @@ -325,7 +327,7 @@ function myJsonPost(Qid, div_title, div_content, _class) { function myJsonPage(Qid, div_title, div_content) { $.mobile.loading('show'); var pageId = parseInt(Qid); - FONTE.dbHandler.executeSql("SELECT * FROM xm24_pages WHERE id = ?;", [pageId], function (resultSet) { + FONTE.dbHandler.executeSql("SELECT DISTINCT * FROM xm24_pages WHERE id = ?;", [pageId], function (resultSet) { for (var i = 0; i < resultSet.rows.length; i++) { var data = resultSet.rows.item(i); var id = data.id; @@ -342,7 +344,7 @@ function myJsonPage(Qid, div_title, div_content) { function myJsonRandomPost(div_title, div_content) { $.mobile.loading('show'); - FONTE.dbHandler.executeSql("SELECT * FROM xm24_posts ORDER BY RANDOM() LIMIT 1;", [], function (resultSet) { + FONTE.dbHandler.executeSql("SELECT DISTINCT * FROM xm24_posts ORDER BY RANDOM() LIMIT 1;", [], function (resultSet) { for (var i = 0; i < resultSet.rows.length; i++) { var val = JSON.parse(resultSet.rows.item(i).post); var id = val.id; diff --git a/www/js/update.js b/www/js/update.js index c980bd1..481ac85 100644 --- a/www/js/update.js +++ b/www/js/update.js @@ -245,9 +245,9 @@ function getLastSinglePageRecur(url, pagenum, categories) { }); }); - if (data.length == 0) { - renderLastNews(FONTE.contentListClass, categories); - } + // if (data.length === 0) { + // renderLastNews(FONTE.contentListClass, categories); + // } }, error: JSONErrorHandler }); diff --git a/www/js/util.js b/www/js/util.js index ccb6f1a..ad149a3 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -8,7 +8,7 @@ function initStorage() { } /*per network info*/ -function checkConnection(code, msgConnect) { +function checkConnection(code, msgConnect, print) { var msgTitle = "Non sei connesso"; msgConnect = msgConnect || "Occore essere connessi per poter ricevere i nuovi articoli"; @@ -23,7 +23,8 @@ function checkConnection(code, msgConnect) { states[Connection.CELL] = 'Cell generic connection'; states[Connection.NONE] = 'No network connection'; if (states[networkState] == 'Unknown connection' || states[networkState] == 'No network connection') { - toastr.warning(msgConnect, msgTitle); + if(! print) + toastr.warning(msgConnect, msgTitle); console.log(code); return false; } else {