mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Add config cloning on instance creation (#747)
* Add instance config cloning on creation * Add test for instance cloning * Add tooltip to copy config button
This commit is contained in:
1 parent
0055f28f45
commit
ce85149b4c
6 files changed
+63
-10
No files matched your search
@@ -312,11 +312,16 @@ export class Config<
|
||||
* Serialize the config to a plain JavaScript object
|
||||
*
|
||||
* @param remote - Location this serialised representation is for
|
||||
* @param filter - When provided, only the given fields are serialized
|
||||
* @returns JSON serializable representation of the config.
|
||||
*/
|
||||
toRemote(remote: ConfigLocation): Static<typeof Config.jsonSchema> {
|
||||
toRemote(remote: ConfigLocation, filter?: (keyof Fields)[]): Static<typeof Config.jsonSchema> {
|
||||
let fields: Record<string, FieldValue> = {};
|
||||
for (let [name, value] of Object.entries(this.fields)) {
|
||||
if (filter && !filter.includes(name as keyof Fields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let def = this.constructor.fieldDefinitions[name];
|
||||
if (
|
||||
this.location !== "control" && !this._checkAccess(name, def, this.location, ConfigAccess.write, false)
|
||||
|
||||
@@ -137,14 +137,16 @@ export class InstanceCreateRequest {
|
||||
|
||||
constructor(
|
||||
public config: Static<typeof InstanceConfig.jsonSchema>,
|
||||
public cloneFromId?: number,
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"config": InstanceConfig.jsonSchema,
|
||||
"cloneFromId": Type.Optional(Type.Number()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.config);
|
||||
return new this(json.config, json.cloneFromId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user