Skip to content

Eren/notif works #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ViewData["Title"] = "Device Monitoring";
}

@section Styles{
@section Styles {
<link rel="stylesheet" href="~/css/index.css" />
}

Expand Down Expand Up @@ -50,7 +50,7 @@
</nav>
</div>

<div id="streamNotif">Copied</div>
<div id="notif" class="d-flex justify-content-center">Copied</div>

<div data-simplebar>
<div class="d-flex flex-row justify-content-between p-2 ms-2 me-2">
Expand Down
101 changes: 64 additions & 37 deletions wwwroot/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ body {
box-sizing: border-box;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
background-color: #fff;
transition: box-shadow 0.3s ease, border-radius 0.3s ease,
background-color 0.3s ease;
transition: box-shadow 0.3s ease, border-radius 0.3s ease, background-color 0.3s ease;
}

[data-card="cameraContainer"]:hover {
box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.3);
border-radius: 1.5rem;
background-color: #dcdcdc;
}
[data-card="cameraContainer"]:hover {
box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.3);
border-radius: 1.5rem;
background-color: #dcdcdc;
}

.camera-card {
width: 100%;
Expand All @@ -45,57 +44,85 @@ body {
scrollbar-color: #333 #f5f5f5;
}

body::-webkit-scrollbar {
width: 8px;
}

body::-webkit-scrollbar-thumb {
background-color: #333;
}
body::-webkit-scrollbar {
width: 8px;
}

body::-webkit-scrollbar-track {
background-color: #f5f5f5;
}
body::-webkit-scrollbar-thumb {
background-color: #333;
}

body::-webkit-scrollbar-track {
background-color: #f5f5f5;
}

#streamNotif {
#notif {
visibility: hidden;
min-width: 3rem;
min-width: 2.4rem;
background-color: #20ad6b;
color: #ffffff;
text-align: center;
border-radius: 2rem;
padding: 2rem;
border-radius: 1rem;
padding: 1rem;
position: fixed;
z-index: 1;
z-index: 1000;
left: 50%;
transform: translateX(-50%);
bottom: 2rem;
font-size: 1.5rem;
font-size: 1.2rem;
opacity: 0.9;
}

#streamNotif.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
#notif.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
from {
bottom: 0;
opacity: 0;
}

to {
bottom: 20px;
opacity: 1;
}
}

@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
from {
bottom: 0;
opacity: 0;
}

to {
bottom: 20px;
opacity: 1;
}
}

@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
from {
bottom: 20px;
opacity: 1;
}

to {
bottom: 0;
opacity: 0;
}
}

@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
from {
bottom: 20px;
opacity: 1;
}

to {
bottom: 0;
opacity: 0;
}
}
55 changes: 26 additions & 29 deletions wwwroot/js/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { CustomTagify } from "./Classes/CustomTagify";
import hljs from "highlight.js";
import { jsonrepair } from "jsonrepair";



// GLOBAL VARIABLES
var jsonDeviceArray = [];
var jsonStringCopy = "";
var errorNotifColor = "#d72a6f";
var successNotifColor = "#20ad6b";
var neutralNotifColor = "#8f6ac4";

$(document).ready(function () {
// TAGIFY RELATED EVENTS
Expand Down Expand Up @@ -194,9 +195,11 @@ window.exportSelectedDevices = function () {
console.error("Export error:", textStatus, errorThrown);

if (xhr.responseJSON && xhr.responseJSON.error) {
alert("Export error: " + xhr.responseJSON.error);
notificate("notif", "Export error: " + xhr.responseJSON.error, errorNotifColor);
//alert("Export error: " + xhr.responseJSON.error);
} else {
alert("Export error occurred.");
notificate("notif", "Export error occurred.", errorNotifColor);
//alert("Export error occurred.");
}
},
});
Expand Down Expand Up @@ -248,9 +251,11 @@ window.exportSelectedDevicesAdvanced = function () {
console.error("Export error:", textStatus, errorThrown);

if (xhr.responseJSON && xhr.responseJSON.error) {
alert("Export error: " + xhr.responseJSON.error);
notificate("notif", "Export error: " + xhr.responseJSON.error, errorNotifColor);
//alert("Export error: " + xhr.responseJSON.error);
} else {
alert("Export error occurred.");
notificate("notif", "Export error occurred.", errorNotifColor);
//alert("Export error occurred.");
}
},
});
Expand Down Expand Up @@ -356,31 +361,23 @@ window.refreshPage = function () {
location.reload(true);
};

//window.copyDevicesJSON = function () {
// navigator.clipboard
// .writeText(jsonStringCopy)
// .then(() => {
// console.log(jsonStringCopy);
// alert("Content is copied to clipboard");
// })
// .catch((error) => {
// alert("Unable to copy the content", error);
// });
//};


window.copyDevicesJSON = function () {
// Check if jsonStringCopy is null or empty
if (!jsonStringCopy || jsonStringCopy.trim() === '') {
notificate("notif", "No content to copy", neutralNotifColor);
return;
}

// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext ) {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard
.writeText(jsonStringCopy)
.then(() => {
console.log(jsonStringCopy);
notificateStream();
//alert("Content is copied to clipboard");
notificate("notif", "Copied", successNotifColor);
})
.catch((error) => {
alert("Unable to copy the content", error);
notificate("notif", "Unable to copy the content", errorNotifColor);
});
} else {
// Use the 'out of viewport hidden text area' trick
Expand All @@ -396,7 +393,7 @@ window.copyDevicesJSON = function () {

try {
document.execCommand('copy');
notificateStream();
notificate("notif", "Copied", successNotifColor);
} catch (error) {
console.error(error);
} finally {
Expand All @@ -411,12 +408,10 @@ document.addEventListener("DOMContentLoaded", function () {
copyButtons.forEach(function (button) {
button.addEventListener("click", function () {
var streamData = button.getAttribute("data-stream");

navigator.clipboard
.writeText(streamData)
.then(() => {
console.log(streamData);
notificateStream();
notificate("notif", "Copied", successNotifColor);
})
.catch((error) => {
console.log(error)
Expand All @@ -425,8 +420,10 @@ document.addEventListener("DOMContentLoaded", function () {
});
});

window.notificateStream = function () {
var x = document.getElementById("streamNotif");
window.notificate = function (elementId, notifText, hexColorCode) {
var x = document.getElementById(elementId);
x.textContent = notifText;
x.style.backgroundColor = hexColorCode;
x.className = "show";
setTimeout(function () { x.className = x.className.replace("show", ""); }, 2500);
}