Skip to content

Commit

Permalink
Merge pull request #732 from HubSpot/star_on_detail_page
Browse files Browse the repository at this point in the history
Star requests from the request detail page
  • Loading branch information
Tom Petr committed Oct 14, 2015
2 parents 63caff3 + 42d3faf commit 4d7f910
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
10 changes: 5 additions & 5 deletions SingularityUI/app/collections/Requests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class Requests extends Collection
request = model.get('request')

deployUserTrimmed = user.split("@")[0]

activeDeployUser = model.get('requestDeployState')?.activeDeploy?.user

if activeDeployUser
activeDeployUserTrimmed = activeDeployUser.split('@')[0]
if deployUserTrimmed is activeDeployUserTrimmed
Expand All @@ -73,7 +73,7 @@ class Requests extends Collection
return false

# Get `active` request type totals by user
getUserRequestTotals: (user) ->
getUserRequestTotals: (user) ->
userRequests = @getUserRequests user

userRequestTotals =
Expand All @@ -87,7 +87,7 @@ class Requests extends Collection
for request in userRequests

type = request.get 'type'

continue if request.get('state') isnt 'ACTIVE'

if type is 'ON_DEMAND' then userRequestTotals.onDemand += 1
Expand All @@ -98,4 +98,4 @@ class Requests extends Collection

userRequestTotals

module.exports = Requests
module.exports = Requests
8 changes: 8 additions & 0 deletions SingularityUI/app/controllers/RequestDetail.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RequestTasks = require '../collections/RequestTasks'
RequestHistoricalTasks = require '../collections/RequestHistoricalTasks'
RequestDeployHistory = require '../collections/RequestDeployHistory'
RequestHistory = require '../collections/RequestHistory'
Requests = require '../collections/Requests'

RequestDetailView = require '../views/request'
ExpandableTableSubview = require '../views/expandableTableSubview'
Expand Down Expand Up @@ -52,6 +53,9 @@ class RequestDetailController extends Controller
@collections.taskHistory = new RequestHistoricalTasks [], {@requestId}
@collections.deployHistory = new RequestDeployHistory [], {@requestId}

# For starring (never fetched here)
@collections.requests = new Requests [], {}

#
# Subviews
#
Expand Down Expand Up @@ -106,6 +110,7 @@ class RequestDetailController extends Controller
#
@setView new RequestDetailView _.extend {@requestId, @subviews},
model: @models.request
collection: @collections.requests

@refresh()

Expand All @@ -124,6 +129,9 @@ class RequestDetailController extends Controller
@ignore404
app.caughtError()

requestFetch.success =>
@models.request.set('starred', @collections.requests.isStarred(@models.request.id))

if @models.activeDeployStats.deployId?
@models.activeDeployStats.fetch().error @ignore404

Expand Down
18 changes: 18 additions & 0 deletions SingularityUI/app/styles/detailHeader.styl
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,21 @@

.deploy-title
color #bbb

a[data-starred]
margin-right 5px
text-decoration none

a[data-starred="true"]
color $linkBlue
opacity: 1

&:hover
opacity 0.9

a[data-starred="false"]
color $grey
opacity 0.2

&:hover
opacity 0.3
7 changes: 5 additions & 2 deletions SingularityUI/app/templates/requestDetail/requestHeader.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
{{! Left side, info }}
<div class="col-md-7">
<h4>
<a class="star" data-action="starToggle" data-starred="{{ data.starred }}" data-id="{{ data.id }}">
<span class="glyphicon glyphicon-star"></span>
</a>

<span class="request-state" data-state="{{ data.state }}">
{{humanizeText data.state}}
</span>

<span class="request-type">
{{humanizeText data.type}}
</span>

</h4>

<h2>
Expand Down Expand Up @@ -68,7 +71,7 @@
Bounce
</a>
{{/if}}

{{#unless config.hideNewRequestButton}}
<a class="btn btn-primary" href="{{appRoot}}/requests/edit/{{ data.id }}">
Edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{{/unless}}
{{#each requests}}
<tr data-request-id="{{ request.id }}">
<td data-value"{{ starred }}"=>
<td data-value="{{ starred }}">
<a class="star" data-action="starToggle" data-starred="{{ starred }}">
<span class="glyphicon glyphicon-star"></span>
</a>
Expand Down
12 changes: 12 additions & 0 deletions SingularityUI/app/views/request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RequestView extends View
'click [data-action="unpause"]': 'unpauseRequest'
'click [data-action="bounce"]': 'bounceRequest'
'click [data-action="exit-cooldown"]': 'exitCooldownRequest'
'click [data-action="starToggle"]': 'toggleStar'

'click [data-action="run-now"]': 'runTask'

Expand Down Expand Up @@ -127,4 +128,15 @@ class RequestView extends View
flashDeployHistory: ->
@subviews.deployHistory.flash()

toggleStar: (e) ->
$target = $(e.currentTarget)
id = $target.attr('data-id')
@collection.toggleStar id

starred = $target.attr('data-starred') is "true"
if starred
$target.attr 'data-starred', 'false'
else
$target.attr 'data-starred', 'true'

module.exports = RequestView

0 comments on commit 4d7f910

Please sign in to comment.