Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds +VISIBLE metatag #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion doc/taskwiki.txt
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ Examples:
-----------------------
5.2.5 Meta virtual tags

Currently there is one meta virtual tag: -VISIBLE. This tag can be used to
Currently there is one meta virtual tag: VISIBLE. This tag can be used to
filter out tasks that are displayed elsewhere in the same taskwiki file.

Example:
Expand All @@ -414,6 +414,15 @@ Example:
~ == Work coding tasks | project:Work.Coding ==
~ == Work review tasks | project:Work.Review ==

Reversely, it can be used to display under a viewport only tasks that are
already displayed in the same taskwiki file.

Example:

~ == All work tasks by priority | +VISIBLE
~ == Task for main work | project:Work.main ==
~ == Tasks for weekend work | project:Work.weekend ==

----------------
5.2.6 Inspection

Expand Down
26 changes: 18 additions & 8 deletions taskwiki/viewport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ViewPort(object):
* [ ] Make sure the hosting is working
"""

meta_tokens = ('-VISIBLE',)
meta_tokens = ('-VISIBLE', '+VISIBLE')

def __init__(self, line_number, cache, tw,
name, filterstring, defaultstring, sort=None):
Expand Down Expand Up @@ -171,6 +171,8 @@ def get_complement_tag(tag):
for token in taskfilter_args:
if token == '-VISIBLE':
meta['visible'] = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
meta['visible'] = False
if token == '-VISIBLE' or token == '+VISIBLE':
meta['visible'] = token[0] == '+'

elif token == '+VISIBLE':
meta['visible'] = True

taskfilter_args = [x for x in taskfilter_args
if x not in self.meta_tokens]
Expand Down Expand Up @@ -282,7 +284,7 @@ def matching_tasks(self):
task for task in self.tw.tasks.filter(*args)
)
# -VISIBLE virtual tag used
elif self.meta.get('visible') is False:
elif self.meta.get('visible') is not None:
# Determine which tasks are outside the viewport
all_vwtasks = set(self.cache.vwtask.values())
vwtasks_outside_viewport = all_vwtasks - set(self.tasks)
Expand All @@ -291,12 +293,20 @@ def matching_tasks(self):
if t is not None
)

# Return only those that are not duplicated outside
# of the viewport
return set(
task for task in self.tw.tasks.filter(*args)
if task not in tasks_outside_viewport
)
if not self.meta['visible']:
# Return only those that are not duplicated outside
# of the viewport
return set(
task for task in self.tw.tasks.filter(*args)
if task not in tasks_outside_viewport
)
else:
# Return only those that are duplicated outside
# of the viewport
return set(
task for task in self.tw.tasks.filter(*args)
if task in tasks_outside_viewport
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            return set(
                task for task in self.tw.tasks.filter(*args)
                if (task in tasks_outside_viewport) == self.meta['visible']
            )


def get_tasks_to_add_and_del(self):
# Find the tasks that are new and tasks that are no longer
Expand Down
67 changes: 65 additions & 2 deletions tests/test_viewport.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def execute(self):
assert self.py("print(vim.current.buffer)", regex="<buffer taskwiki.")


class TestViewportInspectionWithVisibleTag(MultiSyntaxIntegrationTest):
class TestViewportInspectionWithNonVisibleTag(MultiSyntaxIntegrationTest):

viminput = """
HEADER2(Work tasks | +work -VISIBLE)
Expand Down Expand Up @@ -315,6 +315,42 @@ def execute(self):
assert self.py("print(vim.current.buffer)", regex="<buffer taskwiki.")


class TestViewportInspectionWithVisibleTag(MultiSyntaxIntegrationTest):

viminput = """
HEADER2(Work tasks | +work +VISIBLE)

HEADER2(Home tasks | +home)
* [ ] tag work task #{uuid}
"""

vimoutput = """
ViewPort inspection:
--------------------
Name: Work tasks
Filter used: -DELETED -PARENT ( +work )
Defaults used: tags:['work']
Ordering used: status+,end+,due+,priority-,project+
Matching taskwarrior tasks: 0
Displayed tasks: 1
Tasks to be added:
Tasks to be deleted: tag work task
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

I'd appreciate a comment explaining what this test really tests, as I don't think it's obvious. :-/

"""

tasks = [
dict(description="tag work task", tags=['work', 'home']),
dict(description="tag work task 2", tags=['home']),
]

def execute(self):
self.command("w", regex="written$", lines=1)
self.client.feedkeys('1gg')
self.client.feedkeys(r'\<CR>')
self.client.eval('0') # wait for command completion

assert self.py("print(vim.current.buffer)", regex="<buffer taskwiki.")


class TestViewportsUnicodeTaskGeneration(MultiSyntaxIntegrationTest):

viminput = """
Expand Down Expand Up @@ -545,7 +581,7 @@ def execute(self):
"'Work tasks' is not defined, using default.", lines=2)


class TestViewportsVisibleMetaTag(MultiSyntaxIntegrationTest):
class TestViewportsInvisibleMetaTag(MultiSyntaxIntegrationTest):

viminput = """
HEADER2(Home tasks | project:Home -VISIBLE)
Expand All @@ -572,6 +608,33 @@ def execute(self):
self.command("w", regex="written$", lines=1)


class TestViewportsVisibleMetaTag(MultiSyntaxIntegrationTest):

viminput = """
HEADER2(Home tasks | project:Home +VISIBLE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the project:Home, as otherwise this isn't testing the +VISIBLE meta tag at all, the chore task would be there anyway.


HEADER2(Chores | project:Home.Chores)
"""

vimoutput = """
HEADER2(Home tasks | project:Home +VISIBLE)
* [ ] chore task #{uuid}

HEADER2(Chores | project:Home.Chores)
* [ ] chore task #{uuid}
"""

tasks = [
dict(description="home task", project='Home.Random'),
dict(description="chore task", project='Home.Chores'),
]

def execute(self):
# Currently, two saves are necessary for VISIBLE to take effect
self.command("w", regex="written$", lines=1)
self.command("w", regex="written$", lines=1)


class TestViewportsPreserveHierarchyUponCompletion(MultiSyntaxIntegrationTest):

viminput = """
Expand Down