Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2129 from geoadmin/teo_cancel
Browse files Browse the repository at this point in the history
Cancel the print process
  • Loading branch information
oterral committed Feb 18, 2015
2 parents 5d53d29 + 48b324e commit 2415b4d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/components/offline/partials/offline-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
translate>offline_save</button>
<button ng-show="isDownloading"class="btn btn-danger"
ng-click="abort()"
translate>offline_abort</button>
translate>abort</button>
</div>

107 changes: 78 additions & 29 deletions src/components/print/PrintDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
'pascalprecht.translate']);

module.controller('GaPrintDirectiveController', function($rootScope, $scope,
$http, $window, $translate, $timeout,
gaLayers, gaPermalink, gaBrowserSniffer, gaWaitCursor) {
$http, $q, $window, $translate, $timeout, gaLayers, gaPermalink,
gaBrowserSniffer, gaWaitCursor) {

var pdfLegendsToDownload = [];
var pdfLegendString = '_big.pdf';
Expand All @@ -23,7 +23,8 @@
var printConfigLoaded = false;
var currentTime = undefined;
var layersYears = [];

var canceller;
var currentMultiPrintId;
$scope.options.multiprint = false;
$scope.options.movie = false;
$scope.options.printing = false;
Expand All @@ -32,8 +33,10 @@

// Get print config
var updatePrintConfig = function() {
var http = $http.get($scope.options.printConfigUrl);
http.success(function(data) {
canceller = $q.defer();
var http = $http.get($scope.options.printConfigUrl, {
timeout: canceller.promise
}).success(function(data) {
$scope.capabilities = data;

// default values:
Expand Down Expand Up @@ -591,6 +594,27 @@
$scope.options.printing = false;
};

// Abort the print process
var pollMultiPromise; // Promise of the last $timeout called
$scope.abort = function() {
$scope.options.printing = false;
// Abort the current $http request
if (canceller) {
canceller.resolve();
}
// Abort the current $timeout
if (pollMultiPromise) {
$timeout.cancel(pollMultiPromise);
}
// Tell the server to cancel the print process
if (currentMultiPrintId) {
$http.get($scope.options.printPath + 'cancel?id=' +
currentMultiPrintId);
currentMultiPrintId = null;
}
};

// Start the print process
$scope.submit = function() {
if (!$scope.options.active) {
return;
Expand All @@ -613,6 +637,7 @@
pdfLegendsToDownload = [];
layersYears = [];

// Transform layers to literal
angular.forEach(layers, function(layer) {
if (layer.visible) {
var attribution = layer.attribution;
Expand Down Expand Up @@ -648,6 +673,8 @@
});
defaultPage['timestamp'] = years.join(',');
}

// Transform graticule to literal
if ($scope.options.graticule) {
var graticule = {
'baseURL': 'http://wms.geo.admin.ch/',
Expand All @@ -663,6 +690,8 @@
};
encLayers.push(graticule);
}

// Transform overlays to literal
// FIXME this is a temporary solution
var overlays = $scope.map.getOverlays();
var resolution = $scope.map.getView().getResolution();
Expand Down Expand Up @@ -705,25 +734,34 @@
}
});

var scales = this.scales.map(function(scale) {
return parseInt(scale.value);
});
var that = this;
$http.get($scope.options.shortenUrl, {

// Get the short link
var shortLink;
canceller = $q.defer();
var promise = $http.get($scope.options.shortenUrl, {
timeout: canceller.promise,
params: {
url: gaPermalink.getHref()
}
}).success(function(response) {
shortLink = response.shorturl.replace('/shorten', '');
});

// Build the complete json then send it to the print server
promise.then(function() {
if (!$scope.options.printing) {
return;
}
var movieprint = $scope.options.movie && $scope.options.multiprint;
var spec = {
layout: that.layout.name,
layout: $scope.layout.name,
srs: proj.getCode(),
units: proj.getUnits() || 'm',
rotation: -((view.getRotation() * 180.0) / Math.PI),
app: 'config',
lang: lang,
//use a function to get correct dpi according to layout (A4/A3)
dpi: getDpi(that.layout.name, that.dpi),
dpi: getDpi($scope.layout.name, $scope.dpi),
layers: encLayers,
legends: encLegends,
enableLegends: (encLegends && encLegends.length > 0),
Expand All @@ -733,22 +771,29 @@
angular.extend({
center: getPrintRectangleCenterCoord(),
bbox: getPrintRectangleCoords(),
display: [that.layout.map.width, that.layout.map.height],
display: [$scope.layout.map.width, $scope.layout.map.height],
// scale has to be one of the advertise by the print server
scale: $scope.scale.value,
dataOwner: '© ' + attributions.join(),
shortLink: response.shorturl.replace('/shorten', ''),
shortLink: shortLink || '',
rotation: -((view.getRotation() * 180.0) / Math.PI)
}, defaultPage)
]
};

var startPollTime;
var pollErrors;
var pollMulti = function(url) {
$timeout(function() {
var http = $http.get(url);
http.success(function(data) {
pollMultiPromise = $timeout(function() {
if (!$scope.options.printing) {
return;
}
canceller = $q.defer();
var http = $http.get(url, {
timeout: canceller.promise
}).success(function(data) {
if (!$scope.options.printing) {
return;
}
if (!data.getURL) {
// Write progress using the following logic
// First 60% is pdf page creationg
Expand Down Expand Up @@ -781,6 +826,10 @@
$scope.downloadUrl(data.getURL);
}
}).error(function() {
if ($scope.options.printing == false) {
pollErrors = 0;
return;
}
pollErrors += 1;
if (pollErrors > 2) {
$scope.options.printing = false;
Expand All @@ -791,18 +840,21 @@
}, POLL_INTERVAL, false);
};

var printUrl = that.capabilities.createURL;
var printUrl = $scope.capabilities.createURL;
//When movie is on, we use printmulti
if (movieprint) {
printUrl = printUrl.replace('/print/', '/printmulti/');
}
var http = $http.post(printUrl + '?url=' +
encodeURIComponent(printUrl), spec);
http.success(function(data) {
canceller = $q.defer();
var http = $http.post(printUrl + '?url=' + encodeURIComponent(printUrl),
spec, {
timeout: canceller.promise
}).success(function(data) {
if (movieprint) {
//start polling process
var pollUrl = $scope.options.printPath + 'progress?id=' +
data.idToCheck;
currentMultiPrintId = data.idToCheck;
startPollTime = new Date();
pollErrors = 0;
pollMulti(pollUrl);
Expand All @@ -812,18 +864,16 @@
}).error(function() {
$scope.options.printing = false;
});
}).error(function() {
$scope.options.printing = false;
});
};

function getDpi(layoutName, dpiConfig) {
var getDpi = function(layoutName, dpiConfig) {
if (/a4/i.test(layoutName) && dpiConfig.length > 1) {
return dpiConfig[1].value;
} else {
return dpiConfig[0].value;
}
}
};

var getPrintRectangleCoords = function() {
// Framebuffer size!!
Expand Down Expand Up @@ -935,13 +985,12 @@
});

module.directive('gaPrint',
function($http, $log, $translate) {
function() {
return {
restrict: 'A',
templateUrl: 'components/print/partials/print.html',
controller: 'GaPrintDirectiveController',
link: function(scope, elt, attrs, controller) {
}
link: function(scope, elt, attrs, controller) {}
};
}
);
Expand Down
9 changes: 8 additions & 1 deletion src/components/print/partials/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
</div>
</div>
<div class="ga-print-progress" ng-if="options.printing && options.progress != ''">{{options.progress}}</div>
<button type="submit" class="btn btn-default col-xs-12" accesskey="p" ng-disabled="options.printing" ng-click="submit()" translate>print_action</button>
<button ng-show="options.printing" class="btn btn-danger col-xs-12"
ng-click="abort()"
translate>abort</button>
<button type="submit"
class="btn btn-default col-xs-12"
accesskey="p"
ng-hide="options.printing"
ng-click="submit()" translate>print_action</button>
<!-- this span is purely for e2e testing purposes, to detect print success/failure in DOM -->
<span ng-if="options.printsuccess"></span>
</form>
2 changes: 1 addition & 1 deletion src/locales/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"abort": "Abbrechen",
"add_layer": "Layer hinzufügen",
"add_wms_layer_failed": "Fehler beim Laden WMS Layer",
"add_wms_layer_succeeded": "WMS Layer erfolgreich geladen",
Expand Down Expand Up @@ -180,7 +181,6 @@
"object_information": "Objekt-Information",
"obstacle_deleted_last_2_weeks": "Gelöschte Hindernisse letzte 2 Wochen",
"obstacle_started_last_2_weeks": "Aktivierte Hindernisse letzte 2 Wochen",
"offline_abort": "Abbrechen",
"offline_abort_warning": "Wollen Sie wirklich alle Karten löschen?",
"offline_bad_layer_type": "Einer der Datensätze kann nicht für den Offline-Gebrauch gespeichert werden.",
"offline_clear_db_error": "Fehler beim Löschen der gespeicherten Karten. Bitte versuchen Sie es noch einmal.",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/empty.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"vu_service_link_label": "",
"vu_service_link_href": "",
"offline_save": "",
"offline_abort": "",
"abort": "",
"offline_modal_title": "",
"offline_delete_data": "",
"offline_show_extent": "",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"abort": "Abort",
"add_layer": "Add Layer",
"add_wms_layer_failed": "Error when loading WMS layer",
"add_wms_layer_succeeded": "WMS layer successfully loaded",
Expand Down Expand Up @@ -180,7 +181,6 @@
"object_information": "Object information",
"obstacle_deleted_last_2_weeks": "Deleted obstacles of last 2 weeks",
"obstacle_started_last_2_weeks": "Activated obstacles of last 2 weeks",
"offline_abort": "Abort",
"offline_abort_warning": "Do you really want to delete all maps?",
"offline_bad_layer_type": "A layer has an invalid type. It can't be saved for an offline use. ",
"offline_clear_db_error": "Error clearing saved maps. Please try again.",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"abort": "Annuler",
"add_layer": "Ajouter couche",
"add_wms_layer_failed": "Erreur au chargement de la couche WMS",
"add_wms_layer_succeeded": "Couche WMS chargée avec succès",
Expand Down Expand Up @@ -180,7 +181,6 @@
"object_information": "Information objet",
"obstacle_deleted_last_2_weeks": "Obstacles supprimés ces 2 dernières semaines",
"obstacle_started_last_2_weeks": "Obstacles activés ces 2 dernières semaines",
"offline_abort": "Annuler",
"offline_abort_warning": "Voulez-vous vraiment supprimer tous les cartes?",
"offline_bad_layer_type": "Une couche a un type invalide. Elle ne peut être sauvegardée pour un usage hors-ligne.",
"offline_clear_db_error": "Erreur lors de la suppression de la base de données. Réessayez.",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/it.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"abort": "Annullare",
"add_layer": "Aggiungere layer",
"add_wms_layer_failed": "Errore nel caricamento del layer WMS",
"add_wms_layer_succeeded": "Layer WMS caricato con successo",
Expand Down Expand Up @@ -180,7 +181,6 @@
"object_information": "Informazione oggetto",
"obstacle_deleted_last_2_weeks": "Ostacoli soppressi nelle ultime 2 settimane",
"obstacle_started_last_2_weeks": "Ostacoli attivati nelle ultime 2 settimane",
"offline_abort": "Annullare",
"offline_abort_warning": "Volete veramente cancellare tutte le carte?",
"offline_bad_layer_type": "Uno dei layer non è valido. Non potrà venir salvato per l'uso offline.",
"offline_clear_db_error": "Errore nell'eliminazione delle carte. Riprovare.",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/rm.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"abort": "Annullar",
"add_layer": "Agiuntar Layer",
"add_wms_layer_failed": "Sbagl tar il chargiar de la WMS layer",
"add_wms_layer_succeeded": "Chargià con success il WMS Layer",
Expand Down Expand Up @@ -180,7 +181,6 @@
"object_information": "Objekt infurmaziun",
"obstacle_deleted_last_2_weeks": "Gelöschte Hindernisse letzte 2 Wochen",
"obstacle_started_last_2_weeks": "Aktivierte Hindernisse letzte 2 Wochen",
"offline_abort": "Annullar",
"offline_abort_warning": "Vulais Vus propi stizzar tut ils chartas?",
"offline_bad_layer_type": "Einer der Datensätze kann nicht für den Offline-Gebrauch gespeichert werden.",
"offline_clear_db_error": "Errur cun stizzar las chartas memorisadas. Per plaschair empruvais anc ina giada.",
Expand Down

0 comments on commit 2415b4d

Please sign in to comment.