Skip to content
Browse files

restructured js similar to MVC. added details for notifications

  • Loading branch information...
1 parent 20f8054 commit a51f4e8b0e2b3d8fe7170a429d70bcfdf03c73cd @nitindhar7 committed Mar 21, 2012
View
3 manifest.json
@@ -1,5 +1,5 @@
{
- "name": "rangr",
+ "name": "Rangr from Forrst",
"version": "0.1.0",
"description": "Rangr is a Google Chrome extension that pulls a users notification data from Forrst.com and presents it in the browser in a soft, non-intrusive manner",
"browser_action": {
@@ -11,6 +11,7 @@
"default_icon": "icon.png",
"permissions": [
"notifications",
+ "tabs",
"https://forrst.com/api/v2/"
]
}
View
8 src/core.html
@@ -1,10 +1,10 @@
<html>
<head>
<script src="js/lib/jquery.js"></script>
- <script src="js/rangr_storage_dao.js"></script>
- <script src="js/auth_controller.js"></script>
- <script src="js/notification.js"></script>
- <script src="js/base_controller.js"></script>
+ <script src="js/model/rangr_storage_dao.js"></script>
+ <script src="js/controller/auth_controller.js"></script>
+ <script src="js/model/notification.js"></script>
+ <script src="js/controller/base_controller.js"></script>
</head>
<body>
</body>
View
15 src/js/base_controller.js
@@ -1,15 +0,0 @@
-var storageDao = new RangrStorageDao();
-
-actionStartup();
-
-function actionStartup() {
-
- // TODO: check if access token exists
-
- // TODO: if token exists fetch notifications
-
- // TODO: if no notifications exist show appropriate notification
-
- // TODO: if >3 notifications exist show 2 individual notification views, else show combo notification
-
-}
View
2 src/js/auth_controller.js → src/js/controller/auth_controller.js
@@ -6,6 +6,8 @@ var MSG_LOGOUT_SUCCESS = "Successfully logged out!";
var storageDao = new RangrStorageDao();
+// TODO: session timing?
+
function requestHandler(request, sender, sendResponse) {
if(request.type == "login") {
View
60 src/js/controller/base_controller.js
@@ -0,0 +1,60 @@
+actionSetup();
+
+function actionSetup() {
+
+ var NOTIFICATIONS_GROUP_THRESHOLD = 2;
+
+ var storageDao = new RangrStorageDao();
+ var token = storageDao.getToken();
+ var notifications = [];
+ var notificationsCount = 0;
+
+ if(token != null) {
+ $.ajax({
+ data: {access_token: token, grouped: true},
+ dataType: "json",
+ type: "get",
+ url: "https://forrst.com/api/v2/notifications",
+ success: function(response) {
+ // TODO: what happens where there is no notification?
+ for(item in response.resp.items) {
+ for(notification in response.resp.items[item]) {
+ notifications.push(response.resp.items[item][notification]);
+ notificationsCount++;
+ }
+ }
+
+ notificationsCount = 2;
+
+ if(notificationsCount == 0 || notificationsCount > NOTIFICATIONS_GROUP_THRESHOLD) {
+ var notification = new Notification('images/ajax-loader.gif', '', notificationsCount + ' notifications found').build();
+ notification.show();
+ }
+ else {
+ var i = 0;
+ for(key in notifications) {
+ i++; if (i > 2) break;
+
+ // TODO: show default forrst photo if notification doesnt contain user's thumbnail url
+ var notification = new Notification(notifications[key].data.photo,
+ notifications[key].object_type + ' ' + notifications[key].behavior,
+ ' @' + notifications[key].data.actor
+ ).build();
+ notification.onclick = function() {
+ chrome.tabs.create({url: 'http://forrst.com' + notifications[key].data.object_url})
+ notification.cancel();
+ };
+ notification.show();
+ console.log(notifications[key]);
+ }
+ }
+ },
+ error: function() {
+ }
+ });
+ }
+ else {
+ alert("not logged in!");
+ }
+
+}
View
0 src/js/login_controller.js → src/js/controller/login_controller.js
File renamed without changes.
View
0 src/js/notification.js → src/js/model/notification.js
File renamed without changes.
View
2 src/js/rangr_storage_dao.js → src/js/model/rangr_storage_dao.js
@@ -2,6 +2,8 @@ function RangrStorageDao() {
var RANGR_ACCESS_TOKEN_KEY = "rangr_access_token";
+ // TODO: maybe cache token in memory
+
this.getToken = function() {
return localStorage.getItem(RANGR_ACCESS_TOKEN_KEY);
};
View
2 src/login_view.html
@@ -1,7 +1,7 @@
<html>
<head>
<script src="js/lib/jquery.js"></script>
- <script src="js/login_controller.js"></script>
+ <script src="js/controller/login_controller.js"></script>
<link rel="stylesheet" href="css/login_view.css" type="text/css">
</head>
<body>

0 comments on commit a51f4e8

Please sign in to comment.
Something went wrong with that request. Please try again.