From 985aa0427c346e83f8d9f5643dde9e7531fbef50 Mon Sep 17 00:00:00 2001 From: Henry Gross-Hellsen <6283258+cowpod@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:03:30 -0800 Subject: [PATCH] hide some table elements on mobile, dynamic ui for /build, expose db id in api --- api/index.php | 4 +- functions/change_show_all.php | 11 --- index.php | 159 +++++++++----------------------- resources/js/global.js | 38 +++++++- resources/js/page_build.js | 136 +++++++++++++++++++-------- resources/js/page_lib-mods.js | 29 +++--- resources/js/page_modloaders.js | 2 +- resources/js/page_modpack.js | 14 ++- 8 files changed, 206 insertions(+), 187 deletions(-) delete mode 100644 functions/change_show_all.php diff --git a/api/index.php b/api/index.php index 7da9cd6..1921a44 100644 --- a/api/index.php +++ b/api/index.php @@ -75,8 +75,10 @@ $modq = $db->query("SELECT * FROM mods"); if ($modq) { foreach ($modq as $mod) { + if ($mod['type']!='mod') continue; $filesize = isset($mod['filesize']) ? $mod['filesize'] : 0; $modentry = [ + 'id'=>$mod['id'], 'pretty_name'=>$mod['pretty_name'], 'name'=>$mod['name'], 'version'=>$mod['version'], @@ -86,7 +88,7 @@ 'filesize'=>$filesize ]; - array_push($modslist,$modentry); + array_push($modslist, $modentry); } } echo json_encode($modslist, JSON_UNESCAPED_SLASHES); diff --git a/functions/change_show_all.php b/functions/change_show_all.php deleted file mode 100644 index a5c3ea6..0000000 --- a/functions/change_show_all.php +++ /dev/null @@ -1,11 +0,0 @@ -

Builds


- +
- + - + @@ -1104,7 +1104,7 @@ function uri($uri) { " id="b-"> - + - + - @@ -1343,11 +1342,20 @@ function uri($uri) { echo ': For Minecraft '.$mod['mcversion'].', you have '.$user['minecraft'].'. May not be compatible!'; } ?> - -
BuildName MinecraftJavaJava Mods
@@ -1292,9 +1292,8 @@ function uri($uri) {
Mod Name VersionMinecraftMinecraft
+ > + } elseif(empty($mod)) { ?> + - -
+
-

Mods /functions/upgrade1.3.5to1.4.0.php'; - - ?>

+

Mods


- -

- type="checkbox" name="showall" class="custom-control-input" id="showall"> +

- + - - + - - query("SELECT * FROM mods WHERE type = 'mod' AND loadertype = '".$loadertype."'"); - // todo: use a group-by? - - $name_version_details=[]; // [serialize([name,prettyname])=>[id,version,mcversion],...] - - if ($mods_compatq && sizeof($mods_compatq)>0) { - foreach($mods_compatq as $mod){ - // skip if any version of this mod is already in build - if (in_array($mod['name'], $modsluglist)) - continue; - - // skip incompatible mods as long as we're not showing all - if (!in_range($mod['mcversion'], $user['minecraft']) && (empty($_SESSION['showall']) || !$_SESSION['showall'])) - continue; - - $tuple=serialize([$mod['name'],$mod['pretty_name']]); - - if (empty($name_version_details[$tuple])) { - $name_version_details[$tuple]=[]; - } - - array_push($name_version_details[$tuple], [$mod['id'], !empty($mod['version']) ? $mod['version'] : '', $mod['mcversion']]); - } - } - - if (sizeof($name_version_details)==0) { - echo "
There are no mods available for this version. Upload mods in Mod Library.
"; - } else { - foreach ($name_version_details as $tuple=>$version_details) { - [$name, $prettyname] = unserialize($tuple); - $mcversion=""; - $version=""; - ?> - - - - - - - - - - - - +
Mod NameMod Name Version
- - Issue(s)Add to Build
+ +

Other Files

@@ -1532,7 +1455,7 @@ function uri($uri) { ?> - + var modslist_0 = '0 ? $modslist[0] : "" ?>'; var build_id = ''; + var mcv=""; + var type="";
@@ -1590,9 +1515,9 @@ function uri($uri) { Name - Category + Category Desc. - Author + Author @@ -1690,10 +1615,10 @@ function uri($uri) { - - + + @@ -1733,7 +1658,7 @@ function uri($uri) { ?> - + - + @@ -1934,10 +1859,10 @@ function uri($uri) {
Mod nameAuthor - Versions - Mod nameAuthor + Versions +
>Unknown" : $mod['pretty_name'] ?>>Unknown"; } ?> class="d-none d-md-table-cell">Unknown"; } ?> @@ -1884,7 +1809,7 @@ function uri($uri) {
Minecraft Forge VersionLinkLink
- - - - + + + + @@ -2130,7 +2055,7 @@ function uri($uri) { - + @@ -2144,7 +2069,7 @@ function uri($uri) { - + - + - `); } else { - $("#cog-"+name).hide(); - $("#times-"+name).show(); + // $('#btn-add-mod-'+name).html('Add to build'); } } }; - request.open("GET", "./functions/add-mod.php?bid="+build_id+"&id="+$("#versionselect-"+name).val()); + console.log("./functions/add-mod.php?bid="+build_id+"&id="+id) + request.open("GET", "./functions/add-mod.php?bid="+build_id+"&id="+id); request.send(); } -$("#search").on('keyup',function(){ - tr = document.getElementById("modstable").getElementsByTagName("tr"); - for (var i = 0; i < tr.length; i++) { +function add_mod_row(id,pretty_name,name,vs,mcv) { + if (pretty_name=='' || name=='' || versions=='' || mcv=='') { + var addbutton=`Issue(s)`; + } else { + var addbutton=`Add to build`; + } + + var vs_str = ``; + for (let v of vs) { + vs_str += ``; + } - td = tr[i].getElementsByTagName("td")[0]; - if (td) { + $('#build-available-mods').append(` + + + + + + `); +} - console.log(td); - console.log(td.innerHTML.toUpperCase()) - if (td.innerHTML.toUpperCase().indexOf($("#search").val().toUpperCase()) > -1) { - tr[i].style.display = ""; - } else { - tr[i].style.display = "none"; +function parsemods(obj) { + let showall = $('#showall').is(':checked'); + let added_num=0; + + let vs={}; + for (let mod of obj) { + if (mod['name'] in vs) { + vs[mod['name']].push(mod['version']); + } else { + vs[mod['name']]=[mod['version']]; + } + } + let filter=$("#search").val(); + for (let mod of obj) { + if (filter=='' || filter==undefined || mod['pretty_name'].toLowerCase().includes(filter)||mod['name'].toLowerCase().includes(filter)) { + if (mod['mcversion']=='' || mcv==mod['mcversion'] || isVersionInInterval(`'${mcv}'`, mod['mcversion']) || showall) { + add_mod_row(mod['id'], mod['pretty_name'],mod['name'],vs[mod['name']],mcv); + added_num+=1; } } } + if (added_num==0) { + if (filter!='') { + $('#no-mods-available-search-results').show(); + } else { + $('#no-mods-available').show(); + } + } +} + +async function getmods() { + return new Promise((resolve, reject) => { + $('#build-available-mods').empty(); + $('#no-mods-available').hide(); + $('#no-mods-available-search-results').hide(); + if (get_cached('available_mods')) { + parsemods(JSON.parse(get_cached('available_mods'))); + } else { + var request = new XMLHttpRequest(); + request.onreadystatechange = function() { + if (request.readyState == 4 && request.status == 200) { + set_cached('available_mods',request.responseText,30); + parsemods(JSON.parse(request.responseText)); + resolve(true) + } + } + request.onerror = function() { + console.log('could not get mods from api'); + reject(false) + } + request.open("GET", 'api/mod'); + request.send(); + } + }); +} + +$("#search").on('keyup', async function(){ + await getmods(); // get mods on type + }); $("#search2").on('keyup',function(){ tr = document.getElementById("filestable").getElementsByTagName("tr"); @@ -140,18 +202,15 @@ $("#search2").on('keyup',function(){ } }); $('#showall').change(function() { - var request = new XMLHttpRequest(); - request.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - window.location.reload(); - } - }; - if ( $('#showall').is(':checked') ) { - request.open("GET", "./functions/change_show_all.php?showall=true"); + if ($('#showall').is(':checked')) { + $('#mods-for-version-string').text(' for Minecraft '+mcv); + $('#mods-for-version-string').show(); } else { - request.open("GET", "./functions/change_show_all.php?showall=false"); + $('#mods-for-version-string').hide(); } - request.send(); + + set_cached('showall', $('#showall').is(':checked'), -1); + getmods(mcv, type); }); $(document).on('change', '.form-control', function() { @@ -169,4 +228,9 @@ $(document).on('change', '.form-control', function() { } console.log('#btn-add-mod-'+modid); } +}); + +$(document).ready(function() { + $('#showall').prop('checked', get_cached('showall')); + getmods(); }); \ No newline at end of file diff --git a/resources/js/page_lib-mods.js b/resources/js/page_lib-mods.js index 97088b7..7d6929b 100644 --- a/resources/js/page_lib-mods.js +++ b/resources/js/page_lib-mods.js @@ -108,7 +108,7 @@ function sendFile(file, i) { $('#table-available-mods').append(` - + - + - + `; @@ -202,7 +202,7 @@ function getdescription(id) { if (id in details) { console.log('got cached details'); showdetails(id); - } else if (havelocalstorage && 'details_'+id in localStorage) { + } else if (get_cached('details_'+id)) { console.log('got cached details from localstorage'); details[id]=JSON.parse(localStorage['details_'+id]); showdetails(id); @@ -216,9 +216,7 @@ function getdescription(id) { request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { let obj = JSON.parse(request.responseText); - if (havelocalstorage && !(id in localStorage)) { - localStorage['details_'+id]=request.responseText; - } + set_cached('details_'+id, request.responseText,1800); details[id]=obj; console.log('got new description'); showdetails(id); @@ -280,7 +278,7 @@ async function getversions(id) { request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { let obj = JSON.parse(request.responseText); - set_cached('versions_'+id, request.responseText); + set_cached('versions_'+id, request.responseText, 1800); console.log('got new versions for id='+id); versions[id] = obj; @@ -348,6 +346,9 @@ function installmod() { console.log(url); + let mcv = $('#mcv option:selected').attr('mc'); + let type = $('#mcv option:selected').attr('type'); + var request = new XMLHttpRequest(); var postdata=new FormData(); postdata.append('url',url); @@ -355,6 +356,9 @@ function installmod() { var filename=url.substring(url.lastIndexOf('/') + 1); postdata.append('filename', filename); } + postdata.append('fallback_mcversion', mcv); + // postdata.append('fallback_type', type); + request.open("POST", "./functions/send_mods.php", true); request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { @@ -402,7 +406,7 @@ function installmod() { $('#table-available-mods').append(` - + - + `); diff --git a/resources/js/page_modpack.js b/resources/js/page_modpack.js index 2d4a5ff..f6e91d3 100644 --- a/resources/js/page_modpack.js +++ b/resources/js/page_modpack.js @@ -18,7 +18,7 @@ $("#mplist").change(function() { }); $("#newbname").on("keyup",function(){ - if (sbna.indexOf($("#newbname").val())==false) { + if (sbna.includes($("#newbname").val())) { $("#newbname").addClass("is-invalid"); $("#warn_newbname").show(); $("#create1").prop("disabled",true); @@ -31,7 +31,7 @@ $("#newbname").on("keyup",function(){ } }); $("#newname").on("keyup",function(){ - if (sbna.indexOf($("#newname").val())==false) { + if (sbna.includes($("#newname").val())) { $("#newname").addClass("is-invalid"); $("#warn_newname").show(); $("#copybutton").prop("disabled",true); @@ -42,7 +42,7 @@ $("#newname").on("keyup",function(){ } }); - function edit(id) { +function edit(id) { window.location = "./build?id="+id; } function remove_box(id,name) { @@ -102,6 +102,14 @@ function remove(id) { $("#latest-mc-li").hide(); } + for (let b of bd) { + if (b['id']==id) { + let name=b['name']; + bd.splice(bd.indexOf(b),1); + sbna.splice(sbna.indexOf(name),1); + } + } + } }; // request.open("GET", "./functions/delete-build.php?id="+id+"&pack=");
MinecraftVersionLoader TypeMinecraftVersionType
Version Minecraft LoaderFileFile
scope="row">Unknown' : $mod['version'] ?> >Unknown' : $mod['mcversion'] ?> >Unknown' : $mod['loadertype'] ?>>Unknown' : $mod['filename'] ?> class="d-none d-md-table-cell">Unknown' : $mod['filename'] ?>
${name} ${v}${mcv}${mcv} - -
${pretty_name} + ${addbutton} +
${pretty_name[i]}${author[i]}${author[i]} ${num_versions}
@@ -189,9 +189,9 @@ function addrow(hit) { var row = `
${hit['title']}${categories}${categories} ${description}${author}${author} ${btn}
${pretty_name[i]}${author[i]}${author[i]} ${num_versions}
@@ -526,7 +530,7 @@ $('#searchbutton').on('click', async function() { results[searchquery]=hits; - set_cached(searchquery, hits); + set_cached(searchquery, hits, 1800); } else { console.log('no hits'); @@ -561,9 +565,4 @@ $(document).ready(function() { installed=fetch_installed() loop_count+=1 } - let loop_count2=0; - while (havelocalstorage==null && loop_count2 < 3) { - havelocalstorage = isLocalStorageAvailable(); - loop_count2+=1 - } }); diff --git a/resources/js/page_modloaders.js b/resources/js/page_modloaders.js index eb87c47..2f826d4 100644 --- a/resources/js/page_modloaders.js +++ b/resources/js/page_modloaders.js @@ -288,7 +288,7 @@ async function chf(link,name,id,mc) {
${mc} ${name}${link}${link}