-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51d5a3b
commit 094aa16
Showing
11 changed files
with
211 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
angular.module('PEPFAR.approvals').directive('analyticsStatus', analyticsStatusDirective); | ||
|
||
function analyticsStatusDirective() { | ||
return { | ||
restrict: 'E', | ||
scope: true, | ||
template: '<div class="analytics-status-update" ng-bind="analyticsStatusCtrl.getStatusText()"></div>', | ||
controller: analyticsStatusCtrl, | ||
controllerAs: 'analyticsStatusCtrl', | ||
bindToController: true | ||
}; | ||
|
||
function analyticsStatusCtrl(analyticsStatus, $timeout) { | ||
var vm = this; | ||
var analyticsUpdateInterval; | ||
|
||
vm.getStatusText = getStatusText; | ||
|
||
initialise(); | ||
function initialise() { | ||
getStatusUpdate(); | ||
} | ||
|
||
function getStatusUpdate() { | ||
analyticsStatus.getIntervalSinceLastAnalyticsTableSuccess() | ||
.then(function (intervalSinceLastAnalyticsTableSuccess) { | ||
|
||
analyticsUpdateInterval = [ | ||
'Data was updated', | ||
intervalSinceLastAnalyticsTableSuccess, | ||
'ago' | ||
].join(' '); | ||
}) | ||
.catch(function (message) { | ||
analyticsUpdateInterval = message; | ||
$timeout(getStatusUpdate, 30000); | ||
}) | ||
.finally(function () { | ||
$timeout(getStatusUpdate, 30000); | ||
}); | ||
} | ||
|
||
function getStatusText() { | ||
return analyticsUpdateInterval; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
angular.module('PEPFAR.approvals').factory('analyticsStatus', analyticsStatus); | ||
|
||
function analyticsStatus(Restangular, errorHandler, $q) { | ||
return { | ||
getIntervalSinceLastAnalyticsTableSuccess: getIntervalSinceLastAnalyticsTableSuccess | ||
}; | ||
|
||
function getIntervalSinceLastAnalyticsTableSuccess() { | ||
var NOT_FOUND_MESSAGE = 'Unable to find last updated time'; | ||
|
||
return Restangular.all('system').get('info') | ||
.then(function (systemInfo) { | ||
if (systemInfo.intervalSinceLastAnalyticsTableSuccess) { | ||
return systemInfo.intervalSinceLastAnalyticsTableSuccess; | ||
} | ||
return $q.reject(NOT_FOUND_MESSAGE); | ||
}) | ||
.catch(function () { | ||
return $q.reject(NOT_FOUND_MESSAGE); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"0.3.0","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"[email protected]"},"launch_path":"index.html","default_locale":"en","activities":{"dhis":{"href":"*"}}} | ||
{"version":"0.3.1","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"[email protected]"},"launch_path":"index.html","default_locale":"en","activities":{"dhis":{"href":"*"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/specs/analyticsstatus/analyticsstatus-directive_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
describe('Analytis status directive', function () { | ||
var element; | ||
var scope; | ||
var $timeout; | ||
|
||
beforeEach(module('PEPFAR.approvals', function ($provide) { | ||
$provide.factory('analyticsStatus', function ($q) { | ||
return { | ||
getIntervalSinceLastAnalyticsTableSuccess: jasmine.createSpy() | ||
.andReturn($q.when(fixtures.get('system/info').intervalSinceLastAnalyticsTableSuccess)) | ||
}; | ||
}); | ||
})); | ||
beforeEach(inject(function ($injector) { | ||
$rootScope = $injector.get('$rootScope'); | ||
$compile = $injector.get('$compile'); | ||
$timeout = $injector.get('$timeout'); | ||
element = angular.element('<analytics-status></analytics-status>'); | ||
|
||
scope = $rootScope.$new(); | ||
element = $compile(element)(scope).children().first(); | ||
scope.$digest(); | ||
})); | ||
|
||
it('should compile to a div', function () { | ||
expect(element.prop('tagName')).toBe('DIV'); | ||
}); | ||
|
||
it('should show the time of the last update', function () { | ||
expect(element[0].textContent).toEqual('Data was updated 996 h, 36 m, 11 s ago'); | ||
}); | ||
|
||
it('should update the time after a certain period', inject(function (analyticsStatus, $q) { | ||
expect(element[0].textContent).toEqual('Data was updated 996 h, 36 m, 11 s ago'); | ||
|
||
analyticsStatus.getIntervalSinceLastAnalyticsTableSuccess | ||
.andReturn($q.when('0 h, 36 m, 11 s')); | ||
|
||
$timeout.flush(30000); | ||
|
||
expect(element[0].textContent).toEqual('Data was updated 0 h, 36 m, 11 s ago'); | ||
})); | ||
|
||
it('should not display anything if the status update failed', inject(function (analyticsStatus, $q) { | ||
expect(element[0].textContent).toEqual('Data was updated 996 h, 36 m, 11 s ago'); | ||
|
||
analyticsStatus.getIntervalSinceLastAnalyticsTableSuccess | ||
.andReturn($q.reject('Unable to find last updated time')); | ||
|
||
$timeout.flush(30000); | ||
|
||
expect(element[0].textContent).toEqual('Unable to find last updated time'); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters