Skip to content

Commit 99f79c6

Browse files
committed
#174 connect to pdf service
1 parent 6fe7850 commit 99f79c6

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
lines changed

app/config/config.example.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
//Do not modify the structure of this
1414
window.__env = {
1515
// View Editor Version
16-
version: '4.0.1',
16+
version: '4.0.2',
1717
// API url
1818
apiUrl: 'http://localhost:8080',
1919
// Base url
2020
baseUrl: '',
21+
printUrl: 'http://localhost:8080/convert',
2122
enableDebug: true,
2223
// Configuration for the banner below the login modal (only visible at login)
2324
loginBanner: {

app/js/mms/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ angular.module('mmsApp', ['mms', 'mms.directives', 'app.tpls', 'fa.directive.bor
6161
var mmsHost = window.location.protocol + '//' + window.location.host;
6262
URLServiceProvider.setMmsUrl(mmsHost);
6363
}
64-
64+
if (window.__env.printUrl) {
65+
URLServiceProvider.setPrintUrl(window.__env.printUrl);
66+
}
6567

6668

6769

app/js/mms/controllers/controller.utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@ function MmsAppUtils($q, $uibModal, $timeout, $location, $window, growl,
256256
if (result.tof != '') htmlArr.push(result.tof);
257257
htmlArr.push(result.contents, '</body></html>');
258258
var htmlString = htmlArr.join('');
259+
growl.info('Generating, please wait...', {ttl: -1});
259260
UtilsService.exportHtmlAs(mode, {htmlString: htmlString, name: viewOrDocOb.name, projectId: viewOrDocOb._projectId, refId: viewOrDocOb._refId, css: css})
260261
.then(function(result) {
262+
growl.success('File Downloaded', {ttl: -1});
261263
deferred.resolve(result);
262264
}, function(reason){
263265
deferred.reject(reason);
266+
growl.error('Generation Failed');
264267
});
265268
}
266269
} else {

app/js/mms/controllers/fulldoc.controller.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function($scope, $state, $anchorScroll, $location, $timeout, $http, FullDocument
5757
$scope.bbApi.addButton(UxService.getButtonBarButton('print'));
5858
var exportButtons = UxService.getButtonBarButton('export');
5959
exportButtons.dropdown_buttons.push(UxService.getButtonBarButton("convert-pdf"));
60+
//exportButtons.dropdown_buttons.push(UxService.getButtonBarButton("word"));
6061
$scope.bbApi.addButton(exportButtons);
6162
$scope.bbApi.setToggleState('show-comments', rootScopeSvc.veCommentsOn());
6263
$scope.bbApi.setToggleState('show-elements', rootScopeSvc.veElementsOn());
@@ -172,9 +173,9 @@ function($scope, $state, $anchorScroll, $location, $timeout, $http, FullDocument
172173
fullDocumentService.loadRemainingViews(function() {
173174
MmsAppUtils.printModal(documentOb, refOb, true, 3)
174175
.then(function(ob) {
175-
growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
176+
//growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
176177
}, function(reason){
177-
growl.error("Exporting as PDF file Failed: " + reason.message);
178+
//growl.error("Exporting as PDF file Failed: " + reason.message);
178179
});
179180
});
180181
}));
@@ -189,9 +190,9 @@ function($scope, $state, $anchorScroll, $location, $timeout, $http, FullDocument
189190
fullDocumentService.loadRemainingViews(function() {
190191
MmsAppUtils.printModal(documentOb, refOb, true, 2)
191192
.then(function(ob) {
192-
growl.info('Exporting as Word file. Please wait for a completion email.',{ttl: -1});
193+
//growl.info('Exporting as Word file. Please wait for a completion email.',{ttl: -1});
193194
}, function(reason){
194-
growl.error("Exporting as Word file Failed: " + reason.message);
195+
//growl.error("Exporting as Word file Failed: " + reason.message);
195196
});
196197
});
197198
}));

app/js/mms/controllers/view.controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ angular.module('mmsApp')
246246
return;
247247
MmsAppUtils.printModal(viewOb, refOb, false, 3)
248248
.then(function(ob) {
249-
growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
249+
// growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
250250
}, function(reason){
251-
growl.error("Exporting as PDF file Failed: " + reason.message);
251+
//growl.error("Exporting as PDF file Failed: " + reason.message);
252252
});
253253
}));
254254

@@ -263,9 +263,9 @@ angular.module('mmsApp')
263263
return;
264264
MmsAppUtils.printModal(viewOb, refOb, false, 2)
265265
.then(function(ob) {
266-
growl.info('Exporting as Word file. Please wait for a completion email.',{ttl: -1});
266+
//growl.info('Exporting as Word file. Please wait for a completion email.',{ttl: -1});
267267
}, function(reason){
268-
growl.error("Exporting as Word file Failed: " + reason.message);
268+
//growl.error("Exporting as Word file Failed: " + reason.message);
269269
});
270270
}));
271271

app/partials/mms/printConfirm.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ <h4>{{action}} {{type | lowercase}}</h4>
1616
</p>
1717
<p ng-if="mode !== 1">
1818
<span ng-if="type === 'VIEW'">
19-
Click on {{action | uppercase}} to generate a {{label}} of this view (it will not include table of contents or cover pages). You will receive an email with subject line "HTML to {{label}} generation completed" with a link to the generated {{label | uppercase}}. If you want the full document instead, please click on GO TO FULL DOCUMENT.
19+
Click on {{action | uppercase}} to generate a {{label}} of this view (it will not include table of contents or cover pages). If you want the full document instead, please click on GO TO FULL DOCUMENT.
2020
</span>
2121
<span ng-if="type === 'DOCUMENT'">
22-
Please wait until the full document appears in this pane before continuing. You will receive an email with subject line "HTML to {{label}} generation completed" with a link to the generated {{label}}.
22+
Please wait until the full document appears in this pane before continuing.
2323
</span>
2424
</p>
2525
<p ng-if="type == 'DOCUMENT' && mode === 3">

src/services/URLService.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ angular.module('mms')
44
.provider('URLService', function URLServiceProvider() {
55
var baseUrl = '/api';
66
var mmsUrl = 'localhost:8080';
7+
var printUrl = 'http://localhost:8080/convert';
78
this.setBaseUrl = function (base) {
89
baseUrl = base;
910
};
1011
this.setMmsUrl = function (mms) {
1112
mmsUrl = mms;
1213
};
14+
this.setPrintUrl = function (print) {
15+
printUrl = print;
16+
};
1317
this.$get = [function URLServiceFactory() {
14-
return urlService(baseUrl, mmsUrl);
18+
return urlService(baseUrl, mmsUrl, printUrl);
1519
}];
1620
});
1721

@@ -37,9 +41,8 @@ angular.module('mms')
3741
* (You may run into problems like cross origin security policy that prevents it from
3842
* actually getting the resources from a different server, solution TBD)
3943
*/
40-
function urlService(baseUrl, mmsUrl) {
44+
function urlService(baseUrl, mmsUrl, printUrl) {
4145
var root = mmsUrl + baseUrl;
42-
var jobsRoot = 'https://cae-pma-int:8443/';
4346
var token;
4447

4548
var getRoot = function() {
@@ -149,9 +152,8 @@ function urlService(baseUrl, mmsUrl) {
149152
* @param {string} refId id of the ref
150153
* @returns {string} The url
151154
*/
152-
var getExportHtmlUrl = function(projectId, refId) {
153-
return root + "/projects/" + projectId +
154-
"/refs/" + refId + '/convert';
155+
var getExportHtmlUrl = function() {
156+
return printUrl;
155157
};
156158

157159

src/services/UtilsService.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,14 +1324,21 @@ function UtilsService($q, $http, CacheService, URLService, ApplicationService, _
13241324
accept = 'application/pdf';
13251325
}
13261326
var deferred = $q.defer();
1327-
$http.post(URLService.getExportHtmlUrl(data.projectId, data.refId), {
1328-
'Content-Type' : 'text/html',
1329-
'Accepts' : accept,
1330-
'body': data.htmlString,
1331-
'name': data.name,
1332-
'css': data.css
1327+
$http.post(URLService.getExportHtmlUrl(), {
1328+
'html': data.htmlString,
1329+
'css': data.css,
1330+
'format': exportType == 2 ? 'docx' : 'pdf'
1331+
}, {
1332+
responseType: 'blob'
13331333
})
1334-
.then(function() {
1334+
.then(function(data2) {
1335+
var blob = new Blob([data2.data], {type: accept});
1336+
var a = window.document.createElement('a');
1337+
var url = window.URL.createObjectURL(blob);
1338+
a.href = url;
1339+
a.download = data.name + (exportType == 2 ? '.docx' : '.pdf');
1340+
a.click();
1341+
window.URL.revokeObjectURL(url);
13351342
deferred.resolve('ok');
13361343
}, function(error) {
13371344
URLService.handleHttpStatus(error.data, error.status, error.headers, error.config, deferred);

0 commit comments

Comments
 (0)