[Mobile] AgentService

Replaced name queryService with agentService.
This commit is contained in:
Shivam Dave
2015-08-04 10:11:25 -07:00
parent 9b922913a0
commit 3d524d7572
16 changed files with 54 additions and 54 deletions

View File

@ -10,8 +10,8 @@
"depends": [ "$location" ] "depends": [ "$location" ]
}, },
{ {
"key": "queryService", "key": "agentService",
"implementation": "/services/QueryService.js", "implementation": "/services/AgentService.js",
"depends": [ "$window" ] "depends": [ "$window" ]
} }
], ],
@ -65,7 +65,7 @@
{ {
"key": "TreeNodeController", "key": "TreeNodeController",
"implementation": "controllers/TreeNodeController.js", "implementation": "controllers/TreeNodeController.js",
"depends": [ "$scope", "$timeout", "queryService" ] "depends": [ "$scope", "$timeout", "agentService" ]
}, },
{ {
"key": "ActionGroupController", "key": "ActionGroupController",

View File

@ -50,7 +50,7 @@ define(
* expand-to-show-navigated-object behavior.) * expand-to-show-navigated-object behavior.)
* @constructor * @constructor
*/ */
function TreeNodeController($scope, $timeout, queryService) { function TreeNodeController($scope, $timeout, agentService) {
var selectedObject = ($scope.ngModel || {}).selectedObject, var selectedObject = ($scope.ngModel || {}).selectedObject,
isSelected = false, isSelected = false,
hasBeenExpanded = false; hasBeenExpanded = false;
@ -88,7 +88,7 @@ define(
} }
function checkMobile() { function checkMobile() {
return queryService.isMobile(navigator.userAgent); return agentService.isMobile(navigator.userAgent);
} }
// Consider the currently-navigated object and update // Consider the currently-navigated object and update

View File

@ -22,7 +22,7 @@
/*global define,Promise*/ /*global define,Promise*/
/** /**
* Module defining QueryService. * Module defining AgentService.
*/ */
define( define(
@ -35,7 +35,7 @@ define(
* info using a comparison between the userAgent and key * info using a comparison between the userAgent and key
* device names * device names
*/ */
function QueryService($window) { function AgentService($window) {
// Gets the UA name if it is one of the following. // Gets the UA name if it is one of the following.
// If it is not (a desktop for example) nothing is // If it is not (a desktop for example) nothing is
@ -97,6 +97,6 @@ define(
}; };
} }
return QueryService; return AgentService;
} }
); );

View File

@ -29,7 +29,7 @@ define(
describe("The tree node controller", function () { describe("The tree node controller", function () {
var mockScope, var mockScope,
mockTimeout, mockTimeout,
mockQueryService, mockAgentService,
controller; controller;
function TestObject(id, context) { function TestObject(id, context) {
@ -44,8 +44,8 @@ define(
beforeEach(function () { beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", ["$watch", "$on"]); mockScope = jasmine.createSpyObj("$scope", ["$watch", "$on"]);
mockTimeout = jasmine.createSpy("$timeout"); mockTimeout = jasmine.createSpy("$timeout");
mockQueryService = jasmine.createSpyObj("queryService", ["isMobile"]); mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
controller = new TreeNodeController(mockScope, mockTimeout, mockQueryService); controller = new TreeNodeController(mockScope, mockTimeout, mockAgentService);
}); });
it("allows tracking of expansion state", function () { it("allows tracking of expansion state", function () {

View File

@ -25,12 +25,12 @@
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14. * MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
*/ */
define( define(
["../../src/services/QueryService"], ["../../src/services/AgentService"],
function (QueryService) { function (AgentService) {
"use strict"; "use strict";
describe("The url service", function () { describe("The url service", function () {
var queryService, var agentService,
mockWindow, mockWindow,
mockNavigator; mockNavigator;
@ -47,24 +47,24 @@ define(
[ "userAgent" ] [ "userAgent" ]
); );
queryService = new QueryService(mockWindow); agentService = new AgentService(mockWindow);
}); });
it("get current device user agent", function () { it("get current device user agent", function () {
mockNavigator.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36"; mockNavigator.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36";
queryService.isMobile(mockNavigator.userAgent); agentService.isMobile(mockNavigator.userAgent);
mockNavigator.userAgent = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53"; mockNavigator.userAgent = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53";
queryService.isMobile(mockNavigator.userAgent); agentService.isMobile(mockNavigator.userAgent);
}); });
it("get orientation of the current device", function () { it("get orientation of the current device", function () {
mockWindow.outerWidth = 768; mockWindow.outerWidth = 768;
mockWindow.outerHeight = 1024; mockWindow.outerHeight = 1024;
queryService.getOrientation(); agentService.getOrientation();
mockWindow.outerWidth = 1024; mockWindow.outerWidth = 1024;
mockWindow.outerHeight = 768; mockWindow.outerHeight = 768;
queryService.getOrientation(); agentService.getOrientation();
}); });
}); });
} }

View File

@ -13,7 +13,7 @@
"directives/MCTDrag", "directives/MCTDrag",
"directives/MCTResize", "directives/MCTResize",
"directives/MCTScroll", "directives/MCTScroll",
"services/QueryService", "services/AgentService",
"services/UrlService", "services/UrlService",
"StyleSheetLoader" "StyleSheetLoader"
] ]

View File

@ -24,7 +24,7 @@
"implementation": "gestures/InfoGesture.js", "implementation": "gestures/InfoGesture.js",
"depends": [ "depends": [
"$timeout", "$timeout",
"queryService", "agentService",
"infoService", "infoService",
"INFO_HOVER_DELAY" "INFO_HOVER_DELAY"
] ]
@ -34,7 +34,7 @@
"implementation": "gestures/InfoButtonGesture.js", "implementation": "gestures/InfoButtonGesture.js",
"depends": [ "depends": [
"$document", "$document",
"queryService", "agentService",
"infoService" "infoService"
] ]
} }
@ -48,7 +48,7 @@
"$document", "$document",
"$window", "$window",
"$rootScope", "$rootScope",
"queryService" "agentService"
] ]
} }
], ],

View File

@ -37,7 +37,7 @@ define(
* @param {DomainObject} domainObject the domain object for which to * @param {DomainObject} domainObject the domain object for which to
* show information * show information
*/ */
function InfoGestureButton($document, queryService, infoService, element, domainObject) { function InfoGestureButton($document, agentService, infoService, element, domainObject) {
var dismissBubble, var dismissBubble,
pendingBubble, pendingBubble,
touchPosition, touchPosition,
@ -82,10 +82,10 @@ define(
} }
// Checks if you are on a mobile device, if the device is // Checks if you are on a mobile device, if the device is
// mobile (queryService.isMobile() = true), then // mobile (agentService.isMobile() = true), then
// the a click on something (info button) brings up // the a click on something (info button) brings up
// the bubble // the bubble
if (queryService.isMobile(navigator.userAgent)) { if (agentService.isMobile(navigator.userAgent)) {
element.on('click', showBubble); element.on('click', showBubble);
} }

View File

@ -38,7 +38,7 @@ define(
* @param {DomainObject} domainObject the domain object for which to * @param {DomainObject} domainObject the domain object for which to
* show information * show information
*/ */
function InfoGesture($timeout, queryService, infoService, DELAY, element, domainObject) { function InfoGesture($timeout, agentService, infoService, DELAY, element, domainObject) {
var dismissBubble, var dismissBubble,
pendingBubble, pendingBubble,
mousePosition, mousePosition,
@ -93,9 +93,9 @@ define(
} }
// Checks if you are on a mobile device, if the device is // Checks if you are on a mobile device, if the device is
// not mobile (queryService.isMobile() = false), then // not mobile (agentService.isMobile() = false), then
// the pendingBubble and therefore hovering is allowed // the pendingBubble and therefore hovering is allowed
if (!queryService.isMobile(navigator.userAgent)) { if (!agentService.isMobile(navigator.userAgent)) {
// Show bubble (on a timeout) on mouse over // Show bubble (on a timeout) on mouse over
element.on('mouseenter', showBubble); element.on('mouseenter', showBubble);
} }

View File

@ -33,7 +33,7 @@ define(
* Displays informative content ("info bubbles") for the user. * Displays informative content ("info bubbles") for the user.
* @constructor * @constructor
*/ */
function InfoService($compile, $document, $window, $rootScope, queryService) { function InfoService($compile, $document, $window, $rootScope, agentService) {
function display(templateKey, title, content, position) { function display(templateKey, title, content, position) {
var body = $document.find('body'), var body = $document.find('body'),
@ -61,7 +61,7 @@ define(
// info bubble positioned as normal (with triangle pointing // info bubble positioned as normal (with triangle pointing
// to where clicked or pressed) // to where clicked or pressed)
bubble.css('position', 'absolute'); bubble.css('position', 'absolute');
if(queryService.isPhone(navigator.userAgent)) { if(agentService.isPhone(navigator.userAgent)) {
bubble.css('right', 5 + 'px'); bubble.css('right', 5 + 'px');
bubble.css('left', 5 + 'px'); bubble.css('left', 5 + 'px');
bubble.css('top', 40 + 'px'); bubble.css('top', 40 + 'px');

View File

@ -28,7 +28,7 @@ define(
describe("The info gesture", function () { describe("The info gesture", function () {
var mockTimeout, var mockTimeout,
mockQueryService, mockAgentService,
mockInfoService, mockInfoService,
testDelay = 12321, testDelay = 12321,
mockElement, mockElement,
@ -51,7 +51,7 @@ define(
beforeEach(function () { beforeEach(function () {
mockTimeout = jasmine.createSpy('$timeout'); mockTimeout = jasmine.createSpy('$timeout');
mockTimeout.cancel = jasmine.createSpy('cancel'); mockTimeout.cancel = jasmine.createSpy('cancel');
mockQueryService = jasmine.createSpyObj('queryService', ['isMobile']); mockAgentService = jasmine.createSpyObj('agentService', ['isMobile']);
mockInfoService = jasmine.createSpyObj( mockInfoService = jasmine.createSpyObj(
'infoService', 'infoService',
[ 'display' ] [ 'display' ]
@ -81,7 +81,7 @@ define(
gesture = new InfoGesture( gesture = new InfoGesture(
mockTimeout, mockTimeout,
mockQueryService, mockAgentService,
mockInfoService, mockInfoService,
testDelay, testDelay,
mockElement, mockElement,

View File

@ -26,7 +26,7 @@
{ {
"key": "menu", "key": "menu",
"implementation": "gestures/ContextMenuGesture.js", "implementation": "gestures/ContextMenuGesture.js",
"depends": ["$timeout", "queryService"] "depends": ["$timeout", "agentService"]
} }
], ],
"components": [ "components": [
@ -54,7 +54,7 @@
{ {
"key": "menu", "key": "menu",
"implementation": "actions/ContextMenuAction.js", "implementation": "actions/ContextMenuAction.js",
"depends": [ "$compile", "$document", "$window", "$rootScope", "queryService" ] "depends": [ "$compile", "$document", "$window", "$rootScope", "agentService" ]
} }
] ]
} }

View File

@ -47,7 +47,7 @@ define(
* @param actionContexr the context in which the action * @param actionContexr the context in which the action
* should be performed * should be performed
*/ */
function ContextMenuAction($compile, $document, $window, $rootScope, queryService, actionContext) { function ContextMenuAction($compile, $document, $window, $rootScope, agentService, actionContext) {
function perform() { function perform() {
var winDim = [$window.innerWidth, $window.innerHeight], var winDim = [$window.innerWidth, $window.innerHeight],
@ -95,11 +95,11 @@ define(
// Stop propagation so that clicks on the menu do not close the menu // Stop propagation so that clicks on the menu do not close the menu
// Stop propagation so that touches on the menu do not close the menu // Stop propagation so that touches on the menu do not close the menu
if (!queryService.isMobile(navigator.userAgent)) { if (!agentService.isMobile(navigator.userAgent)) {
menu.on('mousedown', function (event) { menu.on('mousedown', function (event) {
event.stopPropagation(); event.stopPropagation();
}); });
} else if (queryService.isMobile(navigator.userAgent)) { } else if (agentService.isMobile(navigator.userAgent)) {
menu.on('touchstart', function (event) { menu.on('touchstart', function (event) {
event.stopPropagation(); event.stopPropagation();
}); });
@ -108,9 +108,9 @@ define(
// Dismiss the menu when body is clicked/touched elsewhere // Dismiss the menu when body is clicked/touched elsewhere
// ('mousedown' because 'click' breaks left-click context menus) // ('mousedown' because 'click' breaks left-click context menus)
// ('touchstart' because 'touch' breaks context menus up) // ('touchstart' because 'touch' breaks context menus up)
if (!queryService.isMobile(navigator.userAgent)) { if (!agentService.isMobile(navigator.userAgent)) {
body.on('mousedown', dismiss); body.on('mousedown', dismiss);
} else if (queryService.isMobile(navigator.userAgent)) { } else if (agentService.isMobile(navigator.userAgent)) {
body.on('touchstart', dismiss); body.on('touchstart', dismiss);
} }

View File

@ -39,19 +39,19 @@ define(
* @param {DomainObject} domainObject the object on which actions * @param {DomainObject} domainObject the object on which actions
* in the context menu will be performed * in the context menu will be performed
*/ */
function ContextMenuGesture($timeout, queryService, element, domainObject) { function ContextMenuGesture($timeout, agentService, element, domainObject) {
var actionContext, var actionContext,
stop, stop,
isPressing, isPressing,
longTouchTime = 500; longTouchTime = 500;
// When context menu event occurs, show object actions instead // When context menu event occurs, show object actions instead
if (!queryService.isMobile(navigator.userAgent)) { if (!agentService.isMobile(navigator.userAgent)) {
element.on('contextmenu', function (event) { element.on('contextmenu', function (event) {
actionContext = {key: 'menu', domainObject: domainObject, event: event}; actionContext = {key: 'menu', domainObject: domainObject, event: event};
stop = domainObject.getCapability('action').perform(actionContext); stop = domainObject.getCapability('action').perform(actionContext);
}); });
} else if (queryService.isMobile(navigator.userAgent)) { } else if (agentService.isMobile(navigator.userAgent)) {
// If on mobile device, then start timeout for the single touch event // If on mobile device, then start timeout for the single touch event
// during the timeout 'isPressing' is true. // during the timeout 'isPressing' is true.
element.on('touchstart', function (event) { element.on('touchstart', function (event) {

View File

@ -43,7 +43,7 @@ define(
mockBody, mockBody,
mockWindow, mockWindow,
mockRootScope, mockRootScope,
mockQueryService, mockAgentService,
mockScope, mockScope,
mockElement, mockElement,
mockDomainObject, mockDomainObject,
@ -61,7 +61,7 @@ define(
mockBody = jasmine.createSpyObj("body", JQLITE_FUNCTIONS); mockBody = jasmine.createSpyObj("body", JQLITE_FUNCTIONS);
mockWindow = { innerWidth: MENU_DIMENSIONS[0] * 4, innerHeight: MENU_DIMENSIONS[1] * 4 }; mockWindow = { innerWidth: MENU_DIMENSIONS[0] * 4, innerHeight: MENU_DIMENSIONS[1] * 4 };
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]); mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
mockQueryService = jasmine.createSpyObj("queryService", ["isMobile"]); mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockScope = {}; mockScope = {};
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
@ -81,7 +81,7 @@ define(
mockDocument, mockDocument,
mockWindow, mockWindow,
mockRootScope, mockRootScope,
mockQueryService, mockAgentService,
mockActionContext mockActionContext
); );
}); });
@ -160,13 +160,13 @@ define(
}); });
it("mobile", function () { it("mobile", function () {
mockQueryService.isMobile.andReturn(true); mockAgentService.isMobile.andReturn(true);
action = new ContextMenuAction( action = new ContextMenuAction(
mockCompile, mockCompile,
mockDocument, mockDocument,
mockWindow, mockWindow,
mockRootScope, mockRootScope,
mockQueryService, mockAgentService,
mockActionContext mockActionContext
); );
action.perform(); action.perform();

View File

@ -37,7 +37,7 @@ define(
describe("The 'context menu' gesture", function () { describe("The 'context menu' gesture", function () {
var mockTimeout, var mockTimeout,
mockElement, mockElement,
mockQueryService, mockAgentService,
mockDomainObject, mockDomainObject,
mockEvent, mockEvent,
gesture, gesture,
@ -46,11 +46,11 @@ define(
beforeEach(function () { beforeEach(function () {
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockTimeout = jasmine.createSpy("$timeout"); mockTimeout = jasmine.createSpy("$timeout");
mockQueryService = jasmine.createSpyObj("queryService", ["isMobile"]); mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
mockEvent = jasmine.createSpyObj("event", ["preventDefault"]); mockEvent = jasmine.createSpyObj("event", ["preventDefault"]);
gesture = new ContextMenuGesture(mockTimeout, mockQueryService, mockElement, mockDomainObject); gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
// Capture the contextmenu callback // Capture the contextmenu callback
fireGesture = mockElement.on.mostRecentCall.args[1]; fireGesture = mockElement.on.mostRecentCall.args[1];
@ -76,8 +76,8 @@ define(
}); });
it("mobile", function () { it("mobile", function () {
mockQueryService.isMobile.andReturn(true); mockAgentService.isMobile.andReturn(true);
gesture = new ContextMenuGesture(mockTimeout, mockQueryService, mockElement, mockDomainObject); gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
// Capture the contextmenu callback // Capture the contextmenu callback
fireGesture = mockElement.on.mostRecentCall.args[1]; fireGesture = mockElement.on.mostRecentCall.args[1];