mozilla/treeherder-ui — pull request #232 by tojonmz (2014-10-15 17:05:04+00:00)
Title: Bug 1074241 - Reset the internal job model position on a job clear

This work fixes Bugzilla bug [1074241](https://bugzilla.mozilla.org/show_bug.cgi?id=1074241).

The internal state of the last selected job was being preserved, so when you used the failure navigation keys they continued from where you last were. The Sheriffs want them to always start from the beginning via **n/j**, or start from the end via **k/p** after a job is deselected.

For an example, a ggc build selected at some mid-point in the resultset:

![resetjobmodelpositionscenario](https://cloud.githubusercontent.com/assets/3660661/4649501/227b0808-548b-11e4-978f-533602bd0004.jpg)

In production, if the user clicks away to deselect the job and then presses **n/j** we currently get:

![resetjobmodelbehaviorcurrent](https://cloud.githubusercontent.com/assets/3660661/4649522/6cdfa732-548b-11e4-83ba-055e41e6269c.jpg)

With the fix, we get:

![resetjobmodelbehaviorproposed](https://cloud.githubusercontent.com/assets/3660661/4649532/7e86f0c6-548b-11e4-97c5-321249e01bf4.jpg)

Most of the code changed, involved supporting Esc, which also closes the job panel.

I spoke with @jeads in channel about the correct implementation for this, creating an event listener and a new event for clearing selected job styles. Since they weren't accessible in controllers/main and otherwise would require replicating code there.

The code which resets the position is this bit below. It is used in two locations, in one spot for a click away workflow, and another for the Esc workflow.

`ThResultSetModel.setSelectedJob($rootScope.repoName);`

Everything seems to work fine with this change, closing the job panel manually, via Esc, via click-away, using the pinboard in conjunction with the job panel, looping backwards through the job failures via k/p.

There are other things we'd like to fix, like deselecting a job when the job panel is manually closed, which would also yield this effect, but that is a separate bug and lower priority.

Tested on Windows:
FF Release **32.0.3**
Chrome Latest Release **37.0.2062.124 m**

Adding @camd and @wlach for review.