From f7eb296740ab5bfb8295149d4d8a0db5bd75566d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Roche?= Date: Wed, 26 Nov 2014 14:06:30 -0800 Subject: [PATCH] Open 3DR support ticket for your missions --- .../controllers/dapiControllers.coffee | 52 +++++++++++++++---- src/scripts/routes.coffee | 4 ++ src/scripts/services/dapiServices.coffee | 4 ++ src/views/mission/detail-window.html | 9 ++++ src/views/mission/support-ticket.html | 32 ++++++++++++ .../missionDetailController.coffee | 10 ++-- 6 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 src/views/mission/support-ticket.html diff --git a/src/scripts/controllers/dapiControllers.coffee b/src/scripts/controllers/dapiControllers.coffee index 780de551..1f279354 100644 --- a/src/scripts/controllers/dapiControllers.coffee +++ b/src/scripts/controllers/dapiControllers.coffee @@ -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") @@ -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 @@ -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') @@ -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 diff --git a/src/scripts/routes.coffee b/src/scripts/routes.coffee index 6597d590..e0162b61 100644 --- a/src/scripts/routes.coffee +++ b/src/scripts/routes.coffee @@ -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', diff --git a/src/scripts/services/dapiServices.coffee b/src/scripts/services/dapiServices.coffee index f3f9e986..e86c170c 100644 --- a/src/scripts/services/dapiServices.coffee +++ b/src/scripts/services/dapiServices.coffee @@ -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) diff --git a/src/views/mission/detail-window.html b/src/views/mission/detail-window.html index ad05cda1..6d64acf0 100644 --- a/src/views/mission/detail-window.html +++ b/src/views/mission/detail-window.html @@ -132,6 +132,15 @@
Share:
+
+ +
+ diff --git a/src/views/mission/support-ticket.html b/src/views/mission/support-ticket.html new file mode 100644 index 00000000..36d6ff4f --- /dev/null +++ b/src/views/mission/support-ticket.html @@ -0,0 +1,32 @@ + + + diff --git a/test/units/controllers/missionDetailController.coffee b/test/units/controllers/missionDetailController.coffee index 9f48cfd1..2f683a13 100644 --- a/test/units/controllers/missionDetailController.coffee +++ b/test/units/controllers/missionDetailController.coffee @@ -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', -> @@ -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()}"