Interaction logic for AddTimer.xaml
Exemplo n.º 1
0
        private async void ShowAddTimer(string preLoadJiraRef = null)
        {
            var selected        = DataModel.LockedTimers.Where(x => x.IsSelected).ToList();
            var selectedTimers  = selected.Select(x => modelHelpers.Gallifrey.IdleTimerCollection.GetTimer(x.UniqueId)).Where(x => x != null).ToList();
            var lockedTimerDate = selected.First().DateForTimer;

            modelHelpers.CloseFlyout(this);
            var addFlyout = new AddTimer(modelHelpers, startDate: lockedTimerDate, enableDateChange: false, idleTimers: selectedTimers, jiraRef: preLoadJiraRef);
            await modelHelpers.OpenFlyout(addFlyout);

            if (addFlyout.AddedTimer)
            {
                foreach (var lockedTimerModel in selected)
                {
                    modelHelpers.Gallifrey.IdleTimerCollection.RemoveTimer(lockedTimerModel.UniqueId);
                }

                if (modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers().Any())
                {
                    modelHelpers.OpenFlyout(this);
                    DataModel.RefreshLockedTimers(modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers());
                }
                else
                {
                    modelHelpers.SetSelectedTimer(addFlyout.NewTimerId);
                }
            }
            else
            {
                modelHelpers.OpenFlyout(this);
            }
        }
Exemplo n.º 2
0
        private async void AddTimer(object sender, RoutedEventArgs e)
        {
            if (DataModel.SelectedSearchResult == null)
            {
                await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "No Selected Item", "You Need To Select An Item To Add A Timer For It");

                Focus();
                return;
            }

            modelHelpers.CloseFlyout(this);
            if (openFromAdd || openFromEdit)
            {
                SelectedJira = DataModel.SelectedSearchResult;
            }
            else
            {
                var addFlyout = new AddTimer(modelHelpers, DataModel.SelectedSearchResult.Reference, selectedDateTab);
                await modelHelpers.OpenFlyout(addFlyout);

                if (addFlyout.AddedTimer)
                {
                    modelHelpers.SetSelectedTimer(addFlyout.NewTimerId);
                }
                else
                {
                    await modelHelpers.OpenFlyout(this);
                }
            }
        }
Exemplo n.º 3
0
        private async void AddButton(object sender, RoutedEventArgs e)
        {
            var startDate = ViewModel.TimerDates.FirstOrDefault(x => x.DateIsSelected)?.TimerDate ?? DateTime.Today;

            var addTimer = new AddTimer(ModelHelpers, startDate: startDate);
            await ModelHelpers.OpenFlyout(addTimer);
            if (addTimer.AddedTimer)
            {
                ModelHelpers.SetSelectedTimer(addTimer.NewTimerId);
            }
        }
Exemplo n.º 4
0
 private async void CreateTimerFromInactive(object sender, MouseButtonEventArgs e)
 {
     var dummyIdleTimer = new IdleTimer(DateTime.Now, DateTime.Now, Model.TimeTimeActivity, Guid.NewGuid());
     var addFlyout = new AddTimer(ModelHelpers, idleTimers: new List<IdleTimer> { dummyIdleTimer }, enableDateChange: false);
     await ModelHelpers.OpenFlyout(addFlyout);
     if (addFlyout.AddedTimer)
     {
         ModelHelpers.SetSelectedTimer(addFlyout.NewTimerId);
         ModelHelpers.Gallifrey.ResetInactiveAlert();
     }
 }
Exemplo n.º 5
0
        private void AddTimer(object sender, RoutedEventArgs e)
        {
            var model = (SearchModel)DataContext;

            if (model.SelectedSearchResult == null)
            {
                viewModel.MainWindow.ShowMessageAsync("No Selected Item", "You Need To Select An Item To Add A Timer For It");
                return;
            }

            if (openFromAdd)
            {
                SelectedJira = model.SelectedSearchResult;
            }
            else
            {
                var addFlyout = new AddTimer(viewModel, model.SelectedSearchResult.Reference);
                viewModel.MainWindow.OpenFlyout(addFlyout);
            }

            IsOpen = false;
        }
Exemplo n.º 6
0
        private async void AddToFillDay()
        {
            var startDate = ViewModel.TimerDates.FirstOrDefault(x => x.DateIsSelected)?.TimerDate ?? DateTime.Today;
            var recordedToDate = ModelHelpers.Gallifrey.JiraTimerCollection.GetTotalTimeForDateNoSeconds(startDate);
            var target = ModelHelpers.Gallifrey.Settings.AppSettings.TargetLogPerDay;

            if (recordedToDate < target)
            {
                var dummyIdleTimer = new IdleTimer(DateTime.Now, DateTime.Now, target.Subtract(recordedToDate), Guid.NewGuid());
                var addTimer = new AddTimer(ModelHelpers, startDate: startDate, idleTimers: new List<IdleTimer> {dummyIdleTimer}, enableDateChange: false);
                await ModelHelpers.OpenFlyout(addTimer);
                if (addTimer.AddedTimer)
                {
                    ModelHelpers.SetSelectedTimer(addTimer.NewTimerId);
                }
            }
            else
            {
                await DialogCoordinator.Instance.ShowMessageAsync(ModelHelpers.DialogContext, "No Extra Time", "You Have Already Hit The Target For This Date!");
            }


        }
Exemplo n.º 7
0
        private void AddTimer(object sender, RoutedEventArgs e)
        {
            var model = (SearchModel)DataContext;
            if (model.SelectedSearchResult == null)
            {
                viewModel.MainWindow.ShowMessageAsync("No Selected Item", "You Need To Select An Item To Add A Timer For It");
                return;
            }

            if (openFromAdd)
            {
                SelectedJira = model.SelectedSearchResult;
            }
            else
            {
                var addFlyout = new AddTimer(viewModel, model.SelectedSearchResult.Reference);
                viewModel.MainWindow.OpenFlyout(addFlyout);
            }

            IsOpen = false;
        }
Exemplo n.º 8
0
        private async void PasteButton(object sender, RoutedEventArgs e)
        {
            var pastedData = Clipboard.GetText();
            string jiraRef = null;
            try
            {
                var pastedUri = new Uri(pastedData);
                var jiraUri = new Uri(ModelHelpers.Gallifrey.Settings.JiraConnectionSettings.JiraUrl);
                if (pastedUri.Host == jiraUri.Host)
                {
                    var uriDrag = pastedUri.AbsolutePath;
                    jiraRef = uriDrag.Substring(uriDrag.LastIndexOf("/") + 1);
                }
            }
            catch (Exception)
            {
                //ignored
            }

            if (string.IsNullOrWhiteSpace(jiraRef))
            {
                jiraRef = pastedData;
            }
        
            if (ModelHelpers.Gallifrey.JiraConnection.DoesJiraExist(jiraRef))
            {
                var startDate = ViewModel.TimerDates.FirstOrDefault(x => x.DateIsSelected)?.TimerDate ?? DateTime.Today;
                var addTimer = new AddTimer(ModelHelpers, startDate: startDate, jiraRef: jiraRef);
                await ModelHelpers.OpenFlyout(addTimer);
                if (addTimer.AddedTimer)
                {
                    ModelHelpers.SetSelectedTimer(addTimer.NewTimerId);
                }
            }
            else
            {
                await DialogCoordinator.Instance.ShowMessageAsync(ModelHelpers.DialogContext, "Invalid Jira", $"Unable To Locate That Jira.\n\nJira Ref Pasted: '{jiraRef}'");
            }
        }
Exemplo n.º 9
0
        private async Task AddFromUrl(string url)
        {
            var uriDrag = new Uri(url).AbsolutePath;
            var jiraRef = uriDrag.Substring(uriDrag.LastIndexOf("/") + 1);
            var todaysDate = DateTime.Now.Date;
            var dayTimers = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimersForADate(todaysDate).ToList();

            if (dayTimers.Any(x => x.JiraReference == jiraRef))
            {
                ModelHelpers.Gallifrey.JiraTimerCollection.StartTimer(dayTimers.First(x => x.JiraReference == jiraRef).UniqueId);
                ModelHelpers.RefreshModel();
                ModelHelpers.SelectRunningTimer();
            }
            else
            {
                //Validate jira is real
                try
                {
                    ModelHelpers.Gallifrey.JiraConnection.GetJiraIssue(jiraRef);
                }
                catch (NoResultsFoundException)
                {
                    await DialogCoordinator.Instance.ShowMessageAsync(ModelHelpers.DialogContext, "Invalid Jira", $"Unable To Locate That Jira.\n\nJira Ref Dropped: '{jiraRef}'");
                    return;
                }

                //show add form, we know it's a real jira & valid
                var addTimer = new AddTimer(ModelHelpers, startDate: todaysDate, jiraRef: jiraRef, startNow: true);
                await ModelHelpers.OpenFlyout(addTimer);
                if (addTimer.AddedTimer)
                {
                    ModelHelpers.SetSelectedTimer(addTimer.NewTimerId);
                }
            }
        }
Exemplo n.º 10
0
        private async void ShowAddTimer(string preLoadJiraRef = null)
        {
            var selected = DataModel.LockedTimers.Where(x => x.IsSelected).ToList();
            var selectedTimers = selected.Select(x => modelHelpers.Gallifrey.IdleTimerCollection.GetTimer(x.UniqueId)).Where(x => x != null).ToList();
            var lockedTimerDate = selected.First().DateForTimer;
            modelHelpers.HideFlyout(this);
            var addFlyout = new AddTimer(modelHelpers, startDate: lockedTimerDate, enableDateChange: false, idleTimers: selectedTimers, jiraRef: preLoadJiraRef);
            await modelHelpers.OpenFlyout(addFlyout);

            if (addFlyout.AddedTimer)
            {
                foreach (var lockedTimerModel in selected)
                {
                    modelHelpers.Gallifrey.IdleTimerCollection.RemoveTimer(lockedTimerModel.UniqueId);
                }

                if (modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers().Any())
                {
                    modelHelpers.OpenFlyout(this);
                    DataModel.RefreshLockedTimers(modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers());
                }
                else
                {
                    modelHelpers.CloseFlyout(this);
                    modelHelpers.SetSelectedTimer(addFlyout.NewTimerId);
                }
            }
            else
            {
                modelHelpers.OpenFlyout(this);
            }
        }
Exemplo n.º 11
0
        private async void AddTimer(object sender, RoutedEventArgs e)
        {
            if (DataModel.SelectedSearchResult == null)
            {
                await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "No Selected Item", "You Need To Select An Item To Add A Timer For It");
                Focus();
                return;
            }

            modelHelpers.CloseFlyout(this);
            if (openFromAdd || openFromEdit)
            {
                SelectedJira = DataModel.SelectedSearchResult;
            }
            else
            {
                var addFlyout = new AddTimer(modelHelpers, DataModel.SelectedSearchResult.Reference, selectedDateTab);
                await modelHelpers.OpenFlyout(addFlyout);
                if (addFlyout.AddedTimer)
                {
                    modelHelpers.SetSelectedTimer(addFlyout.NewTimerId);
                }
                else
                {
                    modelHelpers.OpenFlyout(this);
                }
            }
        }