Skip to content

Commit 7b0fc49

Browse files
committed
CRUD rooms
1 parent 68f4baf commit 7b0fc49

File tree

6 files changed

+299
-1
lines changed

6 files changed

+299
-1
lines changed

Diff for: Zenergy/Zenergy/Pages/rooms.html

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<div class="container ">
2+
<div class="row">
3+
<div class="col-md-12">
4+
<h2>Rooms managment</h2>
5+
<form>
6+
<div class="form-group">
7+
<div class="input-group">
8+
<div class="input-group-addon"><i class="glyphicon glyphicon-search"></i></div>
9+
10+
<input type="text" class="form-control" placeholder="Search for a room (by name)" ng-model="searchRoom.roomName">
11+
</div>
12+
</div>
13+
</form>
14+
15+
<script type="text/ng-template" id="deleteRoomContent.html">
16+
<div class="modal-header">
17+
<h3 class="modal-title">Are you sur you want to delete room n° {{roomToDelete.roomId}} ?</h3>
18+
</div>
19+
<div class="modal-footer">
20+
<button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
21+
<button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
22+
</div>
23+
</script>
24+
25+
<script type="text/ng-template" id="updateRoomContent.html">
26+
<div class="modal-header">
27+
<h3 class="modal-title">Edit room n° {{roomToUpdate.roomId}} ?</h3>
28+
</div>
29+
<div class="modal-body">
30+
<div class="container ">
31+
<div class="row">
32+
<div class="col-md-4">
33+
<div class="form-group">
34+
<label>Name:</label>
35+
<input type="text" class="form-control" ng-model="roomToUpdate.roomName">
36+
</div>
37+
<div class="form-group">
38+
<label>Superficy:</label>
39+
<input type="number" class="form-control" ng-model="roomToUpdate.roomSuperficy">
40+
</div>
41+
<div class="form-group">
42+
<label>Capacity:</label>
43+
<input type="number" class="form-control" ng-model="roomToUpdate.maxCapacity">
44+
</div>
45+
</div>
46+
<div class="col-md-8">
47+
<div class="form-group">
48+
<label>Accessories:</label>
49+
<table class="table table-striped">
50+
<thead>
51+
<tr>
52+
<th>ID</th>
53+
<th>Name</th>
54+
<th>Quantity</th>
55+
</tr>
56+
</thead>
57+
<tbody>
58+
<tr ng-repeat="rc in roomToUpdate.roomContent" id="trAcc{{rc.accessoryId}}">
59+
<td>{{rc.accessoryId}}</td>
60+
<td>{{rc.accessory.accessoryName}}</td>
61+
<td>{{rc.accessoryQuantityInRoom }}</td>
62+
<td width="20%"><button type="button" class="btn btn-warning btn-block" ng-click="deleteRC(rc)" ><span class="glyphicon glyphicon glyphicon-remove" aria-hidden="true"></span></button></td>
63+
</tr>
64+
<tr >
65+
</tbody>
66+
</table>
67+
<div ng-show="showInputsAcc" class="form-group">
68+
<select name="mySelect" id="mySelect"
69+
ng-options="a.accessoryName for a in accessories"
70+
ng-model="newRC.accessory"></select>
71+
<input placeholder="Quantity" type="number" ng-model="newRC.accessoryQuantityInRoom" />
72+
</div>
73+
<button type="button" ng-hide="showInputsAcc" class="btn btn-success btn-sm" ng-click="addRC(rc)" ><span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span></button>
74+
<input ng-disabled="newRC.accessory==null || newRC.accessoryQuantityInRoom=='' || newRC.accessoryQuantityInRoom==null" ng-show="showInputsAcc" class="btn btn-success btn-sm" value="Add" ng-click="confirmRC()" />
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
</div>
80+
<div class="modal-footer">
81+
<button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
82+
</div>
83+
</script>
84+
<table class="table table-striped">
85+
<thead>
86+
<tr>
87+
<th>
88+
<a href="" ng-click="sortType = 'roomId' ; sortReverse = !sortReverse">
89+
Room ID
90+
<span ng-show="sortType == 'roomId' && sortReverse" class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
91+
<span ng-show="sortType == 'roomId' && !sortReverse" class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
92+
</a>
93+
</th>
94+
<th>
95+
<a href="" ng-click="sortType = 'roomName'; sortReverse = !sortReverse">
96+
Name
97+
<span ng-show="sortType == 'roomName' && sortReverse" class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
98+
<span ng-show="sortType == 'roomName' && !sortReverse" class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
99+
</a>
100+
</th>
101+
<th>
102+
<a href="" ng-click="sortType = 'roomSuperficy'; sortReverse = !sortReverse">
103+
Superficy (m²)
104+
<span ng-show="sortType == 'roomSuperficy' && sortReverse" class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
105+
<span ng-show="sortType == 'roomSuperficy' && !sortReverse" class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
106+
</a>
107+
</th>
108+
<th>
109+
<a href="" ng-click="sortType = 'maxCapacity'; sortReverse = !sortReverse">
110+
Capacity
111+
<span ng-show="sortType == 'maxCapacity' && sortReverse" class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
112+
<span ng-show="sortType == 'maxCapacity' && !sortReverse" class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
113+
</a>
114+
</th>
115+
</tr>
116+
</thead>
117+
<tbody>
118+
<tr ng-repeat="r in rooms | orderBy:sortType:sortReverse| filter:searchRoom" id="tr{{r.roomId}}">
119+
<td>{{r.roomId}}</td>
120+
<td>{{r.roomName}}</td>
121+
<td>{{r.roomSuperficy}}</td>
122+
<td>{{r.maxCapacity}}</td>
123+
<td width="100px"><input class="btn btn-primary btn-sm" value="Edit" ng-click="update(r)" /></td>
124+
<td width="100px"><input class="btn btn-danger btn-sm" value="Delete" ng-click="delete(r)" /></td>
125+
</tr>
126+
<tr ng-show="showInputs">
127+
<td></td>
128+
<td><input placeholder="Name" ng-model="newRoom.roomName" /></td>
129+
<td><input placeholder="Superficy" type="number" ng-model="newRoom.roomSuperficy" /></td>
130+
<td><input placeholder="Capacity" type="number" ng-model="newRoom.maxCapacity" /></td>
131+
</tr>
132+
</tbody>
133+
</table>
134+
<input ng-hide="showInputs" class="btn btn-success btn-lg" value="Add one" ng-click="add()" />
135+
<input ng-disabled="newRoom.roomName=='' " ng-show="showInputs" class="btn btn-success btn-sm" value="Add" ng-click="confirm()" />
136+
</div>
137+
</div>
138+
</div>

Diff for: Zenergy/Zenergy/Scripts/Controllers/productsPageController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
$scope.add = function () {
8888
$scope.showInputs = true;
89-
$scope.newProduct = new Product();
89+
$scope.newProduct = new Product({productName:''});
9090
};
9191

9292
$scope.confirm = function () {
+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
zenergyApp.controller("roomsPageController", ["$scope", "$resource", "$uibModal","$location", function ($scope, $resource, $uibModal,$location) {
2+
3+
if ($scope.isAdmin()) {
4+
5+
$scope.sortType = 'roomId'; // set the default sort type
6+
$scope.sortReverse = false; // set the default sort order
7+
$scope.searchRoom = ''; // set the default search/filter term
8+
$scope.showInputs = false;
9+
10+
11+
var Room = $resource('api/rooms/:roomId', { roomId: '@id' }, {
12+
update: {
13+
method: 'PUT' // this method issues a PUT request
14+
}
15+
});
16+
17+
$scope.rooms = Room.query(function () {
18+
});
19+
20+
var Accessory = $resource('api/accessories/', {
21+
});
22+
23+
$scope.accessories = Accessory.query(function () {
24+
});
25+
26+
27+
$scope.delete = function (r) {
28+
29+
$scope.roomToDelete = r;
30+
31+
var modalInstance = $uibModal.open({
32+
animation: true,
33+
templateUrl: 'deleteRoomContent.html',
34+
controller: 'deleteRoomModalController',
35+
size: 'sm',
36+
resolve: {
37+
roomToDelete: function () {
38+
return $scope.roomToDelete;
39+
}
40+
}
41+
});
42+
43+
modalInstance.result.then(function () {
44+
//Suppression du produit.
45+
Room.delete({ roomId: $scope.roomToDelete.roomId });
46+
$('#tr' + $scope.roomToDelete.roomId).fadeOut('slow', function () {
47+
var index = $scope.rooms.indexOf($scope.roomToDelete);
48+
$scope.rooms.splice(index, 1);
49+
});
50+
51+
}, function () {
52+
});
53+
};
54+
55+
$scope.update = function (r) {
56+
57+
$scope.roomToUpdate = r;
58+
console.log($scope.roomToUpdate)
59+
60+
var modalInstance = $uibModal.open({
61+
animation: true,
62+
templateUrl: 'updateRoomContent.html',
63+
controller: 'updateRoomModalController',
64+
size: 'lg',
65+
resolve: {
66+
roomToUpdate: function () {
67+
return $scope.roomToUpdate;
68+
},
69+
accessories: function () {
70+
return $scope.accessories;
71+
}
72+
}
73+
});
74+
75+
modalInstance.result.then(function () {
76+
//Maj du produit.
77+
$scope.roomToUpdate.$update({ roomId: $scope.roomToUpdate.roomId });
78+
79+
}, function () {
80+
});
81+
};
82+
83+
84+
$scope.add = function () {
85+
$scope.showInputs = true;
86+
$scope.newRoom = new Room({roomName:''});
87+
};
88+
89+
$scope.confirm = function () {
90+
var r = Room.save(null, $scope.newRoom, function () {
91+
$scope.rooms.push(r);
92+
$scope.showInputs = false;
93+
});
94+
}
95+
96+
}
97+
else
98+
$location.path("/")
99+
}]);
100+
101+
zenergyApp.controller('deleteRoomModalController', function ($scope, $uibModalInstance, roomToDelete) {
102+
103+
$scope.roomToDelete = roomToDelete;
104+
105+
$scope.ok = function () {
106+
$uibModalInstance.close();
107+
};
108+
109+
$scope.cancel = function () {
110+
$uibModalInstance.dismiss('cancel');
111+
};
112+
});
113+
114+
115+
zenergyApp.controller('updateRoomModalController', function ($scope, $uibModalInstance,$resource, roomToUpdate, accessories) {
116+
117+
var RC = $resource('api/roomContents/', {
118+
});
119+
$scope.roomToUpdate = roomToUpdate;
120+
$scope.showInputsAcc = false;
121+
$scope.accessories = accessories;
122+
123+
$scope.ok = function () {
124+
$uibModalInstance.close();
125+
};
126+
127+
$scope.deleteRC = function (rc) {
128+
//Suppression du RoomContent
129+
RC.delete({ roomId: rc.roomId, accessoryId: rc.accessoryId });
130+
$('#trAcc' + rc.accessoryId).fadeOut('slow', function () {
131+
var index = $scope.roomToUpdate.roomContent.indexOf(rc);
132+
$scope.roomToUpdate.roomContent.splice(index, 1);
133+
});
134+
};
135+
136+
137+
$scope.addRC = function () {
138+
$scope.showInputsAcc = true;
139+
$scope.newRC = new RC({ roomId: $scope.roomToUpdate.roomId});
140+
};
141+
142+
$scope.confirmRC = function () {
143+
$scope.newRC.accessoryId = $scope.newRC.accessory.accessoryId;
144+
var temp = $scope.newRC.accessory.accessoryName;
145+
delete $scope.newRC.accessory;
146+
var rc = RC.save(null, $scope.newRC, function () {
147+
rc.accessory = { accessoryName: temp };
148+
$scope.roomToUpdate.roomContent.push(rc);
149+
$scope.showInputsAcc = false;
150+
});
151+
}
152+
153+
});

Diff for: Zenergy/Zenergy/Scripts/Lib/_references.js

128 Bytes
Binary file not shown.

Diff for: Zenergy/Zenergy/Scripts/zenergyApp.js

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ zenergyApp.config(function ($routeProvider) {
3939
templateUrl: 'Pages/products.html',
4040
controller: 'productsPageController'
4141
})
42+
43+
.when('/Rooms', {
44+
templateUrl: 'Pages/rooms.html',
45+
controller: 'roomsPageController'
46+
})
4247
});
4348

4449

Diff for: Zenergy/Zenergy/Zenergy.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
<Content Include="Pages\accountManagement.html" />
319319
<Content Include="Pages\products.html" />
320320
<Content Include="Pages\profile.html" />
321+
<Content Include="Pages\rooms.html" />
321322
<Content Include="Pages\users.html" />
322323
<Content Include="Scripts\Controllers\accountManagementPageController.js" />
323324
<Content Include="Scripts\Controllers\homePageController.js" />
@@ -326,6 +327,7 @@
326327
<Content Include="Scripts\Controllers\productsPageController.js" />
327328
<Content Include="Scripts\Controllers\registerPageController.js" />
328329
<Content Include="Scripts\Controllers\profilePageController.js" />
330+
<Content Include="Scripts\Controllers\roomsPageController.js" />
329331
<Content Include="Scripts\Controllers\usersPageController.js" />
330332
<Content Include="Scripts\Factories\authInterceptorService.js" />
331333
<Content Include="Scripts\Factories\tokenService.js" />

0 commit comments

Comments
 (0)