Skip to content
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
52 changes: 43 additions & 9 deletions src/scripts/controllers/dapiControllers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,38 @@ class VehicleDetailController extends DetailController

super(data)

class MissionSupportController
@$inject: ['$log', '$scope', 'mission', 'user', 'missionService']
constructor: (@log, @scope, @mission, @user, @service) ->
@log.info 'hello this is modals reporting!'
@scope.mission = @mission
@scope.user = @user
@scope.extraInfo = ''

send_support_ticket: (form = {$dirty: false}) =>
ticketPayload = {priority: 'unused'}
if form.$dirty
ticketPayload.extraInfo = form.extraInfo.$viewValue
@service.openSupportTicket(@mission, ticketPayload).then (response) =>
@scope.$dismiss('cancel')

class MissionDetailController extends DetailController
@$inject: ['$modal', '$log', '$scope', '$routeParams', 'missionService', '$rootScope', 'authService', '$window', '$sce', 'ngProgressLite']
constructor: (@modal, @log, scope, routeParams, @service, @rootScope, @authService, window, @sce, ngProgressLite) ->
scope.$on 'loading-started', (event, config) -> ngProgressLite.start() if event.currentScope.urlBase == config.url
scope.$on 'loading-complete', (event, config) -> ngProgressLite.done() if event.currentScope.urlBase == config.url
@$inject: ['$modal', '$log', '$scope', '$routeParams', 'preFetchedMission', 'missionService', '$rootScope', 'authService', '$window', '$sce', 'ngProgressLite']
constructor: (@modal, @log, @scope, routeParams, @record, @service, @rootScope, @authService, window, @sce, ngProgressLite) ->
@scope.$on 'loading-started', (event, config) -> ngProgressLite.start() if event.currentScope.urlBase == config.url
@scope.$on 'loading-complete', (event, config) -> ngProgressLite.done() if event.currentScope.urlBase == config.url

super(scope, routeParams, window)
@scope.urlBase = @urlBase # FIXME - is there a better way to pass this out to the html?
super(@scope, routeParams, window, false)

# make sure we call this since its the function that
# fixes the record and sets up open graph tags
@handle_fetch_response(@record)

@scope.urlBase = @urlBase
@scope.center = {}
@scope.bounds = {}
@scope.geojson = {}
@scope.record = @record

@service.get_geojson(@routeParams.id).then (result) =>
@log.debug("Setting geojson")
Expand Down Expand Up @@ -469,6 +490,18 @@ class MissionDetailController extends DetailController
name = 'doarama' + @record.id
@window.open(@scope.doaramaURL, name, "width=940,height=420,scrollbars=no,left=#{x},top=#{y}")

@get_support_modal = () =>
@log.info('creating window dialog for support tickets')
dialog = @modal.open
templateUrl: '/views/mission/support-ticket.html'
controller: 'missionSupportController as controller'
resolve:
mission: =>
@record
user: ['$route', 'userService', ($route, userService) =>
userService.getId(@record.userName)
]

# Subclasses can override if they would like to strip content out before submitting
get_record_for_submit: =>
# The server doesn't understand this yet
Expand All @@ -482,10 +515,10 @@ class MissionDetailController extends DetailController

# We update open social data so facebook shows nice content
handle_fetch_response: (data) =>
super(data)

# FIXME - unify these fixups with the regular mission record fetch - should be in the service instead!
fixupMission(data, @authService.getUser())
@record = fixupMission(data, @authService.getUser())

super(data)

if !data.latitude?
@set_error('This mission did not include location data')
Expand Down Expand Up @@ -549,6 +582,7 @@ class MissionAnalysisController extends BaseController
angular.module('app').controller 'userDetailController', UserDetailController
angular.module('app').controller 'vehicleDetailController', VehicleDetailController
angular.module('app').controller 'missionDetailController', MissionDetailController
angular.module('app').controller 'missionSupportController', MissionSupportController
angular.module('app').controller 'missionParameterController', MissionParameterController
angular.module('app').controller 'missionPlotController', MissionPlotController
angular.module('app').controller 'missionAnalysisController', MissionAnalysisController
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/routes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class Config
controller: 'missionDetailController as controller'
title: 'Detail'
templateUrl: '/views/mission/detail-window.html'
resolve:
preFetchedMission: ['$route', 'missionService', ($route, missionService) ->
missionService.getId($route.current.params.id)
]
.when '/parameters/:id',
templateUrl: '/views/mission/parameters-window.html'
.when '/analysis/:id',
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/services/dapiServices.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class MissionService extends RESTService

endpoint: "mission"

openSupportTicket: (mission, ticketPayload) =>
@log.debug "Posting new Ticket"
@postId("#{mission.id}/openTicket", ticketPayload)

getAllMissions: (fetchParams) =>
fetchParams or= @getFetchParams()
@getMissionsFromParams(fetchParams)
Expand Down
9 changes: 9 additions & 0 deletions src/views/mission/detail-window.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ <h5>Share:</h5>
</div>
</div>

<div class="col-sm-12" ng-show="controller.isMine()">
<div class="row support">
<h5>Support</h5>
<a ng-click="controller.get_support_modal()" class="btn btn-primary">
3DR support ticket
</a>
</div>
</div>

</div>

</section>
Expand Down
32 changes: 32 additions & 0 deletions src/views/mission/support-ticket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="modal-header">
<h3 class="modal-title">3DR Support Ticket</h3>
</div>
<div class="modal-body">
<form name="supportTicketForm" ng-submit="controller.send_support_ticket(supportTicketForm)" novalidate>
<div class="row">
<div class="col-sm-12">
<div class="row form-group">
<label class="col-sm-2 control-label" for="contactEmail">Email:</label>
<div class="col-sm-10">
<input disabled type="text" class="form-control" ng-model="user.email" name="contactEmail" />
</div>
</div>
</div>
</div>
<div class="row form-group">
<label class="col-sm-2 control-label" for="extraInfo">Message</label>
<div class="col-sm-10">
<textarea ng-model="extraInfo" name="extraInfo" class="form-control">
</textarea>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-warning" ng-click="$dismiss('cancel')">Cancel</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
</div>
10 changes: 3 additions & 7 deletions test/units/controllers/missionDetailController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ describe "missionDetailController", ->
routeParamsStub = jasmine.createSpy('routeParamsStub')
routeParamsStub.id = 218

@userDetailController = $controller('missionDetailController', { '$scope': @scope, '$routeParams': routeParamsStub })
@userDetailController = $controller('missionDetailController', { '$scope': @scope, '$routeParams': routeParamsStub, 'preFetchedMission': @mission })

@urlBase = 'https://api.droneshare.com/api/v1'
@httpBackend = _$httpBackend_
@httpBackend.whenGET("#{@urlBase}/auth/user").respond 200, @user
@httpBackend.whenGET("#{@urlBase}/mission/#{routeParamsStub.id}").respond 200, @mission
@httpBackend.whenGET("#{@urlBase}/mission/#{routeParamsStub.id}/messages.geo.json").respond 200, @geojson

it 'gets mission record by params', ->
expect(@scope.record).toBeUndefined()
@scope.$apply()
@httpBackend.flush()
it 'it pre-fetches the mission object on router resolve', ->
expect(@scope.record).not.toBeUndefined()

describe 'get_geojson', ->
Expand All @@ -46,8 +44,6 @@ describe "missionDetailController", ->

describe 'handle_fetch_response', ->
it 'gets formats date to present to users', ->
@scope.$apply()
@httpBackend.flush()
createdOn = new Date(@mission.createdOn)
expect(@scope.record.dateString).toEqual "#{createdOn.toDateString()} - #{createdOn.toLocaleTimeString()}"

Expand Down