<commit_before>angular.module('spotmop.search', [])

/**
 * Routing 
 **/
.config(function($stateProvider) {
	$stateProvider
		.state('search', {
			url: "/search/:query/:type",
			templateUrl: "app/search/template.html",
			controller: 'SearchController',
			
			// this specifies default values if there are none defined in the URL
			params: {
				type: { squash: true, value: 'all' },
				query: { squash: true, value: null }
			}
		});
})
	
/**
 * Main controller
 **/
.controller('SearchController', function SearchController( $scope, $rootScope, $state, $stateParams, $timeout, SpotifyService ){
	
	$scope.tracklist = {tracks: [], type: 'track'};
	$scope.albums = [];
	$scope.artists = [];
	$scope.playlists = [];
	$scope.type = $stateParams.type;
	$scope.query = $stateParams.query;
	$scope.loading = false;
	var searchDelayer;
	
	$scope.dropdownActive = false;
	$scope.toggleDropdown = function(){
		if( $scope.dropdownActive )
			$scope.dropdownActive = false;
		else
			$scope.dropdownActive = true;
	}
	
	// focus on our search field on load
	if( !$scope.isTouchDevice() )
		$(document).find('.search-form input.query').focus();
	
	// if we've just loaded this page, and we have params, let's perform a search
	if( $scope.query )
		performSearch( $scope.type, $scope.query );
	
	/**
	 * Watch our query string for changes
	 * When changed, clear all results, wait for 0.5 seconds for next key, then fire off the search
	 **/
    var tempQuery = '', queryTimeout;
    $scope.$watch('query', function(newValue, oldValue){
		
		if( newValue != oldValue && newValue && newValue != '' ){
			$scope.loading = true;
			$scope.tracklist = {tracks: [], type: 'track'};
			$scope.albums = [];
			$scope.artists = [];
			$scope.playlists = [];
			
			if (queryTimeout)
				$timeout.cancel(queryTimeout);

			tempQuery = newValue;
			queryTimeout = $timeout(function() {
				$scope.query = tempQuery;
				performSearch( $scope.type, $scope.query );	
			}, 1000);
		}
    })
	
	
	/**
	 * Fetch the search results
	 * This defines the type of search requests we'll perform, and thus the page layout
	 * @param type = string (type of search results, all/artist/playlist/album/etc)
	 * @param query = string
	 **/
	function performSearch( type, query ){
	
		if( typeof(type) === 'undefined' )
			var type = $scope.type;
	
		switch( type ){
			
			case 'track' :
				SpotifyService.getSearchResults( 'track', query, 50 )
					.then( function(response){
						$scope.tracklist = response.tracks;
						$scope.tracklist.tracks = response.tracks.items;
						$scope.tracklist.type = 'track';
						$scope.next = response.tracks.next;
					});
				break;
			
			case 'album' :
				SpotifyService.getSearchResults( 'album', query, 50 )
					.then( function(response){		
						$scope.albums = response.albums;
						$scope.next = response.albums.next;
					});<commit_msg>Disable auto-search as it kills mobile UX<commit_after>angular.module('spotmop.search', [])

/**
 * Routing 
 **/
.config(function($stateProvider) {
	$stateProvider
		.state('search', {
			url: "/search/:query/:type",
			templateUrl: "app/search/template.html",
			controller: 'SearchController',
			
			// this specifies default values if there are none defined in the URL
			params: {
				type: { squash: true, value: 'all' },
				query: { squash: true, value: null }
			}
		});
})
	
/**
 * Main controller
 **/
.controller('SearchController', function SearchController( $scope, $rootScope, $state, $stateParams, $timeout, SpotifyService ){
	
	$scope.tracklist = {tracks: [], type: 'track'};
	$scope.albums = [];
	$scope.artists = [];
	$scope.playlists = [];
	$scope.type = $stateParams.type;
	$scope.query = $stateParams.query;
	$scope.loading = false;
	var searchDelayer;
	
	// focus on our search field on load (if not touch device, otherwise we get annoying on-screen keyboard)
	if( !$scope.isTouchDevice() )
		$(document).find('.search-form input.query').focus();
	
	// if we've just loaded this page, and we have params, let's perform a search
	if( $scope.query )
		performSearch( $scope.type, $scope.query );
	
	/**
	 * Watch our query string for changes
	 * When changed, clear all results, wait for 0.5 seconds for next key, then fire off the search
    var tempQuery = '', queryTimeout;
    $scope.$watch('query', function(newValue, oldValue){
		
		if( newValue != oldValue && newValue && newValue != '' ){
			$scope.loading = true;
			$scope.tracklist = {tracks: [], type: 'track'};
			$scope.albums = [];
			$scope.artists = [];
			$scope.playlists = [];
			
			if (queryTimeout)
				$timeout.cancel(queryTimeout);

			tempQuery = newValue;
			queryTimeout = $timeout(function() {
				$scope.query = tempQuery;
				performSearch( $scope.type, $scope.query );	
			}, 1000);
		}
    })
	 **/
	
	
	/**
	 * Fetch the search results
	 * This defines the type of search requests we'll perform, and thus the page layout
	 * @param type = string (type of search results, all/artist/playlist/album/etc)
	 * @param query = string
	 **/
	function performSearch( type, query ){
	
		if( typeof(type) === 'undefined' )
			var type = $scope.type;
	
		switch( type ){
			
			case 'track' :
				SpotifyService.getSearchResults( 'track', query, 50 )
					.then( function(response){
						$scope.tracklist = response.tracks;
						$scope.tracklist.tracks = response.tracks.items;
						$scope.tracklist.type = 'track';
						$scope.next = response.tracks.next;
					});
				break;
			
			case 'album' :
				SpotifyService.getSearchResults( 'album', query, 50 )
					.then( function(response){		
						$scope.albums = response.albums;
						$scope.next = response.albums.next;
					});
{'fraction_non_alphanumeric': 0.15319148936170213, 'fraction_numerical': 0.0035460992907801418, 'mean_word_length': 3.2734848484848484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1755508', 'n_tokens_mistral': 2108, 'n_tokens_neox': 1749, 'n_words': 459}