Complete Task in List of Changes

Currently, when one clicks Changes for a ToDo list, it raises an error. The Changes view shows a logged-in user what has been updated, but clicking on a completed task brings up an error:

Unable to open 'Complete' in the current context

This should do something else. If a task is opened and a user clicks changes, it displays the editor on that task.

This is due to the following code:

PRCompleteToDoTaskCommand(class)>>isValidIn:
	^ (super isValidIn: aContext) and: [ aContext structure isRoot not and: [ aContext structure parent isToDo ] ]

One reason the code is written this way is so the Complete option only shows up on the menu when a task is open - it doesn't make sense to "complete" the Syntax page. The menu is the gray text at the bottom of this page, or in the left pane of the default install:

Complete in bold for a task
The code related to this is:

isValidIn: aContext
	^ (super isValidIn: aContext)
		and: [ aContext command class = self
				or: [ aContext command isView
						and: [ aContext command viewComponentClass isNotNil
								and: [ aContext command viewComponentClass = PRChangesView ] ] ] ]

The scenarios that this handles are:

  • When viewing or editing a page which is not a task or todo option, the Complete menu option should not show up
  • When opening the changes view from a page that contains some child which is a ToDo Task, any time the task was completed should be listed, and clicking on the open link should access that page
  • The Complete menu option is only available when viewing a complete history item, it opens the normal pier page editor

The tests for equality make adding a subclass of PRCompleteToDoTaskCommand more difficult than necessary, but this code is sufficient to create a non-abstract test. This allows adding:

PRCommand>>shouldBeIncludedInCompleteHistory
	^ false
PRViewCommand>>shouldBeIncludedInCompleteHistory
	^ self viewComponentClass isNotNil
		and: [ self viewComponentClass = PRChangesView ]
PRCompleteToDoTaskCommand>>shouldBeIncludedInCompleteHistory
	^ true

Then #isValidIn: can ask aContext's command if it should be displayed instead of performing checks itself.

Posted by John Borden at 26 April 2020, 10:31 pm with tags Pier link