From 298b4436a6515099b5185310fb7b0ee6951f6bd1 Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Mon, 13 Sep 2021 16:33:58 +0200 Subject: [PATCH 1/2] fix form-workflow link + fix user props + fix add text to pdf --- .../entity/SignRequestParams.java | 10 +++ .../repository/UserPropertieRepository.java | 4 +- .../service/UserPropertieService.java | 53 +++++++------- .../service/WorkflowService.java | 8 ++- .../service/utils/pdf/PdfService.java | 2 +- .../controller/admin/FormAdminController.java | 2 +- .../web/controller/user/UserController.java | 12 ++-- .../web/ws/FormWsController.java | 2 +- .../static/js/modules/help/UserParamsHelp.js | 2 +- .../modules/ui/signrequests/WorkspacePdf.js | 15 +++- .../static/js/modules/utils/PdfViewer.js | 7 +- .../static/js/prototypes/SignRequestParams.js | 72 +++++++++++++------ .../fragments/sides/side-dashboard.html | 2 +- .../user/signrequests/includes/tools.html | 2 +- .../user/signrequests/includes/workspace.html | 12 ++++ 15 files changed, 138 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/entity/SignRequestParams.java b/src/main/java/org/esupportail/esupsignature/entity/SignRequestParams.java index 85366226e..27412408f 100644 --- a/src/main/java/org/esupportail/esupsignature/entity/SignRequestParams.java +++ b/src/main/java/org/esupportail/esupsignature/entity/SignRequestParams.java @@ -61,6 +61,8 @@ public class SignRequestParams { private Integer blue = 0; + private Integer fontSize = 12; + public Long getId() { return id; } @@ -268,4 +270,12 @@ public Integer getBlue() { public void setBlue(Integer blue) { this.blue = blue; } + + public Integer getFontSize() { + return fontSize; + } + + public void setFontSize(Integer fontSize) { + this.fontSize = fontSize; + } } diff --git a/src/main/java/org/esupportail/esupsignature/repository/UserPropertieRepository.java b/src/main/java/org/esupportail/esupsignature/repository/UserPropertieRepository.java index b2e4b09ff..742884264 100644 --- a/src/main/java/org/esupportail/esupsignature/repository/UserPropertieRepository.java +++ b/src/main/java/org/esupportail/esupsignature/repository/UserPropertieRepository.java @@ -3,6 +3,8 @@ import org.esupportail.esupsignature.entity.UserPropertie; import org.springframework.data.repository.CrudRepository; +import java.util.List; + public interface UserPropertieRepository extends CrudRepository { - UserPropertie findByUserEppn(String userEppn); + List findByUserEppn(String userEppn); } diff --git a/src/main/java/org/esupportail/esupsignature/service/UserPropertieService.java b/src/main/java/org/esupportail/esupsignature/service/UserPropertieService.java index e72ff565b..2c271d634 100644 --- a/src/main/java/org/esupportail/esupsignature/service/UserPropertieService.java +++ b/src/main/java/org/esupportail/esupsignature/service/UserPropertieService.java @@ -7,10 +7,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; @Service public class UserPropertieService { @@ -33,12 +30,16 @@ public void createUserPropertieFromMails(User user, List recipientEmails } public void createUserPropertie(User user, User favoriteUser) { - UserPropertie userPropertie = getUserProperties(user.getEppn()); - if (userPropertie == null) { + List userProperties = getUserProperties(user.getEppn()); + if (userProperties == null || userProperties.size() == 0) { addPropertie(user, favoriteUser); } else { - userPropertie.getFavorites().put(favoriteUser, new Date()); - userPropertieRepository.save(userPropertie); + for(UserPropertie userPropertie : userProperties) { + if(userPropertie.getFavorites().containsKey(favoriteUser)) { + userPropertie.getFavorites().put(favoriteUser, new Date()); + userPropertieRepository.save(userPropertie); + } + } } } @@ -50,26 +51,24 @@ private void addPropertie(User user, User favoriteUser) { } public List getFavoritesEmails(String userEppn) { - List favoriteUserEmails = new ArrayList<>(); - UserPropertie userPropertie = getUserProperties(userEppn); - if(userPropertie != null) { - Map favorites = userPropertie.getFavorites(); - if (favorites.size() > 0) { - List> entrySet = new ArrayList<>(favorites.entrySet()); - entrySet.sort(Map.Entry.comparingByValue().reversed()); - for (int i = 0; i < Math.min(entrySet.size(), 5); i++) { - favoriteUserEmails.add(entrySet.get(i).getKey().getEmail()); + Set favoriteUserEmails = new HashSet<>(); + List userProperties = getUserProperties(userEppn); + if(userProperties != null && userProperties.size() > 0) { + for(UserPropertie userPropertie : userProperties) { + Map favorites = userPropertie.getFavorites(); + if (favorites.size() > 0) { + List> entrySet = new ArrayList<>(favorites.entrySet()); + entrySet.sort(Map.Entry.comparingByValue().reversed()); + for (int i = 0; i < Math.min(entrySet.size(), 5); i++) { + favoriteUserEmails.add(entrySet.get(i).getKey().getEmail()); + } } } } - return favoriteUserEmails; - } - - public UserPropertie getUserProperties(String userEppn) { - return userPropertieRepository.findByUserEppn(userEppn); + return new ArrayList<>(favoriteUserEmails); } - public UserPropertie getUserPropertiesByUserEppn(String userEppn) { + public List getUserProperties(String userEppn) { return userPropertieRepository.findByUserEppn(userEppn); } @@ -81,8 +80,10 @@ public void delete(Long id) { @Transactional public void delete(String authUserEppn, Long id) { - UserPropertie userPropertie = getUserPropertiesByUserEppn(authUserEppn); - User user = userService.getById(id); - userPropertie.getFavorites().remove(user); + List userProperties = getUserProperties(authUserEppn); + for(UserPropertie userPropertie : userProperties) { + User user = userService.getById(id); + userPropertie.getFavorites().remove(user); + } } } diff --git a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java index 408116690..63e99bfef 100644 --- a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java +++ b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java @@ -595,6 +595,7 @@ public void setWorkflowSetupFromJson(Long id, InputStream inputStream) throws IO String savedTitle = workflow.getTitle(); ObjectMapper objectMapper = new ObjectMapper(); Workflow workflowSetup = objectMapper.readValue(inputStream.readAllBytes(), Workflow.class); + workflow.getWorkflowSteps().clear(); for(WorkflowStep workflowStepSetup : workflowSetup.getWorkflowSteps()) { Optional optionalWorkflowStep = workflow.getWorkflowSteps().stream().filter(workflowStep1 -> workflowStep1.getId().equals(workflowStepSetup.getId())).findFirst(); if(optionalWorkflowStep.isPresent()) { @@ -606,7 +607,12 @@ public void setWorkflowSetupFromJson(Long id, InputStream inputStream) throws IO workflow.getWorkflowSteps().add(newWorkflowStep); } } - update(workflow, workflowSetup.getCreateBy(), workflowSetup.getManagers().toArray(String[]::new), workflowSetup.getManagers()); + workflow.getTargets().clear(); + update(workflow, workflowSetup.getCreateBy(), null, workflowSetup.getManagers()); + for(Target target : workflowSetup.getTargets()) { + Target newTarget = targetService.createTarget(target.getTargetType(), target.getTargetUri()); + workflow.getTargets().add(newTarget); + } workflow.setName(savedName); workflow.setTitle(savedTitle); return; diff --git a/src/main/java/org/esupportail/esupsignature/service/utils/pdf/PdfService.java b/src/main/java/org/esupportail/esupsignature/service/utils/pdf/PdfService.java index 1c62cbad0..1e776ae94 100644 --- a/src/main/java/org/esupportail/esupsignature/service/utils/pdf/PdfService.java +++ b/src/main/java/org/esupportail/esupsignature/service/utils/pdf/PdfService.java @@ -189,7 +189,7 @@ private void stampImageToPage(SignRequest signRequest, SignRequestParams signReq addLink(signRequest, signRequestParams, user, fixFactor, pdDocument, pdPage, newDate, dateFormat, xAdjusted, yAdjusted); } } else if (signRequestParams.getTextPart() != null && !signRequestParams.getTextPart().isEmpty()) { - int fontSize = (int) (12 * signRequestParams.getSignScale() * .75); + int fontSize = (int) (signRequestParams.getFontSize() * signRequestParams.getSignScale() * .75); PDFont pdFont = PDTrueTypeFont.load(pdDocument, new ClassPathResource("static/fonts/LiberationSans-Regular.ttf").getFile(), WinAnsiEncoding.INSTANCE); contentStream.beginText(); contentStream.setFont(pdFont, fontSize); diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/admin/FormAdminController.java b/src/main/java/org/esupportail/esupsignature/web/controller/admin/FormAdminController.java index 3c4654a01..8f85b18c1 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/admin/FormAdminController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/admin/FormAdminController.java @@ -325,4 +325,4 @@ public String importFormSetup(@PathVariable("id") Long id, return "redirect:/admin/forms/update/" + id; } -} +} \ No newline at end of file diff --git a/src/main/java/org/esupportail/esupsignature/web/controller/user/UserController.java b/src/main/java/org/esupportail/esupsignature/web/controller/user/UserController.java index f758b5146..c4e7d1c71 100644 --- a/src/main/java/org/esupportail/esupsignature/web/controller/user/UserController.java +++ b/src/main/java/org/esupportail/esupsignature/web/controller/user/UserController.java @@ -169,12 +169,14 @@ public List searchUserList(@RequestParam(value="searchString") String se @GetMapping("/properties") public String properties(@ModelAttribute("authUserEppn") String authUserEppn, Model model) { - UserPropertie userPropertie = userPropertieService.getUserPropertiesByUserEppn(authUserEppn); - if (userPropertie != null) { - List> entrySet = new ArrayList<>(userPropertie.getFavorites().entrySet()); - entrySet.sort(Map.Entry.comparingByValue().reversed()); + List userProperties = userPropertieService.getUserProperties(authUserEppn); + if (userProperties != null && userProperties.size() > 0) { Map sortedMap = new LinkedHashMap<>(); - entrySet.forEach(e -> sortedMap.put(e.getKey(), e.getValue())); + for (UserPropertie userPropertie : userProperties) { + List> entrySet = new ArrayList<>(userPropertie.getFavorites().entrySet()); + entrySet.sort(Map.Entry.comparingByValue().reversed()); + entrySet.forEach(e -> sortedMap.put(e.getKey(), e.getValue())); + } model.addAttribute("userProperties", sortedMap); } List fieldProperties = fieldPropertieService.getFieldProperties(authUserEppn); diff --git a/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java b/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java index 45d4b1417..d6b6ad63d 100644 --- a/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java +++ b/src/main/java/org/esupportail/esupsignature/web/ws/FormWsController.java @@ -28,7 +28,7 @@ public class FormWsController { @PostMapping(value = "/{id}/new") @Operation(description = "Création d'une nouvelle instance d'un formulaire") public Long start(@PathVariable Long id, - @RequestParam String eppn, + @RequestParam @Parameter(description = "Eppn du propriétaire du futur document") String eppn, @RequestParam(required = false) @Parameter(description = "Liste des participants pour chaque étape", example = "[stepNumber*email]") List recipientEmails, @RequestParam(required = false) @Parameter(description = "Lites des numéros d'étape pour lesquelles tous les participants doivent signer", example = "[stepNumber]") List allSignToCompletes, @RequestParam(required = false) @Parameter(description = "Liste des destinataires finaux", example = "[email]") List targetEmails, diff --git a/src/main/resources/static/js/modules/help/UserParamsHelp.js b/src/main/resources/static/js/modules/help/UserParamsHelp.js index de0f181ee..24aa79ca6 100644 --- a/src/main/resources/static/js/modules/help/UserParamsHelp.js +++ b/src/main/resources/static/js/modules/help/UserParamsHelp.js @@ -22,7 +22,7 @@ export class UserParamsHelp { this.intro.addStep({ intro: "Sur cette page vous pouvez modifier vos paramètres de signature :" + "
    " + - "
  • Ajouter / supprimer des images de votre siganture
  • " + + "
  • Ajouter / supprimer des images de votre signature
  • " + "
  • Ajouter un certificat pour effectuer des signatures électroniques
  • " + "
  • Ajuster vos paramètres d'alerte
  • " + "
" diff --git a/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js b/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js index b00e0bdc8..b42fb2e23 100644 --- a/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js +++ b/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js @@ -321,7 +321,8 @@ export class WorkspacePdf { } checkSignsPositions() { - if(this.signPosition.signRequestParamses.size > 0) { + let testSign = Array.from(this.signPosition.signRequestParamses.values()); + if(testSign.filter(s => s.signImageNumber >= 0 && s.isSign).length > 0) { for (let i = 0; i < this.currentSignRequestParamses.length; i++) { if (this.currentSignRequestParamses[i].ready == null || !this.currentSignRequestParamses[i].ready) { return false; @@ -993,13 +994,20 @@ export class WorkspacePdf { selected: true }); } - if(this.status === "draft" || this.status === "pending" || this.postits.length > 0) { + if(this.status === "draft" || this.status === "pending") { data.push({ innerHTML: '
Annoter
', text: 'Annoter', value: 'comment' }); } + if(this.status !== "draft" && this.status !== "pending" && this.postits.length > 0) { + data.push({ + innerHTML: '
Voir les annotations
', + text: 'Consulter les annotations', + value: 'comment' + }); + } data.push({ innerHTML: '
Mode lecture
', text: 'Lecture', @@ -1015,6 +1023,9 @@ export class WorkspacePdf { data: data }); } + if(this.changeModeSelector != null) { + this.changeModeSelector.set("read"); + } } changeMode(e) { diff --git a/src/main/resources/static/js/modules/utils/PdfViewer.js b/src/main/resources/static/js/modules/utils/PdfViewer.js index 83dd19e9c..88d6884a2 100644 --- a/src/main/resources/static/js/modules/utils/PdfViewer.js +++ b/src/main/resources/static/js/modules/utils/PdfViewer.js @@ -619,7 +619,7 @@ export class PdfViewer extends EventFactory { $(this).unbind(); $(this).remove(); }); - let signFieldNumber = 0; + let signFieldNumber = 1; for (let i = 0; i < items.length; i++) { let item = items[i]; console.debug("debug - " + ">> Start compute item of type : " + item.fieldType); @@ -640,13 +640,14 @@ export class PdfViewer extends EventFactory { signField.css("font-size", 8); signField.attr("data-id", signFieldNumber); signField.on('click', function () { + console.info("click on " + signFieldNumber); let report = $("#report_" + $(this).attr("data-id")); - if (report.length) { + if (report != null) { $("#reportModal").modal("show"); $("div[id^='report_']").each(function () { $(this).hide(); }); - report.show(); + report.css("display", "block"); } }) // signField.attr("data-toggle", "modal"); diff --git a/src/main/resources/static/js/prototypes/SignRequestParams.js b/src/main/resources/static/js/prototypes/SignRequestParams.js index 438411ee4..6a8155b24 100644 --- a/src/main/resources/static/js/prototypes/SignRequestParams.js +++ b/src/main/resources/static/js/prototypes/SignRequestParams.js @@ -66,22 +66,7 @@ export class SignRequestParams extends EventFactory { this.cross.css("z-index", "5"); this.cross.attr("data-id", this.id); let self = this; - this.cross.draggable({ - containment: "#pdf", - scroll: false, - drag: function() { - let thisPos = $(this).position(); - if(!self.firstLaunch) { - let x = Math.round(thisPos.left / self.currentScale); - let y = Math.round(thisPos.top / self.currentScale); - self.xPos = x; - self.yPos = y; - } else { - self.firstLaunch = false; - window.scrollTo(0, self.yPos); - } - } - }); + this.madeCrossDraggable(); this.cross.resizable({ aspectRatio: true, resize: function(event, ui) { @@ -193,6 +178,26 @@ export class SignRequestParams extends EventFactory { } } + madeCrossDraggable() { + let self = this; + this.cross.draggable({ + containment: "#pdf", + scroll: false, + drag: function() { + let thisPos = $(this).position(); + if(!self.firstLaunch) { + let x = Math.round(thisPos.left / self.currentScale); + let y = Math.round(thisPos.top / self.currentScale); + self.xPos = x; + self.yPos = y; + } else { + self.firstLaunch = false; + window.scrollTo(0, self.yPos); + } + } + }); + } + initEventListeners() { let self = this; this.cross.on("mousedown click", function (e) { @@ -303,9 +308,10 @@ export class SignRequestParams extends EventFactory { this.border.removeClass("static-border"); this.border.addClass("anim-border"); this.tools.removeClass("d-none"); - if(this.textareaExtra != null) { - this.textareaExtra.removeClass("sign-textarea-lock"); - this.textareaExtra.focus(); + if(this.textareaPart != null) { + this.textareaPart.removeClass("sign-textarea-lock"); + this.textareaPart.focus(); + this.cross.draggable("disable"); } } @@ -610,16 +616,36 @@ export class SignRequestParams extends EventFactory { this.cross.append(divExtraHtml); this.cross.attr('title', 'Double click pour éditer'); this.textareaPart = $("#textPart_" + this.id); - this.textareaPart.css('pointer-events', 'none'); this.textareaPart.css('width', '100%'); // this.textareaPart.css('height', '100%'); this.textareaPart.on("input", function () { self.resizeText(); }); - this.cross.dblclick(function() { - self.textareaPart.focus(); - }); + // this.cross.dblclick(function() { + // self.textareaPart.focus(); + // }); this.resizeText(); + this.cross.resizable("destroy"); + let textGrow = $("#textGrow_" + this.id); + let textReduce = $("#textReduce_" + this.id); + textGrow.show(); + textReduce.show(); + textGrow.on("click", function () { + self.fontSize = self.fontSize + 1 + self.resizeText(); + }); + textReduce.on("click", function () { + self.fontSize = self.fontSize - 1 + self.resizeText(); + }); + this.textareaPart.focusout(function (){ + self.cross.draggable("enable"); + self.textareaPart.css('pointer-events', 'none'); + }); + this.textareaPart.focusin(function (){ + self.cross.draggable("disable"); + self.textareaPart.css('pointer-events', 'auto'); + }); } resizeText() { diff --git a/src/main/resources/templates/fragments/sides/side-dashboard.html b/src/main/resources/templates/fragments/sides/side-dashboard.html index c6303a535..29982bff0 100644 --- a/src/main/resources/templates/fragments/sides/side-dashboard.html +++ b/src/main/resources/templates/fragments/sides/side-dashboard.html @@ -5,7 +5,7 @@
- +
Choix du mode :
diff --git a/src/main/resources/templates/user/signrequests/includes/workspace.html b/src/main/resources/templates/user/signrequests/includes/workspace.html index 97fb38bbc..2b5488c3e 100644 --- a/src/main/resources/templates/user/signrequests/includes/workspace.html +++ b/src/main/resources/templates/user/signrequests/includes/workspace.html @@ -92,6 +92,18 @@ style="z-index: 3;"> + +