Skip to content

Commit

Permalink
AI update
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland-Lannuzel committed Jan 7, 2025
1 parent 04ce524 commit 0406e8e
Show file tree
Hide file tree
Showing 22 changed files with 623 additions and 39 deletions.
194 changes: 194 additions & 0 deletions Project/Sources/Classes/AiWizard.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
property personas; _originIcons : Collection
property _originIcon : Picture

Class constructor($formName : Text)

This:C1470._originIcons:=This:C1470.getIcons()
This:C1470.personas:=This:C1470.getPersonas()

Function getPersonas()->$personas : Collection


var $folder : 4D:C1709.Folder
var $file : 4D:C1709.File
var $lang : 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; *)
$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))

$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))

// local personas
For ($i; 0; $localizedPersonaFolders.length-1)
$folder:=$localizedPersonaFolders[$i]
If ($folder.exists=False:C215)
$folder:=$defaultPersonaFolders[$i]
End if
If ($folder.exists=True:C214)

$files:=$folder.files(fk ignore invisible:K87:22)
For each ($file; $files)
//$validated:=This.JSONvalidate("persona"; $file.getText())
$validated:=True:C214
If ($validated)
$persona:=JSON Parse:C1218($file.getText())
$persona._fileName:=$file.fullName
$persona._origin:=Choose:C955($i; "Default"; "Resources"; "Single User")
$persona._originIcon:=This:C1470._originIcons[$i]
$personas.push($persona)
End if
End for each

End if
End for

// data (server) personas
$dataPersonas:=AI_GetPersonas($lang) // executed on server
For each ($persona; $dataPersonas)
$persona._origin:="All Users"
$persona._originIcon:=This:C1470._originIcons[3]
End for each
$personas.combine($dataPersonas)


Function getIcons()->$icons : Collection

var $fileNames : Collection
var $fileName; $filePath : Text
var $picture : Picture

$icons:=[]
$fileNames:=["locker.png"; "database.png"; "single.png"; "multi.png"]
For each ($fileName; $fileNames)
$filePath:=File:C1566("/RESOURCES/Images/AI/"+$FileName).platformPath
READ PICTURE FILE:C678($filePath; $picture)
$icons.push($picture)
End for each

Function getPersona($id : Integer)->$persona : Object

If ($id<=This:C1470.personas.length)
$persona:=This:C1470.personas[$id]
End if



Function save($persona : Object)

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

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

Case of
: ($persona._origin="default") // 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

$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

$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

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

End case


If ($folder#Null:C1517)

$file:=File:C1566($folder.path+$persona.name+".json"; fk posix path:K87:1)
OB REMOVE:C1226($persona; "_origin")
OB REMOVE:C1226($persona; "_originIcon")

$json:=JSON Stringify:C1217($persona; *)
$file.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

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

Case of
: ($persona._origin="default") // 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

$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

$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

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

End case


If ($folder#Null:C1517)

$file:=File:C1566($folder.path+$persona.name+".json"; fk posix path:K87:1)

If ($file.exists)
$file.delete()
End if

Else // data folder case

AI_SavePersona($persona; $lang)

End if




7 changes: 7 additions & 0 deletions Project/Sources/Forms/D_Personas/ObjectMethods/Button2.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


var $col1; $col2 : Collection

$col1:=Form:C1466.ai.personas.copy()
$col2:=$col1.extract("name")

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SET TIMER:C645(-1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Form:C1466.persona._origin:=Form:C1466.saveDestination.values[Form:C1466.saveDestination.index]
SET TIMER:C645(-1)
11 changes: 11 additions & 0 deletions Project/Sources/Forms/D_Personas/ObjectMethods/btnDelete.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIRM:C162(".Are you sure?.")
If (ok=1)
Form:C1466.ai.delete(Form:C1466.persona)

Form:C1466.ai:=cs:C1710.AiWizard.new()
LISTBOX SELECT ROW:C912(*; "LB_Personas"; 1; lk replace selection:K53:1)

Form:C1466.personasDD:={values: Form:C1466.ai.personas.extract("name"); index: 0}
SET TIMER:C645(-1)

End if
8 changes: 8 additions & 0 deletions Project/Sources/Forms/D_Personas/ObjectMethods/btnSave.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Form:C1466.ai.save(Form:C1466.persona)

Form:C1466.ai:=cs:C1710.AiWizard.new()
LISTBOX SELECT ROW:C912(*; "LB_Personas"; 1; lk replace selection:K53:1)

Form:C1466.personasDD:={values: Form:C1466.ai.personas.extract("name"); index: 0}

SET TIMER:C645(-1)
Loading

0 comments on commit 0406e8e

Please sign in to comment.