/// <summary> /// Instantiates the page. /// </summary> /// <returns></returns> public override Page InstantiatePage() { UPMDocumentPage page = this.Page != null ? new UPMDocumentPage(this.Page.Identifier) : new UPMDocumentPage(new RecordIdentifier(this.InfoAreaId, null)); UPMAction searchAction = new UPMAction(null); searchAction.SetTargetAction(this, this.Search); page.SearchAction = searchAction; return(page); }
/// <summary> /// Searches the operation did finish with result. /// </summary> /// <param name="operation">The operation.</param> /// <param name="result">The result.</param> public override void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult result) { this.currentSearchOperation = null; UPMDocumentPage newPage = (UPMDocumentPage)this.InstantiatePage(); newPage.Invalid = false; newPage.SearchType = ((UPMDocumentPage)this.Page).SearchType; newPage.SearchPlaceholder = ((UPMDocumentPage)this.Page).SearchPlaceholder; newPage.AvailableOnlineSearch = ((UPMDocumentPage)this.Page).AvailableOnlineSearch; this.FillPageWithDocumentsResult(newPage, result); Page oldPage = this.Page; this.TopLevelElement = newPage; this.ModelControllerDelegate.ModelControllerDidChange(this, oldPage, newPage, null, null); }
private void BuildPage() { this.recordIdentification = this.ViewReference.ContextValueForKey("RecordId"); this.InfoAreaId = this.recordIdentification.InfoAreaId(); this.ConfigName = this.ViewReference.ContextValueForKey("ConfigName"); this.filterName = this.ViewReference.ContextValueForKey("FilterName"); string hideOnlineButtonString = this.ViewReference.ContextValueForKey("hideOnlineOfflineButton"); this.hideOnlineButton = hideOnlineButtonString == "true"; string fullTextSearchString = this.ViewReference.ContextValueForKey("FullTextSearch"); this.fullTextSearch = !(string.IsNullOrEmpty(fullTextSearchString) || fullTextSearchString == "false"); UPMDocumentPage page = (UPMDocumentPage)this.InstantiatePage(); page.SearchType = SearchPageSearchType.OfflineSearch; page.LabelText = LocalizedString.TextProcessDocuments; page.Invalid = true; page.AvailableOnlineSearch = !this.hideOnlineButton; string headerName = this.ViewReference.ContextValueForKey("HeaderName"); UPConfigHeader header = null; if (!string.IsNullOrEmpty(headerName)) { header = ConfigurationUnitStore.DefaultStore.HeaderByName(headerName); } if (header != null) { page.LabelText = header.Label; } this.TopLevelElement = page; List <string> availableFilters = new List <string>(); for (int i = 1; i <= 5; i++) { string availableFilterName = this.ViewReference.ContextValueForKey($"Filter{i}"); if (!string.IsNullOrEmpty(availableFilterName)) { availableFilters.Add(availableFilterName); } } this.AddFilters(availableFilters); this.ApplyLoadingStatusOnPage(page); }
private bool FillPageWithDocumentsResult(UPMDocumentPage page, UPCRMResult result) { int count = result?.RowCount ?? 0; if (count == 0) { return(false); } UPMDocumentSection lastSection = null; int groupingIndex = -1; for (int i = 0; i < result.ColumnCount; i++) { if (result.ColumnFieldMetaInfoAtIndex(i).FunctionName == "groupingKey") { groupingIndex = i; break; } } page.AvailableGrouping = groupingIndex != -1; DocumentInfoAreaManager documentInfoAreaManager = new DocumentInfoAreaManager(this.preparedSearch.CombinedControl.InfoAreaId, this.preparedSearch.CombinedControl, null); Dictionary <string, UPMDocumentSection> groupDictionary = new Dictionary <string, UPMDocumentSection>(); for (int i = 0; i < count; i++) { UPCRMResultRow resultRow = (UPCRMResultRow)result.ResultRowAtIndex(i); DocumentData documentData = documentInfoAreaManager.DocumentDataForResultRow(resultRow); string groupValue = string.Empty; if (groupingIndex != -1) { groupValue = resultRow.ValueAtIndex(groupingIndex); } UPMDocumentSection section; bool isLastSection; if (string.IsNullOrEmpty(groupValue)) { groupValue = "#"; isLastSection = true; section = lastSection; } else { isLastSection = false; section = groupDictionary.ValueOrDefault(groupValue); } if (section == null) { section = new UPMDocumentSection(StringIdentifier.IdentifierWithStringId(groupValue)) { GroupName = new UPMStringField(StringIdentifier.IdentifierWithStringId(groupValue)) { StringValue = groupValue } }; if (isLastSection) { lastSection = section; // Dont add to page here # should always be the last } else { groupDictionary.SetObjectForKey(section, groupValue); page.AddChild(section); } } UPMDocument document = new UPMDocument(documentData); section.AddChild(document); } if (lastSection != null) { page.AddChild(lastSection); } return(true); }
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}"); } }