private static BaseEntity GetCommentParentEntity(BaseItemViewModel selectedItem) { if (selectedItem is CommentViewModel commentViewModel) { return(commentViewModel.ParentEntity); } return(null); }
public static void ViewCommentParentDetails(BaseItemViewModel selectedItem) { try { var commentViewModel = selectedItem as CommentViewModel; if (commentViewModel == null) { throw new Exception($"Unrecognized type {selectedItem.Entity.TypeName}."); } var selectedEntity = commentViewModel.ParentEntity; ViewEntityDetailsInternal(selectedEntity); } catch (Exception ex) { MessageBox.Show("Unable to open details window.\n\n" + "Failed with message: " + ex.Message, ToolWindowHelper.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Download the script for the selected item if possible /// </summary> internal static async void DownloadScript(BaseItemViewModel selectedItem) { try { if (selectedItem?.Entity == null) { return; } var test = selectedItem.Entity as Test; if (test == null) { return; } OctaneServices octaneService; octaneService = OctaneServices.GetInstance(); string testName; if (test.SubType == TestBDDScenario.SUBTYPE_BDD_SCENARIO_TEST) { var bddScenario = await octaneService.FindEntityAsync(test, new List <string>() { CommonFields.BDDSpec }); string bddSpecName = Utility.GetPropertyOfChildEntity(bddScenario, CommonFields.BDDSpec, "name").ToString(); string bddSpecId = Utility.GetPropertyOfChildEntity(bddScenario, CommonFields.BDDSpec, "id").ToString(); testName = bddSpecName + "_" + bddSpecId; } else { testName = test.Name; } var testScript = await octaneService.GetTestScript(test.Id); MainWindow.PluginPackage.CreateFile(testName, testScript.Script); } catch (Exception ex) { MessageBox.Show("Unable to obtain script.\n\n" + "Failed with message: " + ex.Message, ToolWindowHelper.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void ViewTaskParentDetails(BaseItemViewModel selectedItem) { try { if (selectedItem?.Entity == null) { return; } if (selectedItem.Entity.TypeName != Task.TYPE_TASK) { throw new Exception($"Unrecognized type {selectedItem.Entity.TypeName}."); } var selectedEntity = (BaseEntity)selectedItem.Entity.GetValue("story"); ViewEntityDetailsInternal(selectedEntity); } catch (Exception ex) { MessageBox.Show("Unable to open details window.\n\n" + "Failed with message: " + ex.Message, ToolWindowHelper.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } }
protected void InitBaseItemViewModel(BaseItemViewModel viewModel) { viewModel.EntityStateNameCode = EntityCacheRepository.GetEntityStateNameCode(viewModel.EntityStateId); }
// TODO remove useMyItems and use a more generic mechanism to obtain the BaseItemViewModel private void ValidateContextMenuItems <T>(T entity, List <MenuItemEnum> expectedMenuItems, bool useMyItems = true, bool setActiveItem = false) where T : BaseEntity { try { BaseItemViewModel selectedItem; if (useMyItems) { var viewModel = new OctaneMyItemsViewModel(); viewModel.LoadMyItemsAsync().Wait(); selectedItem = viewModel.MyItems.FirstOrDefault(i => i.ID == entity.Id); if (setActiveItem) { OctaneItemViewModel.SetActiveItem(selectedItem as OctaneItemViewModel); } } else { selectedItem = new BaseItemViewModel(entity); } Assert.IsNotNull(selectedItem, "Couldn't find entity"); var cm = new ContextMenu(); ToolWindowHelper.ConstructContextMenu(cm, selectedItem, _viewDetailsDelegate, _viewTaskParentDetailsDelegate, _viewCommentParentDetailsDelegate, _openInBrowserDelegate, _copyCommitMessageDelegate, _downloadScriptDelegate, _startWorkDelegate, _stopWorkDelegate, null, null); Assert.AreEqual(expectedMenuItems.Count, cm.Items.Count, "Mismatched number of menu items in context menu"); var items = new MenuItem[cm.Items.Count]; cm.Items.CopyTo(items, 0); int index = 0; foreach (var item in expectedMenuItems) { switch (item) { case MenuItemEnum.ViewDetails: ValidateMenuItem(items, index, ToolWindowHelper.ViewDetailsHeader, ViewDetailsValue); break; case MenuItemEnum.TaskViewParentDetails: ValidateMenuItem(items, index, ToolWindowHelper.ViewTaskParentDetailsHeader, ViewTaskParentDetailsValue); break; case MenuItemEnum.CommentViewParentDetails: ValidateMenuItem(items, index, ToolWindowHelper.CopyCommitMessageHeader, ViewCommentParentDetailsValue); break; case MenuItemEnum.OpenInBrowser: ValidateMenuItem(items, index, ToolWindowHelper.OpenInBrowserHeader, OpenInBrowserValue); break; case MenuItemEnum.CopyCommitMessage: ValidateMenuItem(items, index, ToolWindowHelper.CopyCommitMessageHeader, CopyCommitMessageValue); break; case MenuItemEnum.DownloadScript: ValidateMenuItem(items, index, ToolWindowHelper.DownloadScriptHeader, DownloadScriptValue); break; case MenuItemEnum.StartWork: ValidateMenuItem(items, index, ToolWindowHelper.StartWorkHeader, StartWorkValue); break; case MenuItemEnum.StopWork: ValidateMenuItem(items, index, ToolWindowHelper.StopWorkHeader, StopWorkValue); break; } index++; } } finally { EntityService.DeleteById <T>(WorkspaceContext, entity.Id); } }
public SelectItemMessage(BaseItemViewModel vm) { Vm = vm; }
/// <summary> /// Construct the context menu for the given selected item /// </summary> internal static void ConstructContextMenu(ContextMenu cm, BaseItemViewModel selectedItem, Action <object> viewDetailsDelegate, Action <object> viewTaskParentDetailsDelegate, Action <object> viewCommentParentDetailsDelegate, Action <object> openInBrowserDelegate, Action <object> copyCommitMessageDelegate, Action <object> downloadScriptDelegate, Action <object> startWorkDelegate, Action <object> stopWorkDelegate, Action <object> addToMyWorkDelegate, Action <object> removeFromMyWorkDelegate) { try { if (cm == null) { return; } cm.Items.Clear(); if (selectedItem == null) { return; } var selectedEntity = selectedItem.Entity; var entityType = Utility.GetConcreteEntityType(selectedEntity); // view details if (viewDetailsDelegate != null && DetailsToolWindow.IsEntityTypeSupported(entityType)) { cm.Items.Add(new MenuItem { Header = ViewDetailsHeader, Command = new DelegatedCommand(viewDetailsDelegate) }); } // view task parent details var taskParentEntity = Utility.GetTaskParentEntity(selectedEntity); if (viewTaskParentDetailsDelegate != null && selectedEntity.TypeName == Task.TYPE_TASK && taskParentEntity != null && DetailsToolWindow.IsEntityTypeSupported(entityType)) { cm.Items.Add(new MenuItem { Header = ViewTaskParentDetailsHeader, Command = new DelegatedCommand(viewTaskParentDetailsDelegate) }); } // view comment parent details var commentParentEntity = GetCommentParentEntity(selectedItem); if (viewCommentParentDetailsDelegate != null && commentParentEntity != null && DetailsToolWindow.IsEntityTypeSupported(Utility.GetConcreteEntityType(commentParentEntity))) { cm.Items.Add(new MenuItem { Header = ViewCommentParentDetailsHeader, Command = new DelegatedCommand(viewCommentParentDetailsDelegate) }); } // open in browser if (openInBrowserDelegate != null) { cm.Items.Add(new MenuItem { Header = OpenInBrowserHeader, Command = new DelegatedCommand(openInBrowserDelegate) }); } var octaneItem = selectedItem as OctaneItemViewModel; // download gherkin script if (downloadScriptDelegate != null && (entityType == TestGherkin.SUBTYPE_GHERKIN_TEST || entityType == TestBDDScenario.SUBTYPE_BDD_SCENARIO_TEST)) { cm.Items.Add(new MenuItem { Header = DownloadScriptHeader, Command = new DelegatedCommand(downloadScriptDelegate) }); } // start work if (startWorkDelegate != null && octaneItem != null && !octaneItem.IsActiveWorkItem && (entityType == WorkItem.SUBTYPE_STORY || entityType == WorkItem.SUBTYPE_QUALITY_STORY || entityType == WorkItem.SUBTYPE_DEFECT || entityType == Task.TYPE_TASK)) { cm.Items.Add(new MenuItem { Header = StartWorkHeader, Command = new DelegatedCommand(startWorkDelegate) }); } // stop work if (stopWorkDelegate != null && octaneItem != null && octaneItem.IsActiveWorkItem && (entityType == WorkItem.SUBTYPE_STORY || entityType == WorkItem.SUBTYPE_QUALITY_STORY || entityType == WorkItem.SUBTYPE_DEFECT || entityType == Task.TYPE_TASK)) { cm.Items.Add(new MenuItem { Header = StopWorkHeader, Command = new DelegatedCommand(stopWorkDelegate) }); } // copy commit message if (octaneItem != null && octaneItem.IsSupportCopyCommitMessage && (entityType == WorkItem.SUBTYPE_STORY || entityType == WorkItem.SUBTYPE_QUALITY_STORY || entityType == WorkItem.SUBTYPE_DEFECT || entityType == Task.TYPE_TASK)) { cm.Items.Add(new MenuItem { Header = CopyCommitMessageHeader, Command = new DelegatedCommand(copyCommitMessageDelegate) }); } // add to my work if (addToMyWorkDelegate != null && (DetailsToolWindow.IsEntityTypeSupported(entityType) || entityType == TestBDDScenario.SUBTYPE_BDD_SCENARIO_TEST)) { cm.Items.Add(new MenuItem { Header = AddToMyWorkHeader, Command = new DelegatedCommand(addToMyWorkDelegate) }); } // remove from my work if (removeFromMyWorkDelegate != null) { cm.Items.Add(new MenuItem { Header = RemoveFromMyWorkHeader, Command = new DelegatedCommand(removeFromMyWorkDelegate) }); } } catch (Exception ex) { MessageBox.Show("Unable to show context menu.\n\n" + "Failed with message: " + ex.Message, AppName, MessageBoxButton.OK, MessageBoxImage.Error); } }