<commit_before>/**
 * ownCloud - Music app
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2018 - 2020
 */


angular.module('Music').controller('AllTracksViewController', [
	'$rootScope', '$scope', 'playlistService', 'libraryService', 'alphabetIndexingService', '$timeout',
	function ($rootScope, $scope, playlistService, libraryService, alphabetIndexingService, $timeout) {

		$rootScope.currentView = window.location.hash;

		var _tracks = null;
		var _indexChars = alphabetIndexingService.indexChars();

		// Tracks are split into "buckets" to facilitate lazy loading. One track-list directive
		// is created for each bucket. All tracks in a single bucket have the same indexing char
		// but a single indexing char may have several buckets.
		var BUCKET_MAX_SIZE = 100;
		$scope.trackBuckets = null;

		// $rootScope listeneres must be unsubscribed manually when the control is destroyed
		var _unsubFuncs = [];

		function subscribe(event, handler) {
			_unsubFuncs.push( $rootScope.$on(event, handler) );
		}

		$scope.$on('$destroy', function () {
			_.each(_unsubFuncs, function(func) { func(); });
		});

		function play(startIndex /*optional*/) {
			playlistService.setPlaylist('alltracks', _tracks, startIndex);
			playlistService.publish('play');
		}

		// Call playlistService to play all songs in the current playlist from the beginning
		$scope.onHeaderClick = function() {
			play();
		};

		// Play the list, starting from a specific track
		$scope.onTrackClick = function(trackId) {
			// play/pause if currently playing list item clicked
			if ($scope.$parent.currentTrack && $scope.$parent.currentTrack.id === trackId) {
				playlistService.publish('togglePlayback');
			}
			// on any other list item, start playing the list from this item
			else {
				var index = _.findIndex(_tracks, function(i) {return i.track.id == trackId;});
				play(index);
			}
		};

		/**
		 * Gets track data to be dislayed in the tracklist directive
		 */
		$scope.getTrackData = function(listItem, index, scope) {
			var track = listItem.track;
			return {
				title: track.artistName + ' - ' + track.title,
				tooltip: '',
				number: scope.$parent.bucket.baseIndex + index + 1,
				id: track.id
			};
		};

		/**
		 * Two functions for the alphabet-navigation directive integration
		 */
		$scope.getBucketName = function(index) {
			return $scope.trackBuckets[index].name;
		};
		$scope.getBucketElementId = function(index) {
			return 'track-bucket-' + index;
		};

		$scope.getDraggable = function(trackId) {
			return { track: trackId };
		};

		function findTrackFromBucket(bucket, trackId) {
			return _(bucket.tracks).find(function(item) {
				return item.track.id == trackId;
			});
		}

		function bucketElementForTrack(trackId) {
			var track = libraryService.getTrack(trackId);<commit_msg>Remove one unused js function<commit_after>/**
 * ownCloud - Music app
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2018 - 2020
 */


angular.module('Music').controller('AllTracksViewController', [
	'$rootScope', '$scope', 'playlistService', 'libraryService', 'alphabetIndexingService', '$timeout',
	function ($rootScope, $scope, playlistService, libraryService, alphabetIndexingService, $timeout) {

		$rootScope.currentView = window.location.hash;

		var _tracks = null;
		var _indexChars = alphabetIndexingService.indexChars();

		// Tracks are split into "buckets" to facilitate lazy loading. One track-list directive
		// is created for each bucket. All tracks in a single bucket have the same indexing char
		// but a single indexing char may have several buckets.
		var BUCKET_MAX_SIZE = 100;
		$scope.trackBuckets = null;

		// $rootScope listeneres must be unsubscribed manually when the control is destroyed
		var _unsubFuncs = [];

		function subscribe(event, handler) {
			_unsubFuncs.push( $rootScope.$on(event, handler) );
		}

		$scope.$on('$destroy', function () {
			_.each(_unsubFuncs, function(func) { func(); });
		});

		function play(startIndex /*optional*/) {
			playlistService.setPlaylist('alltracks', _tracks, startIndex);
			playlistService.publish('play');
		}

		// Call playlistService to play all songs in the current playlist from the beginning
		$scope.onHeaderClick = function() {
			play();
		};

		// Play the list, starting from a specific track
		$scope.onTrackClick = function(trackId) {
			// play/pause if currently playing list item clicked
			if ($scope.$parent.currentTrack && $scope.$parent.currentTrack.id === trackId) {
				playlistService.publish('togglePlayback');
			}
			// on any other list item, start playing the list from this item
			else {
				var index = _.findIndex(_tracks, function(i) {return i.track.id == trackId;});
				play(index);
			}
		};

		/**
		 * Gets track data to be dislayed in the tracklist directive
		 */
		$scope.getTrackData = function(listItem, index, scope) {
			var track = listItem.track;
			return {
				title: track.artistName + ' - ' + track.title,
				tooltip: '',
				number: scope.$parent.bucket.baseIndex + index + 1,
				id: track.id
			};
		};

		/**
		 * Two functions for the alphabet-navigation directive integration
		 */
		$scope.getBucketName = function(index) {
			return $scope.trackBuckets[index].name;
		};
		$scope.getBucketElementId = function(index) {
			return 'track-bucket-' + index;
		};

		$scope.getDraggable = function(trackId) {
			return { track: trackId };
		};

		function bucketElementForTrack(trackId) {
			var track = libraryService.getTrack(trackId);
{'fraction_non_alphanumeric': 0.12513125656282814, 'fraction_numerical': 0.004550227511375569, 'mean_word_length': 3.7664720600500416, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6262256', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1671, 'n_words': 485}