Skip to content

Commit

Permalink
add a refresh option that you can trigger in your template to reset t…
Browse files Browse the repository at this point in the history
…he download
  • Loading branch information
fredkingham committed May 24, 2017
1 parent 61b4652 commit 24b9d4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions reporting/static/js/reporting/services/report.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
angular.module('opal.reporting').factory('Report', function($window, $interval, $http){
"use strict";
var Report = function(reportDefinition){
this.refresh();
_.extend(this, reportDefinition);
this.asyncWaiting = false;
this.asyncReady = false;
this.criteria = {};
};

Report.prototype = {
refresh: function(){
this.asyncWaiting = false;
this.asyncReady = false;
this.reportStatusUrl = null;
this.reportFileUrl = null;
},
downloadAsynchronously: function(){
$window.open(this.reportFileUrl, '_blank');
},
Expand Down
15 changes: 14 additions & 1 deletion reporting/static/js/test/report.service.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Report', function(){
"use strict";
"use strict";
var Report, $window, $httpBackend, $interval, $rootScope;


Expand Down Expand Up @@ -27,6 +27,19 @@ var Report, $window, $httpBackend, $interval, $rootScope;
expect(report.asyncWaiting).toBe(false);
});

it('should refresh the report', function(){
var report = new Report({download_link: "some_link"});
report.asyncReady = true;
report.asyncWaiting = true;
report.reportStatusUrl = "blah";
report.reportFileUrl = "otherBlah";
report.refresh();
expect(report.asyncReady).toBe(false);
expect(report.asyncWaiting).toBe(false);
expect(report.reportStatusUrl).toBe(null);
expect(report.reportFileUrl).toBe(null);
});

it('show open a window on download', function(){
var report = new Report({reportFileUrl: "some_link"});
report.downloadAsynchronously();
Expand Down

0 comments on commit 24b9d4e

Please sign in to comment.