mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Functions into dbmodels, introduced air
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package dbmodels
|
||||
|
||||
import "github.com/pocketbase/pocketbase/tools/types"
|
||||
|
||||
var EDITORSTATE_VALUES = []string{"Unknown", "ToDo", "Seen", "Partially Edited", "Waiting", "Review", "Edited"}
|
||||
|
||||
var ITEM_TYPE_VALUES = []string{
|
||||
@@ -410,10 +412,10 @@ var SERIES_RELATIONS = []string{
|
||||
"In anderer Sprache",
|
||||
}
|
||||
|
||||
const (
|
||||
PUBLIC_VIEW_RULE = ""
|
||||
PUBLIC_LIST_RULE = ""
|
||||
var PUBLIC_VIEW_RULE = types.Pointer("")
|
||||
var PUBLIC_LIST_RULE = types.Pointer("")
|
||||
|
||||
const (
|
||||
PLACES_TABLE = "places"
|
||||
AGENTS_TABLE = "agents"
|
||||
SERIES_TABLE = "series"
|
||||
@@ -486,7 +488,3 @@ const (
|
||||
ITEMS_CONDITION_FIELD = "condition"
|
||||
ITEMS_IDENTIFIER_FIELD = "identifier"
|
||||
)
|
||||
|
||||
func RelationTableName(collection1, collection2 string) string {
|
||||
return "R_" + collection1 + "_" + collection2
|
||||
}
|
||||
|
||||
66
dbmodels/functions.go
Normal file
66
dbmodels/functions.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package dbmodels
|
||||
|
||||
import "github.com/pocketbase/pocketbase/core"
|
||||
|
||||
func SetBasicPublicRules(collection *core.Collection) {
|
||||
collection.ViewRule = PUBLIC_VIEW_RULE
|
||||
collection.ListRule = PUBLIC_LIST_RULE
|
||||
}
|
||||
|
||||
func SetMusenalmIDField(fieldlist *core.FieldsList) {
|
||||
fieldlist.Add(&core.TextField{Name: MUSENALMID_FIELD, Max: 64, Required: false})
|
||||
}
|
||||
|
||||
func SetEditorStateField(fieldlist *core.FieldsList) {
|
||||
fieldlist.Add(&core.SelectField{Name: EDITSTATE_FIELD, Required: false, Values: EDITORSTATE_VALUES})
|
||||
}
|
||||
|
||||
func SetNotesAndAnnotationsField(fieldlist *core.FieldsList) {
|
||||
fieldlist.Add(&core.EditorField{Name: ANNOTATION_FIELD, Required: false, ConvertURLs: false})
|
||||
fieldlist.Add(&core.EditorField{Name: COMMENT_FIELD, Required: false, ConvertURLs: false})
|
||||
}
|
||||
|
||||
func AddMusenalmIDIndex(collection *core.Collection) {
|
||||
AddIndex(collection, MUSENALMID_FIELD, true)
|
||||
}
|
||||
|
||||
func AddIndex(collection *core.Collection, field string, unique bool) {
|
||||
name := collection.Name
|
||||
collection.AddIndex("idx_"+name+"_"+field, unique, field, "")
|
||||
}
|
||||
|
||||
func RelationTableName(collection1, collection2 string) string {
|
||||
return "R_" + collection1 + "_" + collection2
|
||||
}
|
||||
|
||||
func BasicRelationCollection(app core.App, sourcetablename, targettablename string, relations []string) (*core.Collection, error) {
|
||||
stable, err := app.FindCollectionByNameOrId(sourcetablename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ttable, err := app.FindCollectionByNameOrId(targettablename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
collection := core.NewBaseCollection(RelationTableName(stable.Name, ttable.Name))
|
||||
SetBasicPublicRules(collection)
|
||||
|
||||
fields := core.NewFieldsList(
|
||||
&core.RelationField{Name: stable.Name, Required: true, CollectionId: stable.Id, MinSelect: 1, MaxSelect: 1},
|
||||
&core.RelationField{Name: ttable.Name, Required: true, CollectionId: ttable.Id, MinSelect: 1, MaxSelect: 1},
|
||||
&core.SelectField{Name: RELATION_TYPE_FIELD, Required: true, Values: relations, MaxSelect: 1},
|
||||
&core.BoolField{Name: RELATION_CONJECTURE_FIELD, Required: false},
|
||||
&core.BoolField{Name: RELATION_UNCERTAIN_FIELD, Required: false},
|
||||
)
|
||||
|
||||
SetNotesAndAnnotationsField(&fields)
|
||||
|
||||
collection.Fields = fields
|
||||
AddIndex(collection, stable.Name, false)
|
||||
AddIndex(collection, ttable.Name, false)
|
||||
AddIndex(collection, RELATION_TYPE_FIELD, false)
|
||||
|
||||
return collection, nil
|
||||
}
|
||||
Reference in New Issue
Block a user