<commit_before>"use strict"

angular.module( "app.controllers.HomeCtrl", []).controller "HomeCtrl", [
	"$scope"
	"audio"

	( $scope, audio ) ->
		$scope.list = []
		$scope.localPath = "D:/vk-music"

		$scope.getList = ( callback = -> ) ->
			audio.getList $scope.localPath, ( list ) ->
				$scope.list = list
				$scope.$apply()
				callback list
		$scope.getCount = audio.getCount
		$scope.isOfType = audio.isOfType

		_ = require "lodash"

		throttledApply = _.throttle ->
			$scope.$apply()
		, 50

		$scope.upload = ( item, callback = -> ) ->
			audio.upload item, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()
			, throttledApply
		$scope.download = ( item, callback = -> ) ->
			audio.download item, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()
			, throttledApply

		$scope.removeLocal = ( item, callback = -> ) ->
			audio.removeLocal item, $scope.localPath, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()
		$scope.removeLocal = ( item, callback = -> ) ->
			audio.removeRemote item, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()

		$scope.isSyncing = no
		$scope.syncDown = ( callback = -> ) ->
			unless $scope.isSyncing
				$scope.isSyncing = yes

				downloadRecursive = ->
					next = audio.getFirst "remoteOnly"
					if next?
						$scope.download next, downloadRecursive
					else
						$scope.isSyncing = no
						callback()

				removeLocalRecursive = ->
					next = audio.getFirst "localShouldRemove"
					if next?
						$scope.removeLocal next, removeLocalRecursive
					else
						downloadRecursive()

				removeLocalRecursive()
			else
				callback()
		$scope.syncUp = ( callback = -> ) ->
			unless $scope.isSyncing
				$scope.isSyncing = yes

				uploadRecursive = ->
					next = audio.getFirst "localOnly"
					if next?
						$scope.upload next, uploadRecursive
					else
						$scope.isSyncing = no
						callback()

				removeRemoteRecursive = ->
					next = audio.getFirst "remoteShouldRemove"
					if next?
						$scope.removeRemote next, removeRemoteRecursive
					else
						uploadRecursive()

				removeRemoteRecursive()
			else
				callback()

		$scope.sync = ( callback = -> ) ->
			unless $scope.isSyncing
				$scope.getList ->
					$scope.syncDown ->
						$scope.syncUp ->
							callback()

		$scope.getList ->
			$( "body" ).scrollspy target: "#menu"
			window.scroll 0, $( "#remote" ).offset().top

<commit_msg>feat(home): update UI at the end of any action by calling `$scope.$apply()`<commit_after>"use strict"

angular.module( "app.controllers.HomeCtrl", []).controller "HomeCtrl", [
	"$scope"
	"audio"

	( $scope, audio ) ->
		$scope.list = []
		$scope.localPath = "D:/vk-music"

		$scope.getList = ( callback = -> ) ->
			audio.getList $scope.localPath, ( list ) ->
				$scope.list = list
				$scope.$apply()
				callback list
		$scope.getCount = audio.getCount
		$scope.isOfType = audio.isOfType

		_ = require "lodash"

		throttledApply = _.throttle ->
			$scope.$apply()
		, 50

		$scope.upload = ( item, callback = -> ) ->
			audio.upload item, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()
			, throttledApply
		$scope.download = ( item, callback = -> ) ->
			audio.download item, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()
			, throttledApply

		$scope.removeLocal = ( item, callback = -> ) ->
			audio.removeLocal item, $scope.localPath, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()
		$scope.removeLocal = ( item, callback = -> ) ->
			audio.removeRemote item, $scope.localPath, ->
				$scope.$apply()
				$( "body" ).scrollspy "refresh"
				callback()

		$scope.isSyncing = no
		$scope.syncDown = ( callback = -> ) ->
			unless $scope.isSyncing
				$scope.isSyncing = yes
				$scope.$apply()

				downloadRecursive = ->
					next = audio.getFirst "remoteOnly"
					if next?
						$scope.download next, downloadRecursive
					else
						$scope.isSyncing = no
						$scope.$apply()
						callback()

				removeLocalRecursive = ->
					next = audio.getFirst "localShouldRemove"
					if next?
						$scope.removeLocal next, removeLocalRecursive
					else
						downloadRecursive()

				removeLocalRecursive()
			else
				callback()
		$scope.syncUp = ( callback = -> ) ->
			unless $scope.isSyncing
				$scope.isSyncing = yes
				$scope.$apply()

				uploadRecursive = ->
					next = audio.getFirst "localOnly"
					if next?
						$scope.upload next, uploadRecursive
					else
						$scope.isSyncing = no
						$scope.$apply()
						callback()

				removeRemoteRecursive = ->
					next = audio.getFirst "remoteShouldRemove"
					if next?
						$scope.removeRemote next, removeRemoteRecursive
					else
						uploadRecursive()

				removeRemoteRecursive()
			else
				callback()

		$scope.sync = ( callback = -> ) ->
			unless $scope.isSyncing
				$scope.getList ->
					$scope.syncDown ->
						$scope.syncUp ->
							callback()

		$scope.getList ->
			$( "body" ).scrollspy target: "#menu"
			window.scroll 0, $( "#remote" ).offset().top


{'fraction_non_alphanumeric': 0.15113156885308784, 'fraction_numerical': 0.0011507479861910242, 'mean_word_length': 2.6040082930200414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1871416', 'n_tokens_mistral': 2243, 'n_tokens_neox': 1694, 'n_words': 345}