// inject firebase service
var app = angular.module("level", ["firebase"]); 

app.controller("levelCtrl",  

	// Implementation the todoCtrl 
	function($scope, $firebaseArray,$window,$timeout) {
        $scope.current = 0;
        $scope.total = 100;
        value = '0%';
		var ref=firebase.database().ref("pi");
    	ref.orderByChild("Name").equalTo("Kit").once("child_added", function(dataRef) {
            $scope.$apply(function() {
            $scope.level = dataRef.child("level").val();
            $scope.current = dataRef.child("current").val();
            $scope.total = dataRef.child("total").val();
            $scope.value = $scope.current/$scope.total*100 + "%";
            knobfunction($scope.value);
           });
        });
        
        $scope.add = function (){
			$scope.current=0;
            $scope.total = 150;
            $scope.level = 6;
            $scope.value = ($scope.current)/$scope.total*100 +"%";
            knobfunction($scope.value);
            //window.alert("Congratulation! Level Up!");
        };

    }
);

function compile(element){
  var el = angular.element(element);    
  $scope = el.scope();
    $injector = el.injector();
    $injector.invoke(function($compile){
       $compile(el)($scope)
    })     
}
@@ -184,24 +184,127 @@
 $timeout) %7B%0A
+        $scope.pi = %7B%0A            current : 0,%0A            total : 0,%0A            level : 50%0A        %7D%0A
         $sco
@@ -889,11 +889,20 @@
 ()%7B%0A
-%09%09%09
+            
 $sco
@@ -911,17 +911,19 @@
 .current
-=
+ = 
 0;%0A     
@@ -979,16 +979,110 @@
 el = 6;%0A
+%09%09%09$scope.pi.current = 0;%0A            $scope.pi.total = 150;%0A            $scope.pi.level = 6;%0A
         
@@ -1172,32 +1172,178 @@
 ($scope.value);%0A
+            var path = %22pi/-KXZT3IRQsjkIkOel4J5%22;%0A            var itemRef = firebase.database().ref(path);%0A            itemRef.update($scope.pi);%0A
             //wi

update level