Skip to content

Commit

Permalink
Added chat screen
Browse files Browse the repository at this point in the history
  • Loading branch information
saoron committed Aug 1, 2016
1 parent d2cae09 commit 56a019f
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 96 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var functions = require('firebase-functions');
// var functions = require('firebase-functions');

// // converts the "text" key of messages pushed to /messages to uppercase
// exports.upperCaser = functions.database().path('/messages/{id}').on('value', function(event) {
// exports.upperCaser = functions.database().path('/messages/{id}/title/').on('value', function(event) {
// // prevent infinite loops
// if (event.data.child('uppercased').val()) { return; }
//

// return event.data.ref.update({
// text: event.data.child('text').val().toUpperCase(),
// uppercased: true
Expand Down
Binary file modified www/.DS_Store
Binary file not shown.
34 changes: 34 additions & 0 deletions www/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,38 @@
left: 31px;
top: 14px;
font-size: 33px;
}
.reset{
float: right;
margin: 24px;
margin-top: 0;
font-size: 40px;
}
.full{
height: 570px;
width: 100%;
background: #f7f7f7;
margin: 0;
padding: 0;
}
.compose{
position: absolute;
bottom: 70px;
width: 100%;
}
.compose label{
float: left;
padding-left: 5px;
}
.compose input{
float: right;
border: 1px solid #333;
width: 56%;
margin-right: 6px;
margin-top: -10px;
border-radius: 4px;
}
.compose button{
float: right;
margin-top: -5px;
}
Binary file added www/img/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/img/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/img/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/img/4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/img/5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed www/img/adam.jpg
Binary file not shown.
Binary file removed www/img/ben.png
Binary file not shown.
Binary file removed www/img/max.png
Binary file not shown.
Binary file removed www/img/mike.png
Binary file not shown.
Binary file removed www/img/perry.png
Binary file not shown.
43 changes: 22 additions & 21 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope, $firebaseArray) {


var messagesRef = firebase.database().ref().child("messages");

// all server changes are applied in realtime
$scope.messages = $firebaseArray(messagesRef);


$scope.addNewMessage =function(){


$scope.messages.push('xxxx')


}
.controller('DashCtrl', function($scope, messageMain) {


messageMain().$bindTo($scope, "msgs")


})

.controller('ChatsCtrl', function($scope, Chats) {
.controller('ChatsCtrl', function($scope, userMessages) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
Expand All @@ -31,10 +17,25 @@ angular.module('starter.controllers', [])
//$scope.$on('$ionicView.enter', function(e) {
//});

$scope.chats = Chats.all();
$scope.remove = function(chat) {
Chats.remove(chat);
};
//$scope.chats = Chats.all();
userMessages().$bindTo($scope, "userMessages")


$scope.sendMsg = function(){


var ref = firebase.database().ref("userMessages");
ref.push({ 'text': $scope.msgBody, 'pic': $scope.randPic() });
$scope.msgBody = '';



}

$scope.randPic = function(){
return parseInt(Math.random() * (5 - 1) + 1);
}

})

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
Expand Down
95 changes: 48 additions & 47 deletions www/js/services.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
angular.module('starter.services', ['firebase'])

.factory('Chats', function() {
// Might use a resource here that returns a JSON array

// Some fake testing data
var chats = [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'img/ben.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'img/max.png'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'img/adam.jpg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'img/perry.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'img/mike.png'
}];

return {
all: function() {
return chats;
},
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
},
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
}
}
return null;



.factory("messageMain", ["$firebaseObject",
function($firebaseObject) {
return function() {
// create a reference to the database node where we will store our data
var ref = firebase.database().ref("msgs");


// return it as a synchronized object
return $firebaseObject(ref);
}
};
})
}
])

.factory("userMessages", ["$firebaseObject",
function($firebaseObject) {
return function() {
// create a reference to the database node where we will store our data
var ref = firebase.database().ref("userMessages");


// return it as a synchronized object
return $firebaseObject(ref);
}
}
])
























Expand Down
Binary file modified www/lib/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions www/lib/caret/caret.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified www/lib/ionic/.DS_Store
Binary file not shown.
Binary file modified www/templates/.DS_Store
Binary file not shown.
21 changes: 13 additions & 8 deletions www/templates/tab-chats.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<ion-view view-title="Chats">
<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/chats/{{chat.id}}">
<img ng-src="{{chat.face}}">
<h2>{{chat.name}}</h2>
<p>{{chat.lastText}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in userMessages" type="item-text-wrap" href="#/tab/chats/{{chat.id}}">
<img ng-src="img/{{chat.pic}}.gif">
<p>{{chat.text}}</p>

<ion-option-button class="button-assertive" ng-click="remove(chat)">
Delete
</ion-option-button>
</ion-item>
</ion-list>


</ion-content>

<div class="compose">
<button ng-click="sendMsg()">Send</button>
<input type="text" ng-model="msgBody" />
<label class="pull-right">Whatcha Say?</label>
</div>


</ion-view>
13 changes: 2 additions & 11 deletions www/templates/tab-dash.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<ion-view>
<ion-content class="padding">
<ion-content scroll="false">

<textarea class="full" id="msgsMain" ng-model="msgs.mainMessage" ng-model-options="{ updateOn: 'default blur', debounce: {'default': 500, 'blur': 0} }" ></textarea>

<ion-list>
<ion-item ng-repeat="msg in messages">
{{msg}}!
</ion-item>
</ion-list>




<button class="btn- btn-info" ng-click="addNewMessage()">+</button>

</ion-content>
</ion-view>
2 changes: 1 addition & 1 deletion www/templates/tab-tic.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1 class="text-center" ng-show="name"> Hey {{name}}</h1>
</div>


<button ng-click="resetBoard()">Reset</button>
<button ng-click="resetBoard()" class="reset"><span class="ion-ios-refresh"></span></button>

</ion-content>
</ion-view>
13 changes: 8 additions & 5 deletions www/templates/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
-->
<ion-tabs class="tabs-icon-top tabs-color-active-positive">

<!-- Chat Tab -->
<ion-tab title="Chat" icon-off="ion-ios-pulse" icon-on="ion-chatbubble" href="#/tab/dash">
<!-- Canvas Tab -->
<ion-tab title="Chat Canavs" icon-off="ion-chatbubble" icon-on="ion-chatbubble" href="#/tab/dash">
<ion-nav-view name="tab-dash"></ion-nav-view>
</ion-tab>

<!-- Users Tab -->
<ion-tab title="Users" icon-off="ion-person-stalker" icon-on="ion-ios-chatboxes" href="#/tab/chats">
<!-- Chat Tab -->
<ion-tab title="Chat Bubble" icon-off="ion-chatbubbles" icon-on="ion-chatbubbles" href="#/tab/chats">
<ion-nav-view name="tab-chats"></ion-nav-view>
</ion-tab>



<!-- Users Tab -->
<ion-tab title="Users" icon-off="ion-person-stalker" icon-on="ion-ios-chatboxes" href="#/tab/tic">
<ion-tab title="TicTacToe" icon-off="ion-ios-grid-view" icon-on="ion-ios-grid-view" href="#/tab/tic">
<ion-nav-view name="tab-tic"></ion-nav-view>
</ion-tab>




</ion-tabs>

0 comments on commit 56a019f

Please sign in to comment.