Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into dev
  • Loading branch information
fraticelli committed Jul 18, 2019
2 parents 415c032 + 2670dfb commit bebf8a1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 61 deletions.
22 changes: 12 additions & 10 deletions src/main/java/it/cnr/si/web/rest/HelpdeskResource.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.cnr.si.web.rest;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import it.cnr.si.domain.ExternalProblem;
import it.cnr.si.flows.ng.utils.JSONResponseEntity;
import it.cnr.si.security.AuthoritiesConstants;
import it.cnr.si.service.HelpdeskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -13,8 +12,9 @@
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import it.cnr.si.security.AuthoritiesConstants;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RolesAllowed({AuthoritiesConstants.USER})
Expand All @@ -29,9 +29,10 @@ public class HelpdeskResource {


@PostMapping(value = "/helpdesk/sendWithAttachment", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity sendWithAttachment(HttpServletRequest req, @RequestParam("file") MultipartFile uploadedMultipartFile) {
// todo: riscrivere perchè hd viene inizializzato nel service
log.info("Invio mail helpdesk con allegato");
public ResponseEntity sendWithAttachment(HttpServletRequest req, @RequestParam("allegato_data") MultipartFile allegato) {
HashMap response = new HashMap();

log.info("Invio mail helpdesk con allegato");
ExternalProblem hd = new ExternalProblem();

hd.setTitolo(PREFISSO_TITOLO + req.getParameter("titolo"));
Expand All @@ -43,9 +44,10 @@ public ResponseEntity sendWithAttachment(HttpServletRequest req, @RequestParam("
hd.setCategoria(new Integer(req.getParameter("categoria")));
hd.setCategoriaDescrizione(req.getParameter("categoriaDescrizione"));
Long id = helpdeskService.newProblem(hd);
helpdeskService.addAttachments(id, uploadedMultipartFile);

return JSONResponseEntity.ok();
helpdeskService.addAttachments(id, allegato);

response.put("segnalazioneId", id);
return JSONResponseEntity.ok(response);
}


Expand All @@ -54,7 +56,7 @@ public ResponseEntity sendWithoutAttachment(@RequestBody ExternalProblem hdDataM
log.info("InvHashmaio mail helpdesk senza allegato");
HashMap response = new HashMap();
hdDataModel.setTitolo(PREFISSO_TITOLO + hdDataModel.getTitolo());
response.put("segnalazioneId" ,helpdeskService.newProblem(hdDataModel));
response.put("segnalazioneId", helpdeskService.newProblem(hdDataModel));

return JSONResponseEntity.ok(response);
}
Expand Down
73 changes: 33 additions & 40 deletions src/main/webapp/app/pages/helpdesk/helpdesk.controller.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
(function() {
(function () {
'use strict';

angular
.module("sprintApp")
.controller("HelpdeskController", HelpdeskController);

HelpdeskController.$inject = ["$scope", "dataService", "$log", "$uibModal", "$state", "AlertService"];
HelpdeskController.$inject = ["$scope", "dataService", "$log", "$state", "AlertService", "utils"];

function HelpdeskController($scope, dataService, $log, $uibModal, $state, AlertService) {
var vm = this;
vm.hdDataModel = {};
function HelpdeskController($scope, dataService, $log, $state, AlertService, utils) {
var vm = this, data;
vm.hdDataModel = {};
$scope.data = {};

$scope.submitHelpdesk = function() {
$scope.submitHelpdesk = function () {
if ($scope.helpdeskForm.$invalid) {
angular.forEach($scope.helpdeskForm.$error, function(field) {
angular.forEach(field, function(errorField) {
angular.forEach($scope.helpdeskForm.$error, function (field) {
angular.forEach(field, function (errorField) {
errorField.$setTouched();
});
});
AlertService.warning("Inserire tutti i valori obbligatori.");
} else {
vm.hdDataModel.titolo = $scope.helpdeskModel.titolo;
vm.hdDataModel.descrizione = $scope.helpdeskModel.descrizione;
vm.hdDataModel.categoria = $scope.id;
vm.hdDataModel.categoriaDescrizione = $scope.$parent.vm.hdDataModel;

dataService.helpdesk.sendWithoutAttachment(vm.hdDataModel).then(
function(response) {
if (response.data.segnalazioneId) {
$uibModal.open({
template: '<div class="modal-header">'+
' <h4 class="modal-title">Segnalazione inviata correttamente</h4>'+
' </div>'+
' <div class="modal-body">'+
' <button class="btn btn-primary" type="button" ng-click="fatto()"><span class="glyphicon glyphicon-remove"></span> Chiudi</button>'+
' </div>',
scope: $scope
});
}
},
function(error) {
$log.error(error);
$uibModal.open({
template: '<div class="modal-header">'+
' <h4 class="modal-title">Segnalazione NON inviata per problemi tecnici: riprovare in seguito</h4>'+
' </div>'+
'<div class="modal-body">'+
' <button class="btn btn-primary" type="button" ng-click="$dismiss()"><span class="glyphicon glyphicon-remove"></span> Chiudi</button>'+
'</div>'
});
}
);
vm.hdDataModel.titolo = $scope.helpdeskModel.titolo;
vm.hdDataModel.descrizione = $scope.helpdeskModel.descrizione;
vm.hdDataModel.categoria = $scope.id;
vm.hdDataModel.categoriaDescrizione = $scope.$parent.vm.hdDataModel;
var request;
if ($scope.attachments.allegato.data) {
utils.prepareForSubmit($scope.data, $scope.attachments);
data = $.extend($scope.data, vm.hdDataModel);
request = dataService.helpdesk.sendWithAttachment(data);
} else {
request = dataService.helpdesk.sendWithoutAttachment(vm.hdDataModel);
}
request.then(function (response) {
if (response.data.segnalazioneId) {
AlertService.success("Segnalazione Helpdesk inviata con successo");
$state.go('home');
}
},
function (error) {
$log.error(error);
AlertService.error("Segnalazione NON inviata per problemi tecnici: riprovare in seguito");
}
);
}
$scope.fatto = function() {
$scope.fatto = function () {
$state.go("home");
};
};
Expand Down
10 changes: 8 additions & 2 deletions src/main/webapp/app/pages/helpdesk/helpdesk.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
<label for="emailMessage" translate="helpdesk.form.messaggio">Message</label>
<textarea class="form-control" id="emailMessage" ng-model="helpdeskModel.descrizione" placeholder="{{'helpdesk.form.messaggio' | translate}}" rows="5" ng-required="true" ></textarea>
</div>
<br>
<button type="submit" class="btn btn-primary" name="sendMail" translate="helpdesk.form.invia">Send</button>
<div class="form-group" ng-hide="idHelpdesk">
<form novalidate class="flows-form" name="fileForm" ng-submit="submitHelpdesk()">
<div>
<fileinput name="allegato" label="Allegato Segnalazione" multiple=false cnr-required=false />
</div>
<button class="btn btn-primary" type="submit" translate="helpdesk.form.invia"> Send<span class="glyphicon glyphicon-arrow-right"></span></button>
</form>
</div>
</form>
</div>
</div>
Expand Down
18 changes: 9 additions & 9 deletions src/main/webapp/app/services/cnr/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
.factory('dataService', Data);


Data.$inject = ['$http'];
Data.$inject = ['$http', 'Upload'];

function Data($http) {
function Data($http, Upload) {
return {

avvisi: {
Expand Down Expand Up @@ -254,13 +254,13 @@
}
},
helpdesk: {
// sendWithAttachment: function(hd, attachment){
// return $http({
// url: 'api/helpdesk/sendWithAttachment',
// method: 'Post',
// params: {}
// });
// },
sendWithAttachment: function (data) {
return Upload.upload({
url: 'api/helpdesk/sendWithAttachment',
method: 'Post',
data: data,
});
},
sendWithoutAttachment: function (hdDataModel) {
return $http.post("api/helpdesk/sendWithoutAttachment", hdDataModel)
}
Expand Down

0 comments on commit bebf8a1

Please sign in to comment.