More App New UI - Code Changes

Code Changes for New UI.
This commit is contained in:
Zeja Pyle 2022-06-07 22:40:24 -04:00 committed by GitHub
parent 625b2c9c0b
commit b1f0747b62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 135 additions and 145 deletions

View file

@ -25,7 +25,7 @@
"action": "", "action": "",
"script": "" "script": ""
}; };
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.screenChanged.connect(onScreenChanged); tablet.screenChanged.connect(onScreenChanged);
var button = tablet.addButton({ var button = tablet.addButton({
@ -48,7 +48,7 @@
isActive: appStatus isActive: appStatus
}); });
} }
button.clicked.connect(clicked); button.clicked.connect(clicked);
function sendRunningScriptList() { function sendRunningScriptList() {

View file

@ -19,44 +19,18 @@
<script src="jquery-3.5.1.min.js"></script> <script src="jquery-3.5.1.min.js"></script>
<script> <script>
//Defaults //Defaults
var DEFAULT_PER_PAGE = 3; var NUMBER_OF_RECORDS_PER_LOAD = 20;
var DEFAULT_OFFSET = 0; var loadRecordsUpTo = NUMBER_OF_RECORDS_PER_LOAD;
//Parameters var seachedFieldsFilter = ["name"];
function findGetParameter(parameterName) { var previousSearch = "";
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
var offset = findGetParameter("offset");
if (offset === null) {
offset = DEFAULT_OFFSET;
}
offset = parseInt(offset);
var perpage = findGetParameter("perpage");
if (perpage === null) {
perpage = DEFAULT_PER_PAGE;
}
perpage = parseInt(perpage);
var search = findGetParameter("search");
if (search === null) {
search = "";
}
//Paths //Paths
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname; var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
var developmentMode = window.location.toString().split("?")[1]; var developmentMode = window.location.toString().split("?")[1];
var rootPath; var rootPath;
var metadataScriptSrc = "https://more.overte.org/applications/metadata.js"; var metadataScriptSrc = "https://more.overte.org/applications/metadata.js";
if (developmentMode === "dev") { // Development mode loads locally, if not, load from repo. if (developmentMode === "dev") { // Development mode loads locally, if not, load from repo.
console.info("Setting applications to local.") console.info("Setting applications to local.")
rootPath = currentPath.replace("more/more.html", "applications/"); rootPath = currentPath.replace("more/more.html", "applications/");
@ -69,22 +43,68 @@
} }
//Search //Search
function doSearch(keyword) { function doSearch() {
offset = 0; var keyword = document.getElementById("searchtextbox").value;
search = keyword; if (keyword === "") {
listBuilder(keyword, offset, perpage); document.getElementById("clear_search").style.display = "none";
document.getElementById("searchFiltersBar").style.display = "none";
} else {
if (document.getElementById("searchFiltersBar").style.display === "none") {
seachedFieldsFilter = ["name"];
}
document.getElementById("clear_search").style.display = "block";
document.getElementById("searchFiltersBar").style.display = "inline-block";
displaySearchFieldsFilter();
}
if (previousSearch !== keyword) {
loadRecordsUpTo = NUMBER_OF_RECORDS_PER_LOAD;
document.getElementById("list").scrollTop = 0;
}
listBuilder(keyword, loadRecordsUpTo);
previousSearch = keyword;
} }
function clearSearch() { function clearSearch() {
offset = 0; loadRecordsUpTo = NUMBER_OF_RECORDS_PER_LOAD;
document.searchbar.searchtextbox.value = ""; document.getElementById("searchtextbox").value = "";
search = ""; doSearch();
listBuilder("", offset, perpage);
} }
function filterSearchField(targeted) {
if (seachedFieldsFilter.indexOf(targeted) === -1) {
seachedFieldsFilter.push(targeted);
} else {
seachedFieldsFilter = arrayRemove(seachedFieldsFilter, targeted);
}
loadRecordsUpTo = NUMBER_OF_RECORDS_PER_LOAD;
displaySearchFieldsFilter();
doSearch();
}
function arrayRemove(arr, value) {
return arr.filter(function(ele){
return ele != value;
});
}
function displaySearchFieldsFilter() {
if (seachedFieldsFilter.indexOf("name") === -1) {
document.getElementById("searchFilterName").className = "fieldsSearchFilterOff";
} else {
document.getElementById("searchFilterName").className = "fieldsSearchFilterOn";
}
if (seachedFieldsFilter.indexOf("description") === -1) {
document.getElementById("searchFilterDesc").className = "fieldsSearchFilterOff";
} else {
document.getElementById("searchFilterDesc").className = "fieldsSearchFilterOn";
}
}
//Running scripts //Running scripts
var buttonList = []; var buttonList = [];
function requestRunningScriptData() { function requestRunningScriptData() {
var readyEvent = { var readyEvent = {
"action": "requestRunningScriptData" "action": "requestRunningScriptData"
@ -134,60 +154,40 @@
EventBridge.emitWebEvent(JSON.stringify(readyEvent)); EventBridge.emitWebEvent(JSON.stringify(readyEvent));
} }
</script> </script>
<link href="https://fonts.googleapis.com/css?family=Merriweather|Quicksand:400,700&display=swap" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet">
</head> </head>
<body><form name = "searchbar" onsubmit="submitForm(event);"> <body>
<font class="mainTitle">Add more functionalities...</font><br> <div id="header">
<table style = "width:100%;"> <font class="mainTitle">Add more functionalities...</font><br>
<tr > <div id="search_container">
<td style = "vertical-align:middle; text-align:left;"> <input id="searchtextbox" maxlength="40" placeholder = "Search..." onkeyup = "doSearch();">
<table> <span id="clear_search" onclick='clearSearch();'>&#11199;</span>
<tr> </div>
<td style = "vertical-align:middle; text-align:left;"> <div id="searchFiltersBar">
<div class = "searchbox"> <button title="Name" class='fieldsSearchFilterOn' id='searchFilterName' onClick = 'filterSearchField("name");'>NAME</button>&nbsp;
<input class = "searchtextbox" name = "searchtextbox" size = "26" maxlength="32" onkeypress="monitorEnter(event, this);"> <a href="#" onclick='clearSearch();'><img src="del-x-16.png"></a> <button title="Description" class='fieldsSearchFilterOff' id='searchFilterDesc' onClick = 'filterSearchField("description");'>DESCRIPTION</button>
</div> </div>
</td>
<td style = "vertical-align:middle; text-align:left;">
<a href = "#" onclick = 'doSearch(document.searchbar.searchtextbox.value);'><img src="search-32.png"></a>
</td>
</tr>
</table>
</td>
<td style = "vertical-align:middle; text-align:right;">
<div id = 'pager_top' style = "vertical-align: middle;"></div>
</td>
</tr>
</table>
</form>
<div id = "data"></div>
<div style="width:98%; text-align:right;">
<div style = "vertical-align: middle;" id = 'pager_footer'></div>
</div> </div>
<hr> <div id="list">
<p class="mainDesc">Want to contribute and add your own app?<br> <div id="cards"></div>
Read the <a href="https://overte-org.github.io/community-apps/web/index.html">guide</a>!</p> <div id="sidewalk"></div>
<script> </div>
function monitorEnter(e) { <div id="footer">
var code = (e.keyCode ? e.keyCode : e.which); Want to contribute and add your own app?<br>
if (code == 13) { See this repository: <font class="blue">github.com/overte-org/community-apps</font>
doSearch(document.searchbar.searchtextbox.value); </div>
}
} <script>
function submitForm(event){
event.preventDefault();
}
document.searchbar.searchtextbox.value = search;
var pageContent = ""; var pageContent = "";
function displayApp(item) { function displayApp(item) {
pageContent = pageContent + "<a name = '" + window.btoa(item.directory) + "'><table class='item'><tr>"; pageContent = pageContent + "<div class='list_background'></div>";
pageContent = pageContent + "<td><div class='iconContainer'><img src='" + rootPath + item.icon + "' style='width:50px;'><br><font class = 'caption'>" + item.caption + "</font></div></td>"; pageContent = pageContent + "<div class='card'>";
pageContent = pageContent + "<a name = '" + window.btoa(item.directory) + "'><table class='item'><tr class='item'>";
pageContent = pageContent + "<td class='item' style='width: 76px;'><div class='iconContainer'>";
pageContent = pageContent + "<img src='" + rootPath + item.icon + "' style='width:50px;'><br>";
pageContent = pageContent + "<font class = 'caption'>" + item.caption + "</font></div></td>";
var btn = ""; var btn = "";
var absoluteJsFile = rootPath + item.jsfile; var absoluteJsFile = rootPath + item.jsfile;
@ -198,79 +198,69 @@
}; };
buttonList.push(btndata); buttonList.push(btndata);
pageContent = pageContent + "<td><font class='appname'>" + item.name + "<br></font><font class = 'appdesc'>" + item.description + "<br></font><div id = '"+ window.btoa(item.directory) +"' align='right'>" + btn + "</div></td>"; pageContent = pageContent + "<td class='item'><div style='width: 100%; text-align: left; padding: 0px;'><font class='appname'>" + item.name + "<br></font>";
pageContent = pageContent + "</tr></table><br>"; pageContent = pageContent + "<font class = 'appdesc'>" + item.description + "<br></font></div>";
pageContent = pageContent + "<div id = '" + window.btoa(item.directory) + "' align='right'>" + btn + "</div></td>";
pageContent = pageContent + "</tr></table>";
pageContent = pageContent + "</div>";
} }
function listBuilder(searchKeyword, listOffset, listPerPage) { function listBuilder(searchKeyword, upTo) {
buttonList = []; buttonList = [];
var counterDir = -1;
var counterDisp = 0; var counterDisp = 0;
var index = 0; var index = 0;
var lowItem = ""; var lowItem = "";
var needNext = false; var lowDesc = "";
pageContent = ""; pageContent = "";
var loadMoreRequired = false;
for (index = 0; index < metadata.applications.length; index++) { for (index = 0; index < metadata.applications.length; index++) {
lowItem = metadata.applications[index].name.toLowerCase(); lowItem = metadata.applications[index].name.toLowerCase();
if (lowItem.indexOf(searchKeyword.toLowerCase()) !== -1 && metadata.applications[index].isActive == true) { lowDesc = metadata.applications[index].description.toLowerCase();
counterDir = counterDir + 1; var query;
if ((counterDir >= listOffset) && (counterDir < (listOffset + listPerPage))) { if (searchKeyword === "") {
displayApp(metadata.applications[index]); query = true;
counterDisp = counterDisp + 1; } else {
} query = ((seachedFieldsFilter.indexOf("name") !== -1 && lowItem.indexOf(searchKeyword.toLowerCase()) !== -1)||
if (counterDir >= (listOffset + listPerPage)) { (seachedFieldsFilter.indexOf("description") !== -1 && lowDesc.indexOf(searchKeyword.toLowerCase()) !== -1));
needNext = true; }
if (query && metadata.applications[index].isActive == true) {
displayApp(metadata.applications[index]);
counterDisp = counterDisp + 1;
if (counterDisp >= upTo) {
loadMoreRequired = true;
break; break;
} }
} }
} }
var pagerPrevious = "<a href='#' onclick='pagetoPrevious();'><img src='minus-16.png'></a>";
if (listOffset <= 0) {
pagerPrevious = "<img src='blank_minus-16.png'>";
}
var pagerNext = "<a href='#' onclick='pagetoNext();'><img src='plus-16.png'></a>";
if (needNext == false) {
pagerNext = "<img src='blank_plus-16.png'>";
}
var countA = listOffset + 1;
var countB = listOffset + counterDisp;
var pagerHtml = pagerPrevious + "<font class='pager'>&nbsp;&nbsp;" + countA + " - " + countB + "&nbsp;&nbsp;</font>" + pagerNext;
if (counterDisp > 0 ) { if (loadMoreRequired) {
document.getElementById("pager_top").innerHTML = pagerHtml; pageContent = pageContent + "<div class='list_background'><button id='load_more' onclick = 'loadMore();'>LOAD MORE...</button></div>";
document.getElementById("data").innerHTML = pageContent;
document.getElementById("pager_footer").innerHTML = pagerHtml;
} else { } else {
document.getElementById("data").innerHTML = "<hr><div align='center'><font class='noresult'><br><br><br><br>Sorry, no result found.<br><br><br><br><br><br></font></div><hr>"; pageContent = pageContent + "<div class='list_background'></div>";
} }
requestRunningScriptData();
} if (counterDisp > 0 ) {
document.getElementById("cards").innerHTML = pageContent;
//pager } else {
function pagetoPrevious(){ document.getElementById("cards").innerHTML = "<div align='center'><font class='noresult'><br><br><br><br>Sorry, no result found.<br><br><br><br><br><br></font></div>";
offset = offset - perpage;
if (offset < 0) {
offset = 0;
} }
listBuilder(search, offset, perpage); requestRunningScriptData();
} }
function pagetoNext(){
offset = offset + perpage;
listBuilder(search, offset, perpage);
}
$.getScript(metadataScriptSrc, function(data, textStatus, jqxhr) {
listBuilder(search, offset, perpage); $.getScript(metadataScriptSrc, function(data, textStatus, jqxhr) {
doSearch();
}); });
function loadMore() {
loadRecordsUpTo = loadRecordsUpTo + NUMBER_OF_RECORDS_PER_LOAD;
doSearch();
}
document.getElementById("searchFiltersBar").style.display = "none";
</script> </script>
</body> </body>
</html> </html>