Skip to content

Commit 1cb52f7

Browse files
committed
Read multiples notifications and deleted fields of property.new #57 #55
1 parent 92ec074 commit 1cb52f7

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

src/main/java/com/arnaugarcia/assessoriatorrelles/domain/Property.java

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class Property implements Serializable {
4444
@Column(name = "service_type")
4545
private ServiceType serviceType;
4646

47-
@NotNull
4847
@Column(name = "ref", nullable = false)
4948
private String ref;
5049

src/main/java/com/arnaugarcia/assessoriatorrelles/repository/NotificationRepository.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.data.domain.Page;
55
import org.springframework.data.domain.Pageable;
66
import org.springframework.data.jpa.repository.JpaRepository;
7+
import org.springframework.data.jpa.repository.Modifying;
78
import org.springframework.data.jpa.repository.Query;
89

910
import java.util.List;
@@ -20,8 +21,9 @@ public interface NotificationRepository extends JpaRepository<Notification,Long>
2021
@Query("select notification from Notification notification where notification.user.login = ?#{principal.username} AND notification.seen = false order by notification.date desc")
2122
Page<Notification> findByUserAndSeenIsFalse(Pageable pageable);
2223

23-
@Query("update Notification n set n.seen = true where n = :notification")
24-
void setReadNotification(Notification notification);
24+
@Modifying
25+
@Query("update Notification n set n.seen = true where n = :id")
26+
void setReadNotification(Long id);
2527

2628
@Query("update Notification n set n.seen = false where n.id = :id")
2729
void setUnReadNotification(Long id);

src/main/java/com/arnaugarcia/assessoriatorrelles/web/rest/NotificationResource.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ public ResponseEntity<Notification> updateNotification(@RequestBody Notification
7777
.body(result);
7878
}
7979

80+
/**
81+
* PUT /notifications : Updates an existing notification.
82+
*
83+
* @param notificationList the notification to update
84+
* @return the ResponseEntity with status 200 (OK) and with body the updated notification,
85+
* or with status 400 (Bad Request) if the notification is not valid,
86+
* or with status 500 (Internal Server Error) if the notification couldnt be updated
87+
* @throws URISyntaxException if the Location URI syntax is incorrect
88+
*/
89+
@PutMapping("/notifications/multiple")
90+
@Timed
91+
public ResponseEntity<List<Notification>> updateMultipleNotification(@RequestBody List<Notification> notificationList) throws URISyntaxException {
92+
log.debug("REST request to update multiple Notification : {}", notificationList.size());
93+
if (notificationList.isEmpty()) {
94+
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("notification", "emptylist", "The list is empty")).body(null);
95+
}else{
96+
for (Notification notification : notificationList){
97+
notificationRepository.setReadNotification(notification.getId());
98+
}
99+
return ResponseEntity.ok()
100+
.headers(HeaderUtil.createEntityUpdateAlert("notification", notificationList.toString()))
101+
.body(notificationList);
102+
}
103+
}
104+
80105
/**
81106
* GET /notifications : get all the notifications.
82107
*
@@ -168,11 +193,11 @@ public ResponseEntity<Void> deleteNotification(@PathVariable Long id) {
168193
/**
169194
* DELETE /notifications/
170195
*
171-
* @param list of notifications to delete
196+
* @param ids of notifications to delete
172197
* @return the ResponseEntity with status 200 (OK)
173198
*/
174199
@DeleteMapping("/notifications")
175-
// URL: [6,17
200+
// URL: [6-2-4]
176201
@Timed
177202
@Transactional
178203
public ResponseEntity<Void> deleteMultipleNotification(@RequestParam Long cacheBuster, @RequestParam String ids) {

src/main/webapp/app/dashboard/entities/notification/notification.controller.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
.module('assessoriaTorrellesApp')
66
.controller('NotificationController', NotificationController);
77

8-
NotificationController.$inject = ['$scope', '$state', 'DataUtils', 'Notification', 'ParseLinks', 'AlertService', 'pagingParams', 'paginationConstants'];
8+
NotificationController.$inject = ['$scope', '$state', 'DataUtils', 'Notification', 'AlertService', 'pagingParams', 'paginationConstants'];
99

10-
function NotificationController ($scope, $state, DataUtils, Notification, ParseLinks, AlertService, pagingParams, paginationConstants) {
10+
function NotificationController ($scope, $state, DataUtils, Notification, AlertService, pagingParams, paginationConstants) {
1111
var vm = this;
1212

1313
vm.loadPage = loadPage;
@@ -30,11 +30,16 @@
3030
function onError(error) {
3131
AlertService.error(error.data.message);
3232
}
33+
$state.go($state.current);
3334
}
3435

3536
vm.deleteNotifications = function deleteNotifications() {
36-
console.log("ids" + getAllChecked());
37-
Notification.multipleDelete({"ids" : getAllChecked()}, $state.go($state.current, {}, {reload: true}));
37+
Notification.multipleDelete({"ids" : getAllChecked()}, reloadView(), console.log("Error"));
38+
};
39+
40+
vm.updateNotifications = function updateNotifications() {
41+
console.log(getAllNotificationsChecked());
42+
Notification.setRead(getAllNotificationsChecked(), reloadView(), console.log("ERROR :("))
3843

3944
};
4045

@@ -75,5 +80,19 @@
7580
return allChecked;
7681

7782
}
83+
84+
function getAllNotificationsChecked() {
85+
var allChecked = [];
86+
angular.forEach(vm.notifications, function (itm) {
87+
if (itm.selected){
88+
allChecked.push(itm);
89+
}
90+
});
91+
return allChecked;
92+
}
93+
94+
function reloadView(){
95+
$state.go($state.current, {}, {reload: true});
96+
}
7897
}
7998
})();

src/main/webapp/app/dashboard/entities/notification/notification.service.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'byUser': { method: 'GET', isArray: true, url: 'api/notifications/byUser'},
1515
'byUserActive': { method: 'GET', isArray: true, url: 'api/notifications/byUser/active'},
1616
'multipleDelete': { method: 'DELETE', isArray: true, url: 'api/notifications/'},
17+
'setRead': { method: 'PUT', isArray: true, url: 'api/notifications/multiple'},
1718
'get': {
1819
method: 'GET',
1920
transformResponse: function (data) {

src/main/webapp/app/dashboard/entities/notification/notifications.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ <h3 class="box-title" data-translate="assessoriaTorrellesApp.notification.home.t
5454
<input type="checkbox" class="btn btn-default btn-sm" ng-click="vm.toggleAll()" ng-model="vm.isAllSelected">
5555
<div class="btn-group">
5656
<button type="button" class="btn btn-default btn-sm" ng-click="vm.deleteNotifications()"><i class="fa fa-trash-o"></i></button>
57-
<button type="button" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></button>
58-
<button type="button" class="btn btn-default btn-sm"><i class="fa fa-share"></i></button>
57+
<button type="button" class="btn btn-default btn-sm" ng-click="vm.updateNotifications()"><i class="fa fa-envelope-o"></i></button>
58+
<button type="button" class="btn btn-default btn-sm" ng-click="vm.updateNotifications()"><i class="fa fa-envelope"></i></button>
5959
</div>
6060
<!-- /.btn-group -->
6161
<button type="button" class="btn btn-default btn-sm"><i class="fa fa-refresh"></i></button>

src/main/webapp/app/dashboard/entities/property/dashboard.property-new.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ <h3 class="box-title" data-translate="assessoriaTorrellesApp.property.admin.main
7070
</select>
7171
</div>
7272
<div class="form-group">
73-
<label class="control-label" data-translate="assessoriaTorrellesApp.property.ref"
73+
<!-- <label class="control-label" data-translate="assessoriaTorrellesApp.property.ref"
7474
for="field_ref">Ref</label>
7575
<input type="text" class="form-control" name="ref" id="field_ref_prop"
7676
ng-model="vm.property.ref"
77-
required/>
77+
required/>-->
7878
<div ng-show="editForm.ref.$invalid">
7979
<p class="help-block"
8080
ng-show="editForm.ref.$error.required" data-translate="entity.validation.required">
@@ -252,10 +252,10 @@ <h3 class="box-title" data-translate="assessoriaTorrellesApp.property.location">
252252
</div>
253253

254254

255-
<div class="form-group">
255+
<!--<div class="form-group">
256256
<label class="control-label" data-translate="assessoriaTorrellesApp.location.ref" for="field_ref">Ref</label>
257257
<input type="text" class="form-control" name="ref" id="field_ref" ng-model="vm.location.ref"/>
258-
</div>
258+
</div>-->
259259
<div class="form-group">
260260
<label class="control-label" data-translate="assessoriaTorrellesApp.location.province" for="field_province">Province</label>
261261
<input type="text" class="form-control" name="province" id="field_province" ng-model="vm.location.province" required />

0 commit comments

Comments
 (0)