summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/DataModel.js10
-rw-r--r--www/js/NewsCtrl.js100
-rw-r--r--www/js/app.js54
3 files changed, 160 insertions, 4 deletions
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; i<data.length; i++)
+ {
+ $scope.newsItems.push({title:data[i].title, url:data[i].url, date:data[i].date});
+ }
+
+ });
+
+}]);
diff --git a/www/js/app.js b/www/js/app.js
index 6f7a98d8..716104e7 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -68,6 +68,7 @@ angular.module('zmApp', [
desktopUrl: "/zm",
desktopApiUrl: "/api/zm",
latestRelease: "https://api.github.com/repos/pliablepixels/zmNinja/releases/latest",
+ blogUrl:"http://pliablepixels.github.io/feed.json",
nphSwitchTimer:6000,
eventHistoryTimer:10000,
@@ -426,6 +427,40 @@ angular.module('zmApp', [
}
//console.log ("UPDATE " + zmVersion);
});
+
+ ZMDataModel.zmLog ("Checking for news updates");
+ $http.get(zm.blogUrl)
+ .success (function (data) {
+ $rootScope.newBlogPost = "";
+ if (data.length <=0)
+ {
+ $rootScope.newBlogPost="";
+ return;
+ }
+
+ var lastDate = $localstorage.get("latestBlogPostChecked");
+ if (!lastDate)
+ {
+ $rootScope.newBlogPost="(new post)";
+ return;
+ }
+
+ var mLastDate = moment(lastDate);
+ var mItemDate = moment(data[0].date);
+
+ if (mItemDate.diff(mLastDate) >0)
+ {
+ 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: '/',