Esempio n. 1
0
 public StartStopMessage(TimeEntryData sender) : base(sender)
 {
 }
Esempio n. 2
0
 public TimeEntryMessage(TimeEntryData data, DataAction action)
 {
     Data   = data;
     Action = action;
 }
Esempio n. 3
0
        protected async override Task AddOrUpdateEntryAsync(TimeEntryData entry)
        {
            int groupIndex;
            int newIndex;
            NotifyCollectionChangedAction groupAction;

            TimeEntryData existingEntry;
            DateGroup     grp;
            bool          isNewGroup;

            if (FindExistingEntry(entry, out grp, out existingEntry))
            {
                if (entry.StartTime != existingEntry.StartTime)
                {
                    var date     = entry.StartTime.ToLocalTime().Date;
                    var oldIndex = GetTimeEntryIndex(existingEntry);

                    // Move TimeEntry to another DateGroup
                    if (grp.Date != date)
                    {
                        // Remove entry from previous DateGroup: //TODO: remove dateGroup too?
                        grp.Remove(existingEntry);
                        groupIndex = GetDateGroupIndex(grp);
                        await UpdateCollectionAsync(grp, NotifyCollectionChangedAction.Replace, groupIndex);

                        // Move entry to new DateGroup
                        grp = GetGroupFor(entry, out isNewGroup);
                        grp.Add(entry);
                        Sort();

                        newIndex = GetTimeEntryIndex(entry);
                        await UpdateCollectionAsync(entry, NotifyCollectionChangedAction.Move, newIndex, oldIndex);

                        // Update new container DateGroup
                        groupIndex  = GetDateGroupIndex(grp);
                        groupAction = isNewGroup ? NotifyCollectionChangedAction.Add : NotifyCollectionChangedAction.Replace;
                        await UpdateCollectionAsync(grp, groupAction, groupIndex);

                        return;
                    }

                    // Move TimeEntry inside DateGroup
                    grp.TimeEntryList.UpdateData(entry);
                    Sort();

                    // Update group
                    groupIndex = GetDateGroupIndex(grp);
                    await UpdateCollectionAsync(grp, NotifyCollectionChangedAction.Replace, groupIndex);

                    newIndex = GetTimeEntryIndex(entry);
                    if (newIndex != oldIndex)
                    {
                        // Move if index is differente.
                        await UpdateCollectionAsync(entry, NotifyCollectionChangedAction.Move, newIndex, oldIndex);
                    }

                    // Update in any condition
                    await UpdateCollectionAsync(entry, NotifyCollectionChangedAction.Replace, newIndex);
                }
                else
                {
                    // Update TimeEntry only
                    grp.TimeEntryList.UpdateData(entry);

                    // Update entry
                    newIndex = GetTimeEntryIndex(entry);
                    await UpdateCollectionAsync(entry, NotifyCollectionChangedAction.Replace, newIndex);
                }
            }
            else
            {
                // Add new TimeEntry
                grp = GetGroupFor(entry, out isNewGroup);
                grp.Add(entry);
                Sort();

                // Update group
                groupIndex  = GetDateGroupIndex(grp);
                groupAction = isNewGroup ? NotifyCollectionChangedAction.Add : NotifyCollectionChangedAction.Replace;
                await UpdateCollectionAsync(grp, groupAction, groupIndex);

                // Add new TimeEntry
                newIndex = GetTimeEntryIndex(entry);
                await UpdateCollectionAsync(entry, NotifyCollectionChangedAction.Add, newIndex);
            }
        }
 public void ChangeTimeEntryStart(TimeSpan diffTime)
 {
     data = TimeEntryModel.ChangeStartTime(data, data.StartTime + diffTime);
     UpdateView();
     ServiceContainer.Resolve <ITracker> ().CurrentScreen = "Change Start Time";
 }
Esempio n. 5
0
        private async Task CreateTestData()
        {
            var workspace = await DataStore.PutAsync(new WorkspaceData()
            {
                RemoteId = 1,
                Name     = "Unit Testing",
            });

            var user = await DataStore.PutAsync(new UserData()
            {
                RemoteId           = 1,
                Name               = "Tester",
                DefaultWorkspaceId = workspace.Id,
            });

            tag1 = await DataStore.PutAsync(new TagData()
            {
                RemoteId    = 1,
                Name        = DefaultTag,
                WorkspaceId = workspace.Id,
            });

            tag2 = await DataStore.PutAsync(new TagData()
            {
                RemoteId    = 2,
                Name        = "Tag #2",
                WorkspaceId = workspace.Id,
            });

            tag3 = await DataStore.PutAsync(new TagData()
            {
                RemoteId    = 3,
                Name        = "Tag #3",
                WorkspaceId = workspace.Id,
            });

            timeEntry = await DataStore.PutAsync(new TimeEntryData()
            {
                RemoteId    = 1,
                Description = "Initial concept",
                State       = TimeEntryState.Finished,
                StartTime   = MakeTime(09, 12),
                StopTime    = MakeTime(10, 1),
                WorkspaceId = workspace.Id,
                UserId      = user.Id,
            });

            await DataStore.PutAsync(new TimeEntryTagData()
            {
                RemoteId    = 1,
                TimeEntryId = timeEntry.Id,
                TagId       = tag1.Id,
            });

            await DataStore.PutAsync(new TimeEntryTagData()
            {
                RemoteId    = 2,
                TimeEntryId = timeEntry.Id,
                TagId       = tag2.Id,
            });
        }
Esempio n. 6
0
 public void Add(TimeEntryData dataObject)
 {
     dataObjects.Add(dataObject);
     OnUpdated();
 }
Esempio n. 7
0
 protected virtual Task RemoveEntryAsync(TimeEntryData entry)
 {
     throw new NotImplementedException("You can't call this method in base class " + GetType().Name);
 }
Esempio n. 8
0
        private static void ResetTags(IDataStoreContext ctx, TimeEntryData timeEntryData, TimeEntryJson json)
        {
            // Don't touch the tags when the field is null
            if (json.Tags == null)
            {
                return;
            }

            var con = ctx.Connection;

            // Resolve tags to IDs:
            var tagIds = new List <Guid> ();

            foreach (var tagName in json.Tags)
            {
                // Prevent importing empty (invalid) tags:
                if (String.IsNullOrWhiteSpace(tagName))
                {
                    continue;
                }

                var id = ctx.GetTagIdFromName(timeEntryData.WorkspaceId, tagName);

                if (id == Guid.Empty)
                {
                    // Need to create a new tag:
                    var tagData = new TagData()
                    {
                        Name        = tagName,
                        WorkspaceId = timeEntryData.WorkspaceId,
                    };
                    con.Insert(tagData);

                    id = timeEntryData.Id;
                }

                tagIds.Add(id);
            }

            // Iterate over TimeEntryTags and determine which to keep and which to discard:
            var inters   = con.Table <TimeEntryTagData> ().Where(m => m.TimeEntryId == timeEntryData.Id);
            var toDelete = new List <TimeEntryTagData> ();

            foreach (var inter in inters)
            {
                if (tagIds.Contains(inter.TagId))
                {
                    tagIds.Remove(inter.TagId);
                }
                else
                {
                    toDelete.Add(inter);
                }
            }

            // Delete unused tags intermediate rows:
            foreach (var inter in toDelete)
            {
                ctx.Delete(inter);
            }

            // Create new intermediate rows:
            foreach (var tagId in tagIds)
            {
                ctx.Put(new TimeEntryTagData()
                {
                    TagId       = tagId,
                    TimeEntryId = timeEntryData.Id,
                });
            }
        }
Esempio n. 9
0
        public TimeEntryData Import(IDataStoreContext ctx, TimeEntryJson json, Guid?localIdHint = null, TimeEntryData mergeBase = null)
        {
            var log = ServiceContainer.Resolve <ILogger> ();

            var data = GetByRemoteId <TimeEntryData> (ctx, json.Id.Value, localIdHint);

            var merger = mergeBase != null ? new TimeEntryMerger(mergeBase) : null;

            if (merger != null && data != null)
            {
                merger.Add(new TimeEntryData(data));
            }

            if (json.DeletedAt.HasValue)
            {
                if (data != null)
                {
                    // TODO: Delete TimeEntryTag intermediate data
                    log.Info(Tag, "Deleting local data for {0}.", data.ToIdString());
                    ctx.Delete(data);
                    data = null;
                }
            }
            else if (merger != null || ShouldOverwrite(data, json))
            {
                data = data ?? new TimeEntryData();
                ImportJson(ctx, data, json);

                if (merger != null)
                {
                    merger.Add(data);
                    data = merger.Result;
                }

                if (merger != null)
                {
                    log.Info(Tag, "Importing {0}, merging with local data.", data.ToIdString());
                }
                else
                {
                    log.Info(Tag, "Importing {0}, replacing local data.", data.ToIdString());
                }

                data = ctx.Put(data);

                // Also update tags from the JSON we are merging:
                if (mergeBase == null || (mergeBase != null && mergeBase.ModifiedAt != data.ModifiedAt))
                {
                    log.Info(Tag, "Resetting tags for {0}.", data.ToIdString());
                    ResetTags(ctx, data, json);
                }
            }
            else
            {
                log.Info(Tag, "Skipping import of {0}.", json.ToIdString());
            }

            return(data);
        }
Esempio n. 10
0
 public bool CanContain(TimeEntryData data)
 {
     return(dataObjects.Last().IsGroupableWith(data));
 }
Esempio n. 11
0
 public TimeEntryGroup(TimeEntryData data)
 {
     Add(data);
 }
Esempio n. 12
0
 public void Update(TimeEntryData data)
 {
     dataObjects.UpdateData(data);
     Sort();
 }
Esempio n. 13
0
 public void Add(TimeEntryData data)
 {
     dataObjects.Add(data);
 }
Esempio n. 14
0
 public UserTimeEntryStateChangeMessage(object sender, TimeEntryData data) : base(sender)
 {
     this.data = data;
 }
Esempio n. 15
0
        public static TimeEntryJson Export(this TimeEntryData data, IDataStoreContext ctx)
        {
            var converter = ServiceContainer.Resolve <TimeEntryJsonConverter> ();

            return(converter.Export(ctx, data));
        }
 public EditTimeEntryViewController(TimeEntryData data, List <TagData> tagList)
 {
     this.tagList = tagList;
     this.data    = data;
     ViewModel    = EditTimeEntryViewModel.Init(data, tagList);
 }
Esempio n. 17
0
        private bool FindExistingEntry(TimeEntryData dataObject, out DateGroup dateGroup, out TimeEntryData existingDataObject)
        {
            foreach (var grp in dateGroups)
            {
                foreach (var obj in grp.DataObjects)
                {
                    if (dataObject.Matches(obj))
                    {
                        dateGroup          = grp;
                        existingDataObject = obj;
                        return(true);
                    }
                }
            }

            dateGroup          = null;
            existingDataObject = null;
            return(false);
        }
Esempio n. 18
0
 public TimeEntryGroup(TimeEntryData data)
 {
     DataCollection = new List <TimeEntryData> {
         data
     };
 }
Esempio n. 19
0
 public void Remove(TimeEntryData dataObject)
 {
     dataObjects.Remove(dataObject);
     OnUpdated();
 }
Esempio n. 20
0
 public EditTimeEntryView(TimeEntryData timeEntryData)
 {
     this.timeEntryData = timeEntryData;
     ServiceContainer.Resolve <ITracker> ().CurrentScreen = "Edit Time Entry";
 }
 public void ChangeTimeEntryDuration(TimeSpan newDuration)
 {
     data = TimeEntryModel.SetDuration(data, newDuration);
     UpdateView();
     ServiceContainer.Resolve <ITracker> ().CurrentScreen = "Change Duration";
 }
Esempio n. 22
0
 public static EditTimeEntryViewModel Init(TimeEntryData timeEntryData, List <TagData> tagList)
 {
     return(new EditTimeEntryViewModel(timeEntryData, tagList));
 }
 public void ChangeTimeEntryStop(DateTime newStopTime)
 {
     data = TimeEntryModel.ChangeStoptime(data, newStopTime);
     UpdateView();
     ServiceContainer.Resolve <ITracker> ().CurrentScreen = "Change Stop Time";
 }
Esempio n. 24
0
 public EditTimeEntryFragment(TimeEntryData timeEntry)
 {
     Arguments = new Bundle();
     Arguments.PutString(TimeEntryIdArgument, timeEntry.Id.ToString());
     viewModel = new EditTimeEntryView(timeEntry);
 }