mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2024-12-25 02:29:45 +02:00
feature: create and list modpacks (name only)
This commit is contained in:
parent
fafa37f8aa
commit
f92564b1a8
@ -85,7 +85,7 @@ func ModPackCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var modPackStruct struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
ReadFromRequestBody(w, r, &resp, &modPackStruct)
|
||||
err = ReadFromRequestBody(w, r, &resp, &modPackStruct)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -19,9 +19,6 @@ type ModPackResult struct {
|
||||
Name string `json:"name"`
|
||||
Mods ModsResultList `json:"mods"`
|
||||
}
|
||||
type ModPackResultList struct {
|
||||
ModPacks []ModPackResult `json:"mod_packs"`
|
||||
}
|
||||
|
||||
func NewModPackMap() (ModPackMap, error) {
|
||||
var err error
|
||||
@ -79,18 +76,18 @@ func (modPackMap *ModPackMap) reload() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (modPackMap *ModPackMap) ListInstalledModPacks() ModPackResultList {
|
||||
var modPackResultList ModPackResultList
|
||||
func (modPackMap *ModPackMap) ListInstalledModPacks() []ModPackResult {
|
||||
list := make([]ModPackResult, 0)
|
||||
|
||||
for modPackName, modPack := range *modPackMap {
|
||||
var modPackResult ModPackResult
|
||||
modPackResult.Name = modPackName
|
||||
modPackResult.Mods = modPack.Mods.ListInstalledMods()
|
||||
|
||||
modPackResultList.ModPacks = append(modPackResultList.ModPacks, modPackResult)
|
||||
list = append(list, modPackResult)
|
||||
}
|
||||
|
||||
return modPackResultList
|
||||
return list
|
||||
}
|
||||
|
||||
func (modPackMap *ModPackMap) CreateModPack(modPackName string) error {
|
||||
@ -155,7 +152,7 @@ func (modPackMap *ModPackMap) CreateModPack(modPackName string) error {
|
||||
//reload the ModPackList
|
||||
err = modPackMap.reload()
|
||||
if err != nil {
|
||||
log.Printf("error reloading ModPacks: %s", err)
|
||||
log.Printf("error reloading ModPack: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -181,7 +178,7 @@ func (modPackMap *ModPackMap) CreateEmptyModPack(packName string) error {
|
||||
|
||||
err = modPackMap.reload()
|
||||
if err != nil {
|
||||
log.Printf("error reloading ModPacks: %s", err)
|
||||
log.Printf("error reloading ModPack: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -10,10 +10,13 @@ import AddMod from "./components/AddMod/AddMod";
|
||||
import UploadMod from "./components/UploadMod";
|
||||
import LoadMods from "./components/LoadMods";
|
||||
import Fuse from "fuse.js";
|
||||
import CreateModPack from "./components/CreateModPack";
|
||||
import ModPack from "./components/ModPack";
|
||||
|
||||
const Mods = () => {
|
||||
|
||||
const [installedMods, setInstalledMods] = useState([]);
|
||||
const [modPacks, setModPacks] = useState([])
|
||||
const [factorioVersion, setFactorioVersion] = useState(null);
|
||||
const [fuse, setFuse] = useState(undefined);
|
||||
|
||||
@ -22,6 +25,11 @@ const Mods = () => {
|
||||
.then(setInstalledMods);
|
||||
};
|
||||
|
||||
const fetchModPacks = () => {
|
||||
modsResource.packs.list()
|
||||
.then(setModPacks)
|
||||
}
|
||||
|
||||
const deleteAllMods = () => {
|
||||
modsResource.deleteAll()
|
||||
.then(fetchInstalledMods)
|
||||
@ -32,6 +40,7 @@ const Mods = () => {
|
||||
.then(data => {
|
||||
setFactorioVersion(data.base_mod_version)
|
||||
fetchInstalledMods();
|
||||
fetchModPacks();
|
||||
})
|
||||
|
||||
// fetch list of mods
|
||||
@ -85,11 +94,10 @@ const Mods = () => {
|
||||
</thead>
|
||||
<tbody>
|
||||
{factorioVersion !== null && installedMods.map((mod, i) => <Mod mod={mod} key={i}
|
||||
refreshInstalledMods={fetchInstalledMods}
|
||||
factorioVersion={factorioVersion}/>)}
|
||||
refreshInstalledMods={fetchInstalledMods}
|
||||
factorioVersion={factorioVersion}/>)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
}
|
||||
actions={
|
||||
<Button size="sm" type="danger" onClick={deleteAllMods}>Delete all Mods</Button>
|
||||
@ -100,7 +108,20 @@ const Mods = () => {
|
||||
title="Mod packs"
|
||||
className="mb-6"
|
||||
content={
|
||||
"Test"
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr className="text-left py-1">
|
||||
<th>Name</th>
|
||||
<th/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{modPacks.map((pack, i) => <ModPack key={i} modPack={pack}/>)}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
actions={
|
||||
<CreateModPack onSuccess={fetchModPacks}/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
43
ui/App/views/Mods/components/CreateModPack.jsx
Normal file
43
ui/App/views/Mods/components/CreateModPack.jsx
Normal file
@ -0,0 +1,43 @@
|
||||
import React, {useState} from "react";
|
||||
import Button from "../../../components/Button";
|
||||
import Modal from "../../../components/Modal";
|
||||
import Label from "../../../components/Label";
|
||||
import Input from "../../../components/Input";
|
||||
import {useForm} from "react-hook-form";
|
||||
import modsResource from "../../../../api/resources/mods";
|
||||
|
||||
const CreateModPack = ({onSuccess}) => {
|
||||
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const {handleSubmit, register} = useForm();
|
||||
|
||||
const createModPack = (data) => {
|
||||
setIsCreating(true);
|
||||
|
||||
modsResource.packs.create(data.name)
|
||||
.then(onSuccess)
|
||||
.finally(() => {
|
||||
setIsCreating(false)
|
||||
setIsOpen(false);
|
||||
});
|
||||
}
|
||||
|
||||
return <>
|
||||
<Button onClick={() => setIsOpen(true)}>Create Mod Pack</Button>
|
||||
<Modal title="Create Mod Pack" isOpen={isOpen} content={
|
||||
<form onSubmit={handleSubmit(createModPack)}>
|
||||
<div className="mb-4">
|
||||
<Label text="Name" htmlFor="name"/>
|
||||
<Input name="name" inputRef={register({required: true})}/>
|
||||
</div>
|
||||
<Button size="sm" isLoading={isCreating} isSubmit={true}>Create</Button>
|
||||
</form>
|
||||
}>
|
||||
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
|
||||
export default CreateModPack;
|
12
ui/App/views/Mods/components/ModPack.jsx
Normal file
12
ui/App/views/Mods/components/ModPack.jsx
Normal file
@ -0,0 +1,12 @@
|
||||
import React from "react";
|
||||
|
||||
const ModPack = ({modPack}) => {
|
||||
return (
|
||||
<tr>
|
||||
<td>{modPack.name}</td>
|
||||
<td/>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
export default ModPack;
|
@ -74,6 +74,32 @@ const mods = {
|
||||
const response = await client.get(`/api/mods/portal/info/${mod}`);
|
||||
return response.data;
|
||||
}
|
||||
},
|
||||
packs: {
|
||||
list: async () => {
|
||||
const response = await client.get('/api/mods/packs/list');
|
||||
return response.data;
|
||||
},
|
||||
create: async name => {
|
||||
const response = await client.post('/api/mods/packs/create', {name});
|
||||
return response.data;
|
||||
},
|
||||
delete: async name => {
|
||||
const response = await client.post(`/api/mods/packs/${name}/delete`);
|
||||
return response.data;
|
||||
},
|
||||
download: async name => {
|
||||
const response = await client.get(`/api/mods/packs/${name}/download`);
|
||||
return response.data;
|
||||
},
|
||||
load: async name => {
|
||||
const response = await client.post(`/api/mods/packs/${name}/load`);
|
||||
return response.data;
|
||||
},
|
||||
mods: async name => {
|
||||
const response = await client.get(`/api/mods/packs/${name}/list`);
|
||||
return response.data;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user