public void SelectsFirstItemWhenSetToNonEmptyCollection() { var obs = Observable.Return(new BitmapImage()); var suggestions = new List <AutoCompleteSuggestion> { new AutoCompleteSuggestion("aaaa", obs, ":", ":"), new AutoCompleteSuggestion("bbbb", obs, ":", ":"), new AutoCompleteSuggestion("ccc", obs, ":", ":") }; var result = new AutoCompleteResult(1, new ReadOnlyCollection <AutoCompleteSuggestion>(suggestions)); var advisor = Substitute.For <IAutoCompleteAdvisor>(); advisor.GetAutoCompletionSuggestions(Arg.Any <string>(), Arg.Any <int>()) .Returns(Observable.Return(result)); var textBox = new TextBox(); var autoCompleteBox = new AutoCompleteBox(Substitute.For <IDpiManager>()) { SelectionAdapter = new SelectorSelectionAdapter(new ListBox()), Advisor = advisor, TextBox = new TextBoxAutoCompleteTextInput { TextBox = textBox } }; textBox.Text = ":"; Assert.That(((AutoCompleteSuggestion)autoCompleteBox.SelectedItem).Name, Is.EqualTo("aaaa")); Assert.That(autoCompleteBox.Text, Is.EqualTo(":")); }
private async void OnPlacesRetrieved(object sender, AutoCompleteResult result) { if (!(result.Status == "OK")) { return; } ObservableCollection <LocationModel> addresses = new ObservableCollection <LocationModel>(); //List<string> addresses = new List<string>(); List <AutoCompletePrediction> selectedPrediction = result.AutoCompletePlaces; foreach (AutoCompletePrediction autoCompletePlace in result.AutoCompletePlaces) { Place place = await Places.GetPlace(autoCompletePlace.Place_ID, Constants.googlePlaceApiKey); addresses.Add(new LocationModel { Address = autoCompletePlace.Description, Latitude = place.Latitude.ToString(), Longitude = place.Longitude.ToString() }); } if (addresses.Count == 0) { return; } lvAddresses.ItemsSource = addresses; }
public void IsTrueWhenTextBoxChangesWithPrefixedValue() { var obs = Observable.Return(new BitmapImage()); var suggestions = new List <AutoCompleteSuggestion> { new AutoCompleteSuggestion("aaaa", obs, ":", ":"), new AutoCompleteSuggestion("bbbb", obs, ":", ":"), new AutoCompleteSuggestion("ccc", obs, ":", ":") }; var result = new AutoCompleteResult(0, new ReadOnlyCollection <AutoCompleteSuggestion>(suggestions)); var advisor = Substitute.For <IAutoCompleteAdvisor>(); advisor.GetAutoCompletionSuggestions(Arg.Any <string>(), Arg.Any <int>()) .Returns(Observable.Return(result)); var textBox = new TextBox(); var autoCompleteBox = new AutoCompleteBox(Substitute.For <IDpiManager>()) { SelectionAdapter = new SelectorSelectionAdapter(new ListBox()), Advisor = advisor, TextBox = new TextBoxAutoCompleteTextInput { TextBox = textBox } }; textBox.Text = ":"; Assert.True(autoCompleteBox.IsDropDownOpen); }
public JsonResult Haviors(string query) { var clientResult = new AutoCompleteResult() { query = query, suggestions = new List <Suggestion>() { } }; if (!string.IsNullOrEmpty(query)) { services.Command((db) => { var list = db.Queryable <Havior>().Where(u => u.Name.Contains(query)).ToList(); foreach (var item in list) { clientResult.suggestions.Add(new Suggestion() { value = item.Name, data = item.HaviorID }); } }); } return(Json(clientResult, JsonRequestBehavior.AllowGet)); }
public JsonResult People(string searchText) { List <AutoCompleteResult> results = new List <AutoCompleteResult>(); string accessToken = GetGraphAccessToken(); if (string.IsNullOrEmpty(accessToken)) { // throw a 401 exception here } else { string tenant = _configuration.GetValue <string>("OpenIdConnect:Authority").Replace("https://login.microsoftonline.com/", "").Replace("/", ""); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage graphResult = _client.GetAsync(string.Format("https://graph.windows.net/{0}/users?api-version=1.6&$filter=startswith(surname,'{1}')", tenant, searchText)).Result; dynamic graphData = JsonConvert.DeserializeObject(graphResult.Content.ReadAsStringAsync().Result); if (graphData != null) { foreach (dynamic user in graphData.value) { AutoCompleteResult result = new AutoCompleteResult(); result.label = user.displayName; result.value = user.userPrincipalName; results.Add(result); } } } return(Json(results)); }
private void OnPlacesRetrieved(object sender, AutoCompleteResult result) { if (flag) { var searchBar = (PlacesBar)sender; if (!(result.Status == "OK")) { return; } IList <string> description = new List <string>(); selectedPrediction = result.AutoCompletePlaces; foreach (AutoCompletePrediction autoCompletePlace in result.AutoCompletePlaces) { //SfAutoCompleteItem autoCompleteItem = new SfAutoCompleteItem(autoCompletePlace.Description, "location.png"); description.Add(autoCompletePlace.Description); } if (description.Count == 0) { return; } listView.IsVisible = true; listView.TranslationY = gridSearchBar.Height; listView.TranslationX = gridSearchBar.X; listView.ItemsSource = description; } else { flag = true; } }
private void DisplayMatches(AutoCompleteResult result) { Results.Items.Clear(); foreach (var match in result.Matches) { Results.Items.Add(match); } }
private void LocationBar_PlacesRetrieved(object sender, AutoCompleteResult result) { Results_list.ItemsSource = result.AutoCompletePlaces; if (result.AutoCompletePlaces != null && result.AutoCompletePlaces.Count > 0) { Results_list.IsVisible = true; } }
void Search_Bar_PlacesRetrieved(object sender, AutoCompleteResult result) { results_list.ItemsSource = result.AutoCompletePlaces; spinner.IsRunning = false; spinner.IsVisible = false; if (result.AutoCompletePlaces != null && result.AutoCompletePlaces.Count > 0) { results_list.IsVisible = true; } }
public static void AutoCompleteAsync(List <string> options, string text, Action <AutoCompleteResult> onComplete) { var optionsCopy = new List <string>(options); var result = new AutoCompleteResult(); result.InputText = text; result.OutputText = text; Async.DoWork(() => Thread_AutoComplete(optionsCopy, result), () => onComplete(result)); }
private void SearchBar_PlacesRetrieved(object sender, AutoCompleteResult result) { ResultsList.ItemsSource = result.AutoCompletePlaces; if (result.AutoCompletePlaces != null && result.AutoCompletePlaces.Count > 0) { ResultsList.IsVisible = true; } else { ResultsList.IsVisible = false; } }
public void SearchBarPlacesRetrieved(AutoCompleteResult result, string FromOrTo) { if (FromOrTo == "from") { FromAutoCompletePredictions = result.AutoCompletePlaces; IsFromVisible = true; } else { ToAutoCompletePredictions = result.AutoCompletePlaces; IsToVisible = true; } }
public void HandlesKeyPressesToSelectAndCancelSelections() { var obs = Observable.Return(new BitmapImage()); var suggestions = new List <AutoCompleteSuggestion> { new AutoCompleteSuggestion("aaaa", obs, ":", ":"), new AutoCompleteSuggestion("bbbb", obs, ":", ":"), new AutoCompleteSuggestion("ccc", obs, ":", ":") }; var result = new AutoCompleteResult(2, new ReadOnlyCollection <AutoCompleteSuggestion>(suggestions)); var advisor = Substitute.For <IAutoCompleteAdvisor>(); advisor.GetAutoCompletionSuggestions(Arg.Any <string>(), Arg.Any <int>()) .Returns(Observable.Return(result)); var selectionAdapter = new TestSelectorSelectionAdapter(); var textBox = new TextBox(); var autoCompleteBox = new AutoCompleteBox(Substitute.For <IDpiManager>()) { SelectionAdapter = selectionAdapter, Advisor = advisor, TextBox = new TextBoxAutoCompleteTextInput { TextBox = textBox } }; textBox.Text = "A :a"; textBox.CaretIndex = 4; Assert.AreEqual(4, textBox.CaretIndex); Assert.AreEqual(4, autoCompleteBox.TextBox.CaretIndex); Assert.True(autoCompleteBox.IsDropDownOpen); selectionAdapter.SelectorControl.SelectedIndex = 1; // Select the second item selectionAdapter.DoKeyDown(Key.Enter); Assert.AreEqual("A :bbbb: ", textBox.Text); Assert.False(autoCompleteBox.IsDropDownOpen); textBox.Text = "A :bbbb: :"; textBox.CaretIndex = 10; // Ensure we can re-open the dropdown Assert.True(autoCompleteBox.IsDropDownOpen); selectionAdapter.DoKeyDown(Key.Escape); Assert.False(autoCompleteBox.IsDropDownOpen); Assert.AreEqual("A :bbbb: :", textBox.Text); }
public AutoCompleteResult BuscarMotivoLaudoAutoComplete(string query) { try { int takeCount = 10; IEnumerable <MotivoLaudo> search = _uow.MotivoLaudoRepository.SearchByDescrption(query, takeCount); var suggestions = search.Select(x => new AutoCompleteSuggestionModel(value: x.Descricao, data: x.IdMotivoLaudo)); var response = new AutoCompleteResponseModel(suggestions); return(AutoCompleteResult.FromModel(response)); } catch (Exception e) { throw; } }
private void PlacesSearchBar_PlacesRetrieved(object sender, AutoCompleteResult result) { if (BindingContext is SearchPageViewModel viewModel) { if (viewModel.SearchBarModel.StartBarIsFocused) { viewModel.SearchBarModel.StartLocations = result.AutoCompletePlaces; viewModel.SearchBarModel.StartLocationLoading = false; } else if (viewModel.SearchBarModel.EndBarIsFocused) { viewModel.SearchBarModel.EndLocations = result.AutoCompletePlaces; viewModel.SearchBarModel.EndLocationLoading = false; } } }
private void PlacesSearchBar_PlacesRetrieved(object sender, AutoCompleteResult result) { if (BindingContext is NewEventPageViewModel viewModel) { if (viewModel.SearchBarListView.StartBarIsFocused) { viewModel.SearchBarListView.StartLocations = result.AutoCompletePlaces; } else if (viewModel.SearchBarListView.EndBarIsFocused) { viewModel.SearchBarListView.EndLocations = result.AutoCompletePlaces; } else if (viewModel.SearchBarListView.IntermediateBarIsFocused) { viewModel.SearchBarListView.IntermediateLocations = result.AutoCompletePlaces; } } }
public IEnumerable <AutoCompleteResult> Search(string term) { AutoCompleteResult alias = null; return (_session.QueryOver <Tag>() .Where(x => x.Name.IsInsensitiveLike(term, MatchMode.Start)) .OrderBy(tag => tag.Name).Asc .SelectList(builder => { builder.Select(tag => tag.Id).WithAlias(() => alias.id); builder.Select(tag => tag.Name).WithAlias(() => alias.label); builder.Select(tag => tag.Name).WithAlias(() => alias.value); return builder; }) .TransformUsing(Transformers.AliasToBean <AutoCompleteResult>()) .List <AutoCompleteResult>()); }
public MainWindow() { InitializeComponent(); Observable.FromEventPattern <TextChangedEventArgs>(Input, "TextChanged") .Select(@event => ((TextBox)@event.Sender).Text) .Throttle(0.5.Seconds()).ObserveOnDispatcher() .Do(_ => ClearMatches()) .Where(term => term?.Length > 2) .Do(_ => SetWaiting()) .Select(term => Observable.FromAsync(() => _autoCompleteService.Query(term)) .Timeout(2.Seconds(), Observable.Return(AutoCompleteResult.ErrorResult(term, "timed out"))) .Retry(3) .Catch(Observable.Return(AutoCompleteResult.ErrorResult(term))) .ObserveOnDispatcher() ) .Switch() .Subscribe(DisplayMatches); }
private void OnPlacesRetrieved(object sender, AutoCompleteResult result) { if (!(result.Status == "OK")) { return; } description = new List <string>(); selectedPrediction = result.AutoCompletePlaces; foreach (AutoCompletePrediction autoCompletePlace in result.AutoCompletePlaces) { //SfAutoCompleteItem autoCompleteItem = new SfAutoCompleteItem(autoCompletePlace.Description, "location.png"); description.Add(autoCompletePlace.Description); } if (description.Count == 0) { return; } listView.ItemsSource = description; }
static void Thread_AutoComplete(List <string> options, AutoCompleteResult result) { try { if (AutoCompleteCommand(options, result.InputText, out result.OutputText)) { return; } if (AutoCompleteFileSystem(result.InputText, out result.OutputText)) { return; } } catch { // not a huge deal if auto-complete doesn't work } }
private List <string> FetchAutoCompleteResults(string text, bool include_extras) { System.Threading.Thread.Sleep(100); List <string> retval = new List <string>(); HttpResponseMessage response; string responseContent = string.Empty; response = client.GetAsync("cards/autocomplete?q=" + text + "&include_extras=" + include_extras).Result; response.EnsureSuccessStatusCode(); responseContent = response.Content.ReadAsStringAsync().Result; AutoCompleteResult result = Newtonsoft.Json.JsonConvert.DeserializeObject <AutoCompleteResult>(responseContent); foreach (string card in result.data) { retval.Add(card); } return(retval); }
public void IsFalseAfterASuggestionIsSelected() { var obs = Observable.Return(new BitmapImage()); var suggestions = new List <AutoCompleteSuggestion> { new AutoCompleteSuggestion("aaaa", obs, ":", ":"), new AutoCompleteSuggestion("bbbb", obs, ":", ":"), new AutoCompleteSuggestion("ccc", obs, ":", ":") }; var result = new AutoCompleteResult(2, new ReadOnlyCollection <AutoCompleteSuggestion>(suggestions)); var advisor = Substitute.For <IAutoCompleteAdvisor>(); advisor.GetAutoCompletionSuggestions(Arg.Any <string>(), Arg.Any <int>()) .Returns(Observable.Return(result)); var selectionAdapter = new TestSelectorSelectionAdapter(); var textBox = new TextBox(); var autoCompleteBox = new AutoCompleteBox(Substitute.For <IDpiManager>()) { SelectionAdapter = selectionAdapter, Advisor = advisor, TextBox = new TextBoxAutoCompleteTextInput { TextBox = textBox } }; textBox.Text = "A :a"; textBox.CaretIndex = 4; Assert.AreEqual(4, textBox.CaretIndex); Assert.AreEqual(4, autoCompleteBox.TextBox.CaretIndex); Assert.True(autoCompleteBox.IsDropDownOpen); selectionAdapter.DoCommit(); Assert.That(textBox.Text, Is.EqualTo("A :aaaa: ")); Assert.False(autoCompleteBox.IsDropDownOpen); }
private List <AutoCompleteResult> ExtractAutocompleteSuggestions(ISearchResponse <T> response) { List <AutoCompleteResult> results = new List <AutoCompleteResult>(); var suggestions = response.Suggest["recipe-name-completion"].Select(s => s.Options); foreach (var suggestionsCollection in suggestions) { foreach (var suggestion in suggestionsCollection) { var suggestedRecipe = suggestion.Source; var autocompleteResult = new AutoCompleteResult { Id = suggestedRecipe.ProductId.ToString(), Name = suggestedRecipe.ProductName }; results.Add(autocompleteResult); } } return(results); }
/** * Try to find the best filesystem path or shortcut that matches the input text */ void UpdateAutoComplete(AutoCompleteResult result) { try { var shortcutNames = new List<string>(); // build the list of valid shortcuts foreach (var shortcutName in ShortcutExecutor.GetAllShortcutNames(InstanceParams())) { if (shortcutName.StartsWith(result.InputText, StringComparison.OrdinalIgnoreCase)) { shortcutNames.Add(shortcutName); } } // check history first for a match (but only if it stll exists as a valid shortcut) if (JRunUI.Properties.Settings.Default.History != null) { foreach (var historyName in JRunUI.Properties.Settings.Default.History) { if (historyName.StartsWith(result.InputText, StringComparison.OrdinalIgnoreCase)) { foreach (var shortcutName in shortcutNames) { if (StringComparer.OrdinalIgnoreCase.Equals(shortcutName, historyName)) { result.OutputText = historyName; return; } } } } } // if not found in history, pick the first available one if (shortcutNames.Count > 0) { result.OutputText = shortcutNames[0]; } // if no shortcut found, try completing directories and files else { var drives = System.IO.DriveInfo.GetDrives(); foreach (var drive in drives) { if (AutoCompletDirectory(drive.RootDirectory, result)) { break; } } } } catch { // not a huge deal if auto-complete doesn't work } }
void FromSearchPlacesRetrieved(object sender, AutoCompleteResult result) { (BindingContext as AddRideViewModel).SearchBarPlacesRetrieved(result, "from"); }
/** * Search down the filesystem to see if the user is inputting a filesystem path */ bool AutoCompletDirectory(System.IO.DirectoryInfo dir, AutoCompleteResult result) { if (dir.FullName.StartsWith(result.InputText, StringComparison.OrdinalIgnoreCase)) { result.OutputText = dir.FullName.TrimEnd('\\') + '\\'; } if (result.InputText.StartsWith(dir.FullName, StringComparison.OrdinalIgnoreCase)) { foreach (var subFile in dir.GetFiles()) { if (subFile.FullName.StartsWith(result.InputText, StringComparison.OrdinalIgnoreCase)) { result.OutputText = subFile.FullName; return true; } } foreach (var subDir in dir.GetDirectories()) { if (AutoCompletDirectory(subDir, result)) { return true; } } } return false; }
/** * Handle the results of an autocomplete query. * Will update the textbox's text value */ void HandleAutoCompleteResult(TextBox textbox, AutoCompleteResult result) { if (!String.IsNullOrEmpty(result.OutputText)) { var currentText = GetUnHighlightedText(textbox); // don't update the textbox if it's changed since autocomplete started if (currentText.Equals(result.InputText)) { textbox.Text = result.OutputText; // select/highlight the autocompleted part so the user can easily skip or delete it textbox.Select(result.InputText.Length, result.OutputText.Length - result.InputText.Length); } } }
void ToSearchPlacesRetrieved(object sender, AutoCompleteResult result) { (BindingContext as FindRideViewModel).SearchBarPlacesRetrieved(result, "to"); }
/** * Look thru the shortcuts xml file for shortcuts that partially match the current textbox text */ void UpdateAutoComplete(TextBox textbox) { var text = textbox.Text; if (!String.IsNullOrEmpty(text)) { var result = new AutoCompleteResult(); result.InputText = text; var worker = new System.ComponentModel.BackgroundWorker(); worker.DoWork += (s, args) => UpdateAutoComplete(result); worker.RunWorkerCompleted += (s, args) => HandleAutoCompleteResult(textbox, result); worker.RunWorkerAsync(); } }