[go: nahoru, domu]

Skip to content

Commit

Permalink
Added agent connection test with alert for users
Browse files Browse the repository at this point in the history
  • Loading branch information
dynamic11 committed Sep 4, 2019
1 parent 20aa38f commit d114676
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
16 changes: 16 additions & 0 deletions app/Controllers/Http/HomeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ class HomeController {
response.redirect('back');
}

/**
*
* Change language cookie
*
* @param {view}
*
*/
async testAgentConnection ({ params, antl, request, response }) {
let res = await Outlook.testConnection();
return res;
}

/**
*
* Render user dashboard and gather information for dashboard view
Expand All @@ -94,6 +106,10 @@ class HomeController {
*
*/
async userDashboard ({ antl, view, auth }) {
if (await Outlook.testConnection()) {

};

const code = await this.getAvailableRooms({ antl, user: auth.user, view });
const freqRooms = await this.getFreqBooked(auth.user);
const upcoming = await this.getUpcomming(auth.user);
Expand Down
24 changes: 24 additions & 0 deletions app/Outlook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ module.exports = class Outlook {
}

/**
* check if Agent is running correctly
*
* @returns {Boolean} test connection to agent
*/
async testConnection () {
if (Env.get('DEV_OUTLOOK', 'prod') === 'prod') {
try {
// make a test connection using an empty post request
await axios.post(`${Env.get('EXCHANGE_AGENT_SERVER', 'localhost:3000')}/avail`, {});
} catch (e) {
// console.log(e.response.status);
if (e.response.status === 300) {
// return true (server working)
return 1;
} else {
// return false (server unresponsive)
return 0;
}
}
}
}

/**
* Check if specific room is available at the provided time
*
* @param {String} date Date
* @param {String} from Starting time
Expand Down
1 change: 1 addition & 0 deletions resources/locales/en/mainLayout.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"betaMessage": "Jarvis is currently in development. We appreciate your feedback to help us improve!",
"agentTestMessage": "We are currently experiencing a service outage. We will be back shortly!",
"profile": "Profile",
"feedback": "Feedback",
"logout" : "Logout",
Expand Down
1 change: 1 addition & 0 deletions resources/locales/fr/mainLayout.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"betaMessage": "Jarvis est en développement. Nous apprécions vos commentaires pour nous aider à améliorer!",
"agentTestMessage": "Veuillez noter que nous éprouvons présentement une panne de service. Nous revenons bientôt!",
"profile": "Profil",
"feedback": "Commentaire",
"logout" : "Se déconnecter",
Expand Down
31 changes: 26 additions & 5 deletions resources/views/layouts/mainLayout.edge
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@

<div id='wrapper'>
<!-- Sidebar -->


<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

<!-- Sidebar - Brand -->
Expand Down Expand Up @@ -97,9 +95,19 @@

<!-- Main Content -->
<div id="content">
<div class="alert alert-primary alert-dismissible show m-0 p-2 pl-4" role="alert">
<div class="alert alert-danger alert-dismissible m-0 p-2 pl-4" role="alert" id="agent-error-alert" style="display: none;">
<small>
<i class="fas fa-exclamation-triangle mr-1"></i> {{ antl.formatMessage('mainLayout.agentTestMessage') }}
<a class="text-right ml-1 text-dark" href="mailto: cdhstudio@canada.ca?Subject=Jarvis%20Error">
<i class="fas fa-envelope"></i> {{ antl.formatMessage('mainLayout.feedback') }}</a>
</small>
<button type="button" class="close p-2 pr-4" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="alert alert-primary alert-dismissible m-0 p-2 pl-4" role="alert" id="feedback-alert">
<small>
<i class="fas fa-exclamation-circle"></i> {{ antl.formatMessage('mainLayout.betaMessage') }}
<i class="fas fa-exclamation-circle mr-1"></i> {{ antl.formatMessage('mainLayout.betaMessage') }}
<a class="text-right ml-1 text-dark" href="mailto: cdhstudio@canada.ca?Subject=Jarvis%20Feedback">
<i class="fas fa-envelope"></i> {{ antl.formatMessage('mainLayout.feedback') }}</a>
</small>
Expand Down Expand Up @@ -300,7 +308,20 @@
</script>
@endif


<script>
$.ajax({url: "/test-connection", success: function(result){
//check status of agent
if(result === '1'){
// display agent alert and hide feedback notification
$('#feedback-alert').show();
$('#agent-error-alert').hide();
}else{
// hide agent alert and diplay feedback notification
$('#feedback-alert').hide();
$('#agent-error-alert').show();
}
}});
</script>

@!section('extrajs')

Expand Down
1 change: 1 addition & 0 deletions start/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Route.get('/search/recurring', 'RoomController.searchRooms').as('searchRecurring
Route.post('/confirmBooking', 'BookingController.confirmBooking').as('confirmBooking').validator('BookRoom').middleware(['isUser']);

// Outlook
Route.get('/test-connection', 'HomeController.testAgentConnection').as('testAgentConnection');
Route.get('/authenticate', 'TokenController.getAuthUrl');
Route.get('/authorize', 'TokenController.authorize');
Route.get('/event', 'BookingController.createEvent');
Expand Down

0 comments on commit d114676

Please sign in to comment.