Skip to content

Commit

Permalink
Merge pull request #25 from webability-go/late-night
Browse files Browse the repository at this point in the history
patch v2021.01.25
  • Loading branch information
metalwolf authored Jan 26, 2021
2 parents c2ec4ff + 0e27832 commit 712a00a
Show file tree
Hide file tree
Showing 23 changed files with 682 additions and 305 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ import "github.com/webability-go/xmodules/ingredient"

import "github.com/webability-go/xmodules/material"

v2021-01-25:
- base, user, adminmenu and useradmin support now transactions to setup the modules.
- Errors control and messages enhanced during the installation of the modules.
- Separation of basic installation functions into the xmodules/base/installation.go

v2021-01-20:
- All the modules: enhancement to meet the new main structures and mmodules definition for Xamboo (use of datasource interface, use of bridge and assets modules entries)

Expand Down
5 changes: 3 additions & 2 deletions adminmenu/adminmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func AddOption(ds serverassets.Datasource, data *xdominion.XRecord) error {

// Verify if it exists already

_, err := adminmenu_option.Insert(data)
key, _ := data.GetString("key")
_, err := adminmenu_option.Upsert(key, data)
if err != nil {
ds.Log("main", "Error inserting in adminmenu_option", err)
ds.Log("main", "Error upserting in adminmenu_option", err)
return err
}
return nil
Expand Down
88 changes: 56 additions & 32 deletions adminmenu/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/webability-go/xmodules/adminmenu/assets"
"github.com/webability-go/xmodules/base"
"github.com/webability-go/xmodules/tools"
)

const (
Expand All @@ -18,6 +19,7 @@ const (
DATASOURCE = "adminmenudatasource"
)

var Needs = []string{"base", "user"}
var ModuleAdminMenu = assets.ModuleEntries{
AddGroup: AddGroup,
GetGroup: GetGroup,
Expand All @@ -27,11 +29,16 @@ var ModuleAdminMenu = assets.ModuleEntries{
}

func init() {
messages = tools.BuildMessages(smessages)
m := &base.Module{
ID: MODULEID,
Version: VERSION,
Languages: map[language.Tag]string{language.English: "Administration menu", language.Spanish: "Menu de administración", language.French: "Menu pour l'administration"},
Needs: []string{"base", "user"},
ID: MODULEID,
Version: VERSION,
Languages: map[language.Tag]string{
language.English: tools.Message(messages, "MODULENAME", language.English),
language.Spanish: tools.Message(messages, "MODULENAME", language.Spanish),
language.French: tools.Message(messages, "MODULENAME", language.French),
},
Needs: Needs,
FSetup: Setup, // Called once at the main system startup, once PER CREATED xmodule CONTEXT (if set)
FSynchronize: Synchronize, // Called only to create/rebuild database objects and others on demand (if set)
FStartContext: StartContext, // Called each time a new Server context is created (if set)
Expand All @@ -43,49 +50,66 @@ func init() {
// adds tables and caches to sitecontext::database
func Setup(ds serverassets.Datasource, prefix string) ([]string, error) {

lds := ds.(*base.Datasource)
buildTables(lds)
createCache(lds)
lds.SetModule(MODULEID, VERSION)

go buildCache(lds)
linkTables(ds)
ds.SetModule(MODULEID, VERSION)

return []string{}, nil
}

func Synchronize(ds serverassets.Datasource, prefix string) ([]string, error) {

messages := []string{}
result := []string{}

lds := ds.(*base.Datasource)
// Needed modules: context and translation
vc := base.ModuleInstalledVersion(ds, "base")
if vc == "" {
messages = append(messages, "xmodules/base need to be installed before installing xmodules/adminmenu.")
return messages, nil
ok, res := base.VerifyNeeds(ds, Needs)
result = append(result, res...)
if !ok {
return result, nil
}

vc = base.ModuleInstalledVersion(ds, "user")
if vc == "" {
messages = append(messages, "xmodules/user need to be installed before installing xmodules/adminmenu.")
return messages, nil
installed := base.ModuleInstalledVersion(ds, MODULEID)

// synchro tables
err, r := synchroTables(ds, installed)
result = append(result, r...)
if err != nil {
return result, err
}

// create tables
messages = append(messages, createTables(lds)...)
// fill super admin
messages = append(messages, loadTables(lds)...)
// The rest of the process with a transaction
// lets clone ds to begin a transaction
cds := ds.CloneShell()
_, err = cds.StartTransaction()
if err != nil {
result = append(result, err.Error())
return result, err
}

// Inserting into context-modules
// Be sure context module is on db: fill context module (we should get this from xmodule.conf)
err := base.AddModule(ds, MODULEID, "Administration Admin menu", VERSION)
if err == nil {
messages = append(messages, "The entry "+MODULEID+" was modified successfully in the modules table.")
// installation or upgrade ?
if installed != "" {
err, r = upgrade(cds, installed)
} else {
messages = append(messages, "Error modifying the entry "+MODULEID+" in the modules table: "+err.Error())
err, r = install(cds)
}
result = append(result, r...)
if err == nil {
err = base.AddModule(cds, MODULEID, tools.Message(messages, "MODULENAME"), VERSION)
if err == nil {
result = append(result, tools.Message(messages, "modulemodified", MODULEID))
result = append(result, tools.Message(messages, "commit"))
err = cds.Commit()
if err != nil {
result = append(result, err.Error())
}
return result, err
}
}
result = append(result, tools.Message(messages, "rollback", err))
err1 := cds.Rollback()
if err1 != nil {
result = append(result, err1.Error())
}

return messages, nil
return result, err
}

func StartContext(ds serverassets.Datasource, ctx *serverassets.Context) error {
Expand Down
106 changes: 106 additions & 0 deletions adminmenu/messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package adminmenu

import (
"golang.org/x/text/language"

"github.com/webability-go/xcore/v2"
)

// Do no forget to call tools.BuildMessages from the init
var messages *map[language.Tag]*xcore.XLanguage

var smessages = map[language.Tag]map[string]string{
language.English: {
// Module installation messages
// init.go
"MODULENAME": "Administration menu",
"modulemodified": "The entry %s was modified successfully in the base_module table.",
"commit": "Installation successfull.",
"rollback": "Installation aborted with error: %s",

// util.go
"MAINMENU": "Default Administration menu",
"accessgroup.name": "Access group for menu administration",
"accessgroup.description": "Group of all accesses for menu administration",
"access.name": "Access for menu administration",
"access.description": "Access for menu administration",
"menufolder.name": "Menu constructor",
"menufolder.description1": "Click on this line to see the different options for the administration of menus",
"adminmenugroup.name": "Menu groups",
"adminmenugroup.description1": "Menu groups",
"adminmenuoption.name": "Menu options",
"adminmenuoption.description1": "Menu options",

"moduleerror": "Error modifying the entry %s in the base_module table: %s",
// Datasources transactions
"transaction.exist": "Error creating a transaction: There is already a started transaction.",
"transaction.none": "Error searching the transaction: There is no available transaction.",
"transaction.commitnone": "Error searching the transaction to commit: There is no available transaction.",
"transaction.rollbacknone": "Error searching the transaction to rollback: There is no available transaction.",
"transaction.error": "Error in the transaction: %s",
// Containers
"database.none": "There is no available database in the datasource",
},
language.Spanish: {
// Module installation messages
// init.go
"MODULENAME": "Menu de administración",
"modulemodified": "La entrada %s fue modificada con exito en la tabla base_module.",
"commit": "Instalación exitosa.",
"rollback": "Instalación con error: %s",

// util.go
"MAINMENU": "Menú de administración por defecto",
"accessgroup.name": "Grupos de accesos de la administración de menús",
"accessgroup.description": "Grupos de accesos de la administración de menús",
"access.name": "Acceso de la administración de menús",
"access.description": "Acceso de la administración de menús",
"menufolder.name": "Constructor de menús",
"menufolder.description1": "Haz clic sobre esta linea para ver las diferentes opciones para la administración de menús.",
"adminmenugroup.name": "Grupos de menús",
"adminmenugroup.description1": "Grupos de menús",
"adminmenuoption.name": "Opciones de menús",
"adminmenuoption.description1": "Opciones de menús",

"moduleerror": "Error modificando la entrada %s en la tabla base_module: %s",
// Datasources transactions
"transaction.exist": "Error creating a transaction: There is already a started transaction.",
"transaction.none": "Error searching the transaction: There is no available transaction.",
"transaction.commitnone": "Error searching the transaction to commit: There is no available transaction.",
"transaction.rollbacknone": "Error searching the transaction to rollback: There is no available transaction.",
"transaction.error": "Error in the transaction: %s",
// Containers
"database.none": "There is no available database in the datasource",
},
language.French: {
// Module installation messages
// init.go
"MODULENAME": "Menu pour l'administration",
"modulemodified": "L'entrée %s a été modifiée avec succès dans la table base_module.",
"commit": "Instalation réussie.",
"rollback": "Instalation avec erreur: %s",

// util.go
"MAINMENU": "Menu d'administration par défaut",
"accessgroup.name": "Groupe des accès d'administration de menus",
"accessgroup.description": "Groupe des accès d'administration de menus",
"access.name": "Accès d'administration de menus",
"access.description": "Accès d'administration de menus",
"menufolder.name": "Constructeur de menus",
"menufolder.description1": "Constructeur de menus",
"adminmenugroup.name": "Groupes de menus",
"adminmenugroup.description1": "Groupes de menus",
"adminmenuoption.name": "Options de menus",
"adminmenuoption.description1": "Options de menus",

"moduleerror": "Erreur en modifiant l'entrée %s dans la table base_module: %s",
// Datasources transactions
"transaction.exist": "Error creating a transaction: There is already a started transaction.",
"transaction.none": "Error searching the transaction: There is no available transaction.",
"transaction.commitnone": "Error searching the transaction to commit: There is no available transaction.",
"transaction.rollbacknone": "Error searching the transaction to rollback: There is no available transaction.",
"transaction.error": "Error in the transaction: %s",
// Containers
"database.none": "There is no available database in the datasource",
},
}
Loading

0 comments on commit 712a00a

Please sign in to comment.