Ejemplo n.º 1
0
 public async void DeleteTodo(Todo todo)
 {
     MessageDialog dlg = new MessageDialog("确定要删除此检查项吗?", "提示");
     dlg.Commands.Add(new UICommand("删除", async command =>
     {
         this.StartProgress();
         bool result = await Helper.WorktileClient.DeleteTaskTodo(Task.Pid, Task.Tid, todo.TodoId);
         this.EndProgress();
         if(result)
         {
             Task.Todos.Remove(todo);
         }
         else
         {
             ShowAlert("删除检查项失败,请稍后重试!");
         }
     }));
     dlg.Commands.Add(new UICommand("取消"));
     dlg.DefaultCommandIndex = 0;
     dlg.CancelCommandIndex = 1;
     await dlg.ShowAsync();
 }
Ejemplo n.º 2
0
 public async void UpdateTodoName(Todo todo)
 {
     InputTextDialog inputTextDialog = new InputTextDialog("修改检查项","检查项名称",todo.Name);
     inputTextDialog.PrimaryButtonClick += (async (ContentDialog sender, ContentDialogButtonClickEventArgs e) =>
     {
         InputTextViewModel vm = (InputTextViewModel)sender.DataContext;
         this.StartProgress();
         Todo returnTodo = await Helper.WorktileClient.UpdateTaskTodo(Task.Pid, Task.Tid, todo.TodoId, vm.InputValue);
         this.EndProgress();
         if (returnTodo != null)
         {
             todo.Name = returnTodo.Name;
         }
         else
         {
             ShowAlert("更新检查项内容失败,请稍后重试!");
         }
     });
     await inputTextDialog.ShowAsync();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取项目的任务列表
        /// </summary>
        /// <param name="ProjectId">项目id</param>
        /// <param name="Type">任务类型:all:默认,completed:已完成,uncompleted:未完成,expired:已过期</param>
        /// <returns>ObservableCollection<Task></returns>
        public static async Task<ObservableCollection<Worktile.Model.Task>> GetProjectTaskList(string ProjectId, string Type = "all")
        {
            string url = apiUrl + "tasks" ;
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("pid", ProjectId);
            parameters.Add("access_token", AccessToken);
            parameters.Add("type", Type);
            parameters.Add("rnd", new Random(100).Next().ToString());

            string json = await Helper.HttpHelper.DoGet(url, parameters);
            if (string.IsNullOrEmpty(json))
            {
                return null;
            }
            else
            {
                //开始解析返回数据
                try
                {
                    Debug.WriteLine("开始解析返回json---\n" + json);
                    JArray result = JArray.Parse(json);
                    Debug.WriteLine("解析返回json成功---\n");

                    ObservableCollection<Model.Task> TaskList = new ObservableCollection<Model.Task>();
                    foreach (JObject obj in result)
                    {
                        Model.Task task = new Model.Task();
                        task.Name = obj["name"].ToString();
                        task.Pid = obj["pid"].ToString();
                        task.Tid = obj["tid"].ToString();
                        task.EntryId = obj["entry_id"].ToString();
                        task.EntryName = obj["entry_name"].ToString();
                        task.CreateTime = (DateTime)obj["created_at"];
                        task.UpdateTime = (DateTime)obj["updated_at"];
                        task.Position = (int)obj["pos"];

                        foreach (JObject jLabel in (JArray)obj["labels"])
                        {
                            Label label = new Label();
                            label.Name = jLabel["name"].ToString();
                            label.Color = label.Name.Substring(0, 1).ToUpper() + label.Name.Substring(1);
                            label.Description = jLabel["desc"].ToString();
                            task.Labels.Add(label);
                        }
                        foreach (JObject jTodo in (JArray)obj["todos"])
                        {
                            Todo todo = new Todo();
                            todo.TodoId = jTodo["todo_id"].ToString();
                            todo.Name = jTodo["name"].ToString();
                            todo.Checked = (Model.Task.TaskCompleted)int.Parse(jTodo["checked"].ToString());
                            todo.Position = jTodo["pos"].ToString();
                            task.Todos.Add(todo);
                        }
                        JObject jBadge = (JObject)obj["badges"];
                        TaskBadge badge = new TaskBadge();
                        if (!string.IsNullOrEmpty(jBadge["expire_date"].ToString()))
                        {
                            badge.ExpireDate = (DateTime)jBadge["expire_date"];
                        }
                        badge.CommentCount = (int)jBadge["comment_count"];
                        badge.TodoCheckedCount = (int)jBadge["todo_checked_count"];
                        badge.TodoCount = (int)jBadge["todo_count"];
                        badge.FileCount = (int)jBadge["file_count"];
                        task.Badges = badge;

                        foreach (JObject jWacher in (JArray)obj["watchers"])
                        {
                            MemberInfo wacher = new MemberInfo();
                            wacher.Uid = jWacher["uid"].ToString();
                            wacher.Name = jWacher["name"].ToString();
                            wacher.NickName = jWacher["display_name"].ToString();
                            wacher.HeadImage = jWacher["avatar"].ToString();
                            wacher.Description = jWacher["desc"].ToString();
                            wacher.Status = (UserProfile.UserStatus)int.Parse(jWacher["status"].ToString());
                            wacher.Online = (UserProfile.UserOnline)int.Parse(jWacher["online"].ToString());
                            task.Watchers.Add(wacher);
                        }
                        foreach (JObject jMember in (JArray)obj["members"])
                        {
                            MemberInfo member = new MemberInfo();
                            member.Uid = jMember["uid"].ToString();
                            member.Name = jMember["name"].ToString();
                            member.NickName = jMember["display_name"].ToString();
                            member.HeadImage = jMember["avatar"].ToString();
                            member.Description = jMember["desc"].ToString();
                            member.Status = (UserProfile.UserStatus)int.Parse(jMember["status"].ToString());
                            member.Online = (UserProfile.UserOnline)int.Parse(jMember["online"].ToString());
                            task.Members.Add(member);
                        }
                        task.Completed = (Model.Task.TaskCompleted)int.Parse(obj["completed"].ToString());
                        if (!string.IsNullOrEmpty(obj["expire_date"].ToString()))
                        {
                            task.ExpireDate = (DateTime)obj["expire_date"];
                        }
                        task.Description = obj["desc"].ToString();
                        ProjectInfo project = new ProjectInfo();
                        JObject jProject = (JObject)obj["project"];
                        project.Pid = jProject["pid"].ToString();
                        project.Name = jProject["name"].ToString();
                        project.Picture = jProject["pic"].ToString();
                        project.BackgroundColor = jProject["bg"].ToString();
                        task.Project = project;
                        TaskList.Add(task);
                    }
                    return TaskList;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }
        }
Ejemplo n.º 4
0
 public async void SwitchTodoState(Todo todo)
 {
     this.StartProgress();
     bool result = false;
     if(todo.Checked == Model.Task.TaskCompleted.Completed)
     {
         result = await Helper.WorktileClient.CancelCompleteTaskTodo(Task.Pid, Task.Tid,todo.TodoId);
     }else
     {
         result = await Helper.WorktileClient.CompleteTaskTodo(Task.Pid, Task.Tid,todo.TodoId);
     }
     if(result)
     {
         todo.Checked = todo.Checked == Model.Task.TaskCompleted.Completed ? Model.Task.TaskCompleted.UnCompleted : Model.Task.TaskCompleted.Completed;
     }else
     {
         ShowAlert("更新检查项状态失败,请稍后重试!");
     }
     this.EndProgress();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 修改检查项
        /// </summary>
        /// <param name="ProjectId">项目id</param>
        /// <param name="TaskId">任务id</param>
        /// <param name="TodoId">检查项id</param>
        /// <param name="Name">检查项内容</param>
        /// <returns>Todo</returns>
        public async static Task<Todo> UpdateTaskTodo(string ProjectId, string TaskId,string TodoId, string Name)
        {
            string url = apiUrl + "tasks/" + TaskId + "/todos/" + TodoId + "?pid=" + ProjectId + "&access_token=" + AccessToken;
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("name", Name);

            string json = await Helper.HttpHelper.DoPut(url, parameters);
            if (string.IsNullOrEmpty(json))
            {
                return null;
            }
            else
            {
                //开始解析返回数据
                try
                {
                    Debug.WriteLine("开始解析返回json---\n" + json);
                    JObject result = JObject.Parse(json);
                    Debug.WriteLine("解析返回json成功---\n");

                    Todo todo = new Todo();
                    todo.TodoId = result["todo_id"].ToString();
                    todo.Name = result["name"].ToString();
                    todo.Position = result["pos"].ToString();
                    todo.Checked = (Model.Task.TaskCompleted)int.Parse(result["checked"].ToString());

                    return todo;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }
        }