示例#1
0
 private void JsonObjectToTask(JsonObject json, Model.Task task)
 {
     task.Id        = GetAsString(json, "id");
     task.Title     = GetAsString(json, "title");
     task.Updated   = GetAsDateTime(json, "updated");
     task.SelfLink  = GetAsString(json, "selfLink");
     task.Parent    = GetAsString(json, "parent");
     task.Position  = GetAsString(json, "position");
     task.Notes     = GetAsString(json, "notes");
     task.Status    = GetAsString(json, "status");
     task.Due       = GetAsDateTime(json, "due");
     task.Completed = GetAsDateTime(json, "completed");
     task.Deleted   = GetAsBool(json, "deleted");
     task.Hidden    = GetAsBool(json, "hidden");
     if (json.ContainsKey("links"))
     {
         JsonArray linksArray = json.GetNamedArray("links");
         Link[]    links      = new Link[linksArray.Count];
         for (uint j = 0; j < linksArray.Count; j++)
         {
             Link       link       = new Link();
             JsonObject linkObject = linksArray.GetObjectAt(j);
             link.Type        = GetAsString(linkObject, "type");
             link.Description = GetAsString(linkObject, "description");
             link.Url         = GetAsString(linkObject, "link");
             links[j]         = link;
         }
         task.Links = links;
     }
 }
示例#2
0
        public async System.Threading.Tasks.Task UpdateTask(Model.Task task, TaskList list)
        {
            string     address  = "/lists/" + list.Id + "/tasks/" + task.Id;
            JsonObject json     = TaskToJsonObject(task);
            JsonObject response = await MakePutRequest(address, json);

            JsonObjectToTask(response, task);
        }
示例#3
0
        private void delete_Click(object sender, RoutedEventArgs e)
        {
            TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"];

            Data.Model.Task toDelete = null;
            foreach (Data.Model.TaskList list in taskDataSource.TaskLists)
            {
                if (list.Title == selectedTask.ListTitle)
                {
                    foreach (Data.Model.Task task in list.Tasks)
                    {
                        if (task.Id != null && task.Id == selectedTask.Id)
                        {
                            task.Deleted = true;
                            toDelete     = task;
                            break;
                        }
                    }
                    if (toDelete == null)
                    {
                        // not found, probably task not synchronized so does not have id, trying to find by title
                        foreach (Data.Model.Task task in list.Tasks)
                        {
                            if (task.Title != null && task.Title == selectedTask.Title)
                            {
                                task.Deleted = true;
                                toDelete     = task;
                                break;
                            }
                        }
                    }
                }
            }
            if (toDelete != null)
            {
                showEmptyTaskTextBlock(Messages.GetMsgValue(MessageKey.SELECT_TASK));

                // trying to delete from tasksView
                ObservableCollection <Data.Model.Task> tasksFromView = (ObservableCollection <Data.Model.Task>)tasksView.ItemsSource;
                Data.Model.Task toDeleteFromVisible = null;
                foreach (Data.Model.Task taskFromView in tasksFromView)
                {
                    if ((taskFromView.Id != null && taskFromView.Id == toDelete.Id) || taskFromView.Title == toDelete.Title)
                    {
                        toDeleteFromVisible = taskFromView;
                        break;
                    }
                }
                if (toDeleteFromVisible != null)
                {
                    tasksFromView.Remove(toDeleteFromVisible);
                }
                taskDataSource.RefreshLists();
                RefreshCounters(taskDataSource);
                hideTaskEditButtons();
            }
        }
示例#4
0
        /* Inserts Task to the specified TaskList and updates its details */
        public async System.Threading.Tasks.Task InsertTask(Model.Task task, TaskList list)
        {
            string     address  = "/lists/" + list.Id + "/tasks";
            JsonObject json     = TaskToJsonObject(task);
            JsonObject response = await MakePostRequest(address, json);

            JsonObjectToTask(response, task);
            task.ListTitle = list.Title;
        }
示例#5
0
        async private Task showTask(Data.Model.Task t)
        {
            if (editMode)
            {
                await PopupEditWarningDialog();

                return;
            }

            this.taskListTextBox.Text  = t.ListTitle;
            this.taskTitleTextBox.Text = t.Title;
            this.taskNotesTextBox.Text = t.Notes;

            if (t.Status == "completed")
            {
                hideTaskEditButtons();
                this.delete.Visibility           = Windows.UI.Xaml.Visibility.Visible;
                this.taskUpdatedDateLabel.Text   = "Completed:";
                this.taskUpdatedDateTextBox.Text = t.Completed.ToString();

                taskDueDateLabel.Visibility   = Visibility.Collapsed;
                taskDueDateTextBox.Visibility = Visibility.Collapsed;
                editDueDate.Visibility        = Visibility.Collapsed;
            }
            else
            {
                showTaskEditButtons();
                this.taskUpdatedDateLabel.Text   = "Updated:";
                this.taskUpdatedDateTextBox.Text = t.Updated.ToString();

                taskDueDateLabel.Visibility   = Visibility.Visible;
                taskDueDateTextBox.Visibility = Visibility.Visible;
                editDueDate.Visibility        = Visibility.Visible;
                this.taskDueDateLabel.Text    = "Due:";
                taskDueDateLabel.Foreground   = new SolidColorBrush(Colors.Gray);
                taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Gray);
                if (t.Due != DateTime.MinValue)
                {
                    this.taskDueDateTextBox.Text = t.Due.Date.ToString();
                    if (t.IsOverdue)
                    {
                        taskDueDateLabel.Foreground   = new SolidColorBrush(Colors.Red);
                        taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Red);
                    }
                }
                else
                {
                    this.taskDueDateTextBox.Text = "None";
                }
            }

            HideEmptyTaskTextBlockIfNeeded(t.Status == "completed");
            this.selectedTask = t;
        }
示例#6
0
        public async Task <ObservableCollection <Kompitu.Data.Model.Task> > GetTasks(TaskList taskList)
        {
            string     address = "/lists/" + taskList.Id + "/tasks";
            JsonObject json    = await MakeGetRequest(address);

            ObservableCollection <Kompitu.Data.Model.Task> tasks = new ObservableCollection <Kompitu.Data.Model.Task>();

            if (json.ContainsKey("items"))
            {
                JsonArray lists = json.GetNamedArray("items");
                for (uint i = 0; i < lists.Count; i++)
                {
                    Kompitu.Data.Model.Task task = new Kompitu.Data.Model.Task();
                    JsonObject taskObject        = lists.GetObjectAt(i);
                    JsonObjectToTask(taskObject, task);
                    task.ListTitle = taskList.Title;
                    tasks.Add(task);
                }
            }
            return(tasks);
        }
示例#7
0
        private JsonObject TaskToJsonObject(Model.Task task)
        {
            JsonObject json = new JsonObject();

            json.Add("kind", JsonValue.CreateStringValue("tasks#task"));
            if (task.Id != null)
            {
                json.Add("id", JsonValue.CreateStringValue(task.Id));
            }
            json.Add("title", JsonValue.CreateStringValue(task.Title));
            json.Add("updated", JsonValue.CreateStringValue(task.Updated.ToString("yyyy-MM-dd'T'HH:mm:ss.000Z")));
            if (task.Due != DateTime.MinValue)
            {
                json.Add("due", JsonValue.CreateStringValue(task.Due.ToString("yyyy-MM-dd'T'HH:mm:ss.000Z")));
            }
            json.Add("notes", JsonValue.CreateStringValue(task.Notes));
            json.Add("status", JsonValue.CreateStringValue(task.Status));
            if (task.Status == "completed")
            {
                json.Add("completed", JsonValue.CreateStringValue(task.Completed.ToString("yyyy-MM-dd'T'HH:mm:ss.000Z")));
            }
            return(json);
        }
示例#8
0
 private void markTaskCompleted(Data.Model.Task task)
 {
     task.Status    = "completed";
     task.Completed = DateTime.Now;
     task.Updated   = DateTime.Now;
 }
示例#9
0
        private void SaveNewTask()
        {
            string selectedList = null;
            // show select list popup
            Popup myPopup = new Popup();

            myPopup.HorizontalAlignment   = HorizontalAlignment.Center;
            myPopup.VerticalAlignment     = VerticalAlignment.Center;
            myPopup.IsLightDismissEnabled = false;

            Border b = new Border();

            b.BorderBrush     = new SolidColorBrush(Colors.Gray);
            b.BorderThickness = new Thickness(2);
            b.Width           = 400;

            StackPanel s = new StackPanel();

            b.Child       = s;
            s.Orientation = Orientation.Vertical;
            s.Width       = 400;
            s.Background  = new SolidColorBrush(Colors.White);

            TextBlock text = new TextBlock();

            text.Text       = "Select a list for the task:";
            text.Margin     = new Thickness(10, 5, 20, 0);
            text.Foreground = new SolidColorBrush(Colors.SteelBlue);
            text.FontSize   = 16;
            s.Children.Add(text);

            ComboBox       combo          = new ComboBox();
            TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"];

            combo.ItemsSource       = taskDataSource.VisibleTaskLists;
            combo.DisplayMemberPath = "Title";

            s.Children.Add(combo);
            combo.Margin        = new Thickness(10, 5, 10, 5);
            combo.SelectedIndex = combo.Items.Count - 1;

            Button ok = new Button();

            ok.HorizontalAlignment = HorizontalAlignment.Right;
            ok.Margin  = new Thickness(10, 0, 10, 5);
            ok.Content = "OK";
            ok.Click  += new RoutedEventHandler(async delegate(object sender1, RoutedEventArgs ev)
            {
                selectedList
                    = ((Data.Model.TaskList)combo.SelectedValue).Title;
                Data.Model.TaskList selectedListObject = Data.Model.TaskList.GetByTitle(selectedList, taskDataSource.VisibleTaskLists);
                foreach (Data.Model.Task selectedListTask in selectedListObject.Tasks)
                {
                    if (selectedListTask.Title == taskTitleTextBox.Text)
                    {
                        var messageDialog =
                            new Windows.UI.Popups.MessageDialog(
                                Messages.GetMsgValue(MessageKey.TASK_TITLE_EXISTS_CNTNT), Messages.GetMsgValue(MessageKey.TASK_TITLE_EXISTS_HDR));

                        messageDialog.Commands.Add(new UICommand("OK"));

                        messageDialog.DefaultCommandIndex = 0;
                        await messageDialog.ShowAsync();
                        myPopup.IsOpen = false;
                        return;
                    }
                }
                myPopup.IsOpen                   = false;
                Data.Model.Task task             = new Data.Model.Task();
                task.Updated                     = DateTime.Now;
                this.taskUpdatedDateLabel.Text   = "Updated";
                this.taskUpdatedDateTextBox.Text = task.Updated.ToString();
                task.Title     = taskTitleTextBox.Text;
                task.ListTitle = selectedList;
                task.Status    = "needsAction";
                if (taskDueDateTextBox.Text == "None")
                {
                    task.Due = DateTime.MinValue;
                }
                else
                {
                    task.Due = DateTime.Parse(taskDueDateTextBox.Text);
                }
                if (task.Due == DateTime.MinValue || DateTime.Compare(task.Due, DateTime.Now) >= 0)
                {
                    // not overdue
                    taskDueDateLabel.Foreground   = new SolidColorBrush(Colors.Gray);
                    taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Gray);
                }
                else if (task.Due != DateTime.MinValue && DateTime.Compare(task.Due, DateTime.Now) < 0)
                {
                    taskDueDateLabel.Foreground   = new SolidColorBrush(Colors.Red);
                    taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Red);
                }
                task.Notes     = taskNotesTextBox.Text;
                task.ListTitle = selectedList;
                bool added     = false;
                foreach (Data.Model.TaskList list in taskDataSource.TaskLists.Where(l => l.Title == selectedList))
                {
                    list.Tasks.Add(task);
                    added = true;
                }
                if (added)
                {
                    taskListTextBox.Text = selectedList;
                    selectedTask         = task;
                    taskDataSource.RefreshLists();
                    RefreshCounters(taskDataSource);
                    DisableTaskEditMode(selectedTask);
                    if (selectedTaskList != null)
                    {
                        if (selectedList == selectedTaskList.Title)
                        {
                            ((ObservableCollection <Data.Model.Task>)tasksView.ItemsSource).Add(task);
                        }
                    }
                }
            });
            s.Children.Add(ok);

            myPopup.Child = b;

            myPopup.IsOpen = true;
            myCanvas1.Children.Add(myPopup);
        }
示例#10
0
 private bool IsNotHiddenOrDeleted(Model.Task task)
 {
     return(!(task.Hidden || task.Deleted));
 }
示例#11
0
        public async System.Threading.Tasks.Task DeleteTask(Model.Task task, TaskList list)
        {
            string address = "/lists/" + list.Id + "/tasks/" + task.Id;

            await MakeDeleteRequest(address);
        }