This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDashboard_Notification.vb
497 lines (441 loc) · 25 KB
/
Dashboard_Notification.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Net
Imports System.Resources
Imports System.Text.RegularExpressions
Imports Svg
Public Class Dashboard_Notification
Inherits BaseForm
Private SidePanel As FlowLayoutPanel
Private MainPanel As Transparent.Panel
Private Class RequestTable
Inherits Transparent.Panel
Sub New(
courseCode As Object,
facultyName As Object,
originalFacilityName As Object,
originalDay As Object,
originalStartTime As Object,
originalEndTime As Object,
requestFacilityName As Object,
requestDay As Object,
requestStartTime As Object,
requestEndTime As Object,
status As Object,
requestReason As Object,
rejectReason As Object,
requestDate As Object,
scheduleID As Object,
requestID As Object
)
Me.BorderStyle = BorderStyle.None
Me.Margin = New Padding(0, 0, 0, Globals.Unit(2))
Dim Header As New Label With {
.Text = courseCode & " - " & facultyName,
.Font = Globals.GetFont("Raleway", Globals.Unit(0.75), FontStyle.Bold),
.ForeColor = Globals.Palette("White"),
.BackColor = Globals.Palette("Primary"),
.AutoSize = False,
.Size = New Size(Me.Width, Globals.Unit(1)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(Header)
Dim OriginalLabel As New Label With {
.Text = "Original",
.Font = Globals.GetFont("Raleway", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("White"),
.BackColor = Globals.Palette("Secondary"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(0, Header.Bottom),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(OriginalLabel)
Dim OriginalFacilityLabel As New Label With {
.Text = "Facility: " & originalFacilityName,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("Plain Light"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(2)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(OriginalFacilityLabel)
Dim OriginalDayLabel As New Label With {
.Text = "Day: " & originalDay,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("White"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(3)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(OriginalDayLabel)
Dim OriginalTimeLabel As New Label With {
.Text = "Time: " & originalStartTime & " - " & originalEndTime,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("Plain Light"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(4)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(OriginalTimeLabel)
Dim RequestLabel As New Label With {
.Text = "Request",
.Font = Globals.GetFont("Raleway", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("White"),
.BackColor = Globals.Palette("Secondary"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(Me.Width / 2, Header.Bottom),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(RequestLabel)
Dim RequestFacilityLabel As New Label With {
.Text = "Facility: " & requestFacilityName,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("White"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(Me.Width / 2, Globals.Unit(2)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(RequestFacilityLabel)
Dim RequestDayLabel As New Label With {
.Text = "Day: " & requestDay,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("Plain Light"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(Me.Width / 2, Globals.Unit(3)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(RequestDayLabel)
Dim RequestTimeLabel As New Label With {
.Text = "Time: " & requestStartTime & " - " & requestEndTime,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("White"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(Me.Width / 2, Globals.Unit(4)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(RequestTimeLabel)
Dim ReasonLabel As New Label With {
.Text = "Request Reason: " & requestReason,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("White"),
.AutoSize = False,
.Size = New Size(Me.Width, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(5)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(ReasonLabel)
Dim StatusLabel As New Label With {
.Text = "Status: " & status,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("Plain Light"),
.AutoSize = False,
.Size = New Size(Me.Width, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(6)),
.TextAlign = ContentAlignment.MiddleCenter
}
Me.Controls.Add(StatusLabel)
If rejectReason = Nothing Then
rejectReason = ""
End If
Dim RejectReasonLabel As New Label With {
.Text = "Rejection Rason: " & rejectReason,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark"),
.BackColor = Globals.Palette("White"),
.AutoSize = False,
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(Me.Width / 2, Globals.Unit(6)),
.TextAlign = ContentAlignment.MiddleCenter
}
If status = "rejected" Then
StatusLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
Me.Controls.Add(RejectReasonLabel)
End If
AddHandler Me.Resize, Sub()
Header.Size = New Size(Me.Width, Globals.Unit(1))
OriginalLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
OriginalLabel.Location = New Point(0, Header.Bottom)
OriginalFacilityLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
OriginalFacilityLabel.Location = New Point(0, Globals.Unit(2))
OriginalDayLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
OriginalDayLabel.Location = New Point(0, Globals.Unit(3))
OriginalTimeLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
OriginalTimeLabel.Location = New Point(0, Globals.Unit(4))
RequestLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
RequestLabel.Location = New Point(Me.Width / 2, Header.Bottom)
RequestFacilityLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
RequestFacilityLabel.Location = New Point(Me.Width / 2, Globals.Unit(2))
RequestDayLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
RequestDayLabel.Location = New Point(Me.Width / 2, Globals.Unit(3))
RequestTimeLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
RequestTimeLabel.Location = New Point(Me.Width / 2, Globals.Unit(4))
ReasonLabel.Size = New Size(Me.Width, Globals.Unit(1))
StatusLabel.Size = New Size(Me.Width, Globals.Unit(1))
If status = "rejected" Then
StatusLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
RejectReasonLabel.Size = New Size(Me.Width / 2, Globals.Unit(1))
RejectReasonLabel.Location = New Point(Me.Width / 2, Globals.Unit(6))
End If
End Sub
If status = "rejected" Or status = "approved" Then
Dim Footer As New Transparent.Panel With {
.Size = New Size(Me.Width, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(7)),
.BackColor = Globals.Palette("Primary")
}
Me.Controls.Add(Footer)
AddHandler Me.Resize, Sub()
Footer.Size = New Size(Me.Width, Globals.Unit(1))
Footer.Location = New Point(0, Globals.Unit(7))
End Sub
Return
End If
Dim ApproveButton As New BaseButton With {
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(7)),
.Text = "Approve"
}
AddHandler ApproveButton.Click, Sub()
Try
Dim data As New Dictionary(Of String, String) From {
{"requestID", requestID}
}
Dim response = Globals.API("POST", "admin/dashboard/program/" & Globals.PROGRAM & "/requests/" & requestID & "/approve/", Globals.DictionaryToJSON(data))
Dim Modal As New BaseModal With {
.Title = "Success",
.Message = "Request approved successfully."
}
Modal.ShowDialog()
RaiseEvent Updated(Me, New EventArgs())
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
End Try
End Sub
Me.Controls.Add(ApproveButton)
Dim RejectTextInput As New BaseTextInput With {
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(7)),
.Name = "Reason for rejection",
.Visible = False
}
Me.Controls.Add(RejectTextInput)
Dim RejectButton As New BaseButton With {
.Size = New Size(Me.Width / 2, Globals.Unit(1)),
.Location = New Point(Me.Width / 2, Globals.Unit(7)),
.Text = "Reject",
.SubButton = True
}
AddHandler RejectButton.Click, Sub()
If RejectTextInput.Visible Then
If RejectTextInput.Text = "" Then
RejectTextInput.Alert()
Else
Try
Dim data As New Dictionary(Of String, String) From {
{"rejectReason", RejectTextInput.Text}
}
Dim response = Globals.API("POST", "admin/dashboard/program/" & Globals.PROGRAM & "/requests/" & requestID & "/reject/", Globals.DictionaryToJSON(data))
Dim Modal As New BaseModal With {
.Title = "Success",
.Message = "Request rejected successfully."
}
Modal.ShowDialog()
RaiseEvent Updated(Me, New EventArgs())
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
End Try
End If
Else
RejectTextInput.Visible = True
RejectButton.Text = "Confirm"
ApproveButton.Visible = False
End If
End Sub
Me.Controls.Add(RejectButton)
AddHandler Me.Resize, Sub()
ApproveButton.Size = New Size(Me.Width / 2, Globals.Unit(1))
ApproveButton.Location = New Point(0, Globals.Unit(7))
RejectButton.Size = New Size(Me.Width / 2, Globals.Unit(1))
RejectButton.Location = New Point(Me.Width / 2, Globals.Unit(7))
RejectTextInput.Size = New Size(Me.Width / 2, Globals.Unit(1))
End Sub
End Sub
Public Event Updated(sender As Object, e As EventArgs)
End Class
Protected Sub Dashboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackendSocket.Connect("notifications_admin")
Me.Name = "Dashboard"
Me.SidePanel = New FlowLayoutPanel With {
.Size = New Size(Globals.Unit(2), Me.Contents.Height - (Me.HeaderBar.Height + Me.resizerBarTop.Height)),
.BackColor = Globals.Palette("Plain Light"),
.FlowDirection = FlowDirection.TopDown,
.WrapContents = False,
.AutoScroll = True,
.Padding = New Padding(0, 0, 0, 0),
.Location = New Point(
Me.resizerBarRight.Width,
Me.HeaderBar.Height + Me.resizerBarTop.Height
)
}
Me.Contents.Controls.Add(Me.SidePanel)
Dim CallendarIcon As New PictureBox With {
.Image = Globals.LoadSvgFromResource("Calendar Icon", New Size(Globals.Unit(2), Globals.Unit(2))).Draw(),
.Size = New Size(Globals.Unit(2), Globals.Unit(2)),
.SizeMode = PictureBoxSizeMode.Zoom,
.Cursor = Cursors.Hand,
.Margin = New Padding(0),
.Padding = New Padding(0)
}
AddHandler CallendarIcon.Click, Sub()
BackendSocket.Close()
Me.GoToForm(New Dashboard_Calendar)
End Sub
Me.SidePanel.Controls.Add(CallendarIcon)
Dim CreateIcon As New PictureBox With {
.Image = Globals.LoadSvgFromResource("Create Icon", New Size(Globals.Unit(2), Globals.Unit(2))).Draw(),
.Size = New Size(Globals.Unit(2), Globals.Unit(2)),
.SizeMode = PictureBoxSizeMode.Zoom,
.Cursor = Cursors.Hand,
.Margin = New Padding(0),
.Padding = New Padding(0)
}
AddHandler CreateIcon.Click, Sub()
BackendSocket.Close()
Me.GoToForm(New Dashboard_Create)
End Sub
Me.SidePanel.Controls.Add(CreateIcon)
Dim NotificationIcon As New PictureBox With {
.Image = Globals.LoadSvgFromResource("Notification Icon Active", New Size(Globals.Unit(2), Globals.Unit(2))).Draw(),
.Size = New Size(Globals.Unit(2), Globals.Unit(2)),
.SizeMode = PictureBoxSizeMode.Zoom,
.Cursor = Cursors.Hand,
.Margin = New Padding(0),
.Padding = New Padding(0)
}
Me.SidePanel.Controls.Add(NotificationIcon)
Me.MainPanel = New Transparent.Panel With {
.Size = New Size(
Me.Contents.Width - Me.SidePanel.Width,
Me.Contents.Height - (Me.HeaderBar.Height + Me.resizerBarTop.Height + Me.resizerBarBottom.Height)
),
.AutoScroll = True,
.Location = New Point(
Me.SidePanel.Width + Me.resizerBarRight.Width,
Me.HeaderBar.Height + Me.resizerBarTop.Height
)
}
Me.Contents.Controls.Add(Me.MainPanel)
Dim RequestsPanel As New FlowLayoutPanel With {
.MinimumSize = New Size(Me.MainPanel.Width - Globals.Unit(2), 0),
.MaximumSize = New Size(Me.MainPanel.Width - Globals.Unit(2), 0),
.Location = New Point(Globals.Unit(1), Globals.Unit(1)),
.FlowDirection = FlowDirection.TopDown,
.WrapContents = False,
.AutoSize = True,
.Padding = New Padding(0, 0, 0, 0)
}
AddHandler Me.Resize, Sub()
RequestsPanel.MinimumSize = New Size(Me.MainPanel.Width - Globals.Unit(2), 0)
RequestsPanel.MaximumSize = New Size(Me.MainPanel.Width - Globals.Unit(2), 0)
End Sub
Me.MainPanel.Controls.Add(RequestsPanel)
Me.DisplayRequests(RequestsPanel)
AddHandler BackendSocket.OnMessage, Sub(data As String)
Me.DisplayRequests(RequestsPanel)
End Sub
'Check if the system is already set up
Try
Dim response = Globals.API("GET", "setup", Nothing)
Catch ex As Exception
Dim Modal As New BaseModal With {
.Title = "System Setup",
.Message = "The system is not set up. Please set up the system before logging in.",
.Buttons = New Dictionary(Of String, DialogResult) From {
{"OK", DialogResult.OK},
{"Cancel", DialogResult.Cancel}
}
}
If Modal.ShowDialog() = DialogResult.OK Then
BackendSocket.Close()
Me.GoToForm(New DeanSetup)
Else
Me.Close()
End If
End Try
Loaded = True
Me.Size = Globals.FormSize
End Sub
Protected Sub DisplayRequests(RequestsPanel As FlowLayoutPanel)
RequestsPanel.Controls.Clear()
Dim response = Globals.API("GET", "admin/dashboard/program/" & Globals.PROGRAM & "/requests/", Nothing)
Dim data = Globals.JSONToDictionary(response, True)
For Each request In data.Values
Dim RequestTable As New RequestTable(
request("courseCode"),
request("facultyName"),
request("original")("facilityName"),
request("original")("day"),
request("original")("startTime"),
request("original")("endTime"),
request("request")("facilityName"),
request("request")("day"),
request("request")("startTime"),
request("request")("endTime"),
request("status"),
request("requestReason"),
request("rejectReason"),
request("requestDate"),
request("scheduleID"),
request("requestID")
)
AddHandler RequestsPanel.Resize, Sub()
RequestTable.Size = New Size(RequestsPanel.Width, Globals.Unit(8))
End Sub
RequestsPanel.Controls.Add(RequestTable)
AddHandler RequestTable.Updated, Sub()
RequestsPanel.Size = New Size(RequestsPanel.Width + 1, RequestsPanel.Height + 1)
Me.DisplayRequests(RequestsPanel)
RequestsPanel.Size = New Size(RequestsPanel.Width - 1, RequestsPanel.Height - 1)
End Sub
Next
End Sub
Protected Sub Dashboard_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.Loaded Then
Me.SidePanel.Size = New Size(Globals.Unit(2), Me.Contents.Height - (Me.HeaderBar.Height + Me.resizerBarTop.Height))
Me.MainPanel.Size = New Size(
Me.Contents.Width - (Me.SidePanel.Width + Me.resizerBarLeft.Width + Me.resizerBarRight.Width),
Me.Contents.Height - (Me.HeaderBar.Height + Me.resizerBarTop.Height)
)
End If
End Sub
End Class