Skip to content

Commit

Permalink
implement module field linking
Browse files Browse the repository at this point in the history
  • Loading branch information
ubaldus committed Sep 14, 2024
1 parent becb183 commit e6ff2ce
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
26 changes: 18 additions & 8 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@ func Run(eja TypeApi, sessionSave bool) (result TypeApi, err error) {
}
}
//link
linkingField := ""
if eja.Link.ModuleId > 0 && eja.Link.FieldId > 0 && eja.Link.Label != "" {
eja.Link.ModuleLabel = db.Translate(db.ModuleGetNameById(eja.Link.ModuleId), eja.Owner)
eja.Linking = true
eja.Link.ModuleLabel = db.Translate(db.ModuleGetNameById(eja.Link.ModuleId), eja.Owner)
linkingField = db.ModuleLinksFieldName(eja.ModuleId, eja.Link.ModuleId)
if linkingField != "" {
eja.Values[linkingField] = db.String(eja.Link.FieldId)
eja.SearchLink = false
}
if eja.ModuleId == eja.Link.ModuleId && eja.Id == eja.Link.FieldId && eja.Id > 0 {
//reset
db.SessionCleanLink(eja.Owner)
db.SessionCleanSearch(eja.Owner)
eja.Link = TypeDbLink{}
Expand Down Expand Up @@ -324,14 +331,17 @@ func Run(eja TypeApi, sessionSave bool) (result TypeApi, err error) {
db.SessionPut(eja.Owner, "SearchOffset", db.String(eja.SearchOffset))
eja.Id = 0
}
}

//linking
if eja.Linking {
db.SessionPut(eja.Owner, "Link", db.String(eja.Link.ModuleId), "ModuleId")
db.SessionPut(eja.Owner, "Link", db.String(eja.Link.FieldId), "FieldId")
db.SessionPut(eja.Owner, "Link", eja.Link.Label, "Label")
eja.SearchLinks = db.SearchLinks(eja.Owner, eja.Link.ModuleId, eja.Link.FieldId, eja.ModuleId)
//linking last step
if eja.Linking {
db.SessionPut(eja.Owner, "Link", db.String(eja.Link.ModuleId), "ModuleId")
db.SessionPut(eja.Owner, "Link", db.String(eja.Link.FieldId), "FieldId")
db.SessionPut(eja.Owner, "Link", eja.Link.Label, "Label")
eja.SearchLinks = db.SearchLinks(eja.Owner, eja.Link.ModuleId, eja.Link.FieldId, eja.ModuleId)
if linkingField != "" {
eja.Linking = false
}
}
}

eja.ModuleLabel = db.Translate(eja.ModuleName, eja.Owner)
Expand Down
2 changes: 1 addition & 1 deletion db/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package db
// TypeGroup represents a modular structure containing information about groups.
type TypeGroup struct {
Name string `json:"name"`
Type string `json:"type`
Type string `json:"type"`
Shares []string `json:"shares,omitempty"`
Permissions map[string][]string `json:"permissions,omitempty"`
}
Expand Down
9 changes: 9 additions & 0 deletions db/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ type TypeLink struct {
FieldId int64 `json:"FieldId,omitempty"`
}

// ModuleLinksFieldName retrieve the linking field name if available
func (session *TypeSession) ModuleLinksFieldName(moduleId, linkModuleId int64) string {
if value, err := session.Value("SELECT srcFieldName FROM ejaModuleLinks WHERE dstModuleId=? AND srcModuleId=?", linkModuleId, moduleId); err != nil {
return ""
} else {
return value
}
}

// ModuleLinks retrieves a list of links associated with a specified module.
func (session *TypeSession) ModuleLinks(ownerId int64, moduleId int64) (result []TypeLink) {
ejaPermissions := session.ModuleGetIdByName("ejaPermissions")
Expand Down
9 changes: 8 additions & 1 deletion db/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ func (session *TypeSession) sqliteRun(query string, args ...interface{}) (TypeRu

// sqliteValue executes a SQL query with optional arguments and returns a single string result.
func (session *TypeSession) sqliteValue(query string, args ...interface{}) (result string, err error) {
err = session.Handler.QueryRow(query, args...).Scan(&result)
var nullResult sql.NullString
err = session.Handler.QueryRow(query, args...).Scan(&nullResult)
if err != nil {
return
}
if nullResult.Valid {
result = nullResult.String
} else {
result = ""
}

return
}

Expand Down
2 changes: 1 addition & 1 deletion sys/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package sys

const Name = "Tibula"
const Version = "17.9.10"
const Version = "17.9.14"

var Options TypeConfig
var Commands TypeCommand
2 changes: 1 addition & 1 deletion web/assets/templates/command.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{if and .Link (gt .Link.ModuleId 0) (gt .Link.FieldId 0) }}
{{if and .Linking }}
{{if or (eq .ActionType "Search") (eq .ActionType "List") }}
<div class="form-check form-switch mt-3">
{{if .SearchLink }}
Expand Down

0 comments on commit e6ff2ce

Please sign in to comment.