[go: nahoru, domu]

Skip to content

Commit

Permalink
merge ali-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
notRealLi committed Jun 9, 2019
2 parents 86fceb4 + 745a588 commit 49e9b7a
Show file tree
Hide file tree
Showing 39 changed files with 707 additions and 332 deletions.
57 changes: 45 additions & 12 deletions app/Controllers/Http/BuildingController.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
'use strict';
const Building = use('App/Models/Building');
const RoomFeaturesCategory = use('App/Models/RoomFeaturesCategory');

class BuildingController {
/**
* Reports a room
* show building configuration such as:
* floors, towers, features
*
* @param {Object} Context The context object.
*/
async setBuilding ({ response, params, view }) {
try {
const building = await Building.query()
.where('id', params.id)
.firstOrFail();
async show ({ request, view }) {
const allBuildings = await Building.all();

response.cookie('selectedBuilding', building.toJSON(), { path: '/' });
} catch (err) {
console.log(err);
}
const selectedBuilding = request.cookie('selectedBuilding');

return response.route('home');
const building = await Building.query()
.where('id', selectedBuilding.id)
.with('floor')
.with('tower')
.with('floor.room')
.with('tower.room')
.firstOrFail();

const categories = await RoomFeaturesCategory
.query()
.with('features', (builder) => {
builder.where('building_id', 1);
}).fetch();

return view.render('adminPages.viewBuildingConfig',
{ allBuildings: allBuildings.toJSON(),
building: building.toJSON(),
categories: categories.toJSON()
});
}

/**
* Reports a room
* view all building to manage
*
* @param {Object} Context The context object.
*/
Expand All @@ -33,6 +47,25 @@ class BuildingController {

return view.render('adminPages.selectBuilding', { allBuildings: allBuildings.toJSON() });
}

/**
* store the selected building in the cookie
*
* @param {Object} Context The context object.
*/
async setBuilding ({ response, params, view }) {
try {
const building = await Building.query()
.where('id', params.id)
.firstOrFail();

response.cookie('selectedBuilding', building.toJSON(), { path: '/' });
} catch (err) {
console.log(err);
}

return response.route('home');
}
}

module.exports = BuildingController;
12 changes: 9 additions & 3 deletions app/Controllers/Http/FloorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ class FloorController {
try {
const selectedBuilding = request.cookie('selectedBuilding');

const building = await Building.query().where('name', selectedBuilding).firstOrFail();
const building = await Building.findByOrFail('name', selectedBuilding.name);

// Retrieves user input
const body = request.all();
// Populates the review object's values
const newFloor = new Floor();
newFloor.name = body.floorName;
newFloor.name_english = body.floorNameEnglish;
newFloor.name_french = body.floorNameFrench;
newFloor.building_id = building.id;
await newFloor.save();

session.flash({ notification: 'Floor Added!' });

return response.route('configuration');
} catch (err) {
session.flash({ error: 'Something when wrong. Floor Not Added.' });
console.log(err);
response.redirect('back');
}
}

Expand All @@ -32,12 +35,15 @@ class FloorController {
// Updates room information in database
const floor = await Floor.find(params.id);

floor.name = body.floorName;
floor.name_english = body.floorNameEnglish;
floor.name_french = body.floorNameFrench;
await floor.save();
session.flash({ notification: 'Floor Updated!' });
return response.route('configuration');
} catch (err) {
session.flash({ error: 'Something when wrong. Floor Not Updated.' });
console.log(err);
response.redirect('back');
}
}

Expand Down
Loading

0 comments on commit 49e9b7a

Please sign in to comment.