@@ -3,13 +3,9 @@ import "highlight.js/styles/intellij-light.css";
33import { Tooltip , Toast , Popover } from "bootstrap" ;
44import fontawesome from "@fortawesome/fontawesome-free/js/all.js" ;
55import hljs from "highlight.js" ;
6- // import "@yaireo/tagify/dist/tagify.css";
7- // import Tagify from "@yaireo/tagify";
86import { CustomTagify } from "./CustomTagify.js" ;
97import { jsonrepair } from "jsonrepair" ;
108
11- console . log ( "DeviceManagement.js loaded" ) ;
12-
139export 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