Beispiel #1
0
    def update(self, project_name: str):
        """update project name and description"""
        project: Project = self.fetch(project_name)

        if project:
            print(project)

            new_name = str(
                input(
                    Colors.wrap(Colors.YELLOW,
                                "[?] Type name (Enter to skip):")))
            new_description = str(
                input(
                    Colors.wrap(Colors.YELLOW,
                                "[?] Type description (Enter to skip):")))

            if new_name and len(new_name):
                project.name = new_name

            if new_description and len(new_description):
                project.description = new_description

            updated_project: Project = self.api.update(project)
            print(updated_project)
            print(Colors.wrap(Colors.GREEN, "Project updated successfully"))
        else:
            print(Colors.wrap(Colors.RED, "No project is found"))
Beispiel #2
0
 def complete(self, task_name: str):
     task: Task = self.fetch(task_name)
     if task:
         updated_task: Task = self.api.complete(task.id)
         print(updated_task)
         print(Colors.wrap(Colors.GREEN, "Task completed successfully"))
     else:
         print(Colors.wrap(Colors.RED, "Task not found"))
Beispiel #3
0
    def remove(self, project_name: str):
        project: Project = self.fetch(project_name)

        if project:
            project: Project = self.api.delete(project.id)
            print(project)
            print(Colors.wrap(Colors.GREEN, "Project is deleted successfully"))
        else:
            print(Colors.wrap(Colors.RED, "Project not found"))
    def list_all(self):
        sections: List[Section] = self.api.fetch_all(self.project.id)

        if len(sections):
            for section in sections:
                print(section)
            print(
                Colors.wrap(Colors.CYAN, "Total number of sections: ".format(
                    len(sections))))
        else:
            print(Colors.wrap(Colors.RED, "This project has no section"))
Beispiel #5
0
 def show_summary(self):
     if self.description and len(self.description) > 10:
         print(
             Colors.wrap(Colors.UNDERLINE, "Task") +
             ": {} ({}) / {} / {} ".format(self.name, self.id, self.status,
                                           self.description[:10] + " ..."))
     else:
         print(
             Colors.wrap(Colors.UNDERLINE, "Task") +
             ": {} ({}) / {} / {} ".format(self.name, self.id, self.status,
                                           self.description[:10] + " ..."))
Beispiel #6
0
    def create(self, name: str, description=""):
        if len(name) < 3:
            print(
                Colors.wrap(Colors.RED,
                            "Project name must be at least three characters"))
            exit(1)

        project = Project(name, description)
        created_project: Project = self.api.create(project)

        print(created_project)
        print(Colors.wrap(Colors.GREEN, "Project create successfully"))
Beispiel #7
0
 def list_all(self, project_type="active", listing_format="short"):
     projects: Set[Project] = self.api.fetch_all(project_type)
     if projects and len(projects):
         for project in projects:
             if listing_format == "short":
                 project.show_summary()
             else:
                 print(project)
         print(
             Colors.wrap(
                 Colors.CYAN,
                 "Total number of projects: {}".format(len(projects))))
     else:
         print(Colors.wrap(Colors.RED, "No project is found"))
Beispiel #8
0
    def list_all(self, section_name: str, task_status: str, listing_format="long"):
        tasks = self.__get_tasks_by_section(section_name, task_status)

        if tasks and len(tasks):
            for task in tasks:
                if listing_format == "short":
                    task.show_summary()
                else:
                    print(task)
            print(
                Colors.wrap(Colors.CYAN, "Total number of tasks {}".format(len(tasks)))
            )
        else:
            print(Colors.wrap(Colors.RED, "No task is found in this project"))
Beispiel #9
0
    def create(self, task_name: str, task_description: str, section_name: str):
        if len(task_name) < 3:
            raise TaskError("Task name must be at least three characters")

        section: Section = self.api_section.fetch_by_name(section_name, self.project.id)
        if not section:
            print(Colors.wrap(Colors.RED, "Section not found"))
            exit(145)

        task: Task = Task(
            name=task_name, description=task_description, project_id=self.project.id
        )
        task.section_id = section.id
        self.api.create(task)

        print(Colors.wrap(Colors.GREEN, "Task added successfully"))
Beispiel #10
0
    def update(self, task: Task):
        print(Task(task))

        name: str = str(
            input(Colors.wrap(Colors.YELLOW, "[?] Type name (Enter to skip):"))
        )
        if name and len(name):
            task.name = name

        description: str = str(
            input(Colors.wrap(Colors.YELLOW, "[?] Type description (Enter to skip): "))
        )
        if description and len(description):
            task.description = description

        self.api.update(task)
        print(Colors.wrap(Colors.GREEN, "Task updated successfully"))
Beispiel #11
0
 def __get_tasks_by_section(self, section_name: str, task_status: str):
     """Get all tasks based on section name"""
     if section_name != "all":
         section: Section = self.api_section.fetch_by_name(
             section_name, self.project.id
         )
         if not section:
             print(Colors.wrap(Colors.RED, "Section not found"))
             exit(48)
         return self.api.fetch_all_by_section(section.id, task_status)
     else:
         return self.api.fetch_all(self.project.id, task_status)
Beispiel #12
0
    def archive(self, project_id: int):
        while True:
            try:
                choice = str(
                    input(
                        Colors.wrap(
                            Colors.YELLOW,
                            "Do you want to archive this project [y/n] ?")))
                if choice.lower() in ["y", "yes", "no", "n"]:
                    break
                else:
                    raise ValueError("Invalid choice")
            except ValueError:
                print(Colors.wrap(Colors.RED, "Please choose a valid option"))

        if choice.lower() in ["y", "yes"]:

            project: Project = self.api.archive(project_id)
            print(project)
            print(Colors.wrap(Colors.GREEN,
                              "Project is archived successfully"))
        else:
            print(Colors.wrap(Colors.RED, "No project is archived"))
Beispiel #13
0
 def __repr__(self) -> str:
     return "\n".join((
         Colors.wrap(Colors.UNDERLINE, "Name") +
         ": {} / {}".format(self.name, self.id),
         Colors.wrap(Colors.UNDERLINE, "Status") +
         ": {}".format(self.status),
         Colors.wrap(Colors.UNDERLINE, "Description") +
         ": {}".format(self.description),
         Colors.wrap(Colors.UNDERLINE, "Section") +
         ": {}".format(self._section_name),
         Colors.wrap(Colors.UNDERLINE, "Created") +
         ": {} / ".format(self.created) +
         Colors.wrap(Colors.UNDERLINE, "Updated") +
         ": {}".format(self.updated),
         "\n",
     ))
Beispiel #14
0
 def delete(self, section_name: str):
     section: Section = self.fetch(section_name)
     if section:
         self.api.delete(section.id)
         print(Colors.wrap(Colors.GREEN, "Section deleted successfully"))
Beispiel #15
0
 def create(self, section_name: str):
     section: Section = Section(section_name, self.project.id)
     created_section: Section = self.api.create(section)
     print(created_section)
     print(Colors.wrap(Colors.GREEN, "Section created successfully"))
Beispiel #16
0
 def view(self, name: str):
     project: Project = self.fetch(name)
     if project:
         print(project)
     else:
         Colors.wrap(Colors.RED, "No project is found")
Beispiel #17
0
 def move(self, task_id: int, section_id: int):
     task: Task = self.api.move(task_id, section_id)
     print(task)
     print(Colors.wrap(Colors.GREEN, "Task moved successfully"))
Beispiel #18
0
 def handler(**kwargs):
     try:
         func(kwargs)
     except (ProjectError, SectionError, TaskError) as e:
         print(Colors.wrap(Colors.RED, e))
         exit(1)
Beispiel #19
0
 def handler(*args):
     try:
         return func(*args)
     except requests.exceptions.ConnectionError:
         print(Colors.wrap(Colors.RED, "No internet connection"))
         exit(2)