Skip to content

Commit

Permalink
Merge pull request #1931 from CodeNow/SAN-5482-oops-url
Browse files Browse the repository at this point in the history
San 5482 oops url
  • Loading branch information
Nathan219 authored Dec 10, 2016
2 parents c8c7c20 + c215828 commit d7281cd
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 54 deletions.
48 changes: 7 additions & 41 deletions client/controllers/controllerInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function ControllerInstance(
pageName,
setLastInstance
) {
var CIS = this;
CIS.isInGuide = ahaGuide.isInGuide;
var CI = this;
CI.isInGuide = ahaGuide.isInGuide;
var dataInstance = $scope.dataInstance = {
data: {
unsavedAcvs: [],
Expand Down Expand Up @@ -206,45 +206,16 @@ function ControllerInstance(
break;
}

if (demoFlowService.isInDemoFlow()) {
checkForEnablingHangTightMessage(keypather.get($scope, 'dataInstance.data.instance'));
checkForEnablingUrlCallout(keypather.get($scope, 'dataInstance.data.instance'));
}

$timeout(function () {
favico.setInstanceState(keypather.get($scope, 'dataInstance.data.instance'));
});
});
function checkForEnablingHangTightMessage (instance) {
if (!keypather.get(instance, 'contextVersion.getMainAppCodeVersion()')) {
return;
}
if (isBuildingOrStarting(instance.status())) {
if (!demoFlowService.hasSeenHangTightMessage()) {
data.demoFlowFlags.showHangTightMessage = true;
}
} else {
if (data.demoFlowFlags.showHangTightMessage) {
data.demoFlowFlags.showHangTightMessage = false;
demoFlowService.setItem('hasSeenHangTightMessage', instance.id());
}
}
}
function checkForEnablingUrlCallout (instance) {
if (instance.status() === 'running' &&
keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') &&
!demoFlowService.hasSeenUrlCallout() &&
!data.demoFlowFlags.showHangTightMessage) {
data.demoFlowFlags.showUrlCallout = true;
}
}

$scope.$on('dismissUrlCallout', function () {
if (data.demoFlowFlags.showUrlCallout) {
data.demoFlowFlags.showUrlCallout = false;
demoFlowService.setItem('hasSeenUrlCallout', data.instance.id());
}
});
CI.showHangTightMessage = function () {
return demoFlowService.isInDemoFlow() &&
!demoFlowService.hasSeenHangTightMessage() &&
!!keypather.get(dataInstance.data, 'instance.contextVersion.getMainAppCodeVersion()');
};

if (ahaGuide.isInGuide()) {
if (keypather.get(instancesByPod, 'models.length')) {
Expand All @@ -262,9 +233,4 @@ function ControllerInstance(
function fetchCurrentInstance () {
return fetchInstances({ name: $stateParams.instanceName }, true);
}

function isBuildingOrStarting (status) {
return ['building', 'starting'].indexOf(status) !== -1;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

require('app')
.directive('hangTight', hangTight);

function hangTight(
$interval,
demoFlowService,
watchOncePromise
) {
return {
restrict: 'A',
templateUrl: 'firstBuildNotificationView',
scope: {
instance: '='
},
link: function ($scope) {
var instance = $scope.instance;

watchOncePromise($scope, function () {
return instance.status() === 'running';
}, true)
.then(pollContainerUrl);

function pollContainerUrl () {
var timesToPoll = 15;
var stopPolling = $interval(function (timesToPoll) {
// zero indexed, once we've polled 15 times just go to add branch
if (timesToPoll === 14 && instance.status() === 'running') {
$scope.$emit('demo::dismissUrlCallout', instance.id());
return cancelPolling(stopPolling, instance);
}
return demoFlowService.checkStatusOnInstance(instance)
.then(function (statusOK) {
if (statusOK) {
return cancelPolling(stopPolling, instance);
}
});
}, 1000, timesToPoll);
}

function cancelPolling (stopPolling, instance) {
$interval.cancel(stopPolling);
demoFlowService.setItem('hasSeenHangTightMessage', instance.id());
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ function containerUrl(
$scope.openedContainerUrl = eventTracking.openedContainerUrl;
$scope.shouldShowCopyButton = !UNAVAILABLE_OS_LIST.includes($window.navigator.platform);

$scope.dismissUrlCallout = function () {
$scope.$emit('dismissUrlCallout');
};

$scope.onClipboardEvent = function (err) {
if (err) {
var modifier = getModifierKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ button.btn.btn-xs.white(

a.btn.btn-xs.white(
ng-click = "\
dismissUrlCallout();\
$emit('demo::dismissUrlCallout', instance.id());\
openedContainerUrl();\
"
ng-href = "{{getContainerUrl(instance)}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
)

.grid-block(
ng-if = "!dataInstance.data.instance.isMigrating() && (!$root.featureFlags.demoMultiTierBuilding || !dataInstance.data.demoFlowFlags.showHangTightMessage)"
ng-if = "!dataInstance.data.instance.isMigrating() && (!$root.featureFlags.demoMultiTierBuilding || !CI.showHangTightMessage())"
ng-include = "'buildNotificationView'"
)

.grid-block(
ng-if = "$root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage"
ng-include = "'firstBuildNotificationView'"
ng-if = "CI.showHangTightMessage()"
hang-tight
instance = "dataInstance.data.instance"
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function instanceHeader(
$localStorage,
$stateParams,
ahaGuide,
demoFlowService,
eventTracking,
fetchPullRequest,
keypather
Expand Down Expand Up @@ -38,6 +39,14 @@ function instanceHeader(
});
});
$scope.isInGuide = ahaGuide.isInGuide;

$scope.showUrlCallout = function () {
return demoFlowService.isInDemoFlow() &&
!!keypather.get($scope.instance, 'contextVersion.getMainAppCodeVersion()') &&
!demoFlowService.hasSeenUrlCallout() &&
demoFlowService.hasSeenHangTightMessage() &&
keypather.get($scope.instance, 'status()') === 'running';
};
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
)

.popover.bottom.in.popover-url.below-modals(
ng-if = "$root.featureFlags.demoMultiTierUrl && demoFlowFlags.showUrlCallout"
ng-if = "$root.featureFlags.demoMultiTierUrl && showUrlCallout()"
ng-include = "'containerUrlPopoverView'"
)

Expand Down
23 changes: 21 additions & 2 deletions client/services/demoFlowService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ require('app')
.factory('demoFlowService', demoFlowService);

function demoFlowService(
$http,
$localStorage,
$rootScope,
$q,
currentOrg,
defaultContainerUrl,
keypather,
patchOrgMetadata
) {
Expand Down Expand Up @@ -47,6 +50,17 @@ function demoFlowService(
});
}

function checkStatusOnInstance (instance) {
var url = defaultContainerUrl(instance);
return $http.get(url)
.then(function (res) {
return res.status >= 200 && res.status < 300;
})
.catch(function () {
return true;
});
}

function hasSeenHangTightMessage () {
return $localStorage.hasSeenHangTightMessage;
}
Expand All @@ -68,8 +82,14 @@ function demoFlowService(
function isUsingDemoRepo () {
return $localStorage.isUsingDemoRepo;
}
$rootScope.$on('demo::dismissUrlCallout', function ($event, instanceId) {
if (!hasSeenUrlCallout()) {
setItem('hasSeenUrlCallout', instanceId);
}
});

return {
checkStatusOnInstance: checkStatusOnInstance,
endDemoFlow: endDemoFlow,
getItem: getItem,
hasAddedBranch: hasAddedBranch,
Expand All @@ -81,5 +101,4 @@ function demoFlowService(
setIsUsingDemoRepo: setIsUsingDemoRepo,
setItem: setItem
};

}
}
4 changes: 2 additions & 2 deletions client/templates/viewInstance.jade
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
ng-class = "{\
'green': dataInstance.data.showUpdatedMessage,\
'orange': dataInstance.data.showUpdatingMessage || dataInstance.data.instance.isMigrating(),\
'white below-modals': $root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage\
'white below-modals': $root.featureFlags.demoMultiTierBuilding && CI.showHangTightMessage()\
}"
ng-if = "\
(dataInstance.data.showUpdatingMessage || dataInstance.data.showUpdatedMessage) ||\
dataInstance.data.instance.isMigrating() ||\
($root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage)\
($root.featureFlags.demoMultiTierBuilding && CI.showHangTightMessage())\
"
ng-include = "'viewNotifications'"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use strict';

var $rootScope;
var $scope;
var element;
var $compile;
var $interval;
var $q;
var $elScope;

describe('hangTight'.bold.underline.blue, function () {

var mockInstance;
var demoFlowService;
var mockMainACV;
var mockOpenItems;

beforeEach(function () {
angular.mock.module('app', function ($provide) {
$provide.factory('demoFlowService', function ($q) {
demoFlowService = {
checkStatusOnInstance: sinon.stub().returns($q.when(false)),
setItem: sinon.stub()
};
return demoFlowService;
});
});
angular.mock.inject(function (_$compile_, _$interval_, _$rootScope_, _$q_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
$interval = _$interval_;
$scope = $rootScope.$new();
$q = _$q_;
sinon.stub($interval, 'cancel');

mockMainACV = {
attrs: {
mainACVAttrs: true
}
};
mockInstance = {
attrs: {
name: 'foo'
},
restart: sinon.stub(),
fetch: sinon.stub(),
status: sinon.stub().returns('running'),
stop: sinon.stub(),
start: sinon.stub(),
build: {
deepCopy: sinon.stub()
},
contextVersion: {
getMainAppCodeVersion: sinon.stub().returns(mockMainACV)
},
fetchDependencies: sinon.stub().returns({
models: []
}),
id: sinon.stub().returns(1),
on: sinon.stub()
};
$scope.instance = mockInstance;

mockOpenItems = {};

mockOpenItems.getAllFileModels = sinon.stub().returns(mockOpenItems.models);

var template = directiveTemplate.attribute('hang-tight', {
instance: 'instance',
});

element = $compile(template)($scope);
$scope.$digest();
$elScope = element.isolateScope();
});
});

describe('watching instance', function () {
it('should poll the status until it retuns true', function () {
$interval.flush(1000);
$scope.$digest();
sinon.assert.calledOnce(demoFlowService.checkStatusOnInstance);
demoFlowService.checkStatusOnInstance = sinon.stub().returns($q.when(true));
$interval.flush(1000);
$scope.$digest();
sinon.assert.calledOnce($interval.cancel);
sinon.assert.calledOnce(demoFlowService.setItem);
});
it('should emit dismissUrlCallout when it tries 15 times', function () {
var dismissStub = sinon.stub();
$rootScope.$on('demo::dismissUrlCallout', dismissStub);
$interval.flush(1000);
$scope.$digest();
sinon.assert.calledOnce(demoFlowService.checkStatusOnInstance);
$interval.flush(15000);
$scope.$digest();
sinon.assert.calledOnce(dismissStub);
sinon.assert.calledWith(dismissStub, sinon.match.any, mockInstance.id());
sinon.assert.calledOnce($interval.cancel);
sinon.assert.calledOnce(demoFlowService.setItem);
});
});
});
Empty file.

0 comments on commit d7281cd

Please sign in to comment.