                 $trakt
                     .search filename
                     .then (data) ->
-                        $scope.grid.push data[0]
+
+                        # Add filepath to db
+                        movie = data[0]
+                        movie.path = file.path
+
+                        # Save data to DB
+                        $scope.db.insert movie, (e, item) ->
+                            if e then return console.error e
+
+                            # Add data to main grid
+                            $scope.add_movie movie
+
+
                     .catch (e) ->
                         console.error e
 
 
-        # Add event to document
-        document.addEventListener "dragover", (e) -> e.preventDefault() and e.stopPropagation()
-        document.addEventListener "dragleave", (e) -> e.preventDefault() and e.stopPropagation()
-        document.addEventListener "drop", (e) ->
-            e.preventDefault()
-            e.stopPropagation()
-            $scope.drop e.dataTransfer.files
+        ###*
+         # Add a movie and getting rid of angular fucking digest cycle
+        ###
+        $scope.add_movie = (movie) ->
+            $timeout () ->
+                $scope.grid.push movie
+
+
+
+        #$scope.check = (filepath) ->
+
+        # Init app
+        $scope.init()

 # # MainCtrl
 # Controller of the gummyApp
###
angular.module 'gummyApp'
    .controller 'MainCtrl', ($scope, $rootScope, $trakt, $rotten) ->


        ###*

         # @attribute grid
        ###
        $scope.grid = []


        ###*
         # Init app
         # @method init
        ###
        $scope.init = () ->


            # Add drop event to document
            document.addEventListener "dragover", (e) -> e.preventDefault() and e.stopPropagation()
            document.addEventListener "dragleave", (e) -> e.preventDefault() and e.stopPropagation()
            document.addEventListener "drop", (e) ->
                e.preventDefault()
                e.stopPropagation()
                $scope.drop e.dataTransfer.files


            # Read DB
            $scope.db.find {}, (e, movies) ->
                if e then console.error e

                # Add existing movies to main grid
                for movie in movies
                    $scope.add_movie movie




        ###*
