/**
 * Created by Samuel on 2/11/2016.
 */

var dasApp = angular.module("dashboard", ['firebase']);
dasApp.controller("dashboardController", function ($scope, $firebaseArray, $firebaseObject, $firebaseAuth) {
    $scope.username = "Samuel He";
    var skillsRef = firebase.database().ref().child("skills");
    $scope.skills = $firebaseArray(skillsRef);
    $scope.receiveNewSikll = function () {
        $scope.skills.$add($scope.newSkill);
        $scope.newSkill = '';
    };



    $scope.firebaseObj = {
        "users": [{
            "name": "samuel",
            "id": 232794508173451340,
            "skills": ["Angular", "design", "Nodejs"],
            "teamsAsMember": [4455],
            "teamsAsLeader": [3344],
            "teamsApplying": [8899, 9977],
            "eventsManaging": [666777],
            "profilePic": "https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/11811378_670467616420822_8367557776291472237_n.jpg?oh=daf68581e51d412ce96010adf7d77648&oe=588A7872",
            "notifs": [{
                "sender": "xinyu",
                "receiver": "samuel",
                "type": "invitation",
                "read": false,
                "content": "You were invited to join XXX team"
            }]
        }],
        "events": [{
            "eventID": 666777,
            "adminID": 111194508173451340,
            "allTeams": [3344, 6688],
            "eventName": "3111h",
            "description": "a course",
            "maxSize": 8,
            "minSize": 5
        }],
        "teams": [{
            "teamID": 3344,
            "leaderID": 232794508173451340,
            "membersID": [445664508173451340, 232794508173451340],
            "teamName": "Undefined",
            "belongstoEvent": 666777,
            "preferedSize": 8,
            "pendingApplicants": [1433664508173451340],
            "invitedPeople": [555564508173451340],
            "desiredSkills": ["Angular", "Vue"]
        }]
    };

    var dummyDataRef = firebase.database().ref().child("dummyData");
    dummyDataRef.set($scope.firebaseObj);
    var syncObject = $firebaseObject(dummyDataRef);
    syncObject.$bindTo($scope, "firebaseObj");

    var auth = $firebaseAuth();
    auth.$signInWithPopup("facebook").then(function(firebaseUser) {
        console.log("Signed in as:", firebaseUser.uid);
    }).catch(function(error) {
        console.log("Authentication failed:", error);
    });

});
dasApp.directive("skillitem", function () {
    return {
        restrict: "E",
        templateUrl: "components/skillitem.html",
        scope: {
            name: "@"
        },
        replace: false
    }
});





@@ -2406,90 +2406,202 @@
 );%0A%0A
-%7D);%0AdasApp.directive(%22skillitem%22, function () %7B%0A    return %7B%0A        restrict: %22E%22
+%0A%0A    var newUser = %7B%0A        %22name%22: %22Ace%22,%0A        %22id%22: 232794508173451340,%0A        %22skills%22: %5B%22Angular%22, %22design%22, %22Nodejs%22%5D,%0A        %22teamsAsMember%22: %5B4455%5D,%0A        %22teamsAsLeader%22: %5B3344%5D
 ,%0A  
@@ -2610,46 +2610,327 @@
     
+%22
 te
-mplateUrl: %22components/skillitem.htm
+amsApplying%22: %5B8899, 9977%5D,%0A        %22eventsManaging%22: %5B666777%5D,%0A        %22profilePic%22: %22https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/11811378_670467616420822_8367557776291472237_n.jpg?oh=daf68581e51d412ce96010adf7d77648&oe=588A7872%22,%0A        %22notifs%22: %5B%7B%0A            %22sender%22: %22xinyu%22,%0A            %22receiver%22: %22samue
 l%22,%0A
@@ -2941,37 +2941,118 @@
     
-sco
+    %22ty
 pe
+%22
 : 
-%7B%0A            name: %22@
+%22invitation%22,%0A            %22read%22: false,%0A            %22content%22: %22You were invited to join XXX team
 %22%0A  
@@ -3062,38 +3062,166 @@
    %7D
-,
+%5D
 %0A    
+%7D;%0A
     
-replace: false%0A    %7D
+var usersRef = firebase.database().ref().child(%22dummyData/users%22);%0A    $scope.users = $firebaseArray(usersRef);%0A    $scope.users.$add(newUser);%0A%0A
 %0A%7D);

Add firebase config