Skip to content

Commit

Permalink
Merge pull request #51 from Thorfusion/dev
Browse files Browse the repository at this point in the history
add ability to add mods in modpackbuild
  • Loading branch information
maggi373 authored May 23, 2024
2 parents cb44ea7 + bcfa3f7 commit 75977fe
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 31 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ solder.py is even compatible with original solder's database, visit the install

## Unfinished Features in dev

+ Adding mods in modpack builds, you can currently use add to selected build function and changing modversion works
+ Hashing mods, partially done
+ Pin your favorite modpacks to your menu!

Expand Down
9 changes: 6 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def newmodversion(id):
if "addtoselbuild_submit" in request.form:
if "addtoselbuild_id" not in request.form:
return redirect(id)
Modversion.add_modversion_to_selected_build(request.form["addtoselbuild_id"], id)
Modversion.add_modversion_to_selected_build(request.form["addtoselbuild_id"], id, "0", "1", "0")
return redirect(id)
if "deletemod_submit" in request.form:
if "mod_delete_id" not in request.form:
Expand Down Expand Up @@ -465,19 +465,22 @@ def modpackbuild(id):
Build.update(id, request.form["version"], request.form["mcversion"], publish, private, min_java, request.form["memory"])
return redirect(id)
if "optional_submit" in request.form:
Build_modversion.update_optional(request.form["optional_modid"], request.form["optional_check"])
Build_modversion.update_optional(request.form["optional_modid"], request.form["optional_check"], id)
return redirect(id)
if "selmodver_submit" in request.form:
Modversion.update_modversion_in_build(request.form["selmodver_oldver"], request.form["selmodver_ver"], id)
return redirect(id)
if "delete_submit" in request.form:
if "delete_id" not in request.form:
return redirect(id)
Build_modversion.delete_build_modversion(request.form["delete_id"])
Build_modversion.delete_build_modversion(request.form["delete_id"], id)
return redirect(id)
if "deletebuild_submit" in request.form:
Build.delete_build(id)
return redirect(url_for("modpacklibrary"))
if "add_mod_submit" in request.form:
Modversion.add_modversion_to_selected_build(request.form["modversion"], request.form["modnames"], id, "0", request.form["newoptional"])
return redirect(id)

return render_template("modpackbuild.html", mod_version_combo=mod_version_combo, listmod=listmod, packbuild=packbuild, packbuildname=packbuildname, listmodversions=listmodversions)

Expand Down
8 changes: 4 additions & 4 deletions models/build_modversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def __init__(self, id, modversion_id, build_id, created_at, updated_at, optional
self.optional = optional

@classmethod
def delete_build_modversion(cls, id):
def delete_build_modversion(cls, modversion_id, build_id):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("DELETE FROM build_modversion WHERE id=%s", (id,))
cur.execute("DELETE FROM build_modversion WHERE modversion_id = %s AND build_id = %s", (modversion_id, build_id))
conn.commit()
return None

@classmethod
def update_optional(cls, id, optional):
def update_optional(cls, modversion_id, optional, build_id):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("""UPDATE build_modversion
SET optional = %s
WHERE modversion_id = %s;""", (optional, id))
WHERE modversion_id = %s AND build_id = %s;""", (optional, modversion_id, build_id))
conn.commit()
return None
23 changes: 8 additions & 15 deletions models/modversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,25 @@ def new(cls, mod_id, version, mcversion, md5, filesize, markedbuild):
conn.commit()
cur.execute("SELECT LAST_INSERT_ID() AS id")
id = cur.fetchone()["id"]
conn.commit()
if markedbuild is "1":
cur.execute("SELECT id FROM builds WHERE marked = 1")
marked_build_id = cur.fetchone()["id"]
# when new modversion is added to build, old modversion gets deleted, quite tricky as both values are unique each time and you need to get all modversion and delete them on said build.
cur.execute("SELECT * FROM modversions WHERE mod_id = %s", (mod_id,))
modversions = cur.fetchall()
if modversions:
for mv in modversions:
cur.execute("DELETE FROM build_modversion WHERE modversion_id = %s AND build_id = %s", (mv["id"], marked_build_id))
cur.execute("INSERT INTO build_modversion (modversion_id, build_id) VALUES (%s, %s)", (id, marked_build_id))
conn.commit()
Modversion.add_modversion_to_selected_build(id, mod_id, "0", "1", "0")
return cls(id, mod_id, version, mcversion, md5, now, now, filesize)

@classmethod
def add_modversion_to_selected_build(cls, modver_id, mod_id):
def add_modversion_to_selected_build(cls, modver_id, mod_id, build_id, marked, optional):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT id FROM builds WHERE marked = 1")
marked_build_id = cur.fetchone()["id"]
if marked == "1":
cur.execute("SELECT id FROM builds WHERE marked = 1")
build_id = cur.fetchone()["id"]
# when new modversion is added to build, old modversion gets deleted, quite tricky as both values are unique each time and you need to get all modversion and delete them on said build.
cur.execute("SELECT * FROM modversions WHERE mod_id = %s", (mod_id,))
modversions = cur.fetchall()
if modversions:
for mv in modversions:
cur.execute("DELETE FROM build_modversion WHERE modversion_id = %s AND build_id = %s", (mv["id"], marked_build_id))
cur.execute("INSERT INTO build_modversion (modversion_id, build_id) VALUES (%s, %s)", (modver_id, marked_build_id))
cur.execute("DELETE FROM build_modversion WHERE modversion_id = %s AND build_id = %s", (mv["id"], build_id))
cur.execute("INSERT INTO build_modversion (modversion_id, build_id, optional) VALUES (%s, %s, %s)", (modver_id, build_id, optional))
conn.commit()
return None

Expand Down
2 changes: 2 additions & 0 deletions static/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ main {
}

.image {
max-width: 18em;
min-width: 8em;
width: 10vw;
}

Expand Down
18 changes: 18 additions & 0 deletions static/js/solderpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ function string_to_slug (str) {
return str;
}

function hideoptions(optiontoshow){
// gets the value of selected option
selected = document.getElementById(optiontoshow).value;
// gets all that has the name modlist and makes then hidden
let modlist = document.querySelectorAll('[name="' + "modlist" + '"]');
modlist.forEach(el => {
el.setAttribute('hidden','true')
})
// uses the selected options value to only show matching id's
let modversion = document.querySelectorAll('[id="' + "modversion_" + selected + '"]');
modversion.forEach(el => {
el.removeAttribute("hidden")
})
// hides select a mod first option as that is an invalid answer
document.querySelector('[name="' + "modfirst" + '"]').setAttribute('hidden','true');
document.querySelector('[name="' + "modfirst" + '"]').selected = true;
}

function zipfile_mods(modslug, mcversion, modversion, input, verchange) {
// selects the file
let dataSelect = document.getElementById(input);
Expand Down
27 changes: 19 additions & 8 deletions templates/modpackbuild.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</td>
<td>
<div class="maxcont">
<a href=""><button type="button" class="btn btn-danger buttonwidth" onclick="submitbuttonpress('delete_id', '{{combo[1].id}}', 'delete_submit')">Remove</button></a>
<button type="button" class="btn btn-danger buttonwidth" onclick="submitbuttonpress('delete_id', '{{combo[1].id}}', 'delete_submit')">Remove</button>
</div>
</td>
</tr>
Expand Down Expand Up @@ -64,22 +64,33 @@
<div class="">
<form method="post" action="">
<div class="mb-3">
<label for="description" class="form-label">Select Mod</label>
<select class="form-select" name="description" id="description">
<label for="modnames" class="form-label">Select Mod</label>
<select class="form-select" name="modnames" id="modnames" onchange="hideoptions('modnames');">
<option class="is-invalid" name="modfirst2" hidden="true" selected="selected">Select mod</option>
{%for lmod in listmod%}
<option>{{lmod.name}}</option>
<option value="{{lmod.id}}"
{%for combo in mod_version_combo%}
{% if combo[0].id == lmod.id %}
hidden="true"
{% endif %}
{%endfor%}>{{lmod.pretty_name}}</option>
{%endfor%}
</select>
</div>
<div class="mb-3">
<label for="modversion" class="form-label">Modversion</label>
<input type="text" class="form-control" name="modversion" id="modversion"></input>
<select class="form-select" name="modversion" id="modversion">
<option class="is-invalid" name="modfirst">Select mod first</option>
{%for modlist in listmodversions%}
<option value="{{modlist.id}}" id="modversion_{{modlist.mod_id}}" name="modlist" hidden="true">{{modlist.version}}</option>
{%endfor%}
</select>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="optional" name="optional">
<label class="form-check-label" for="optional">optional</label>
<input class="form-check-input" type="checkbox" value="1" id="newoptional" name="newoptional">
<label class="form-check-label" for="newoptional">Optional</label>
</div>
<input class="btn btn-success" type="submit" value="Add Mod" disabled>
<input class="btn btn-success" type="submit" value="Add Mod" name="add_mod_submit">
</form>
<div class="divider"></div>
<form method="post" action="">
Expand Down

0 comments on commit 75977fe

Please sign in to comment.