Skip to content

Commit d78dcf8

Browse files
author
Ibrahim Ethem Gursoy
committed
Merge remote-tracking branch 'origin/eren/model-fix'
2 parents 2044c8d + 0eb2976 commit d78dcf8

File tree

4 files changed

+35
-118
lines changed

4 files changed

+35
-118
lines changed

Pages/Index.cshtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
<script src="~/js/dist/main.bundle.js"></script>
2323
<script>
2424
var DeviceManagement = DeviceManagementLib.default;
25-
const jsonModel = @Html.Raw(Json.Serialize(Model.Devices));
26-
const deviceManagement = new DeviceManagement("device-checker-status-main", jsonModel);
25+
const deviceManagement = new DeviceManagement("device-checker-status-main");
2726
</script>
2827
}
2928

wwwroot/css/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ body {
4141
body {
4242
overflow-y: scroll;
4343
scrollbar-width: thin;
44-
scrollbar-color: #333 #f5f5f5;
44+
scrollbar-color: #6c757d #f5f5f5;
4545
}
4646

4747
body::-webkit-scrollbar {

wwwroot/js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "1.0.0",
3-
"description": "My webpack project",
4-
"name": "my-webpack-project",
3+
"description": "device-checker-status-desc",
4+
"name": "device-checker-status",
55
"scripts": {
66
"build": "webpack --mode=production",
77
"test": "standard && node my-tests.js"

wwwroot/js/src/Classes/DeviceManagement.js

Lines changed: 31 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import "highlight.js/styles/intellij-light.css";
33
import { Tooltip, Toast, Popover } from "bootstrap";
44
import fontawesome from "@fortawesome/fontawesome-free/js/all.js";
55
import hljs from "highlight.js";
6-
// import "@yaireo/tagify/dist/tagify.css";
7-
// import Tagify from "@yaireo/tagify";
86
import { CustomTagify } from "./CustomTagify.js";
97
import { jsonrepair } from "jsonrepair";
108

11-
console.log("DeviceManagement.js loaded");
12-
139
export default class DeviceManagement {
1410
//GLOBAL VARIABLES
1511
#model = [];
@@ -111,14 +107,37 @@ export default class DeviceManagement {
111107
"data-name": "modal-create-device-container",
112108
});
113109

114-
constructor(containerId, model) {
110+
constructor(containerId) {
115111
this.#containerId = containerId;
116-
this.#model = model;
117-
this.initElements();
118-
this.initBehaviours();
119-
this.initDocumentReadyBehaviours();
120-
this.setupExportButtonMode();
112+
this.fetchDeviceData()
113+
.then(() => {
114+
this.initElements();
115+
this.initBehaviours();
116+
this.initDocumentReadyBehaviours();
117+
this.setupExportButtonMode();
118+
})
119+
.catch((error) => {
120+
console.error("Error fetching data:", error);
121+
});
121122
}
123+
124+
fetchDeviceData() {
125+
return new Promise((resolve, reject) => {
126+
$.ajax({
127+
url: "http://localhost/api/Device/ListDevices",
128+
type: "GET",
129+
dataType: "json",
130+
success: (data) => {
131+
this.#model = data;
132+
resolve();
133+
},
134+
error: (error) => {
135+
reject(error);
136+
},
137+
});
138+
});
139+
}
140+
122141
//METHODS
123142
initElements() {
124143
this.createNavbarElements();
@@ -132,7 +151,6 @@ export default class DeviceManagement {
132151
// this.createPublishDeviceModal();
133152
this.createCameraCardsBody();
134153

135-
//new CustomTagify(this.#filterInput, `[dataFilter]:visible`);
136154
new CustomTagify("#tagify-filter-bar", `[dataFilter]:visible`);
137155
}
138156

@@ -143,7 +161,6 @@ export default class DeviceManagement {
143161

144162
//NAVBAR ELEMENTS CREATION
145163
createNavbarElements() {
146-
const self = this;
147164
// Navbar container
148165
this.#navbarContainer = $("<div>").attr(
149166
"data-name",
@@ -401,7 +418,7 @@ export default class DeviceManagement {
401418

402419
// Dynamic Keys Property Creation
403420
// (Note: This part will depend on actual property names and may need adjustments)
404-
for (let property of Object.getOwnPropertyNames(jsonModel[0])) {
421+
for (let property of Object.getOwnPropertyNames(this.#model[0])) {
405422
const propertyColumn = $("<div>").addClass(
406423
"col-sm-12 col-xl-6 mb-1"
407424
);
@@ -1389,7 +1406,6 @@ export default class DeviceManagement {
13891406
}),
13901407
contentType: "application/json",
13911408
success: function (res) {
1392-
console.log("Success", res);
13931409
this.notificate(
13941410
"notif",
13951411
"Publish successful.",
@@ -1478,11 +1494,9 @@ export default class DeviceManagement {
14781494
);
14791495
});
14801496
} else {
1481-
// Use the 'out of viewport hidden text area' trick
1497+
// Trick used here
14821498
const textArea = document.createElement("textarea");
14831499
textArea.value = this.#jsonStringCopy;
1484-
1485-
// Move textarea out of the viewport so it's not visible
14861500
textArea.style.position = "absolute";
14871501
textArea.style.left = "-999999px";
14881502

@@ -1530,99 +1544,3 @@ export default class DeviceManagement {
15301544
}, 2500);
15311545
}
15321546
}
1533-
1534-
// export class CustomTagify {
1535-
// constructor(inputTargetSelector, searchedElementsSelector) {
1536-
// this.inputTargetSelector = inputTargetSelector;
1537-
// this.searchWordsArray = [];
1538-
// this.searchedElementsSelector = searchedElementsSelector;
1539-
1540-
// var inputBar = document.querySelector(inputTargetSelector),
1541-
// // Initialize tagify to an object
1542-
// tagify = new Tagify(inputBar, {
1543-
// whitelist: this.extractStateUniqueWords(
1544-
// searchedElementsSelector
1545-
// ),
1546-
// placeholder: "Filter",
1547-
// enforceWhitelist: false,
1548-
// });
1549-
1550-
// this.tagify = tagify; // Assign tagify to the instance property
1551-
1552-
// this.tagify.on(`add`, this.onTagAdded.bind(this));
1553-
// this.tagify.on(`remove`, this.onTagRemoved.bind(this));
1554-
1555-
// // Change here: Use a regular function instead of an arrow function
1556-
// inputBar.addEventListener(
1557-
// "keyup",
1558-
// function () {
1559-
// this.filterPageTagify(
1560-
// inputBar.value,
1561-
// '[data-card="container"]:visible'
1562-
// );
1563-
// }.bind(this)
1564-
// );
1565-
// }
1566-
1567-
// extractStateUniqueWords(searchedElementsSelector) {
1568-
// var words = new Set();
1569-
// $(searchedElementsSelector).each(function () {
1570-
// var dataFilterText = $(this).text().toLowerCase().trim();
1571-
// words.add(dataFilterText);
1572-
// });
1573-
// return Array.from(words);
1574-
// }
1575-
1576-
// filterPageTagify(filterString, selector) {
1577-
// var filter = filterString.toLowerCase();
1578-
// console.log(filter);
1579-
1580-
// if (filter.length <= 1 && filter.length > 0) {
1581-
// return;
1582-
// } else {
1583-
// $(selector).filter(function () {
1584-
// $(this).toggle($(this).text().toLowerCase().includes(filter));
1585-
// });
1586-
// }
1587-
// }
1588-
1589-
// onTagAdded(e) {
1590-
// const addedTag = e.detail.data.value;
1591-
// this.searchWordsArray.push(addedTag);
1592-
1593-
// this.searchWordsArray.forEach((filterString) =>
1594-
// this.filterPageTagify(
1595-
// filterString,
1596-
// '[data-card="container"]:visible'
1597-
// )
1598-
// );
1599-
1600-
// this.tagify.whitelist = this.extractStateUniqueWords(
1601-
// this.searchedElementsSelector
1602-
// );
1603-
// }
1604-
1605-
// onTagRemoved(e) {
1606-
// const removedTag = e.detail.data.value;
1607-
1608-
// const index = this.searchWordsArray.findIndex(
1609-
// (tag) => tag === removedTag
1610-
// );
1611-
1612-
// if (index !== -1) {
1613-
// this.searchWordsArray.splice(index, 1);
1614-
// }
1615-
1616-
// if (this.searchWordsArray.length === 0) {
1617-
// $('[data-card="container"]').show();
1618-
// } else {
1619-
// this.searchWordsArray.forEach((filterString) =>
1620-
// this.filterPageTagify(filterString, '[data-card="container"]')
1621-
// );
1622-
// }
1623-
1624-
// this.tagify.whitelist = this.extractStateUniqueWords(
1625-
// this.searchedElementsSelector
1626-
// );
1627-
// }
1628-
// }

0 commit comments

Comments
 (0)