added option to insert/move fields at specific position

This commit is contained in:
Gani Georgiev
2024-11-24 12:41:57 +02:00
parent e9ece220d6
commit 1e92b51cf7
6 changed files with 3827 additions and 3639 deletions
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -4,7 +4,7 @@
// Example:
//
// jsvm.MustRegister(app, jsvm.Config{
// WatchHooks: true,
// HooksWatch: true,
// })
package jsvm
+4 -4
View File
@@ -921,7 +921,7 @@ migrate((app) => {
collection.fields.removeById("f3_id")
// add field
collection.fields.add(new Field({
collection.fields.addAt(8, new Field({
"autogeneratePattern": "",
"hidden": false,
"id": "f4_id",
@@ -975,7 +975,7 @@ migrate((app) => {
}, collection)
// add field
collection.fields.add(new Field({
collection.fields.addAt(8, new Field({
"hidden": false,
"id": "f3_id",
"name": "f3_name",
@@ -1052,7 +1052,7 @@ func init() {
collection.Fields.RemoveById("f3_id")
// add field
if err := collection.Fields.AddMarshaledJSON([]byte(` + "`" + `{
if err := collection.Fields.AddMarshaledJSONAt(8, []byte(` + "`" + `{
"autogeneratePattern": "",
"hidden": false,
"id": "f4_id",
@@ -1115,7 +1115,7 @@ func init() {
}
// add field
if err := collection.Fields.AddMarshaledJSON([]byte(` + "`" + `{
if err := collection.Fields.AddMarshaledJSONAt(8, []byte(` + "`" + `{
"hidden": false,
"id": "f3_id",
"name": "f3_name",
+6 -4
View File
@@ -208,7 +208,7 @@ func (p *plugin) jsDiffTemplate(new *core.Collection, old *core.Collection) (str
upParts = append(upParts, fmt.Sprintf("%s.fields.removeById(%q)\n", varName, oldField.GetId()))
downParts = append(downParts, "// add field")
downParts = append(downParts, fmt.Sprintf("%s.fields.add(new Field(%s))\n", varName, rawOldField))
downParts = append(downParts, fmt.Sprintf("%s.fields.addAt(%d, new Field(%s))\n", varName, i, rawOldField))
}
// created fields
@@ -223,13 +223,14 @@ func (p *plugin) jsDiffTemplate(new *core.Collection, old *core.Collection) (str
}
upParts = append(upParts, "// add field")
upParts = append(upParts, fmt.Sprintf("%s.fields.add(new Field(%s))\n", varName, rawNewField))
upParts = append(upParts, fmt.Sprintf("%s.fields.addAt(%d, new Field(%s))\n", varName, i, rawNewField))
downParts = append(downParts, "// remove field")
downParts = append(downParts, fmt.Sprintf("%s.fields.removeById(%q)\n", varName, newField.GetId()))
}
// modified fields
// (note currently ignoring order-only changes as it comes with too many edge-cases)
for i, newField := range new.Fields {
var rawNewField, rawOldField []byte
@@ -546,7 +547,7 @@ func (p *plugin) goDiffTemplate(new *core.Collection, old *core.Collection) (str
upParts = append(upParts, fmt.Sprintf("%s.Fields.RemoveById(%q)\n", varName, oldField.GetId()))
downParts = append(downParts, "// add field")
downParts = append(downParts, goErrIf(fmt.Sprintf("%s.Fields.AddMarshaledJSON([]byte(`%s`))", varName, escapeBacktick(string(rawOldField)))))
downParts = append(downParts, goErrIf(fmt.Sprintf("%s.Fields.AddMarshaledJSONAt(%d, []byte(`%s`))", varName, i, escapeBacktick(string(rawOldField)))))
}
// created fields
@@ -561,13 +562,14 @@ func (p *plugin) goDiffTemplate(new *core.Collection, old *core.Collection) (str
}
upParts = append(upParts, "// add field")
upParts = append(upParts, goErrIf(fmt.Sprintf("%s.Fields.AddMarshaledJSON([]byte(`%s`))", varName, escapeBacktick(string(rawNewField)))))
upParts = append(upParts, goErrIf(fmt.Sprintf("%s.Fields.AddMarshaledJSONAt(%d, []byte(`%s`))", varName, i, escapeBacktick(string(rawNewField)))))
downParts = append(downParts, "// remove field")
downParts = append(downParts, fmt.Sprintf("%s.Fields.RemoveById(%q)\n", varName, newField.GetId()))
}
// modified fields
// (note currently ignoring order-only changes as it comes with too many edge-cases)
for i, newField := range new.Fields {
var rawNewField, rawOldField []byte