Skip to content

Commit

Permalink
Merge pull request #4633 from adube/738-gmf-print-email
Browse files Browse the repository at this point in the history
GMF Print - support sending printed file to email
  • Loading branch information
fredj committed Feb 15, 2019
2 parents f137492 + 89c844d commit d8173b3
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 4 deletions.
8 changes: 8 additions & 0 deletions contribs/gmf/src/authentication/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import olEventsEventTarget from 'ol/events/Target.js';

/**
* @typedef {Object} User
* @property {string|null} email User's email address
* @property {AuthenticationFunctionalities|null} functionalities Configured functionalities of the user
* @property {boolean|null} is_password_changed True if the password of the user has been changed. False otherwise.
* @property {number|null} role_id the role id of the user.
Expand Down Expand Up @@ -209,6 +210,13 @@ export class AuthenticationService extends olEventsEventTarget {
}).then(successFn);
}

/**
* @return {string|null} User's email
*/
getEmail() {
return this.user_.email || null;
}

/**
* @return {?AuthenticationFunctionalities} The role functionalities.
*/
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/controllers/AbstractDesktopController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gmfControllersAbstractAPIController, {AbstractAPIController} from 'gmf/co
import gmfContextualdataModule from 'gmf/contextualdata/module.js';
import gmfEditingModule from 'gmf/editing/module.js';
import gmfPermalinkShareComponent from 'gmf/permalink/shareComponent.js';
import gmfPrintComponent from 'gmf/print/component.js';
import gmfPrintModule from 'gmf/print/module.js';
import gmfProfileModule from 'gmf/profile/module.js';
import gmfRasterComponent from 'gmf/raster/component.js';
import ngeoDrawFeatures from 'ngeo/draw/features.js';
Expand Down Expand Up @@ -258,7 +258,7 @@ const module = angular.module('GmfAbstractDesktopControllerModule', [
gmfContextualdataModule.name,
gmfEditingModule.name,
gmfPermalinkShareComponent.name,
gmfPrintComponent.name,
gmfPrintModule.name,
gmfProfileModule.name,
gmfRasterComponent.name,
ngeoDrawFeatures.name,
Expand Down
21 changes: 21 additions & 0 deletions contribs/gmf/src/print/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@

</div>

<div
ng-show="$ctrl.smtpSupported && $ctrl.smtpEmail"
class="gmf-print-smtp checkbox">
<label>
<input
ng-disabled="$ctrl.isState('PRINTING')"
ng-model="$ctrl.smtpEnabled"
type="checkbox">
<span translate>Send file by email</span>
</label>
</div>

<div class="gmf-print-actions form-group pull-right">
<span ng-show="$ctrl.isState('PRINTING')">
<i class="fa fa-refresh fa-spinner fa-spin"></i>
Expand Down Expand Up @@ -217,4 +229,13 @@
class="gmf-print-error-capabilities form-group pull-left text-danger">
<p>{{'The print server is unavailable. Please, try later.' | translate}}</p>
</div>

<div
ng-show="$ctrl.smtpMessage"
class="gmf-print-smtp-message form-group pull-left">
<button
class="btn prime"
ng-click="$ctrl.closeSmtpMessage()" translate>Close</button>
<p>{{'The file will be sent to your email when ready.' | translate}}</p>
</div>
</div>
49 changes: 48 additions & 1 deletion contribs/gmf/src/print/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,33 @@ class Controller {
*/
this.rotation = 0;

/**
* The email of the user to which send the file. Obtained from the
* authentication service.
* @type {?string}
*/
this.smtpEmail = null;

/**
* Whether to send the printed file by email or not.
* @type {boolean}
*/
this.smtpEnabled = false;

/**
* Flag that determines whether to show a message notifying the
* user about his upcomping file or not.
* @type {boolean}
*/
this.smtpMessage = false;

/**
* Whether sending file by email is supported or not. Obtained
* from the print capabilities.
* @type {boolean}
*/
this.smtpSupported = false;

/**
* @type {Array.<string>}
*/
Expand Down Expand Up @@ -567,6 +594,11 @@ class Controller {
this.capabilities_ = null;
});

// Store user email
this.$scope_.$watch(() => this.gmfAuthenticationService_.getEmail(), (newValue) => {
this.smtpEmail = newValue;
});

this.$scope_.$watch(() => this.active, (active) => {
this.togglePrintPanel_(active);
});
Expand Down Expand Up @@ -701,6 +733,8 @@ class Controller {
this.layoutInfo.layouts.push(layout.name);
});

this.smtpSupported = data['smtp'] && data['smtp']['enabled'];

this.updateFields_();
}

Expand Down Expand Up @@ -976,8 +1010,10 @@ class Controller {
group.set('printNativeAngle', print_native_angle);
map.setLayerGroup(group);

const email = this.smtpSupported && this.smtpEmail && this.smtpEnabled ? this.smtpEmail : undefined;

const spec = this.ngeoPrint_.createSpec(map, scale, this.layoutInfo.dpi,
this.layoutInfo.layout, format, customAttributes);
this.layoutInfo.layout, format, customAttributes, email);

// Add feature overlay layer to print spec.
const layers = [];
Expand Down Expand Up @@ -1132,6 +1168,10 @@ class Controller {
// The report is ready. Open it by changing the window location.
window.location.href = this.ngeoPrint_.getReportUrl(ref);
this.resetPrintStates_();
// If the file was sent by email, show message
if (this.smtpSupported && this.smtpEmail && this.smtpEnabled) {
this.smtpMessage = true;
}
} else {
console.error(mfResp.error);
this.handleCreateReportError_();
Expand Down Expand Up @@ -1303,6 +1343,13 @@ class Controller {
isState(stateEnumKey) {
return this.gmfPrintState_.state === PrintStateEnum[stateEnumKey];
}

/**
* Close the SMTP message
*/
closeSmtpMessage() {
this.smtpMessage = false;
}
}

module.controller('GmfPrintController', Controller);
Expand Down
14 changes: 14 additions & 0 deletions contribs/gmf/src/print/print.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
width: 5rem;
}
}

.gmf-print-smtp-message {
background-color: white;
clear: both;
padding: 10px;

button {
float: right;
}

p {
margin: 0;
}
}
7 changes: 6 additions & 1 deletion src/print/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ PrintService.prototype.cancel = function(ref, opt_httpConfig) {
* @param {string} layout Layout.
* @param {string} format Formats.
* @param {Object.<string, *>} customAttributes Custom attributes.
* @param {string=} email Email to send the file to.
* @return {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSpec} The print spec.
*/
PrintService.prototype.createSpec = function(
map, scale, dpi, layout, format, customAttributes) {
map, scale, dpi, layout, format, customAttributes, email) {

const specMap = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintMap} */ ({
dpi: dpi,
Expand All @@ -152,6 +153,10 @@ PrintService.prototype.createSpec = function(
layout
};

if (email) {
spec.smtp = {to: email};
}

return spec;
};

Expand Down
8 changes: 8 additions & 0 deletions src/print/mapfish-print-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @property {string} layout
* @property {string} format
* @property {string} lang
* @property {MapFishPrintSMTP} [smtp] STMP object definition
*/


Expand Down Expand Up @@ -184,6 +185,13 @@
* @property {string} fontColor
*/


/**
* @typedef {Object} MapFishPrintSMTP
* @property {string} to Email address
*/


/**
* @hidden
*/
Expand Down

0 comments on commit d8173b3

Please sign in to comment.