Skip to content

Commit

Permalink
#174 connect to pdf service
Browse files Browse the repository at this point in the history
  • Loading branch information
dlamoris committed Mar 6, 2023
1 parent 6fe7850 commit 99f79c6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
3 changes: 2 additions & 1 deletion app/config/config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
//Do not modify the structure of this
window.__env = {
// View Editor Version
version: '4.0.1',
version: '4.0.2',
// API url
apiUrl: 'http://localhost:8080',
// Base url
baseUrl: '',
printUrl: 'http://localhost:8080/convert',
enableDebug: true,
// Configuration for the banner below the login modal (only visible at login)
loginBanner: {
Expand Down
4 changes: 3 additions & 1 deletion app/js/mms/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ angular.module('mmsApp', ['mms', 'mms.directives', 'app.tpls', 'fa.directive.bor
var mmsHost = window.location.protocol + '//' + window.location.host;
URLServiceProvider.setMmsUrl(mmsHost);
}

if (window.__env.printUrl) {
URLServiceProvider.setPrintUrl(window.__env.printUrl);
}



Expand Down
3 changes: 3 additions & 0 deletions app/js/mms/controllers/controller.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,14 @@ function MmsAppUtils($q, $uibModal, $timeout, $location, $window, growl,
if (result.tof != '') htmlArr.push(result.tof);
htmlArr.push(result.contents, '</body></html>');
var htmlString = htmlArr.join('');
growl.info('Generating, please wait...', {ttl: -1});
UtilsService.exportHtmlAs(mode, {htmlString: htmlString, name: viewOrDocOb.name, projectId: viewOrDocOb._projectId, refId: viewOrDocOb._refId, css: css})
.then(function(result) {
growl.success('File Downloaded', {ttl: -1});
deferred.resolve(result);
}, function(reason){
deferred.reject(reason);
growl.error('Generation Failed');
});
}
} else {
Expand Down
9 changes: 5 additions & 4 deletions app/js/mms/controllers/fulldoc.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function($scope, $state, $anchorScroll, $location, $timeout, $http, FullDocument
$scope.bbApi.addButton(UxService.getButtonBarButton('print'));
var exportButtons = UxService.getButtonBarButton('export');
exportButtons.dropdown_buttons.push(UxService.getButtonBarButton("convert-pdf"));
//exportButtons.dropdown_buttons.push(UxService.getButtonBarButton("word"));
$scope.bbApi.addButton(exportButtons);
$scope.bbApi.setToggleState('show-comments', rootScopeSvc.veCommentsOn());
$scope.bbApi.setToggleState('show-elements', rootScopeSvc.veElementsOn());
Expand Down Expand Up @@ -172,9 +173,9 @@ function($scope, $state, $anchorScroll, $location, $timeout, $http, FullDocument
fullDocumentService.loadRemainingViews(function() {
MmsAppUtils.printModal(documentOb, refOb, true, 3)
.then(function(ob) {
growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
//growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
}, function(reason){
growl.error("Exporting as PDF file Failed: " + reason.message);
//growl.error("Exporting as PDF file Failed: " + reason.message);
});
});
}));
Expand All @@ -189,9 +190,9 @@ function($scope, $state, $anchorScroll, $location, $timeout, $http, FullDocument
fullDocumentService.loadRemainingViews(function() {
MmsAppUtils.printModal(documentOb, refOb, true, 2)
.then(function(ob) {
growl.info('Exporting as Word file. Please wait for a completion email.',{ttl: -1});
//growl.info('Exporting as Word file. Please wait for a completion email.',{ttl: -1});
}, function(reason){
growl.error("Exporting as Word file Failed: " + reason.message);
//growl.error("Exporting as Word file Failed: " + reason.message);
});
});
}));
Expand Down
8 changes: 4 additions & 4 deletions app/js/mms/controllers/view.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ angular.module('mmsApp')
return;
MmsAppUtils.printModal(viewOb, refOb, false, 3)
.then(function(ob) {
growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
// growl.info('Exporting as PDF file. Please wait for a completion email.',{ttl: -1});
}, function(reason){
growl.error("Exporting as PDF file Failed: " + reason.message);
//growl.error("Exporting as PDF file Failed: " + reason.message);
});
}));

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

Expand Down
4 changes: 2 additions & 2 deletions app/partials/mms/printConfirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ <h4>{{action}} {{type | lowercase}}</h4>
</p>
<p ng-if="mode !== 1">
<span ng-if="type === 'VIEW'">
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.
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.
</span>
<span ng-if="type === 'DOCUMENT'">
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}}.
Please wait until the full document appears in this pane before continuing.
</span>
</p>
<p ng-if="type == 'DOCUMENT' && mode === 3">
Expand Down
14 changes: 8 additions & 6 deletions src/services/URLService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ angular.module('mms')
.provider('URLService', function URLServiceProvider() {
var baseUrl = '/api';
var mmsUrl = 'localhost:8080';
var printUrl = 'http://localhost:8080/convert';
this.setBaseUrl = function (base) {
baseUrl = base;
};
this.setMmsUrl = function (mms) {
mmsUrl = mms;
};
this.setPrintUrl = function (print) {
printUrl = print;
};
this.$get = [function URLServiceFactory() {
return urlService(baseUrl, mmsUrl);
return urlService(baseUrl, mmsUrl, printUrl);
}];
});

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

var getRoot = function() {
Expand Down Expand Up @@ -149,9 +152,8 @@ function urlService(baseUrl, mmsUrl) {
* @param {string} refId id of the ref
* @returns {string} The url
*/
var getExportHtmlUrl = function(projectId, refId) {
return root + "/projects/" + projectId +
"/refs/" + refId + '/convert';
var getExportHtmlUrl = function() {
return printUrl;
};


Expand Down
21 changes: 14 additions & 7 deletions src/services/UtilsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,14 +1324,21 @@ function UtilsService($q, $http, CacheService, URLService, ApplicationService, _
accept = 'application/pdf';
}
var deferred = $q.defer();
$http.post(URLService.getExportHtmlUrl(data.projectId, data.refId), {
'Content-Type' : 'text/html',
'Accepts' : accept,
'body': data.htmlString,
'name': data.name,
'css': data.css
$http.post(URLService.getExportHtmlUrl(), {
'html': data.htmlString,
'css': data.css,
'format': exportType == 2 ? 'docx' : 'pdf'
}, {
responseType: 'blob'
})
.then(function() {
.then(function(data2) {
var blob = new Blob([data2.data], {type: accept});
var a = window.document.createElement('a');
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = data.name + (exportType == 2 ? '.docx' : '.pdf');
a.click();
window.URL.revokeObjectURL(url);
deferred.resolve('ok');
}, function(error) {
URLService.handleHttpStatus(error.data, error.status, error.headers, error.config, deferred);
Expand Down

0 comments on commit 99f79c6

Please sign in to comment.