Skip to content

Commit

Permalink
Personas Management
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland-Lannuzel committed Jan 14, 2025
1 parent 0406e8e commit a0a0d82
Show file tree
Hide file tree
Showing 33 changed files with 530 additions and 185 deletions.
75 changes: 38 additions & 37 deletions Project/Sources/Classes/AiWizard.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ Function getPersonas()->$personas : Collection

var $folder : 4D:C1709.Folder
var $file : 4D:C1709.File
var $lang : Text
var $lang; $DBname : Text
var $localizedPersonaFolders; $defaultPersonaFolders; $dataPersonas; $files : Collection
var $persona : Object
var $i : Integer
var $validated : Boolean

$lang:=Get database localization:C1009(Current localization:K5:22; *)
$DBname:=Folder:C1567(fk database folder:K87:14; *).name

$personas:=[]

$localizedPersonaFolders:=[]
$defaultPersonaFolders:=[]

$localizedPersonaFolders.push(Folder:C1567("/RESOURCES/4DWP_AI/Personas/"+$lang)) // default
$localizedPersonaFolders.push(Folder:C1567("/RESOURCES/4DWP_AI/Personas/"+$lang; *)) // host resources
$localizedPersonaFolders.push(Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+"4DWP_AI/Personas/"+$lang; fk posix path:K87:1))
$localizedPersonaFolders.push(Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+$DBname+"/Personas/"+$lang; fk posix path:K87:1))

$defaultPersonaFolders.push(Folder:C1567("/RESOURCES/4DWP_AI/Personas/en/"))
$defaultPersonaFolders.push(Folder:C1567("/RESOURCES/4DWP_AI/Personas/en/"; *))
$defaultPersonaFolders.push(Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+"4DWP_AI/Personas/en"; fk posix path:K87:1))
$defaultPersonaFolders.push(Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+$DBname+"/Personas/en"; fk posix path:K87:1))

// local personas
For ($i; 0; $localizedPersonaFolders.length-1)
Expand All @@ -46,7 +48,7 @@ Function getPersonas()->$personas : Collection
If ($validated)
$persona:=JSON Parse:C1218($file.getText())
$persona._fileName:=$file.fullName
$persona._origin:=Choose:C955($i; "Default"; "Resources"; "Single User")
$persona._origin:=$i // 0: "Default" 1:"Resources" 2:"User")
$persona._originIcon:=This:C1470._originIcons[$i]
$personas.push($persona)
End if
Expand All @@ -58,7 +60,7 @@ Function getPersonas()->$personas : Collection
// data (server) personas
$dataPersonas:=AI_GetPersonas($lang) // executed on server
For each ($persona; $dataPersonas)
$persona._origin:="All Users"
$persona._origin:=3 // data folder = "All Users"
$persona._originIcon:=This:C1470._originIcons[3]
End for each
$personas.combine($dataPersonas)
Expand All @@ -84,93 +86,92 @@ Function getPersona($id : Integer)->$persona : Object
$persona:=This:C1470.personas[$id]
End if



Function save($persona : Object)
Function save($persona : Object; $saveWhere : Integer)

var $folder : 4D:C1709.Folder
var $file : 4D:C1709.File
var $lang; $json : Text
var $oldFile; $newFile : 4D:C1709.File
var $lang; $json; $DBname : Text

$lang:=Get database localization:C1009(Current localization:K5:22; *)

Case of
: ($persona._origin="default") // must be saved in the 4DWP resources folder
: ($saveWhere=0) // must be saved in the 4DWP resources folder

$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/"+$lang)
If ($folder.exists=False:C215)
$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/en/")
End if

: ($persona._origin="resources") // must be saved in the host database resources
: ($saveWhere=1) // must be saved in the host database resources

$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/"+$lang; *)
If ($folder.exists=False:C215)
$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/en/"; *)
End if


: ($persona._origin="user") // must be saved in the user's folder
: ($saveWhere=2) // must be saved in the user's folder

$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+"4DWP_AI/Personas/"+$lang; fk posix path:K87:1)
If ($folder.exists=False:C215)
$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+"4DWP_AI/Personas/en"; fk posix path:K87:1)
End if
$DBname:=Folder:C1567(fk database folder:K87:14; *).name
$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+$DBname+"/Personas/"+$lang; fk posix path:K87:1)

: ($persona._origin="data") // must be saved in the data folder
: ($saveWhere=3) // must be saved in the data folder

// later
End case


If ($folder#Null:C1517)

$file:=File:C1566($folder.path+$persona.name+".json"; fk posix path:K87:1)
If ($folder.exists=False:C215)
$folder.create()
End if

$oldFile:=File:C1566($folder.platformPath+$persona._fileName; fk platform path:K87:2)
If ($oldFile.exists) // true if folder has not changed, false otherwise
$oldFile.delete()
End if

$newFile:=File:C1566($folder.platformPath+$persona.name+".json"; fk platform path:K87:2)
OB REMOVE:C1226($persona; "_origin")
OB REMOVE:C1226($persona; "_originIcon")
OB REMOVE:C1226($persona; "_fileName")

$json:=JSON Stringify:C1217($persona; *)
$file.setText($json)
$newFile.setText($json)

Else // data folder case

AI_SavePersona($persona; $lang)

End if



Function delete($persona : Object)

var $folder : 4D:C1709.Folder
var $file : 4D:C1709.File
var $lang; $json : Text
var $lang; $json; $DBname : Text

$lang:=Get database localization:C1009(Current localization:K5:22; *)

Case of
: ($persona._origin="default") // must be saved in the 4DWP resources folder
: ($persona._origin=0) // must be saved in the 4DWP resources folder

$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/"+$lang)
If ($folder.exists=False:C215)
$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/en/")
End if

: ($persona._origin="resources") // must be saved in the host database resources
: ($persona._origin=1) // must be saved in the host database resources

$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/"+$lang; *)
If ($folder.exists=False:C215)
$folder:=Folder:C1567("/RESOURCES/4DWP_AI/Personas/en/"; *)
End if


: ($persona._origin="user") // must be saved in the user's folder
: ($persona._origin=2) // must be saved in the user's folder

$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+"4DWP_AI/Personas/"+$lang; fk posix path:K87:1)
$DBname:=Folder:C1567(fk database folder:K87:14; *).name
$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+$DBname+"/Personas/"+$lang; fk posix path:K87:1)
If ($folder.exists=False:C215)
$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+"4DWP_AI/Personas/en"; fk posix path:K87:1)
$folder:=Folder:C1567(Folder:C1567(fk user preferences folder:K87:10).path+$DBname+"/Personas/en"; fk posix path:K87:1)
End if

: ($persona._origin="data") // must be saved in the data folder
: ($persona._origin=3) // must be saved in the data folder

End case

Expand All @@ -185,7 +186,7 @@ Function delete($persona : Object)

Else // data folder case

AI_SavePersona($persona; $lang)
AI_DeletePersona($persona; $lang)

End if

Expand Down
18 changes: 18 additions & 0 deletions Project/Sources/Forms/D_AI/ObjectMethods/Button.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var $winLeft; $winTop; $winRight; $WinBottom : Integer
var $x1; $y1; $x2; $y2 : Integer



GET WINDOW RECT:C443($winLeft; $winTop; $winRight; $WinBottom)

OBJECT GET COORDINATES:C663(*; "Rect_Frame"; $x1; $y1; $x2; $y2)

If (Form:C1466._extra.expanded)
//FORM SET SIZE($x1; $y2)
SET WINDOW RECT:C444($winLeft; $winTop; $winLeft+$x1-1; $winTop+$y2)
Else
//FORM SET SIZE($x2; $y2)
SET WINDOW RECT:C444($winLeft; $winTop; $winLeft+$x2; $winTop+$y2)
End if

Form:C1466._extra.expanded:=Not:C34(Form:C1466._extra.expanded)
1 change: 1 addition & 0 deletions Project/Sources/Forms/D_AI/ObjectMethods/WParea.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WP UpdateWidget ("WPwidget";"WParea")
Loading

0 comments on commit a0a0d82

Please sign in to comment.