From 214453ca46791fcfa8f80934b8965b613d7fb2b6 Mon Sep 17 00:00:00 2001 From: pliablepixels Date: Wed, 3 Feb 2016 16:34:14 -0500 Subject: integrated blog feed Former-commit-id: 515f38980145bfe216f63287e7c30f6b3c097766 --- www/js/DataModel.js | 10 ++++++ www/js/NewsCtrl.js | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ www/js/app.js | 54 +++++++++++++++++++++++++--- 3 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 www/js/NewsCtrl.js (limited to 'www/js') diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 74365687..cff49302 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -66,6 +66,7 @@ angular.module('zmApp.controllers') 'exitOnSleep':false, 'forceNetworkStop':false, 'defaultPushSound': false, + 'enableBlog':true, }; @@ -267,6 +268,13 @@ angular.module('zmApp.controllers') loginData.exitOnSleep = false; } + if (typeof loginData.enableBlog == 'undefined') + { + zmDebug ("enableBlog does not exist. Setting to true"); + loginData.enableBlog = true; + + } + zmLog ("DataModel init recovered this loginData as " + JSON.stringify(loginData)); } else @@ -277,6 +285,7 @@ angular.module('zmApp.controllers') monitorsLoaded = 0; //console.log("Getting out of ZMDataModel init"); + $rootScope.showBlog = loginData.enableBlog; zmDebug ( "loginData structure values: " + JSON.stringify(loginData)); }, @@ -396,6 +405,7 @@ angular.module('zmApp.controllers') setLogin: function (newLogin) { setLogin(newLogin); + $rootScope.showBlog = newLogin.enableBlog; /* diff --git a/www/js/NewsCtrl.js b/www/js/NewsCtrl.js new file mode 100644 index 00000000..a84cbdfc --- /dev/null +++ b/www/js/NewsCtrl.js @@ -0,0 +1,100 @@ +/* jshint -W041 */ +/* jslint browser: true*/ +/* global cordova,StatusBar,angular,console,moment*/ + +angular.module('zmApp.controllers').controller('zmApp.NewsCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel','$ionicSideMenuDelegate', '$ionicHistory', '$state', '$http', 'zm', '$localstorage', function ($scope, $rootScope, $ionicModal, ZMDataModel,$ionicSideMenuDelegate, $ionicHistory, $state, $http, zm, $localstorage) { +$scope.openMenu = function () { + $ionicSideMenuDelegate.toggleLeft(); + }; + + + //---------------------------------------------------------------- + // Alarm notification handling + //---------------------------------------------------------------- + $scope.handleAlarms = function() + { + $rootScope.isAlarm=!$rootScope.isAlarm; + if (!$rootScope.isAlarm) + { + $rootScope.alarmCount="0"; + $ionicHistory.nextViewOptions({disableBack: true}); + $state.go("events", {"id": 0}, { reload: true }); + } + }; + + + //------------------------------------------------------------------------- + // Lets make sure we set screen dim properly as we enter + // The problem is we enter other states before we leave previous states + // from a callback perspective in ionic, so we really can't predictably + // reset power state on exit as if it is called after we enter another + // state, that effectively overwrites current view power management needs + //------------------------------------------------------------------------ + $scope.$on('$ionicView.enter', function () { + console.log("**VIEW ** News Ctrl Entered"); + ZMDataModel.setAwake(false); + + + }); + + $scope.isUnread = function(itemdate) + { + var lastDate = $localstorage.get("latestBlogPostChecked"); + if (!lastDate) return true; + var mLastDate = moment(lastDate); + var mItemDate = moment(itemdate); + //var unread = mItemDate.diff(mLastDate) >0) ? true:false; + //console.log (unread); + return (mItemDate.diff(mLastDate) >0) ? true:false; + + + }; + + $scope.loadPost = function (item, itemdate) + { + var lastDate = $localstorage.get("latestBlogPostChecked"); + if (!lastDate) + { + ZMDataModel.zmDebug ("First time checking blog posts, I see"); + $localstorage.set("latestBlogPostChecked", itemdate); + } + + else + { + ZMDataModel.zmDebug ("last post checked is " + lastDate); + ZMDataModel.zmDebug ("current post dated is " + itemdate); + + var mLastDate = moment(lastDate); + var mItemDate = moment(itemdate); + if (mItemDate.diff(mLastDate) >0) + { + ZMDataModel.zmDebug ("Updating lastDate to this post"); + $localstorage.set("latestBlogPostChecked", itemdate); + + if (itemdate == $scope.newsItems[0].date) + { + // we are reading the latest post + $rootScope.newBlogPost=""; + } + } + + } + window.open(item, '_blank', 'location=yes'); + return false; + }; + + $scope.newsItems=[]; + + $http.get (zm.blogUrl) + .success (function(data) + { + //console.log ("Here2"); + console.log (JSON.stringify(data)); + for (var i=0; i0) + { + ZMDataModel.zmDebug("New post dated " + data[0].date + " found"); + $rootScope.newBlogPost = "(new post)"; + + } + else + { + ZMDataModel.zmDebug("Latest post dated " + data[0].date + " but you read " + lastDate); + } + + + }); } } @@ -720,6 +755,8 @@ angular.module('zmApp', [ $rootScope.newVersionAvailable = ""; $rootScope.userCancelledAuth = false; $rootScope.online = true; + $rootScope.showBlog = false; + $rootScope.newBlogPost=""; //$rootScope.minAlarmCount = "1"; @@ -1067,17 +1104,26 @@ angular.module('zmApp', [ url: "/login", templateUrl: "templates/login.html", controller: 'zmApp.LoginCtrl', - }); + }) - $stateProvider - .state('help', { + + .state('help', { data: { requireLogin: false }, url: "/help", templateUrl: "templates/help.html", controller: 'zmApp.HelpCtrl', - }) + }) + + .state('news', { + data: { + requireLogin: false + }, + url: "/news", + templateUrl: "templates/news.html", + controller: 'zmApp.NewsCtrl', + }) .state('app', { url: '/', -- cgit v1.2.3