Skip to content

Commit 8845578

Browse files
committed
Added realtime update on logs list
-converted material-design icons from cdn to npm
1 parent f761c3c commit 8845578

File tree

11 files changed

+32
-19
lines changed

11 files changed

+32
-19
lines changed

WebApi/Controllers/LogController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using WebApi.ViewModels;
1313
using WebApi.Helpers;
1414
using WebApi.Services;
15+
using Microsoft.AspNetCore.SignalR;
16+
using Hubs.BroadcastHub;
1517

1618
namespace WebApi.Controllers
1719
{
@@ -21,10 +23,12 @@ public class LogController : ControllerBase
2123
{
2224
private JsonSerializerSettings settings = new JsonSerializerSettings { Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
2325
private readonly ILogService _service;
26+
private readonly IHubContext<BroadcastHub> _hubContext;
2427

25-
public LogController(ILogService service)
28+
public LogController(ILogService service, IHubContext<BroadcastHub> hubContext)
2629
{
2730
_service = service;
31+
_hubContext = hubContext;
2832
}
2933

3034
// GET api/log
@@ -46,6 +50,7 @@ public async Task<IActionResult> Log([FromBody] LogInOutViewModel model)
4650
}
4751

4852
var res = await _service.Log(user);
53+
await _hubContext.Clients.All.SendAsync("employee-logged"); // broadcast to web client
4954
return new OkObjectResult(JsonConvert.SerializeObject(res, settings));
5055
}
5156

WebApi/Hubs/BroadcastHub.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace Hubs.BroadcastHub
55
{
66
public class BroadcastHub : Hub
77
{
8-
public async Task SendMessage(string message)
8+
public async Task SendMessage()
99
{
10-
await Clients.All.SendAsync("send", message);
10+
await Clients.All.SendAsync("employee-logged");
1111
}
1212
}
1313
}

WebClient/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width,initial-scale=1.0">
66
<title>BDF Attendance System</title>
7-
<link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet">
87
</head>
98
<body>
109
<div id="app"></div>

WebClient/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebClient/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@aspnet/signalr": "^1.0.2",
1717
"axios": "^0.18.0",
1818
"lodash": "^4.17.10",
19+
"material-design-icons-iconfont": "^3.0.3",
1920
"moment": "^2.22.2",
2021
"nprogress": "^0.2.0",
2122
"tslib": "^1.9.3",

WebClient/src/components/log-employee-form.vue

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import { mapGetters } from 'vuex'
2626
import { LOG_EMPLOYEE } from '@/store/actions-type'
2727
import { EventBus } from '@/event-bus.js'
28-
import * as signalR from "@aspnet/signalr";
2928
3029
export default {
3130
data () {
@@ -65,18 +64,6 @@ export default {
6564
6665
created () {
6766
EventBus.$emit('toggle-drawer')
68-
},
69-
70-
mounted () {
71-
const connection = new signalR.HubConnectionBuilder()
72-
.withUrl("http://localhost:5000/broadcast")
73-
.build();
74-
75-
connection.on("send", (data) => {
76-
console.log(data)
77-
})
78-
79-
connection.start().catch(err => document.write(err));
8067
}
8168
}
8269
</script>

WebClient/src/components/log-list.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import { mapGetters } from "vuex";
3939
import { FETCH_LOGS } from '@/store/actions-type'
4040
import { EventBus } from '@/event-bus.js'
41+
import BroadcastConnection from '@/services/broadcast-service'
4142
import moment from 'moment'
4243
4344
export default {
@@ -148,6 +149,10 @@ export default {
148149
async mounted () {
149150
await this.initialize()
150151
this.initSettings()
152+
153+
BroadcastConnection.on("employee-logged", () => {
154+
this.initialize()
155+
})
151156
}
152157
}
153158
</script>

WebClient/src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const BASE_URL = "http://localhost:5000/api/"
1+
export const BASE_URL = "http://localhost:5000/"

WebClient/src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { sync } from 'vuex-router-sync'
99
import store from '@/store'
1010
import ApiService from '@/services/api-service'
1111
import 'vuetify/dist/vuetify.min.css'
12+
import 'material-design-icons-iconfont/dist/material-design-icons.css'
1213

1314
Vue.config.productionTip = false
1415

WebClient/src/services/api-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { LOADING_START, LOADING_END } from '@/store/actions-type'
77

88
const ApiService = {
99
init () {
10-
axios.defaults.baseURL = BASE_URL
10+
axios.defaults.baseURL = BASE_URL + 'api/'
1111

1212
// Add a request interceptor
1313
axios.interceptors.request.use((config) => {

0 commit comments

Comments
 (0)