mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-24 05:17:24 +02:00
feature: delete modpacks
This commit is contained in:
parent
e6589d551d
commit
af9462c41d
@ -370,35 +370,10 @@ func CreateModPackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
resp.Success = true
|
||||
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error listing saves: %s", err)
|
||||
log.Printf("Error creating modpack response: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
/*func ListModPacks(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
resp := JSONResponse{
|
||||
Success: false,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
|
||||
|
||||
resp.Data, err = listModPacks(filepath.Join(config.FactorioDir, "modpacks"))
|
||||
if err != nil {
|
||||
resp.Success = false
|
||||
resp.Data = fmt.Sprintf("Error listing modpack files: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error listing modpacks: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
resp.Success = true
|
||||
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error listing saves: %s", err)
|
||||
}
|
||||
}*/
|
||||
|
||||
/*func DownloadModPack(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
|
||||
|
||||
@ -412,6 +387,32 @@ func CreateModPackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, modFile)
|
||||
}*/
|
||||
|
||||
func DeleteModPackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
resp := JSONResponse{
|
||||
Success: false,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
|
||||
|
||||
name := r.FormValue("name")
|
||||
|
||||
resp.Data, err = deleteModPack(name)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
resp.Data = fmt.Sprintf("Error deleting modpack file: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error deleting modpack: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
resp.Success = true
|
||||
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error creating delete modpack response: %s", err)
|
||||
}
|
||||
}
|
||||
/*func DeleteModPack(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
resp := JSONResponse{
|
||||
|
19
src/mods.go
19
src/mods.go
@ -635,3 +635,22 @@ func createModPack(pack_name string) (ModPackList, error) {
|
||||
|
||||
return mod_pack_list, nil
|
||||
}
|
||||
|
||||
func deleteModPack(mod_name string) (ModPackList, error) {
|
||||
var err error
|
||||
var mod_pack_list ModPackList
|
||||
|
||||
err = os.Remove(config.FactorioModPackDir + "/" + mod_name + ".zip")
|
||||
if err != nil {
|
||||
log.Printf("Error when deleting modPack: %s", err)
|
||||
return mod_pack_list, err
|
||||
}
|
||||
|
||||
err = mod_pack_list.getModPacks()
|
||||
if err != nil {
|
||||
log.Printf("error when listing modPacks: %s", err)
|
||||
return mod_pack_list, err
|
||||
}
|
||||
|
||||
return mod_pack_list, nil
|
||||
}
|
||||
|
@ -288,12 +288,12 @@ var apiRoutes = Routes{
|
||||
"GET",
|
||||
"/mods/packs/dl/{modpack}",
|
||||
DownloadModPack,
|
||||
}, {
|
||||
"DeleteModPack",
|
||||
"GET",
|
||||
"/mods/packs/rm/{modpack}",
|
||||
DeleteModPack,
|
||||
}, */{
|
||||
"DeleteModPack",
|
||||
"POST",
|
||||
"/mods/packs/delete",
|
||||
DeleteModPackHandler,
|
||||
}, {
|
||||
"CreateModPack",
|
||||
"POST",
|
||||
"/mods/packs/create",
|
||||
|
@ -1,11 +1,13 @@
|
||||
import React from 'react';
|
||||
import ModManager from "../ModManager.jsx";
|
||||
import NativeListener from 'react-native-listener';
|
||||
|
||||
class ModPackOverview extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.createModPack = this.createModPack.bind(this);
|
||||
this.deleteModPack = this.deleteModPack.bind(this);
|
||||
|
||||
this.state = {
|
||||
listPacks: []
|
||||
@ -71,7 +73,7 @@ class ModPackOverview extends React.Component {
|
||||
error: (jqXHR, status, err) => {
|
||||
console.log('api/mods/packs/create', status, err.toString());
|
||||
|
||||
let json_response = jqXHR.responseJSON
|
||||
let json_response = jqXHR.responseJSON;
|
||||
swal({
|
||||
title: "Error on creating modpack",
|
||||
text: json_response.data,
|
||||
@ -84,8 +86,48 @@ class ModPackOverview extends React.Component {
|
||||
|
||||
deleteModPack(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.nativeEvent.stopImmediatePropagation();
|
||||
|
||||
let this_class = this;
|
||||
let name = $(e.target).parent().prev().html();
|
||||
|
||||
swal({
|
||||
title: "Are you sure?",
|
||||
text: "You really want to delete this modpack?\nThere is no turning back, the modpack will be deleted forever (a very long time)!",
|
||||
type: "info",
|
||||
showCancelButton: true,
|
||||
closeOnConfirm: false,
|
||||
showLoaderOnConfirm: true
|
||||
},
|
||||
function() {
|
||||
$.ajax({
|
||||
url: "/api/mods/packs/delete",
|
||||
method: "POST",
|
||||
data: {name: name},
|
||||
dataType: "JSON",
|
||||
success: (data) => {
|
||||
this_class.setState({
|
||||
listPacks: data.data.mod_packs
|
||||
});
|
||||
|
||||
swal({
|
||||
title: "Modpack deleted successfully",
|
||||
type: "success"
|
||||
});
|
||||
},
|
||||
error: (jqXHR, status, err) => {
|
||||
console.log('api/mods/packs/delete', status, err.toString());
|
||||
|
||||
let json_response = jqXHR.responseJSON || err.toString();
|
||||
json_response = json_response.data || err.toString();
|
||||
|
||||
swal({
|
||||
title: "Error on creating modpack",
|
||||
text: json_response,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
test() {
|
||||
@ -96,29 +138,33 @@ class ModPackOverview extends React.Component {
|
||||
return(
|
||||
<div className="box-body">
|
||||
{
|
||||
this.state.listPacks.map(
|
||||
(modpack, index) => {
|
||||
return(
|
||||
<div className="box collapsed-box">
|
||||
<div className="box-header" data-widget="collapse" style={{cursor: "pointer"}}>
|
||||
<i className="fa fa-plus"></i>
|
||||
<h3 className="box-title">{modpack.name}</h3>
|
||||
<div className="box-tools pull-right">
|
||||
<button className="btn btn-box-tool btn-danger" style={{color: "#fff"}} onClick={this.deleteModPack}>Delete</button>
|
||||
this.state.listPacks != null ?
|
||||
this.state.listPacks.map(
|
||||
(modpack, index) => {
|
||||
return(
|
||||
<div className="box collapsed-box">
|
||||
<div className="box-header" data-widget="collapse" style={{cursor: "pointer"}}>
|
||||
<i className="fa fa-plus"></i>
|
||||
<h3 className="box-title">{modpack.name}</h3>
|
||||
<div className="box-tools pull-right">
|
||||
<NativeListener onClick={this.deleteModPack}>
|
||||
<button className="btn btn-box-tool btn-danger" style={{color: "#fff"}}>Delete</button>
|
||||
</NativeListener>
|
||||
</div>
|
||||
</div>
|
||||
<div className="box-body">
|
||||
<ModManager
|
||||
installedMods={modpack.mods.mods}
|
||||
deleteMod={this.test} //TODO
|
||||
toggleMod={this.test}
|
||||
updateMod={this.test}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="box-body">
|
||||
<ModManager
|
||||
installedMods={modpack.mods.mods}
|
||||
deleteMod={this.test}
|
||||
toggleMod={this.test}
|
||||
updateMod={this.test}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
: null
|
||||
}
|
||||
|
||||
<div className="box">
|
||||
|
@ -18,6 +18,7 @@
|
||||
"react": "^15.0.1",
|
||||
"react-console-component": "^0.6.1",
|
||||
"react-dom": "^15.0.1",
|
||||
"react-native-listener": "^1.0.2",
|
||||
"react-router": "^2.3.0",
|
||||
"sweetalert": "^1.1.3"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user