private void UpdateTimer(JiraTimer timer, TimeSpan?exportTime) { Timer = timer; if (exportTime.HasValue && exportTime.Value < timer.TimeToExport) { ToExportMaxTime = exportTime.Value; } else { ToExportMaxTime = new TimeSpan(timer.TimeToExport.Hours, timer.TimeToExport.Minutes, 0); } ToExportHours = ToExportMaxTime.Hours; ToExportMinutes = ToExportMaxTime.Minutes; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HasParent")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentRef")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentDesc")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraRef")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraDesc")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedHours")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedMinutes")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToExportHours")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToExportMinutes")); }
private JiraTimer GetSelectedTimer() { JiraTimer selectedTimer = null; var selectedTab = tabTimerDays.SelectedTab; if (selectedTab != null) { var selectedList = ((ListBox)selectedTab.Controls[string.Format("lst_{0}", selectedTab.Name)]); if (selectedList != null) { try { selectedTimer = (JiraTimer)selectedList.SelectedItem; } catch (IndexOutOfRangeException) { /* There Seems to be some situations this throws, for no good reason */ } catch (NullReferenceException) { RefreshInternalTimerList(); return(GetSelectedTimer()); } } } if (selectedTimer != null) { return(selectedTimer); } return(null); }
public AdjustTimerWindow(IBackend gallifrey, Guid timerGuid) { this.gallifrey = gallifrey; timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); InitializeComponent(); txtJiraRef.Text = timerToShow.JiraReference; }
public void UpdateTimer(JiraTimer timer, Issue jiraIssue) { UpdateTimer(timer, ToExportMaxTime); OriginalRemaining = jiraIssue.fields.timetracking != null?TimeSpan.FromSeconds(jiraIssue.fields.timetracking.remainingEstimateSeconds) : new TimeSpan(); SetRemaining(); }
public TimerDisplayModel(JiraTimer jiraTimer) { Timer = jiraTimer; Reference = jiraTimer.JiraReference; Description = jiraTimer.JiraName; ParentReference = jiraTimer.JiraParentReference; ParentDescription = jiraTimer.JiraParentName; HasParent = jiraTimer.HasParent; }
public RenameTimerWindow(IBackend gallifrey, Guid timerGuid) { this.gallifrey = gallifrey; timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); InitializeComponent(); txtJiraRef.Text = timerToShow.JiraReference; calStartDate.Value = timerToShow.DateStarted.Date; txtJiraRef.Enabled = timerToShow.HasExportedTime(); }
private ContextMenu BuildTimerListContextMenu(JiraTimer jiraTimerSelected) { if (jiraTimerSelected != null) { return(BuildSelectedTimerContext(jiraTimerSelected)); } else { return(BuildNoTimerContext()); } }
public EditTimerWindow(IBackend gallifrey, Guid timerGuid) { this.gallifrey = gallifrey; timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); InitializeComponent(); txtJiraRef.AutoCompleteCustomSource.AddRange(gallifrey.JiraConnection.GetJiraProjects().Select(x => x.ToString()).ToArray()); showingJiras = false; txtJiraRef.Text = timerToShow.JiraReference; calStartDate.Value = timerToShow.DateStarted.Date; txtJiraRef.Enabled = timerToShow.HasExportedTime(); calStartDate.Enabled = timerToShow.HasExportedTime(); TopMost = gallifrey.Settings.UiSettings.AlwaysOnTop; }
public ExportTimerWindow(IBackend gallifrey, Guid timerGuid) { this.gallifrey = gallifrey; timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); InitializeComponent(); jiraIssue = gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference); var loggedTime = new TimeSpan(); foreach (var worklog in jiraIssue.GetWorklogs()) { if (worklog.StartDate.HasValue && worklog.StartDate.Value.Date == timerToShow.DateStarted.Date && worklog.Author.ToLower() == gallifrey.JiraConnectionSettings.JiraUsername.ToLower()) { loggedTime = loggedTime.Add(new TimeSpan(0, 0, (int)worklog.TimeSpentInSeconds)); } } gallifrey.JiraTimerCollection.SetJiraExportedTime(timerGuid, loggedTime); timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); if (timerToShow.TimeToExport.TotalMinutes <= 0) { MessageBox.Show("There Is No Time To Export", "Nothing To Export", MessageBoxButtons.OK, MessageBoxIcon.Information); DisplayForm = false; } txtJiraRef.Text = timerToShow.JiraReference; txtDescription.Text = timerToShow.JiraName; txtTotalHours.Text = timerToShow.ExactCurrentTime.Hours.ToString(); txtTotalMinutes.Text = timerToShow.ExactCurrentTime.Minutes.ToString(); txtExportedHours.Text = timerToShow.ExportedTime.Hours.ToString(); txtExportedMins.Text = timerToShow.ExportedTime.Minutes.ToString(); txtExportHours.Text = timerToShow.TimeToExport.Hours.ToString(); txtExportMins.Text = timerToShow.TimeToExport.Minutes.ToString(); if (timerToShow.DateStarted.Date != DateTime.Now.Date) { calExportDate.Value = timerToShow.DateStarted.Date.AddHours(12); } else { calExportDate.Value = DateTime.Now; } }
private void UpdateTimer(JiraTimer timer) { Timer = timer; toExportMaxTime = new TimeSpan(timer.TimeToExport.Hours, timer.TimeToExport.Minutes, 0); ToExportHours = toExportMaxTime.Hours; ToExportMinutes = toExportMaxTime.Minutes; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToExportHours")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToExportMinutes")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HasParent")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentRef")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentDesc")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraRef")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraDesc")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedHours")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedMinutes")); }
private ContextMenu BuildSelectedTimerContext(JiraTimer jiraTimer) { var menuItems = new List <MenuItem>(); var dateMenuItems = new List <MenuItem>(); var dateList = gallifrey.JiraTimerCollection.GetValidTimerDates().OrderByDescending(x => x.Date); if (dateList.All(x => x.Date != DateTime.Now.Date)) { dateMenuItems.Add(new MenuItem(DateTime.Now.ToString("ddd, dd MMM"), ListContextDateClicked)); } foreach (var timerlistValue in dateList) { if (timerlistValue.Date != jiraTimer.DateStarted.Date) { dateMenuItems.Add(new MenuItem(timerlistValue.ToString("ddd, dd MMM"), ListContextDateClicked)); } } menuItems.Add(new MenuItem("Add To Date", dateMenuItems.ToArray())); menuItems.Add(new MenuItem("Move Time To New Timer", ListContextSplitClicked)); menuItems.Add(new MenuItem("Delete Timer", btnRemoveTimer_Click)); menuItems.Add(new MenuItem("Adjust Timer Time", btnTimeEdit_Click)); menuItems.Add(new MenuItem("Change Jira Ref/Date", btnRename_Click)); menuItems.Add(new MenuItem("Export Timer", btnExport_Click)); if (jiraTimer.IsRunning) { menuItems.Add(new MenuItem("Stop Timer", ListBoxDoubleClick)); } else { menuItems.Add(new MenuItem("Start Timer", ListBoxDoubleClick)); } return(new ContextMenu(menuItems.ToArray())); }
public ExportModel(JiraTimer timer, TimeSpan?exportTime, IExportSettings exportSettings) { UpdateTimer(timer, exportTime); ExportDate = timer.DateStarted.Date != DateTime.Now.Date ? timer.DateStarted.Date.AddHours(12) : DateTime.Now; switch (exportSettings.DefaultRemainingValue) { case DefaultRemaining.Auto: WorkLogStrategy = WorkLogStrategy.Automatic; break; case DefaultRemaining.Leave: WorkLogStrategy = WorkLogStrategy.LeaveRemaining; break; case DefaultRemaining.Set: WorkLogStrategy = WorkLogStrategy.SetValue; break; } DefaultComment = exportSettings.EmptyExportComment; }
public ExportTimerWindow(IBackend gallifrey, Guid timerGuid) { DisplayForm = true; this.gallifrey = gallifrey; timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); InitializeComponent(); try { jiraIssue = gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference, true); } catch (NoResultsFoundException) { MessageBox.Show(string.Format("Unable To Locate Jira {0}!\nCannot Export Time\nPlease Verify/Correct Jira Reference", timerToShow.JiraReference), "Unable To Locate Jira", MessageBoxButtons.OK, MessageBoxIcon.Error); DisplayForm = false; } gallifrey.JiraTimerCollection.RefreshFromJira(timerGuid, jiraIssue, gallifrey.JiraConnection.CurrentUser); timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid); if (timerToShow.FullyExported) { MessageBox.Show("There Is No Time To Export", "Nothing To Export", MessageBoxButtons.OK, MessageBoxIcon.Information); DisplayForm = false; } txtJiraRef.Text = timerToShow.JiraReference; txtDescription.Text = timerToShow.JiraName; if (timerToShow.HasParent) { txtParentRef.Text = timerToShow.JiraParentReference; txtParentDesc.Text = timerToShow.JiraParentName; } else { txtParentRef.Visible = false; txtParentDesc.Visible = false; lblParentRef.Visible = false; lblParentDesc.Visible = false; } txtTotalHours.Text = timerToShow.ExactCurrentTime.Hours.ToString(); txtTotalMinutes.Text = timerToShow.ExactCurrentTime.Minutes.ToString(); txtExportedHours.Text = timerToShow.ExportedTime.Hours.ToString(); txtExportedMins.Text = timerToShow.ExportedTime.Minutes.ToString(); txtExportHours.Text = timerToShow.TimeToExport.Hours.ToString(); txtExportMins.Text = timerToShow.TimeToExport.Minutes.ToString(); if (jiraIssue.fields.timetracking == null) { txtRemainingHours.Text = "N/A"; txtRemainingMinutes.Text = "N/A"; } else { var remainingTime = jiraIssue.fields.timetracking != null?TimeSpan.FromSeconds(jiraIssue.fields.timetracking.remainingEstimateSeconds) : new TimeSpan(); var hours = (remainingTime.Days * 24) + remainingTime.Hours; txtRemainingHours.Text = hours.ToString(); txtRemainingMinutes.Text = remainingTime.Minutes.ToString(); } if (timerToShow.DateStarted.Date != DateTime.Now.Date) { calExportDate.Value = timerToShow.DateStarted.Date.AddHours(12); } else { calExportDate.Value = DateTime.Now; } radAutoAdjust.Checked = gallifrey.Settings.ExportSettings.DefaultRemainingValue == DefaultRemaining.Auto; radLeaveRemaining.Checked = gallifrey.Settings.ExportSettings.DefaultRemainingValue == DefaultRemaining.Leave; radSetValue.Checked = gallifrey.Settings.ExportSettings.DefaultRemainingValue == DefaultRemaining.Set; radSetValue_CheckedChanged(this, null); TopMost = gallifrey.Settings.UiSettings.AlwaysOnTop; txtComment.AltEnterEvent += btnOK_Click; }
private async void AddButton(object sender, RoutedEventArgs e) { var selected = DataModel.LockedTimers.Where(x => x.IsSelected).ToList(); if (selected.Count == 0) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Nothing Selected", "You Have Not Selected Any Locked Time To Add"); Focus(); return; } var selectedTimers = selected.Select(x => modelHelpers.Gallifrey.IdleTimerCollection.GetTimer(x.UniqueId)).Where(x => x != null).ToList(); if (selected.Count != selectedTimers.Count) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Out Of Date", "The Timer Window Is Out Of Date And Needs To Be Refreshed"); DataModel.RefreshLockedTimers(modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers()); Focus(); return; } var selectedTime = new TimeSpan(); var lockedTimerDate = DateTime.MinValue; foreach (var lockedTimerModel in selected) { if (lockedTimerDate == DateTime.MinValue || lockedTimerDate.Date == lockedTimerModel.DateForTimer) { lockedTimerDate = lockedTimerModel.DateForTimer; selectedTime = selectedTime.Add(lockedTimerModel.IdleTime); } else { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Selection", "All Timers Must Be On The Same Date!"); Focus(); return; } } JiraTimer runningTimer = null; var runningTimerId = modelHelpers.Gallifrey.JiraTimerCollection.GetRunningTimerId(); if (runningTimerId.HasValue) { runningTimer = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(runningTimerId.Value); if (runningTimer.DateStarted.Date != lockedTimerDate.Date) { runningTimer = null; } } var dialog = (BaseMetroDialog)this.Resources["TimeLocation"]; await DialogCoordinator.Instance.ShowMetroDialogAsync(modelHelpers.DialogContext, dialog); var message = dialog.FindChild <TextBlock>("Message"); var runningTimerButton = dialog.FindChild <Button>("RunningTimerButton"); if (runningTimer != null) { message.Text = $"Where Would You Like To Add The Time Worth {selectedTime.FormatAsString(false)}?\n\nNote:- Running Timer Is\n{runningTimer.JiraReference} - {runningTimer.JiraName}"; runningTimerButton.Visibility = Visibility.Visible; } else { message.Text = $"Where Would You Like To Add The Time Worth {selectedTime.FormatAsString(false)}?"; runningTimerButton.Visibility = Visibility.Collapsed; } await dialog.WaitUntilUnloadedAsync(); }
private async void SetupContext(JiraTimer timerToShow, TimeSpan?exportTime, bool skipJiraCheck) { await Task.Delay(50); modelHelpers.HideFlyout(this); if (timerToShow.TempTimer) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Temp Timer", "You Cannot Export A Temporary Timer!"); modelHelpers.CloseHiddenFlyout(this); return; } DataContext = new ExportModel(timerToShow, exportTime, modelHelpers.Gallifrey.Settings.ExportSettings); if (!skipJiraCheck) { Issue jiraIssue = null; var requireRefresh = !timerToShow.LastJiraTimeCheck.HasValue || timerToShow.LastJiraTimeCheck < DateTime.UtcNow.AddMinutes(-15); var showError = false; try { var jiraDownloadResult = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference, requireRefresh), "Downloading Jira Work Logs To Ensure Accurate Export", true, false); switch (jiraDownloadResult.Status) { case ProgressResult.JiraHelperStatus.Cancelled: modelHelpers.CloseHiddenFlyout(this); return; case ProgressResult.JiraHelperStatus.Errored: showError = true; break; case ProgressResult.JiraHelperStatus.Success: jiraIssue = jiraDownloadResult.RetVal; break; } } catch (Exception) { showError = true; } if (showError) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Unable To Locate Jira", $"Unable To Locate Jira {timerToShow.JiraReference}!\nCannot Export Time\nPlease Verify/Correct Jira Reference"); modelHelpers.CloseHiddenFlyout(this); return; } if (requireRefresh) { modelHelpers.Gallifrey.JiraTimerCollection.RefreshFromJira(timerToShow.UniqueId, jiraIssue, modelHelpers.Gallifrey.JiraConnection.CurrentUser); timerToShow = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerToShow.UniqueId); } DataModel.UpdateTimer(timerToShow, jiraIssue); } if (timerToShow.FullyExported) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Nothing To Export", "There Is No Time To Export"); modelHelpers.CloseHiddenFlyout(this); return; } if (timerToShow.IsRunning) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Timer Is Running", "You Cannot Export A Timer While It Is Running"); modelHelpers.CloseHiddenFlyout(this); return; } await modelHelpers.OpenFlyout(this); }