Skip to content

Commit

Permalink
badge with numUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
matiastucci committed Aug 3, 2015
1 parent 2e97971 commit 9391fd2
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<script src="lib/ionic/js/ionic.bundle.js"></script>

<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="lib/socket.io-1.2.0.js"></script>
<script src="lib/angular-socket-io/socket.min.js"></script>

<script src="cordova.js"></script>
Expand Down
1 change: 0 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ angular.module('chat', ['ionic', 'btford.socket-io', 'chat.controllers', 'chat.s
views: {
'tab-users': {
templateUrl: 'templates/tab-users.html',
controller: 'PeopleCtrl'
}
}
})
Expand Down
11 changes: 4 additions & 7 deletions js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module('chat.controllers', [])
$scope.messages = Chat.getMessages();
var typing = false;
var lastTypingTime;
var TYPING_TIMER_LENGTH = 400;
var TYPING_TIMER_LENGTH = 4000;

Socket.on('connect',function(){

Expand Down Expand Up @@ -74,11 +74,8 @@ angular.module('chat.controllers', [])

})

.controller('PeopleCtrl', function($scope, Chats) {
$scope.chats = Chats.all();
$scope.remove = function(chat) {
Chats.remove(chat);
};
.controller('PeopleCtrl', function($scope, Chat) {
$scope.data = Chat.getNumUsers();
})

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
Expand All @@ -87,4 +84,4 @@ angular.module('chat.controllers', [])

.controller('AccountCtrl', function($scope, Chat) {
$scope.username = Chat.getUsername();
});
}, true);
21 changes: 21 additions & 0 deletions js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ angular.module('chat.services', [])
.factory('Chat', function($ionicScrollDelegate, Socket){

var username;
var users = {};
users.numUsers = 0;

var messages = [];
var TYPING_MSG = '. . .';

Expand All @@ -22,6 +25,14 @@ angular.module('chat.services', [])
return notification;
};

var setNumUsers = function(data){
users.numUsers = data.numUsers;
};

Socket.on('login', function (data) {
setNumUsers(data);
});

Socket.on('new message', function(msg){
addMessage(msg);
});
Expand All @@ -42,12 +53,14 @@ angular.module('chat.services', [])
var msg = data.username + ' joined';
var notification = new Notification(data.username,msg);
addMessage(notification);
setNumUsers(data);
});

Socket.on('user left', function (data) {
var msg = data.username + ' left';
var notification = new Notification(data.username,msg);
addMessage(notification);
setNumUsers(data);
});

var scrollBottom = function(){
Expand Down Expand Up @@ -78,6 +91,14 @@ angular.module('chat.services', [])
setUsername: function(usr){
username = usr;
},

getUsernames: function(){
return usernames;
},
getNumUsers: function(){
return users;
},

getMessages: function() {
return messages;
},
Expand Down
3 changes: 3 additions & 0 deletions lib/socket.io-1.2.0.js

Large diffs are not rendered by default.

17 changes: 5 additions & 12 deletions templates/tab-users.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<ion-view view-title="Users">
<ion-content>
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" href="#/tab/users/{{chat.id}}">
<img ng-src="{{chat.face}}">
<h2>{{chat.name}}</h2>
<p>{{chat.lastText}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>

<input type="text" ng-model="data.badgeCount">

{{data.numUsers | json}}

<ion-option-button class="button-assertive" ng-click="remove(chat)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
</ion-view>
2 changes: 1 addition & 1 deletion templates/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ion-nav-view name="tab-chats"></ion-nav-view>
</ion-tab>

<ion-tab title="Contacts" icon-off="ion-ios-people-outline" icon-on="ion-ios-people" href="#/tab/users">
<ion-tab title="Contacts" badge="data.numUsers" badge-style="badge-positive" icon-off="ion-ios-people-outline" icon-on="ion-ios-people" href="#/tab/users" ng-controller="PeopleCtrl">
<ion-nav-view name="tab-users"></ion-nav-view>
</ion-tab>

Expand Down

0 comments on commit 9391fd2

Please sign in to comment.