Skip to content

Commit

Permalink
toast
Browse files Browse the repository at this point in the history
  • Loading branch information
mstgnz committed Jul 7, 2024
1 parent 725c386 commit 6fe677a
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 31 deletions.
13 changes: 13 additions & 0 deletions assets/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
* {
box-shadow: none !important
}

#toast {
position: fixed;
padding: 10px;
width: 30%;
left: 35%;
bottom: 20px;
border-radius: 10px;
border: solid 1px #ddd;
color: brown;
text-transform: lowercase;
display: none;
}
19 changes: 19 additions & 0 deletions assets/js/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let toastTimeout;
const toast = document.getElementById('toast');
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type === 'childList') {
// Display toast
toast.style.display = 'block';
// Clear previous timeout if any
if (toastTimeout) {
clearTimeout(toastTimeout);
}
// Hide toast after 5 seconds
toastTimeout = setTimeout(() => {
toast.style.display = 'none';
}, 5000);
}
}
});
observer.observe(toast, { childList: true });
12 changes: 6 additions & 6 deletions handler/web/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (h *NotificationHandler) EditHandler(w http.ResponseWriter, r *http.Request
}

form := fmt.Sprintf(`
<tr hx-put="/notifications/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/notifications/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td><input name="title" class="form-control" value="%s"></td>
<td><input name="content" class="form-control" value="%s"></td>
Expand All @@ -112,7 +112,7 @@ func (h *NotificationHandler) EditHandler(w http.ResponseWriter, r *http.Request
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/notifications">Cancel</button>
<button class="btn btn-warning" hx-get="/notifications-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/notifications/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down Expand Up @@ -421,7 +421,7 @@ func (h *NotificationHandler) EmailEditHandler(w http.ResponseWriter, r *http.Re
}

form := fmt.Sprintf(`
<tr hx-put="/notifications/email/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/notifications/email/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td>%s</td>
<td><input name="email" class="form-control" value="%s" /></td>
Expand All @@ -433,7 +433,7 @@ func (h *NotificationHandler) EmailEditHandler(w http.ResponseWriter, r *http.Re
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/notifications">Cancel</button>
<button class="btn btn-warning" hx-get="/notifications-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/notifications/email/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down Expand Up @@ -610,7 +610,7 @@ func (h *NotificationHandler) MessageEditHandler(w http.ResponseWriter, r *http.
}

form := fmt.Sprintf(`
<tr hx-put="/notifications/message/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/notifications/message/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td>%s</td>
<td><input name="text" class="form-control" value="%s" /></td>
Expand All @@ -622,7 +622,7 @@ func (h *NotificationHandler) MessageEditHandler(w http.ResponseWriter, r *http.
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/notifications">Cancel</button>
<button class="btn btn-warning" hx-get="/notifications-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/notifications/message/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down
8 changes: 4 additions & 4 deletions handler/web/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h *RequestHandler) EditHandler(w http.ResponseWriter, r *http.Request) err
}

form := fmt.Sprintf(`
<tr hx-put="/requests/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/requests/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td><input name="url" class="form-control" value="%s"></td>
<td><select class="form-select" name="method">
Expand All @@ -102,7 +102,7 @@ func (h *RequestHandler) EditHandler(w http.ResponseWriter, r *http.Request) err
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/requests">Cancel</button>
<button class="btn btn-warning" hx-get="/requests-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/requests/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down Expand Up @@ -398,7 +398,7 @@ func (h *RequestHandler) HeaderEditHandler(w http.ResponseWriter, r *http.Reques
}

form := fmt.Sprintf(`
<tr hx-put="/requests/headers/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/requests/headers/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td><input name="key" class="form-control" value="%s" /></td>
<td><input name="value" class="form-control" value="%s" /></td>
Expand All @@ -410,7 +410,7 @@ func (h *RequestHandler) HeaderEditHandler(w http.ResponseWriter, r *http.Reques
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/requests">Cancel</button>
<button class="btn btn-warning" hx-get="/requests-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/requests/headers/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down
4 changes: 2 additions & 2 deletions handler/web/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (h *ScheduleHandler) EditHandler(w http.ResponseWriter, r *http.Request) er
}

form := fmt.Sprintf(`
<tr hx-put="/schedules/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/schedules/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td>%s</td>
<td>%s</td>
Expand All @@ -121,7 +121,7 @@ func (h *ScheduleHandler) EditHandler(w http.ResponseWriter, r *http.Request) er
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/schedules">Cancel</button>
<button class="btn btn-warning" hx-get="/schedules-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/schedules/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down
4 changes: 2 additions & 2 deletions handler/web/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (h *WebhookHandler) EditHandler(w http.ResponseWriter, r *http.Request) err
scheduleList += "</select>"

form := fmt.Sprintf(`
<tr hx-put="/webhooks/%d" hx-trigger='cancel' hx-ext="json-enc" class='editing'>
<tr hx-put="/webhooks/%d" hx-trigger='cancel' hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" class='editing'>
<th scope="row">%d</th>
<td>%s</td>
<td>%s</td>
Expand All @@ -93,7 +93,7 @@ func (h *WebhookHandler) EditHandler(w http.ResponseWriter, r *http.Request) err
<td>%s</td>
<td>
<div class="hstack gap-1">
<button class="btn btn-warning" hx-get="/webhooks">Cancel</button>
<button class="btn btn-warning" hx-get="/webhooks-pagination" hx-target="#tbody" hx-swap="innerHTML">Cancel</button>
<button class="btn btn-danger" hx-put="/webhooks/%d" hx-include="closest tr">Save</button>
</div>
</td>
Expand Down
3 changes: 1 addition & 2 deletions views/components/group/list.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<h5 class="modal-title">Group Update</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form hx-put="/groups/0" hx-target="#change-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-put="/groups/0" hx-target="#toast" hx-ext="json-enc" novalidate autocomplete="off">
<div class="modal-body">
<div class="form-floating mb-2">
<input type="text" class="form-control" name="name" placeholder="Name" required>
Expand All @@ -63,7 +63,6 @@
</select>
<label for="active">Status</label>
</div>
<span id="change-toast"></span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
Expand Down
1 change: 0 additions & 1 deletion views/components/group/new.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Save</button>
<span id="toast"></span>
</form>
</div>
</div>
Expand Down
9 changes: 3 additions & 6 deletions views/components/notification/new.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class="row">
<div class="col-4 mt-2">
<form hx-post="/notifications" hx-target="#notification-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/notifications" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<input type="text" class="form-control" name="title" placeholder="title" required>
<label for="title">title</label>
Expand Down Expand Up @@ -35,11 +35,10 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Notification Save</button>
<span id="notification-toast"></span>
</form>
</div>
<div class="col-4 mt-2">
<form hx-post="/notifications/email" hx-target="#email-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/notifications/email" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<select class="form-select" name="notification_id" required>
<option value="0" selected>Choose Notification</option>
Expand All @@ -61,11 +60,10 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Email Save</button>
<span id="email-toast"></span>
</form>
</div>
<div class="col-4 mt-2">
<form hx-post="/notifications/message" hx-target="#message-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/notifications/message" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<select class="form-select" name="notification_id" required>
<option value="0" selected>Choose Notification</option>
Expand All @@ -87,7 +85,6 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Message Save</button>
<span id="message-toast"></span>
</form>
</div>
</div>
Expand Down
6 changes: 2 additions & 4 deletions views/components/request/new.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{define "requestNew" }}
<div class="row">
<div class="col-6 mt-2">
<form hx-post="/requests" hx-target="#request-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/requests" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<input type="text" class="form-control" name="url" placeholder="Url" required>
<label for="url">Url</label>
Expand All @@ -30,11 +30,10 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Request Save</button>
<span id="request-toast"></span>
</form>
</div>
<div class="col-6 mt-2">
<form hx-post="/requests/headers" hx-target="#header-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/requests/headers" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<select class="form-select" name="request_id" required>
<option value="0" selected>Choose Request</option>
Expand All @@ -60,7 +59,6 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Header Save</button>
<span id="header-toast"></span>
</form>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions views/components/schedule/new.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{define "scheduleNew" }}
<div class="row justify-content-center mt-2">
<div class="col-8">
<form hx-post="/schedules" hx-target="#schedule" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/schedules" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<select class="form-select" name="group_id" required>
<option value="0" selected>Choose Group</option>
Expand Down Expand Up @@ -51,7 +51,6 @@
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Schedule Save</button>
<span id="schedule"></span>
</form>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions views/components/setting/user-new.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{define "userNew" }}
<div class="row justify-content-center">
<div class="col-6 p-5">
<form hx-post="/settings/users/signup" hx-target="#toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/settings/users/signup" hx-target="#toast" hx-swap="innerHTML" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<input type="text" class="form-control" name="fullname" placeholder="Firstname Lastname" required>
<label for="fullname">Fullname</label>
Expand All @@ -21,7 +21,6 @@
<label for="password">Password</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Sign up</button>
<span id="toast"></span>
</form>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions views/index.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
{{block "content" .}}{{end}}
</main>

<div id="toast"></div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
Expand Down

0 comments on commit 6fe677a

Please sign in to comment.