mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-10 04:19:38 +02:00
mods inside modpacks can now be deleted
This commit is contained in:
parent
9045520ace
commit
40b5f01e4a
@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
"github.com/gorilla/mux"
|
||||
"archive/zip"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type JSONResponse struct {
|
||||
@ -544,6 +545,44 @@ func ModPackToggleModHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func ModPackDeleteModHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
resp := JSONResponse{
|
||||
Success: false,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
|
||||
|
||||
mod_name := r.FormValue("mod_name")
|
||||
mod_pack_name := r.FormValue("mod_pack_name")
|
||||
|
||||
mod_pack_map, err := newModPackMap()
|
||||
if err == nil {
|
||||
if mod_pack_map.checkModPackExists(mod_pack_name) {
|
||||
err = mod_pack_map[mod_pack_name].Mods.deleteMod(mod_name)
|
||||
} else {
|
||||
err = errors.New("ModPack " + mod_pack_name + " does not exist")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
resp.Data = fmt.Sprintf("Error loading modpack file: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error loading modpack: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
resp.Data = mod_pack_map.listInstalledModPacks()
|
||||
resp.Success = true
|
||||
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error creating loading modpack response: %s", err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Lists all save files in the factorio/saves directory
|
||||
func ListSaves(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
|
@ -308,7 +308,12 @@ var apiRoutes = Routes{
|
||||
"POST",
|
||||
"/mods/packs/mod/toggle",
|
||||
ModPackToggleModHandler,
|
||||
} ,{
|
||||
}, {
|
||||
"ModPackDeleteMod",
|
||||
"POST",
|
||||
"/mods/packs/mod/delete",
|
||||
ModPackDeleteModHandler,
|
||||
} ,{
|
||||
"GetServerSettings",
|
||||
"GET",
|
||||
"/settings",
|
||||
|
@ -1,125 +0,0 @@
|
||||
import React from 'react';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
class InstalledMods extends React.Component {
|
||||
componentDidMount() {
|
||||
this.uploadFile = this.uploadFile.bind(this);
|
||||
this.removeMod = this.removeMod.bind(this);
|
||||
}
|
||||
|
||||
updateInstalledMods() {
|
||||
this.props.loadInstalledModList();
|
||||
}
|
||||
|
||||
uploadFile(e) {
|
||||
e.preventDefault();
|
||||
var fd = new FormData();
|
||||
fd.append('modfile', this.refs.file.files[0]);
|
||||
|
||||
$.ajax({
|
||||
url: "/api/mods/upload",
|
||||
type: "POST",
|
||||
data: fd,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: (data) => {
|
||||
var response = JSON.parse(data)
|
||||
if (response.success === true) {
|
||||
this.updateInstalledMods();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
removeMod(i) {
|
||||
var self = this;
|
||||
swal({
|
||||
title: "Are you sure?",
|
||||
text: "Save: " + self.props.installedMods[i] + " will be deleted",
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: "Yes, delete it!",
|
||||
closeOnConfirm: false
|
||||
},
|
||||
() => {
|
||||
$.ajax({
|
||||
url: "/api/mods/rm/" + self.props.installedMods[i],
|
||||
success: (resp) => {
|
||||
if (resp.success === true) {
|
||||
swal("Deleted!", resp.data, "success");
|
||||
self.updateInstalledMods();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return(
|
||||
<div className="box">
|
||||
<div className="box-header">
|
||||
<h3 className="box-title">Installed Mods</h3>
|
||||
</div>
|
||||
|
||||
<div className="box-body">
|
||||
<h4>Upload Mod</h4>
|
||||
<form ref="uploadForm" className="form-inline" encType='multipart/form-data'>
|
||||
<div className="form-group">
|
||||
<label for="modfile">Upload Mod File...</label>
|
||||
<input className="form-control btn btn-default" ref="file" type="file" name="modfile" id="modfile" />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<input className="form-control btn btn-default" type="button" ref="button" value="Upload" onClick={this.uploadFile} />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div className="table-responsive">
|
||||
<table className="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Mod Name</th>
|
||||
<th>Download</th>
|
||||
<th>Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{this.props.installedMods.map ( (mod, i) => {
|
||||
var saveLocation = "/api/mods/dl/" + mod;
|
||||
return(
|
||||
<tr key={i}>
|
||||
<td>
|
||||
{mod}
|
||||
</td>
|
||||
<td>
|
||||
<a className="btn btn-default" href={saveLocation}>Download</a>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn btn-danger btn-small"
|
||||
ref="modInput"
|
||||
type="button"
|
||||
onClick={this.removeMod.bind(this, i)}>
|
||||
<i className="fa fa-trash"></i>
|
||||
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
InstalledMods.propTypes = {
|
||||
installedMods: React.PropTypes.array.isRequired,
|
||||
loadInstalledModList: React.PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
export default InstalledMods
|
@ -24,7 +24,6 @@ class ModUpload extends React.Component {
|
||||
The mods you upload will override every mod, that is already uploaded!<br/>
|
||||
Uploaded mods will be treated same, as if you install mods with the mod-portal-api.<br/><br/>
|
||||
Only zip-files are allowed to upload !!
|
||||
{/*TODO make better english*/}
|
||||
</div>
|
||||
|
||||
<label className="control-label">Select File</label>
|
||||
|
@ -11,6 +11,7 @@ class ModPackOverview extends React.Component {
|
||||
this.deleteModPack = this.deleteModPack.bind(this);
|
||||
this.loadModPack = this.loadModPack.bind(this);
|
||||
this.modPackToggleModHandler = this.modPackToggleModHandler.bind(this);
|
||||
this.modPackDeleteModHandler = this.modPackDeleteModHandler.bind(this);
|
||||
|
||||
this.state = {
|
||||
listPacks: []
|
||||
@ -213,6 +214,51 @@ class ModPackOverview extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
modPackDeleteModHandler(e) {
|
||||
e.preventDefault();
|
||||
let $button = $(e.target);
|
||||
let $row = $button.parents("tr");
|
||||
let mod_name = $row.data("mod-name");
|
||||
let mod_pack = $row.parents(".single-modpack").find("h3").html();7
|
||||
let class_this = this;
|
||||
|
||||
swal({
|
||||
title: "Delete Mod?",
|
||||
text: "This will delete the mod forever",
|
||||
type: "info",
|
||||
showCancelButton: true,
|
||||
closeOnConfirm: false,
|
||||
confirmButtonText: "Delete it!",
|
||||
cancelButtonText: "Close",
|
||||
showLoaderOnConfirm: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
}, function () {
|
||||
$.ajax({
|
||||
url: "/api/mods/packs/mod/delete",
|
||||
method: "POST",
|
||||
data: {
|
||||
mod_name: mod_name,
|
||||
mod_pack_name: mod_pack
|
||||
},
|
||||
dataType: "JSON",
|
||||
success: (data) => {
|
||||
swal("Delete of mod " + mod_name + " inside modPack " + mod_pack + " successful", "", "success");
|
||||
class_this.setState({
|
||||
listPacks: data.data.mod_packs
|
||||
});
|
||||
},
|
||||
error: (jqXHR, status, err) => {
|
||||
console.log('api/mods/packs/mod/delete', status, err.toString());
|
||||
swal({
|
||||
title: "Delete Mod went wrong",
|
||||
text: jqXHR.responseJSON.data,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test() {
|
||||
console.log("test called");
|
||||
}
|
||||
@ -246,7 +292,7 @@ class ModPackOverview extends React.Component {
|
||||
<div className="box-body">
|
||||
<ModManager
|
||||
installedMods={modpack.mods.mods}
|
||||
deleteMod={this.test} //TODO
|
||||
deleteMod={this.modPackDeleteModHandler}
|
||||
toggleMod={this.modPackToggleModHandler}
|
||||
updateMod={this.test}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user