/// <summary> /// Builds the prepared searches. /// </summary> /// <param name="forServer">if set to <c>true</c> [for server].</param> public override void BuildPreparedSearches(bool forServer) { this.PreparedSearches = new List <UPSearchPageModelControllerPreparedSearch>(); this.availableSearches = new List <UPSearchPageModelControllerPreparedSearch>(); UPSearchPageModelControllerPreparedSearch prepareSearch = new UPSearchPageModelControllerPreparedSearch(null, this.ConfigName, null); this.PreparedSearches.Add(prepareSearch); this.availableSearches.Add(prepareSearch); for (int i = 2; i < 99; i++) { string configNameKey = $"Config{i}Name"; string configName2 = this.ViewReference.ContextValueForKey(configNameKey); if (!string.IsNullOrEmpty(configName2)) { UPSearchPageModelControllerPreparedSearch vPrepareSearch = new UPSearchPageModelControllerPreparedSearch(null, configName2, null); this.PreparedSearches.Add(vPrepareSearch); this.availableSearches.Add(vPrepareSearch); } else { break; } } }
/// <summary> /// Initializes a new instance of the <see cref="TimelineSearch"/> class. /// </summary> /// <param name="crmQuery">The CRM query.</param> /// <param name="preparedSearch">The prepared search.</param> public TimelineSearch(UPContainerMetaInfo crmQuery, UPSearchPageModelControllerPreparedSearch preparedSearch) { this.CrmQuery = crmQuery; this.PreparedSearch = preparedSearch; this.TimelineInfoArea = this.PreparedSearch.TimelineConfiguration; string configName = !string.IsNullOrEmpty(this.TimelineInfoArea.ConfigName) ? this.TimelineInfoArea.ConfigName : this.TimelineInfoArea.InfoAreaId; SearchAndList searchAndList = ConfigurationUnitStore.DefaultStore.SearchAndListByName(configName); this.FieldGroupName = searchAndList != null ? searchAndList.FieldGroupName : configName; }
/// <summary> /// Results the section for search result. /// </summary> /// <param name="preparedSearch">The prepared search.</param> /// <param name="result">The result.</param> /// <returns></returns> public virtual UPMResultSection ResultSectionForSearchResult(UPSearchPageModelControllerPreparedSearch preparedSearch, UPCRMResult result) { var configStore = ConfigurationUnitStore.DefaultStore; var resultContext = new UPCoreMappingResultContext(result, preparedSearch.CombinedControl, preparedSearch.ListFieldControl.NumberOfFields); this.SectionContexts.SetObjectForKey(resultContext, preparedSearch.InfoAreaId); var resultSection = new UPMResultSection(StringIdentifier.IdentifierWithStringId($"Search_{preparedSearch.InfoAreaId}")); var infoAreaConfig = configStore.InfoAreaConfigById(preparedSearch.InfoAreaId); if (infoAreaConfig != null) { var colorKey = infoAreaConfig.ColorKey; if (!string.IsNullOrEmpty(colorKey)) { resultSection.BarColor = AureaColor.ColorWithString(colorKey); } var imageName = infoAreaConfig.ImageName; if (!string.IsNullOrEmpty(imageName)) { var fileResource = configStore.ResourceByName(imageName); if (fileResource != null) { resultSection.GlobalSearchIconName = fileResource.FileName; } } } resultSection.SectionField = new UPMField(StringIdentifier.IdentifierWithStringId("SectionLabel")); var sectionName = infoAreaConfig?.PluralName; if (string.IsNullOrEmpty(sectionName)) { var tableInfo = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(preparedSearch.InfoAreaId); sectionName = tableInfo != null ? tableInfo.Label : preparedSearch.InfoAreaId; } resultSection.SectionField.FieldValue = sectionName; var count = result.RowCount; for (var j = 0; j < count; j++) { var dataRow = result.ResultRowAtIndex(j) as UPCRMResultRow; var identifier = new RecordIdentifier(preparedSearch.InfoAreaId, dataRow.RecordIdAtIndex(0)); var resultRow = new UPMResultRow(identifier); resultContext.RowDictionary.Add(resultRow.Key, new UPCoreMappingResultRowContext(dataRow, resultContext)); resultContext.ExpandMapper = preparedSearch.ExpandSettings; resultRow.Invalid = true; resultRow.DataValid = true; resultSection.AddResultRow(resultRow); } return(resultSection); }
/// <summary> /// Creates the new search page with result. /// </summary> /// <param name="results">The results.</param> public virtual void CreateNewSearchPageWithResult(List <UPCRMResult> results) { UPMSearchPage newPage = new UPMSearchPage(this.Page.Identifier); newPage.CopyDataFrom(this.SearchPage); newPage.Invalid = false; int searchCount = this.PreparedSearches?.Count ?? 0; for (int i = 0; i < searchCount && i < results.Count; i++) { UPSearchPageModelControllerPreparedSearch preparedSearch = this.PreparedSearches[i]; if (results[i] != null) { UPCRMResult result = results[i]; if (result.RowCount > 0) { UPMResultSection section = this.ResultSectionForSearchResult(preparedSearch, result); if (section != null) { newPage.AddResultSection(section); } } } } // Hardcoded Detail Action UPMAction switchToDetailAction = new UPMAction(null); switchToDetailAction.IconName = "arrow.png"; switchToDetailAction.SetTargetAction(this, this.SwitchToDetail); newPage.RowAction = switchToDetailAction; UPMAction searchAction = new UPMAction(null); searchAction.SetTargetAction(this, this.Search); newPage.SearchAction = searchAction; UPMSearchPage oldSearchPage = this.SearchPage; this.TopLevelElement = newPage; SearchPageResultState state = SearchPageResultState.OfflineNoLokalData; foreach (UPCRMResult result in results) { if (result != null && result.RowCount > 0) { state = SearchPageResultState.Ok; } } newPage.ResultState = state; this.InformAboutDidChangeTopLevelElement(oldSearchPage, newPage, null, null); }
/// <summary> /// Builds the prepared searches. /// </summary> /// <param name="forServer">if set to <c>true</c> [for server].</param> public virtual void BuildPreparedSearches(bool forServer) { this.PreparedSearches = new List <UPSearchPageModelControllerPreparedSearch>(); var configStore = ConfigurationUnitStore.DefaultStore; var quickSearch = configStore.QuickSearchByName("default"); var infoAreaCount = quickSearch?.NumberOfInfoAreas ?? 0; for (var i = 0; i < infoAreaCount; i++) { var currentInfoAreaId = quickSearch.InfoAreaIdAtIndex(i); var vPrepareSearch = new UPSearchPageModelControllerPreparedSearch(currentInfoAreaId, quickSearch.EntriesForInfoAreaId(currentInfoAreaId)); this.PreparedSearches.Add(vPrepareSearch); } }
/// <summary> /// Searches the specified search page. /// </summary> /// <param name="searchPage">The search page.</param> public override void Search(object searchPage) { if (this.TimelineSearches == null) { this.TimelineSearches = new List <UPSearchPageModelControllerPreparedSearch>(); foreach (ConfigTimelineInfoArea timelineInfoArea in this.TimelineConfiguration.InfoAreas) { UPSearchPageModelControllerPreparedSearch preparedSearch = new UPSearchPageModelControllerPreparedSearch(timelineInfoArea); this.TimelineSearches.Add(preparedSearch); } } UPMCalendarPage calendarPage = (UPMCalendarPage)this.Page; this.fromDate = calendarPage.CalendarFromDate; this.toDate = calendarPage.CalendarToDate; string fromDateString = this.fromDate?.CrmValueFromDate(); string toDateString = this.toDate?.CrmValueFromDate(); int searchCount = this.TimelineSearches.Count; this.searches = new List <TimelineSearch>(); for (int i = 0; i < searchCount; i++) { UPSearchPageModelControllerPreparedSearch preparedSearch = this.TimelineSearches[i]; UPContainerMetaInfo crmQuery = preparedSearch.CrmQueryForValue(null, null, false); if (!string.IsNullOrEmpty(fromDateString)) { UPInfoAreaCondition fromCondition = new UPInfoAreaConditionLeaf(preparedSearch.TimelineConfiguration.InfoAreaId, preparedSearch.TimelineConfiguration.DateField.FieldId, ">=", fromDateString); crmQuery.RootInfoAreaMetaInfo.AddCondition(fromCondition); } if (!string.IsNullOrEmpty(toDateString)) { int dateFieldIndex; dateFieldIndex = preparedSearch.TimelineConfiguration.EndDateField?.FieldId ?? preparedSearch.TimelineConfiguration.DateField.FieldId; UPInfoAreaCondition toCondition = new UPInfoAreaConditionLeaf(preparedSearch.TimelineConfiguration.InfoAreaId, dateFieldIndex, "<=", toDateString); crmQuery.RootInfoAreaMetaInfo.AddCondition(toCondition); } crmQuery.SetLinkRecordIdentification(this.RecordIdentification, preparedSearch.TimelineConfiguration.LinkId); this.searches.Add(new TimelineSearch(crmQuery, preparedSearch)); } this.nextSearch = 0; this.ExecuteNextSearch(); }
/// <inheritdoc/> public override UPMResultSection ResultSectionForSearchResult(UPSearchPageModelControllerPreparedSearch preparedSearch, UPCRMResult result) { UPCoreMappingResultContext resultContext = new UPCoreMappingResultContext(result, preparedSearch.CombinedControl, preparedSearch.ListFieldControl.NumberOfFields); this.SectionContexts.SetObjectForKey(resultContext, preparedSearch.InfoAreaId); bool newSection = this.geoSection == null; if (newSection) { this.geoSection = new UPMResultSection(StringIdentifier.IdentifierWithStringId($"Search_{preparedSearch.InfoAreaId}")); } var count = result.RowCount; for (var j = 0; j < count; j++) { UPCRMResultRow dataRow = result.ResultRowAtIndex(j) as UPCRMResultRow; var identifier = new RecordIdentifier(preparedSearch.InfoAreaId, dataRow.RecordIdAtIndex(0)); UPMResultRow resultRow = new UPMResultRow(identifier); resultRow.DataValid = true; resultContext.RowDictionary.SetObjectForKey(new UPCoreMappingResultRowContext(dataRow, resultContext), resultRow.Key); resultContext.ExpandMapper = preparedSearch.ExpandSettings; resultRow = (UPMResultRow)this.UpdatedElement(resultRow); this.AddDistanceFieldToRow(resultRow); this.geoSection.AddResultRow(resultRow); if (resultRow.RecordImageDocument != null) { this.AnyResultWithImageField = true; } } List <GeoUPMResultRow> sortedArray = this.resultRowsToSort.OrderBy(a => a.Distance).ToList(); this.geoSection.RemoveAllChildren(); foreach (var row in sortedArray) { if (row.ResultRow != null) { this.geoSection.AddResultRow(row.ResultRow); } else { } } return(newSection ? this.geoSection : null); }
private void Search(object _docPage) { UPMDocumentPage docPage = (UPMDocumentPage)_docPage; this.currentSearchOperation?.Cancel(); if (this.preparedSearch == null) { this.preparedSearch = new UPSearchPageModelControllerPreparedSearch(this.InfoAreaId, this.ConfigName, this.filterName); } if (this.preparedSearch.CombinedControl == null) { this.SearchOperationDidFinishWithResult(null, null); return; // dont crash but do nothing if no list exists } IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; FieldControl searchControl = configStore.FieldControlByNameFromGroup("Search", this.preparedSearch.SearchConfiguration.FieldGroupName); if (searchControl != null) { string searchLabel = string.Empty; int count = searchControl.NumberOfFields; for (int i = 0; i < count; i++) { searchLabel = i == 0 ? searchControl.FieldAtIndex(i).Label : $"{searchLabel} | {searchControl.FieldAtIndex(i).Label}"; } docPage.SearchPlaceholder = searchLabel; } if (string.IsNullOrEmpty(docPage.SearchText)) { int range = this.ViewReference.ContextValueForKey("SearchOptions")?.IndexOf("NoEmptySearch") ?? 0; if (range >= 0) { this.SearchOperationDidFinishWithResult(null, null); return; } } List <UPConfigFilter> configFilters = UPMFilter.ActiveFiltersForFilters(docPage.AvailableFilters); UPContainerMetaInfo containerMetaInfo = this.preparedSearch.CrmQueryForValue(docPage.SearchText, configFilters, this.fullTextSearch); if (this.recordIdentification.IsRecordIdentification()) { containerMetaInfo.SetLinkRecordIdentification(this.recordIdentification, 126, 127); } if (docPage.SearchType == SearchPageSearchType.OfflineSearch) { this.currentSearchOperation = containerMetaInfo.Find(UPRequestOption.Offline, this); } else if (docPage.SearchType == SearchPageSearchType.OnlineSearch) { this.currentSearchOperation = containerMetaInfo.Find(this); } else { SimpleIoc.Default.GetInstance <ILogger>().LogError($"Unknown search type: {docPage.SearchType}"); } }
/// <inheritdoc/> public override UPContainerMetaInfo CreateContainerMetaInfoWithValuePreparedSearch(string searchValue, UPSearchPageModelControllerPreparedSearch preparedSearch) { var firstFilter = this.SearchPage.AvailableFilters[0] as UPMDistanceFilter; var vFilter = this.usedFilters.ValueOrDefault(preparedSearch.SearchConfiguration.UnitName) as UPMDistanceFilter; List <UPConfigFilter> configFilter = null; if (vFilter != null) { vFilter.Active = true; vFilter.Radius = firstFilter.Radius; vFilter.LocationResult(this.currentUserLocation); configFilter = UPMFilter.ActiveFiltersForFilters(new List <UPMFilter> { vFilter }); } UPContainerMetaInfo container = preparedSearch.CrmQueryForValue(searchValue, configFilter, false); return(container); }
/// <summary> /// Builds page details /// </summary> public override void BuildPageDetails() { base.BuildPageDetails(); if (string.IsNullOrWhiteSpace(ConfigName)) { ConfigName = InfoAreaId; } InitialSearch = true; Sections = ViewReference.ContextValueForKey(SectionsKey); filterObject = null; // TODO: CRM-59214 - 2018-08-31 - (UPConfigFilter)ViewReference.ContextValueForKey(@"FilterObject"); if (filterObject == null) { filterName = ViewReference.ContextValueForKey(FilterNameKey); } var hasOfflineData = UPCRMDataStore.DefaultStore.HasOfflineData(InfoAreaId); if (!hasOfflineData) { SearchPage.InitiallyOnline = true; SearchPage.SearchType = SearchPageSearchType.OnlineSearch; } var fullTextSearchString = ViewReference.ContextValueForKey(FullTextSearchKey); FullTextSearch = string.IsNullOrWhiteSpace(fullTextSearchString) && fullTextSearchString != FalseCaseKey; if (PreparedSearch == null) { PreparedSearch = MainPreparedSearch; } var configStore = ConfigurationUnitStore.DefaultStore; var searchHeader = configStore.HeaderByNameFromGroup(SearchKey, PreparedSearch.SearchConfiguration?.HeaderGroupName); SearchPage.LabelText = searchHeader != null ? searchHeader.Label : LocalizedString.Localize(LocalizationKeys.TextGroupErrors, LocalizationKeys.KeyErrorsConfigHeaderMissing); var searchLabel = GetSearchLabel(configStore); if (!string.IsNullOrWhiteSpace(searchLabel)) { SearchPage.SearchPlaceholder = searchLabel; } else { SearchPage.HideTextSearch = true; } var enabledFilters = GetEnabledFields(); var availableFilters = new List <string>(); var filterMapping = new Dictionary <string, int>(); PopulateAvailableFiltersAndMapping(availableFilters, filterMapping); FilterIndexMapping = filterMapping; AddFilters(availableFilters, enabledFilters); SearchPage.AvailableOnlineSearch = !ViewReference.ContextValueIsSet(HideOnlineOfflineButtonKey); }
/// <summary> /// Creates the container meta information with value prepared search. /// </summary> /// <param name="searchValue">The search value.</param> /// <param name="preparedSearch">The prepared search.</param> /// <returns></returns> public override UPContainerMetaInfo CreateContainerMetaInfoWithValuePreparedSearch(string searchValue, UPSearchPageModelControllerPreparedSearch preparedSearch) { List <UPConfigFilter> configFilter = null; if (this.usedFilters.ContainsKey(preparedSearch.SearchConfiguration.UnitName)) { UPMFilter vFilter = this.usedFilters[preparedSearch.SearchConfiguration.UnitName]; configFilter = UPMFilter.ActiveFiltersForFilters(new List <UPMFilter> { vFilter }); } UPContainerMetaInfo container = preparedSearch.CrmQueryForValue(searchValue, configFilter, false); return(container); }
/// <summary> /// Creates the container meta information with value prepared search. /// </summary> /// <param name="searchValue">The search value.</param> /// <param name="preparedSearch">The prepared search.</param> /// <returns></returns> public virtual UPContainerMetaInfo CreateContainerMetaInfoWithValuePreparedSearch(string searchValue, UPSearchPageModelControllerPreparedSearch preparedSearch) { UPContainerMetaInfo container = preparedSearch.CrmQueryForValue(searchValue, null, this.FullTextSearch); return(container); }