Exemplo n.º 1
0
        private void ToolbarClicked(object sender, EventArgs e)
        {
            ToolbarItem tappedItem = sender as ToolbarItem;

            if (tappedItem == m_mnuProjectInfo)
            {
                ProjectInfoPage p = new ProjectInfoPage();
                p.Description.Text = m_proj.Description;
                p.Title            = this.Title;
                ((NavigationPage)m_mdp.Detail).PushAsync(p);
            }
            else if (tappedItem == m_mnuDelProj)
            {
                Prompt p = new Prompt()
                {
                    PromptTitle = "Are you sure?", PositiveButtonText = "Yes", NegativeButtonText = "No"
                };
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    DeleteCommand cmd = new DeleteCommand()
                    {
                        Title = m_proj.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the project list
                        ((MainPage)m_mdp).DeleteProject(m_proj);
                        //go back to the home page
                        ((MainPage)m_mdp).DisplayHome();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(m_mdp);
            }
            else if (tappedItem == m_mnuAddMember)
            {
                TextPrompt p = new TextPrompt()
                {
                    PromptTitle = "Enter a Mattermost User ID", Hint = "user_id", PositiveButtonText = "Add", NegativeButtonText = "Cancel", Keyboard = Keyboard.Plain
                };
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    AddMemberCommand cmd = new AddMemberCommand()
                    {
                        Project = m_proj.ID, Member = p.Text
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the task with the new member
                        Member newMember = new Member()
                        {
                            Role = Role.MEMBER, ID = p.Text
                        };
                        m_proj.Members.Add(newMember);
                        //reload the project display
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(m_mdp);
            }
            else if (tappedItem == m_mnuCreateTask)
            {
                ManageTaskPrompt p = new ManageTaskPrompt(m_proj)
                {
                    CanAssign = false, CanSetTitle = true, CanDelete = false, PositiveButtonText = "Create", NegativeButtonText = "Cancel"
                };
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    CreateTaskCommand cmd = new CreateTaskCommand()
                    {
                        Project = m_proj.ID, Title = p.TaskTitle, Due = p.Date, Description = p.Description
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the project with the new Task
                        Models.Task t = new Models.Task()
                        {
                            Name = p.TaskTitle, Due = p.Date, Description = p.Description
                        };
                        m_proj.Tasks.Add(t);
                        //reload the project display
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(m_mdp);
            }
        }
Exemplo n.º 2
0
        public MainPage()
        {
            InitializeComponent();
            MasterPage.ListView.ItemSelected += ListView_ItemSelected;

            m_lblCurTeam   = MasterPage.RootView.FindByName <Label>("txt_cur_team");
            m_lblCurUserId = MasterPage.RootView.FindByName <Label>("txt_cur_userid");

            m_mnuAdminTitle     = MasterPage.RootView.FindByName <StackLayout>("mnu_admin_title");
            m_cellMemberPerms   = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_perms_table");
            m_cellCreateProject = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_create_project");

            m_cellLogin = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_login");
            m_cellAddr  = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_addr");

            //get the config class (will be different based on the platform we built)
            m_config = ConfigFactory.GetInstance();

            //set up the login clicked event listener
            m_cellLogin.Clicked += (o, e) =>
            {
                this.IsPresented = false; //hide the sidebar thing

                if (m_cellLogin.Text == "Logout")
                { //if logout button, do logout and skip the login actions
                    LogoutCommand cmd = new LogoutCommand();
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if (((string)response.GetValue("msg") != "" && response.GetValue("msg") != null) || !(bool)response.GetValue("result"))
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        CompleteLogout();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                    return;
                }
                //execute the login command
                CredsPrompt p = new CredsPrompt()
                {
                    PromptTitle = "Login"
                };
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    LoginCommand cmd = new LoginCommand()
                    {
                        Username = p.Username, Password = p.Password
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("msg") != "" && response.GetValue("msg") != null)
                        { //check if an error was thrown when contacting the server
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        if (response.GetValue("token") == null)
                        { //if token is null then assume the login failed
                            DependencyService.Get <INotification>().ShortAlert("ERROR: Invalid Credentials");
                            return;
                        }
                        m_config.Token = (string)response.GetValue("token");
                        CondorAPI.getInstance().Token = m_config.Token;
                        m_myusername = (string)response.GetValue("username");
                        CompleteLogin();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(this);
            };

            //set up the server address menu event listener
            m_cellAddr.Clicked += new EventHandler((o, e) =>
            {
                this.IsPresented = false;
                AskServerAddress();
            });

            //set up the member permissions menu event listener
            m_cellMemberPerms.Clicked += new EventHandler((o, e) =>
            {
                ((NavigationPage)Detail).PushAsync(new MemberPermsPage(this));
                //hide the sidebar
                this.IsPresented = false;
            });

            //set up the create project menu event listener
            m_cellCreateProject.Clicked += new EventHandler((o, e) =>
            {
                ManageTaskPrompt p = new ManageTaskPrompt(null)
                {
                    PromptTitle = "Create Project", CanAssign = false, CanDelete = false, CanSetTitle = true, CanSetDate = false, PositiveButtonText = "Create"
                };
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    CreateCommand cmd = new CreateCommand()
                    {
                        Creator = m_myusername, Title = p.TaskTitle, Description = p.Description
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //add the new project
                        Project newProject     = new Project(p.PromptTitle.Replace(' ', '_').ToLower());
                        newProject.Title       = p.PromptTitle;
                        newProject.Description = p.Description;
                        //add the creator as a member of the project
                        Member newProjectCreator = new Member();
                        newProjectCreator.ID     = m_myusername;
                        newProjectCreator.Role   = Role.MANAGER;
                        newProject.Members.Add(newProjectCreator);
                        //add the project to the project list
                        m_projects.AppendProject(newProject);
                        //reload the projects list in the sidebar
                        FillProjectsList();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(this);
                //hide the sidebar
                this.IsPresented = false;
            });

            if (m_config.Address != null && !m_config.Address.Equals(""))
            { //if a server address is specified, initialize the app
                Initialize();
            }
            else
            { //otherwise ask for a server address
                AskServerAddress();
            }
        }
Exemplo n.º 3
0
        private void ListItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            ListView senderLV  = (ListView)sender;
            object   tappedObj = e.SelectedItem;

            //don't allow items to be selected
            senderLV.SelectedItem = null;

            //this will be called again when we clear the SelectedItem, so this is here to skip that call
            if (tappedObj == null)
            {
                return;
            }

            if (senderLV == m_lstMembers && m_permManageMembers)
            { //member list triggered this event
                Member tappedMember = tappedObj as Member;
                //can't manage myself
                if (tappedMember == m_me)
                {
                    return;
                }
                ManageMemberPrompt p = new ManageMemberPrompt();
                if (tappedMember.Role == Role.MEMBER)
                {
                    p.State = ManageMemberPrompt.BtnState.PROMOTE;
                }
                else if (tappedMember.Role == Role.MANAGER)
                {
                    p.State = ManageMemberPrompt.BtnState.DEMOTE;
                }
                p.OnPromote += new EventHandler((o, e2) =>
                {
                    PromoteMemberCommand cmd = new PromoteMemberCommand()
                    {
                        Project = m_proj.ID, Member = tappedMember.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        tappedMember.Role = Role.MANAGER;
                        p.State           = ManageMemberPrompt.BtnState.DEMOTE;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDemote += new EventHandler((o, e2) =>
                {
                    DemoteMemberCommand cmd = new DemoteMemberCommand()
                    {
                        Project = m_proj.ID, Member = tappedMember.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        tappedMember.Role = Role.MEMBER;
                        p.State           = ManageMemberPrompt.BtnState.PROMOTE;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDelete += new EventHandler((o, e2) =>
                {
                    Prompt pc = new Prompt()
                    {
                        PromptTitle = "Are you sure?", PositiveButtonText = "Yes", NegativeButtonText = "No"
                    };
                    pc.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                    {
                        DeleteMemberCommand cmd = new DeleteMemberCommand()
                        {
                            Project = m_proj.ID, Member = tappedMember.ID
                        };
                        cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                        {
                            if ((string)response.GetValue("result") != "success")
                            {
                                DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                                return;
                            }
                            m_proj.Members.Remove(tappedMember);
                            ReloadProjectDisplay();
                            pc.Dismiss();
                            p.Dismiss();
                        });
                        CondorAPI.getInstance().Execute(cmd);
                    });
                    pc.Show(m_mdp);
                });
                p.Show(m_mdp);
            }
            else if (senderLV == m_lstMyTasks)
            { //my tasks list triggered this event
                Models.Task        tappedTask = tappedObj as Models.Task;
                ManageMyTaskPrompt p          = new ManageMyTaskPrompt(tappedTask);
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    //do nothing if nothing was changed
                    if (p.SelectedStatus == tappedTask.Status)
                    {
                        return;
                    }
                    //execute the command to set the task status
                    SetTaskStatusCommand cmd = new SetTaskStatusCommand()
                    {
                        Project = m_proj.ID, Task = tappedTask.Name, Status = p.SelectedStatus.str
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the status and reload the display
                        tappedTask.Status = p.SelectedStatus;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(m_mdp);
            }
            else if (senderLV == m_lstAllTasks && m_permManageTasks)
            { //all tasks list triggered this event
                Models.Task      tappedTask = tappedObj as Models.Task;
                ManageTaskPrompt p          = new ManageTaskPrompt(m_proj);
                p.Date           = tappedTask.Due;
                p.Description    = tappedTask.Description;
                p.Status         = (tappedTask.Assigned == null) ? ManageTaskPrompt.BtnStatus.ASSIGN : ManageTaskPrompt.BtnStatus.DEASSIGN;
                p.AssignedMember = tappedTask.Assigned;
                p.OnAssign      += new EventHandler((o, e2) =>
                {
                    AssignTaskCommand cmd = new AssignTaskCommand()
                    {
                        Project = m_proj.ID, Task = tappedTask.Name, Member = p.AssignedMember.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the dialog
                        p.HidePicker();
                        p.Status = ManageTaskPrompt.BtnStatus.DEASSIGN;
                        //update the task and reload the display
                        tappedTask.Assigned = p.AssignedMember;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDeassign += new EventHandler((o, e2) =>
                {
                    DeassignTaskCommand cmd = new DeassignTaskCommand()
                    {
                        Project = m_proj.ID, Task = tappedTask.Name
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the dialog
                        p.Status = ManageTaskPrompt.BtnStatus.ASSIGN;
                        //update the task and reload the display
                        tappedTask.Assigned = null;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDelete += new EventHandler((o, e2) =>
                {
                    DeleteTaskCommand cmd = new DeleteTaskCommand()
                    {
                        Project = m_proj.ID, Title = tappedTask.Name
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //remove the task from the list
                        m_proj.Tasks.Remove(tappedTask);
                        //reload the display
                        ReloadProjectDisplay();
                        //close the prompt
                        p.Dismiss();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    //update the due date if changed
                    if (p.Date.ToFileTimeUtc() != tappedTask.Due.ToFileTimeUtc())
                    {
                        SetTaskDueCommand cmd = new SetTaskDueCommand()
                        {
                            Project = m_proj.ID, Task = tappedTask.Name, Due = p.Date
                        };
                        cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                        {
                            if ((string)response.GetValue("result") != "success")
                            {
                                DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                                return;
                            }
                            //update the due date
                            tappedTask.Due = p.Date;
                            //reload the display
                            ReloadProjectDisplay();
                        });
                        CondorAPI.getInstance().Execute(cmd);
                    }
                    //update the description if changed
                    if (p.Description != tappedTask.Description)
                    {
                        SetTaskDescCommand cmd = new SetTaskDescCommand()
                        {
                            Project = m_proj.ID, Task = tappedTask.Name, Description = p.Description
                        };
                        cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                        {
                            if ((string)response.GetValue("result") != "success")
                            {
                                DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                                return;
                            }
                            //update the description
                            tappedTask.Description = p.Description;
                            //reload the display
                            ReloadProjectDisplay();
                        });
                        CondorAPI.getInstance().Execute(cmd);
                    }
                });
                p.Show(m_mdp);
            }
        }