From 67c5bd4f06360a42e3ca3febf3af9537433e7bd2 Mon Sep 17 00:00:00 2001 From: totoro Date: Fri, 17 Apr 2020 17:32:25 +0900 Subject: [PATCH] switch from calexium_lib to xlib make the first hayamiki web controller outside from application (i.e. Ptah ERP) --- hayamiki_lib | 2 +- hayamiki_web_controller.aproj | 860 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hayamiki_web_controller.ide | 34 ++++++++++++++++++++++++++++++++++ src/app/app_loggers.anubis | 22 ++++++++++++++++++++++ src/generation/create_table.anubis | 17 ++++++++--------- src/generation/cxm_lib_menu.anubis | 4 ++-- src/generation/fields.anubis | 10 +++++----- src/generation/files.anubis | 3 ++- src/generation/header.anubis | 18 ++++++++---------- src/web_controller/controller.anubis | 36 ++++++++++++++++++++++++++++++++++++ src/web_controller/database/generated/fs_file.anubis | 634 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/web_controller/hayamiki.anubis | 884 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/web_controller/hayamiki_plugin.anubis | 40 ++++++++++++++++++++++++++++++++++++++++ src/web_controller/hkc_files_management.anubis | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/web_controller/types/generated/fs_file.anubis | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xlib | 2 +- 16 files changed, 2774 insertions(+), 29 deletions(-) create mode 100644 hayamiki_web_controller.aproj create mode 100644 hayamiki_web_controller.ide create mode 100644 src/app/app_loggers.anubis create mode 100644 src/web_controller/controller.anubis create mode 100644 src/web_controller/database/generated/fs_file.anubis create mode 100644 src/web_controller/hayamiki.anubis create mode 100644 src/web_controller/hayamiki_plugin.anubis create mode 100644 src/web_controller/hkc_files_management.anubis create mode 100644 src/web_controller/types/generated/fs_file.anubis diff --git a/hayamiki_lib b/hayamiki_lib index 11c07a5..6f2ce52 160000 --- a/hayamiki_lib +++ b/hayamiki_lib @@ -1 +1 @@ -Subproject commit 11c07a531623555ac1eee039056f25e7edfc7d5f +Subproject commit 6f2ce5226c55ba46912b382727abd5ef749457cd diff --git a/hayamiki_web_controller.aproj b/hayamiki_web_controller.aproj new file mode 100644 index 0000000..86a9cb5 --- /dev/null +++ b/hayamiki_web_controller.aproj @@ -0,0 +1,860 @@ + + + {90372B21-80FA-4EB8-B17C-072EB55713D7} + Debug + AnyCPU + Exe + model_manager + hayamiki web controller + src\web_controller\hayamiki_plugin.anubis + ./%3b./src%3b./src/web_controller + False + False + False + C:\Program Files (x86)\Anubis\1.14\ + + + bin\Debug\ + True + Full + False + + + bin\Release\ + False + None + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hayamiki_web_controller.ide b/hayamiki_web_controller.ide new file mode 100644 index 0000000..8ebc6e6 --- /dev/null +++ b/hayamiki_web_controller.ide @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 1.0.12.108 +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "hayamiki_generator", "hayamiki_generator.aproj", "7E37A20A-56EA-4128-88F5-FE55B0F5CB45" +EndProject +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "hayamiki_ds_types", "hayamiki_ds_types.aproj", "{06BE5572-9B4A-4F41-A01E-84C730A8F4E4}" +EndProject +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "hayamiki_web_controller", "hayamiki_web_controller.aproj", "{90372B21-80FA-4EB8-B17C-072EB55713D7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {89372B21-80FA-4EB8-B17C-072EB55713D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89372B21-80FA-4EB8-B17C-072EB55713D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89372B21-80FA-4EB8-B17C-072EB55713D6}.Release|Any CPU.Build.0 = Release|Any CPU + {89372B21-80FA-4EB8-B17C-072EB55713D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + 7E37A20A-56EA-4128-88F5-FE55B0F5CB45.Debug|Any CPU.Build.0 = Debug|Any CPU + 7E37A20A-56EA-4128-88F5-FE55B0F5CB45.Debug|Any CPU.ActiveCfg = Debug|Any CPU + 7E37A20A-56EA-4128-88F5-FE55B0F5CB45.Release|Any CPU.Build.0 = Release|Any CPU + 7E37A20A-56EA-4128-88F5-FE55B0F5CB45.Release|Any CPU.ActiveCfg = Release|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Release|Any CPU.Build.0 = Release|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90372B21-80FA-4EB8-B17C-072EB55713D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90372B21-80FA-4EB8-B17C-072EB55713D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90372B21-80FA-4EB8-B17C-072EB55713D7}.Release|Any CPU.Build.0 = Release|Any CPU + {90372B21-80FA-4EB8-B17C-072EB55713D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/app/app_loggers.anubis b/src/app/app_loggers.anubis new file mode 100644 index 0000000..33dc85f --- /dev/null +++ b/src/app/app_loggers.anubis @@ -0,0 +1,22 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 17/04/2020 + * Time: 10:34 + * © David RENÉ + */ + + +transmit xlib/net_services_protocols/logger_client.anubis + + +public define String debug_log = "Debug". + +public define One + logError + ( + String logger_name, + String log_string + )= + logError("HK", logger_name, log_string) +. diff --git a/src/generation/create_table.anubis b/src/generation/create_table.anubis index 93e040d..7cbbd0a 100644 --- a/src/generation/create_table.anubis +++ b/src/generation/create_table.anubis @@ -4,7 +4,7 @@ * Date: 24/01/2016 * Time: 18:13 -Hayamiki is Copyright © 2016-2019 by David RENÉ +Hayamiki is Copyright © 2016-2020 by David RENÉ All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -311,6 +311,7 @@ define String public define Maybe(One) generate_create_table ( + String app_name, List(HK_App) apps, //list of the table model description String dest_dir, String version, @@ -340,8 +341,7 @@ public define Maybe(One) */ read system/logger.anubis -//read calexium_lib/net_services_protocols/logger_service.anubis -read calexium_lib/database/migration_common_sqlite3.anubis +read xlib/database/migration_common_sqlite3.anubis read data_base/sqlite_foreign_key.anubis read data_base/db_types.anubis\n"+ //call the generation of all tables @@ -401,10 +401,9 @@ read system/files.anubis read system/logger.anubis read data_base/db_tools.anubis -read calexium_lib/database/db_utils.anubis -read calexium_lib/database/migration_common_sqlite3.anubis -read calexium_lib/database/migration_sqlite3.anubis -//read calexium_lib/net_services_protocols/logger_service.anubis +read xlib/database/db_utils.anubis +read xlib/database/migration_common_sqlite3.anubis +read xlib/database/migration_sqlite3.anubis read data_base/alter_table.anubis read types/app_types.anubis @@ -452,7 +451,7 @@ public define Maybe(One) . global define Migration - migration_to_v"+version_str+" + "+app_name+"_dbm_to_v"+version_str+" = migration(db_model_version, migrate_to_v"+version_str+", create_v"+version_str+"_tables, create_v"+version_str+"_indexes) . @@ -461,7 +460,7 @@ read hayamiki_lib/view/view_table_manager_types.anubis read src/database/generated/vtm.anubis global define VTM - vtm_v"+version_str+" + "+app_name+"_vtm_v"+version_str+" = vtm( db_model_version, diff --git a/src/generation/cxm_lib_menu.anubis b/src/generation/cxm_lib_menu.anubis index fa8cdf2..c0bab35 100644 --- a/src/generation/cxm_lib_menu.anubis +++ b/src/generation/cxm_lib_menu.anubis @@ -81,8 +81,8 @@ public define Maybe(One) * Time: "+_Int_to_ISO_8601_time(now)+" */ -transmit calexium_lib/web/CXM_making_a_web_site.anubis -transmit calexium_lib/web/widgets/menu.anubis +transmit xlib/web/CXM_making_a_web_site.anubis +transmit xlib/web/widgets/menu.anubis public define List(Menu_Item) applications_cxm_lib_menu diff --git a/src/generation/fields.anubis b/src/generation/fields.anubis index a30e9b0..588e98d 100644 --- a/src/generation/fields.anubis +++ b/src/generation/fields.anubis @@ -51,12 +51,12 @@ public define String ) = if t is { - p_key then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")", + p_key then "extern_type(\"DB_id\", \"xlib/database/db_types.anubis\")", boolean_field then "bool", - date_field(_) then "extern_type(\"DB_date\", \"calexium_lib/database/db_types.anubis\")", - time_field(_) then "extern_type(\"DB_time\", \"calexium_lib/database/db_types.anubis\")", - datetime_field(_) then "extern_type(\"DB_datetime\", \"calexium_lib/database/db_types.anubis\")", - foreign_key(_,_,_,_,_) then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")", + date_field(_) then "extern_type(\"DB_date\", \"xlib/database/db_types.anubis\")", + time_field(_) then "extern_type(\"DB_time\", \"xlib/database/db_types.anubis\")", + datetime_field(_) then "extern_type(\"DB_datetime\", \"xlib/database/db_types.anubis\")", + foreign_key(_,_,_,_,_) then "extern_type(\"DB_id\", \"xlib/database/db_types.anubis\")", integer_field(_) then "int", float_field then "float", char_field(_,_) then "string", diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 50073b1..6d51617 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -261,6 +261,7 @@ define Maybe(One) with db_SHA1 = readString(ini, "DB_MODEL", "SHA1", "N/A"), with version = readString(ini, "DB_MODEL", "Version", "0.0.0.0"), + with app_name= readString(ini, "DB_MODEL", "app_name", ""), println("Saved DB model SHA1 = "+db_SHA1); with current_db_SHA1 = to_ascii(sha1(serialize(db))), println("Current DB model SHA1 = "+current_db_SHA1); @@ -277,7 +278,7 @@ define Maybe(One) println("Generating VTM for Database "+name); make_vtm(apps, destination_dir); println("Generating create for Database "+name); - if generate_create_table(apps, destination_dir, version, current_db_SHA1) is failure then println("failure");failure else + if generate_create_table(app_name, apps, destination_dir, version, current_db_SHA1) is failure then println("failure");failure else println("Generating menu for Database "+name); if generate_hk_menus(apps, destination_dir) is failure then println("failure");failure else if generate_cxm_lib_menus(apps, destination_dir) is failure then println("failure");failure else diff --git a/src/generation/header.anubis b/src/generation/header.anubis index 16e0174..f5732b9 100644 --- a/src/generation/header.anubis +++ b/src/generation/header.anubis @@ -52,16 +52,16 @@ public define Maybe(One) */ transmit tools/basis.anubis -transmit calexium_lib/web/CXM_making_a_web_site.anubis -transmit calexium_lib/web/CXM_common.anubis -transmit calexium_lib/web/CXM_web_dump.anubis -transmit calexium_lib/web/CXM_web_arg_utils.anubis -transmit calexium_lib/web/CXM_json.anubis -transmit calexium_lib/web/widgets/icons_set.anubis +transmit xlib/web/CXM_making_a_web_site.anubis +transmit xlib/web/CXM_common.anubis +transmit xlib/web/CXM_web_dump.anubis +transmit xlib/web/CXM_web_arg_utils.anubis +transmit xlib/web/CXM_json.anubis +transmit xlib/web/widgets/icons_set.anubis transmit data_base/sqlite.anubis transmit data_base/db_tools.anubis -transmit calexium_lib/database/db_utils.anubis -transmit calexium_lib/database/db_types.anubis +transmit xlib/database/db_utils.anubis +transmit xlib/database/db_types.anubis transmit hayamiki_lib/view/types/hk_form.anubis transmit hayamiki_lib/view/types/hk_view.anubis transmit hayamiki_lib/view/types/hk_filter.anubis @@ -71,8 +71,6 @@ transmit system/logger.anubis transmit system/datetime.anubis transmit system/convert.anubis transmit system/string.anubis - -//transmit calexium_lib/net_services_protocols/logger_service.anubis transmit app/app_loggers.anubis ") is failure then failure else foreign_table_header(stream, columns) diff --git a/src/web_controller/controller.anubis b/src/web_controller/controller.anubis new file mode 100644 index 0000000..91f4863 --- /dev/null +++ b/src/web_controller/controller.anubis @@ -0,0 +1,36 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 16/02/2017 + * Time: 00:39 + * © David RENÉ + */ + +read system/logger.anubis +read xlib/web/controllers_web_site.anubis +read hayamiki.anubis +read hayamiki_lib/view/view_table_manager_types.anubis + + +public define WEB_Controller + get_hk_controller + ( + SQLite3DataBase db, + HK_Database hk_db, + VTM _vtm, + (LogLevel, String) -> One logger + ) + = + web_controller("hk_c", var(make_hk_actions(db, hk_db, _vtm, logger))) +. + +public define List(WEB_Controller) + plugin_get_controller + ( + SQLite3DataBase db, + HK_Database hk_db, + VTM _vtm, + (LogLevel, String) -> One logger + ) = + [get_hk_controller(db, hk_db, _vtm, logger)] +. diff --git a/src/web_controller/database/generated/fs_file.anubis b/src/web_controller/database/generated/fs_file.anubis new file mode 100644 index 0000000..eca25ab --- /dev/null +++ b/src/web_controller/database/generated/fs_file.anubis @@ -0,0 +1,634 @@ +/* + * Created by 早見木 (Hayamiki). + * Database generator written by フランスのトトロ aka (David RENÉ) + * Date: 2020-04-11 + * Time: 10:13:41 + * + */ +transmit tools/basis.anubis + +transmit xlib/web/CXM_making_a_web_site.anubis +transmit xlib/web/CXM_common.anubis +transmit xlib/web/CXM_web_dump.anubis +transmit xlib/web/CXM_web_arg_utils.anubis +transmit xlib/web/CXM_json.anubis +transmit xlib/web/widgets/icons_set.anubis +transmit data_base/sqlite.anubis +transmit data_base/db_tools.anubis +transmit xlib/database/db_utils.anubis +transmit xlib/database/db_types.anubis +transmit hayamiki_lib/view/types/hk_form.anubis +transmit hayamiki_lib/view/types/hk_view.anubis +transmit hayamiki_lib/view/types/hk_filter.anubis +transmit hayamiki_lib/types/hayamiki.anubis +transmit hayamiki_lib/controller/hk_sql_utils.anubis +transmit system/logger.anubis +transmit system/datetime.anubis +transmit system/convert.anubis +transmit system/string.anubis +transmit app/app_loggers.anubis + + +transmit types/generated/fs_file.anubis + + +public define Fs_file + get_default_fs_file = + fs_file(none, db_datetime(""), db_datetime(""), "", "", (Int)0, (Int)0, "", "", "", "", "", "", "", ""). + + + +public define List(String) + fs_file_columns = + ["create_date", + "write_date", + "res_model", + "res_name", + "file_size", + "res_id", + "description", + "res_field", + "mimetype", + "name", + "url", + "checksum", + "datas_fname", + "path" ]. + +public define String + fs_file_select_fields = "fs_file.id, fs_file.create_date, fs_file.write_date, fs_file.res_model, fs_file.res_name, fs_file.file_size, fs_file.res_id, fs_file.description, fs_file.res_field, fs_file.mimetype, fs_file.name, fs_file.url, fs_file.checksum, fs_file.datas_fname, fs_file.path". + + + +public define Maybe(Fs_file) + extract_Fs_file_from_web_arg + ( + List(Web_arg) lwa, + String __prefix__ + )= + with id = get_DB_id(lwa, __prefix__+"id"), + with create_date = get_dummy_DB_datetime, + with write_date = get_dummy_DB_datetime, + if get_String(lwa, __prefix__+"res_model") is {failure then failure, success(res_model) then + if get_String(lwa, __prefix__+"res_name") is {failure then failure, success(res_name) then + if get_Int(lwa, __prefix__+"file_size") is {failure then failure, success(file_size) then + if get_Int(lwa, __prefix__+"res_id") is {failure then failure, success(res_id) then + if get_String(lwa, __prefix__+"description") is {failure then failure, success(description) then + if get_String(lwa, __prefix__+"res_field") is {failure then failure, success(res_field) then + if get_String(lwa, __prefix__+"mimetype") is {failure then failure, success(mimetype) then + if get_String(lwa, __prefix__+"name") is {failure then failure, success(name) then + if get_String(lwa, __prefix__+"url") is {failure then failure, success(url) then + if get_String(lwa, __prefix__+"checksum") is {failure then failure, success(checksum) then + if get_String(lwa, __prefix__+"datas_fname") is {failure then failure, success(datas_fname) then + if get_String(lwa, __prefix__+"path") is {failure then failure, success(path) then + success( + fs_file( + id, + create_date, + write_date, + res_model, + res_name, + file_size, + res_id, + description, + res_field, + mimetype, + name, + url, + checksum, + datas_fname, + path)) + }}}}}}}}}}}}. + + + +public define Fs_file + extract_Fs_file_from_web_arg_with_default + ( + List(Web_arg) lwa, + String __prefix__ + )= + fs_file( + get_DB_id(lwa, __prefix__+"id"), + get_dummy_DB_datetime, + get_dummy_DB_datetime, + get_String(lwa, __prefix__+"res_model", ""), + get_String(lwa, __prefix__+"res_name", ""), + get_Int(lwa, __prefix__+"file_size", (Int)0), + get_Int(lwa, __prefix__+"res_id", (Int)0), + get_String(lwa, __prefix__+"description", ""), + get_String(lwa, __prefix__+"res_field", ""), + get_String(lwa, __prefix__+"mimetype", ""), + get_String(lwa, __prefix__+"name", ""), + get_String(lwa, __prefix__+"url", ""), + get_String(lwa, __prefix__+"checksum", ""), + get_String(lwa, __prefix__+"datas_fname", ""), + get_String(lwa, __prefix__+"path", ""), +) +. + + + +public define List(SQLite3_update_field) + extract_Fs_file_update_fields_from_web_arg + ( + List(Web_arg) lwa, + String __prefix__ + )= + []+ + []+ + [field("write_date", bind_Datetime(":v_write_date", db_now))]+ + if get_String(lwa, __prefix__+"res_model") is {failure then [], success(res_model) then [field("res_model", bind_String(":v_res_model", res_model))] }+ + if get_String(lwa, __prefix__+"res_name") is {failure then [], success(res_name) then [field("res_name", bind_String(":v_res_name", res_name))] }+ + if get_Int(lwa, __prefix__+"file_size") is {failure then [], success(file_size) then [field("file_size", bind_Int(":v_file_size", file_size))] }+ + if get_Int(lwa, __prefix__+"res_id") is {failure then [], success(res_id) then [field("res_id", bind_Int(":v_res_id", res_id))] }+ + if get_String(lwa, __prefix__+"description") is {failure then [], success(description) then [field("description", bind_String(":v_description", description))] }+ + if get_String(lwa, __prefix__+"res_field") is {failure then [], success(res_field) then [field("res_field", bind_String(":v_res_field", res_field))] }+ + if get_String(lwa, __prefix__+"mimetype") is {failure then [], success(mimetype) then [field("mimetype", bind_String(":v_mimetype", mimetype))] }+ + if get_String(lwa, __prefix__+"name") is {failure then [], success(name) then [field("name", bind_String(":v_name", name))] }+ + if get_String(lwa, __prefix__+"url") is {failure then [], success(url) then [field("url", bind_String(":v_url", url))] }+ + if get_String(lwa, __prefix__+"checksum") is {failure then [], success(checksum) then [field("checksum", bind_String(":v_checksum", checksum))] }+ + if get_String(lwa, __prefix__+"datas_fname") is {failure then [], success(datas_fname) then [field("datas_fname", bind_String(":v_datas_fname", datas_fname))] }+ + if get_String(lwa, __prefix__+"path") is {failure then [], success(path) then [field("path", bind_String(":v_path", path))] } +. + + +public define Maybe(Fs_file) + extract_fs_file + ( + One -> SQLite3Row table_cursor + ) = + if table_cursor(unique) is + { + error(sql_error) then println(db_error(sql_error, "extract_fs_file")); failure, + no_more_row then failure, + row(cursor) then + success( + fs_file( + db_id((Int)db_integer(cursor)(0)) /* id */, + db_datetime(text(cursor)(1)) /* create_date */, + db_datetime(text(cursor)(2)) /* write_date */, + text(cursor)(3) /* res_model */, + text(cursor)(4) /* res_name */, + (Int)db_integer(cursor)(5) /* file_size */, + (Int)db_integer(cursor)(6) /* res_id */, + text(cursor)(7) /* description */, + text(cursor)(8) /* res_field */, + text(cursor)(9) /* mimetype */, + text(cursor)(10) /* name */, + text(cursor)(11) /* url */, + text(cursor)(12) /* checksum */, + text(cursor)(13) /* datas_fname */, + text(cursor)(14) /* path */ + )) + }. + + +public define String get_fs_file_show_string(SQLite3DataBase db, DB_id _idx). + +define (Int -> SQLite3Datum) -> JsonMember + get_extractor + ( + SQLite3DataBase db, + String component_name, + Bool resolve_fk + )= + if component_name ="id" then ((Int -> SQLite3Datum) cursor) |-> json_member("id", json_int((Int)db_integer(cursor)(0))) + else if component_name ="create_date" then ((Int -> SQLite3Datum) cursor) |-> json_member("create_date", json_string(text(cursor)(1))) + else if component_name ="write_date" then ((Int -> SQLite3Datum) cursor) |-> json_member("write_date", json_string(text(cursor)(2))) + else if component_name ="res_model" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_model", json_string(text(cursor)(3))) + else if component_name ="res_name" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_name", json_string(text(cursor)(4))) + else if component_name ="file_size" then ((Int -> SQLite3Datum) cursor) |-> json_member("file_size", json_int((Int)db_integer(cursor)(5))) + else if component_name ="res_id" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_id", json_int((Int)db_integer(cursor)(6))) + else if component_name ="description" then ((Int -> SQLite3Datum) cursor) |-> json_member("description", json_string(text(cursor)(7))) + else if component_name ="res_field" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_field", json_string(text(cursor)(8))) + else if component_name ="mimetype" then ((Int -> SQLite3Datum) cursor) |-> json_member("mimetype", json_string(text(cursor)(9))) + else if component_name ="name" then ((Int -> SQLite3Datum) cursor) |-> json_member("name", json_string(text(cursor)(10))) + else if component_name ="url" then ((Int -> SQLite3Datum) cursor) |-> json_member("url", json_string(text(cursor)(11))) + else if component_name ="checksum" then ((Int -> SQLite3Datum) cursor) |-> json_member("checksum", json_string(text(cursor)(12))) + else if component_name ="datas_fname" then ((Int -> SQLite3Datum) cursor) |-> json_member("datas_fname", json_string(text(cursor)(13))) + else if component_name ="path" then ((Int -> SQLite3Datum) cursor) |-> json_member("path", json_string(text(cursor)(14))) + else if component_name ="__HK_SHOW_STRING__" then ((Int -> SQLite3Datum) cursor) |-> json_member("__HK_SHOW_STRING__", json_string(get_fs_file_show_string(db, db_id((Int)db_integer(cursor)(0))))) + else ((Int -> SQLite3Datum) cursor) |-> json_member(component_name, json_null) +. + +public define List(((Int -> SQLite3Datum) -> JsonMember)) + make_fs_file_json_extractor + ( + SQLite3DataBase db, + List(String) columns, + Bool resolve_fk + )= + map((String column) |-> get_extractor(db, column, resolve_fk), columns) +. + + +public define List(Fs_file) + _get_all_fs_file + ( + One -> SQLite3Row table_cursor, + List(Fs_file) so_far + ) = + if extract_fs_file(table_cursor) is + { + failure then reverse(so_far), + success(data) then _get_all_fs_file(table_cursor, [data . so_far]) + }. + + +public define Maybe(One -> SQLite3Row) + get_all_fs_file_by_clause + ( + SQLite3DataBase db, + String clause + )= + with final_clause = if clause = "" then + "" + else + "WHERE "+clause, + + if sql_query_timeout(db, "SELECT \"id\", \"create_date\", \"write_date\", \"res_model\", \"res_name\", \"file_size\", \"res_id\", \"description\", \"res_field\", \"mimetype\", \"name\", \"url\", \"checksum\", \"datas_fname\", \"path\" FROM fs_file "+final_clause+";", [], "get_all_fs_file_by_clause") is + { + error(_) then failure, + ok(_, cursor, _) then success(cursor) + } +. + +public define List(Fs_file) + get_all_fs_file_by_clause_to_list_type + ( + SQLite3DataBase db, + String clause + )= + if get_all_fs_file_by_clause(db, clause) is + { + failure then [], + success(cursor) then _get_all_fs_file(cursor, []) + } +. +public define JsonValue + get_all_fs_file_by_clause_to_json + ( + SQLite3DataBase db, + List(String) columns, + Bool resolve_fk, + HK_Referer referer, + String filter, + String order_by + )= + with ref_clause = referer_to_sql_clause(referer, "fs_file", fs_file_columns), + with final_columns = if length(columns) = 0 then ["id". fs_file_columns] else columns, + + with _and_ = if length(ref_clause) > 0 & length(filter) > 0 then " AND " else "", + if get_all_fs_file_by_clause(db, ref_clause+_and_+filter+" "+order_by) is + { + failure then json_array([]), + success(cursor) then + json_array( + get_all_to_json(db, make_fs_file_json_extractor(db, final_columns, resolve_fk), cursor, []) + ) + } +. + + +public define Maybe(Fs_file) + get_fs_file_by_clause + ( + SQLite3DataBase db, + String clause + )= + if sql_query_timeout(db, "SELECT \"id\", \"create_date\", \"write_date\", \"res_model\", \"res_name\", \"file_size\", \"res_id\", \"description\", \"res_field\", \"mimetype\", \"name\", \"url\", \"checksum\", \"datas_fname\", \"path\" FROM fs_file WHERE "+clause+";", [], "get_fs_file_by_clause") is + { + error(_) then failure, + ok(_, cursor, _) then extract_fs_file(cursor) + }. + + + +public define Maybe(Fs_file) + get_mb_fs_file + ( + SQLite3DataBase db, + String idx + )= + get_fs_file_by_clause(db, " id = "+idx). + +public define Maybe(Fs_file) + get_mb_fs_file + ( + SQLite3DataBase db, + Int idx + )= + get_fs_file_by_clause(db, " id = "+to_decimal(idx)). + +public define Maybe(Fs_file) + get_mb_fs_file + ( + SQLite3DataBase db, + DB_id idx + )= + if idx is + { + none then failure, + db_id(_idx) then get_mb_fs_file(db, _idx) + }. + +public define Fs_file + get_fs_file + ( + SQLite3DataBase db, + DB_id idx + )= + if idx is + { + none then get_default_fs_file, + db_id(_idx) then + if get_fs_file_by_clause(db, " id = "+to_decimal(_idx)) is + { + failure then get_default_fs_file, + success(r) then r + } + }. + + + +public define JsonValue + get_one_fs_file_to_json + ( + SQLite3DataBase db, + List(String) columns, + Bool resolve_fk, + DB_id idx + )= + with final_columns = if length(columns) = 0 then ["id", "__HK_SHOW_STRING__". fs_file_columns] else columns, + with error = json_object(map((String col_name) |-> json_member(col_name, json_null), final_columns)), + + if idx is + { + none then error, + db_id(_idx) then + if get_all_fs_file_by_clause(db, "id="+to_decimal(_idx)) is + { + failure then error, + success(cursor) then + if extract_cursor_to_json(db, make_fs_file_json_extractor(db, final_columns, resolve_fk), cursor) is + { + failure then error, + success(result) then result + } + } + } +. + + + +public define Maybe(Int) + update_fs_file + ( + SQLite3DataBase db, + Fs_file fs_file + )= + if fs_file.id is + { + none then + if sql_query_timeout(db, + "INSERT INTO fs_file + (\"create_date\", \"write_date\", \"res_model\", \"res_name\", \"file_size\", \"res_id\", \"description\", \"res_field\", \"mimetype\", \"name\", \"url\", \"checksum\", \"datas_fname\", \"path\") + VALUES + (:v_create_date, :v_write_date, :v_res_model, :v_res_name, :v_file_size, :v_res_id, :v_description, :v_res_field, :v_mimetype, :v_name, :v_url, :v_checksum, :v_datas_fname, :v_path);", + [ + bind_Datetime(":v_create_date", db_now), + bind_Datetime(":v_write_date", db_now), + bind_String_or_NULL(":v_res_model", fs_file.res_model), + bind_String_or_NULL(":v_res_name", fs_file.res_name), + bind_Int(":v_file_size", fs_file.file_size), + bind_Int(":v_res_id", fs_file.res_id), + bind_String_or_NULL(":v_description", fs_file.description), + bind_String_or_NULL(":v_res_field", fs_file.res_field), + bind_String_or_NULL(":v_mimetype", fs_file.mimetype), + bind_String(":v_name", fs_file.name), + bind_String_or_NULL(":v_url", fs_file.url), + bind_String_or_NULL(":v_checksum", fs_file.checksum), + bind_String_or_NULL(":v_datas_fname", fs_file.datas_fname), + bind_String_or_NULL(":v_path", fs_file.path)], + "update_fs_file (INSERT)") is + { + error(sql_error) then + //logError(debug_log, db_error(sql_error, table_name)); + failure, + ok(_, cursor, _) then + if sql_query_scalar(db, "SELECT last_insert_rowid()") is + { + error(_) then failure, + ok(datum) then + with r = if datum is integer(n) then n else 0, + success(r) + } + }, + db_id(idx) then + if sql_query_timeout(db, + "UPDATE fs_file SET + \"write_date\" = :v_write_date, \"res_model\" = :v_res_model, \"res_name\" = :v_res_name, \"file_size\" = :v_file_size, \"res_id\" = :v_res_id, \"description\" = :v_description, \"res_field\" = :v_res_field, \"mimetype\" = :v_mimetype, \"name\" = :v_name, \"url\" = :v_url, \"checksum\" = :v_checksum, \"datas_fname\" = :v_datas_fname, \"path\" = :v_path + WHERE id = "+idx+";", + [ + bind_Datetime(":v_write_date", db_now), + bind_String_or_NULL(":v_res_model", fs_file.res_model), + bind_String_or_NULL(":v_res_name", fs_file.res_name), + bind_Int(":v_file_size", fs_file.file_size), + bind_Int(":v_res_id", fs_file.res_id), + bind_String_or_NULL(":v_description", fs_file.description), + bind_String_or_NULL(":v_res_field", fs_file.res_field), + bind_String_or_NULL(":v_mimetype", fs_file.mimetype), + bind_String(":v_name", fs_file.name), + bind_String_or_NULL(":v_url", fs_file.url), + bind_String_or_NULL(":v_checksum", fs_file.checksum), + bind_String_or_NULL(":v_datas_fname", fs_file.datas_fname), + bind_String_or_NULL(":v_path", fs_file.path)], + "update_fs_file (UPDATE)") is { + error(sql_error) then + logError(debug_log, db_error(sql_error, "update_fs_file")); failure, + ok(_, _, _) then success(idx) } + }. + +public define Maybe(Int) + update_fs_file_from_type + ( + SQLite3DataBase db, + List(Web_arg) lwa + )= + if extract_Fs_file_from_web_arg(lwa, "") is + { + failure then logError(debug_log, "update_fs_file extract_Fs_file_from_web_arg is failure"); failure, + success(fs_file) then update_fs_file(db, fs_file) + }. + +public define Maybe(Int) + update_fs_file_from_fields + ( + SQLite3DataBase db, + List(Web_arg) lwa + )= + insert_or_update(db, "fs_file", get_DB_id(lwa, "id"), extract_Fs_file_update_fields_from_web_arg(lwa, "")) +. + + + +public define String + get_fs_file_show_string + ( + SQLite3DataBase db, + DB_id _idx + )= + if _idx is + { + none then default_select, + db_id(idx) then + if get_mb_fs_file(db, idx) is + { + failure then default_select, + success(obj) then obj.name + } + }. + +define List((List(CoreAttrs), WebArgValue, String)) + _get_selector_fs_file + ( + SQLite3DataBase db, + List(Fs_file) list, + List((List(CoreAttrs), WebArgValue, String)) so_far + )= + if list is + { + [] then [selector_default_entry . reverse(so_far)], + [ h . t ] then + if h.id is + { + none then [selector_default_entry], + db_id(_id) then _get_selector_fs_file(db, t, [([], wav(to_String(_id)), get_fs_file_show_string(db, h.id)) . so_far]) + } + }. + +public define List((List(CoreAttrs), WebArgValue, String)) + get_selector_fs_file + ( + SQLite3DataBase db, + HK_Referer referer, + String filter + )= + with clause = referer_to_sql_clause(referer, "fs_file", fs_file_columns), + + with _and_ = if length(clause) > 0 & length(filter) > 0 then " AND " else "", + _get_selector_fs_file(db, get_all_fs_file_by_clause_to_list_type(db, clause+_and_+filter), []). + +public define List((String, List(HK_Filter))) + get_all_fs_file_view_name + ( + One dummy + )= + [ + ("default", []) + ] +. + + + +define VT_view + _get_viewable_fs_file_default + = + with header = vt_view_row_header([ + text("CREATE_DATE"), + text("WRITE_DATE"), + text("RES_MODEL"), + text("RES_NAME"), + text("FILE_SIZE"), + text("RES_ID"), + text("DESCRIPTION"), + text("RES_FIELD"), + text("MIMETYPE"), + text("NAME"), + text("URL"), + text("CHECKSUM"), + text("DATAS_FNAME"), + text("PATH") + ]), + with model = vt_view_model([ + primary_key, + datetime("CREATE_DATE", "create_date", no_help_text), + datetime("WRITE_DATE", "write_date", no_help_text), + text("RES_MODEL", "res_model", no_help_text), + text("RES_NAME", "res_name", no_help_text), + integer("FILE_SIZE", "file_size", no_help_text), + integer("RES_ID", "res_id", no_help_text), + text_area("DESCRIPTION", "description", no_help_text), + text("RES_FIELD", "res_field", no_help_text), + text("MIMETYPE", "mimetype", no_help_text), + text("NAME", "name", no_help_text), + text("URL", "url", no_help_text), + text("CHECKSUM", "checksum", no_help_text), + text("DATAS_FNAME", "datas_fname", no_help_text), + text("PATH", "path", no_help_text) + ]), + vt_view( + "fs_file", //Name of the database table + "default", //Name of the view + model, + header + ) +. + +public define VT_view + get_viewable_fs_file + ( + String view, + )= + if view = "default" then + _get_viewable_fs_file_default + else + _get_viewable_fs_file_default +. + + +define HK_Form + _get_editable_fs_file_default + ( + Fs_file fs_file, + SQLite3DataBase db + )= + with edit_entries = (List(HK_Form_Entry)) + [ + hidden("id", to_String(fs_file.id)), + primary_key(to_String(fs_file.id)), + information("CREATE_DATE", "create_date", fs_file.create_date.datetime, 18, no_help_text), + information("WRITE_DATE", "write_date", fs_file.write_date.datetime, 18, no_help_text), + text("RES_MODEL", "res_model", fs_file.res_model, no_help_text), + text("RES_NAME", "res_name", fs_file.res_name, no_help_text), + integer("FILE_SIZE", "file_size", fs_file.file_size, no_help_text), + integer("RES_ID", "res_id", fs_file.res_id, no_help_text), + text_area("DESCRIPTION", "description", fs_file.description, none, no_help_text), + text("RES_FIELD", "res_field", fs_file.res_field, no_help_text), + text("MIMETYPE", "mimetype", fs_file.mimetype, no_help_text), + text("NAME", "name", fs_file.name, no_help_text), + text("URL", "url", fs_file.url, no_help_text), + text("CHECKSUM", "checksum", fs_file.checksum, no_help_text), + text("DATAS_FNAME", "datas_fname", fs_file.datas_fname, no_help_text), + text("PATH", "path", fs_file.path, no_help_text) + ], + hk_form_in_list("fs_file", "default", edit_entries, []). + +public define HK_Form + get_editable_fs_file + ( + SQLite3DataBase db, + HK_Form_action action, + String editor_view + )= + with fs_file = if action is + { + new_entry then get_default_fs_file + edit_entry(idx) then get_fs_file(db, idx) + }, + if editor_view = "default" then + _get_editable_fs_file_default(fs_file, db) + else + _get_editable_fs_file_default(fs_file, db) +. diff --git a/src/web_controller/hayamiki.anubis b/src/web_controller/hayamiki.anubis new file mode 100644 index 0000000..8ded324 --- /dev/null +++ b/src/web_controller/hayamiki.anubis @@ -0,0 +1,884 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 16/02/2017 + * Time: 00:40 + * © David RENÉ + */ + +//read types/app_types.anubis +read system/logger.anubis + +read hayamiki_lib/view/types/hk_form.anubis +read hayamiki_lib/view/types/hk_view.anubis +read hayamiki_lib/view/view_table_manager_types.anubis +read hayamiki_lib/view/view_table_manager.anubis +read hayamiki_lib/view/view_apps_renderer.anubis +transmit hayamiki_lib/view/web_action.anubis +transmit hayamiki_lib/view/view_table_renderer.anubis +transmit hayamiki_lib/view/view_editor_renderer.anubis +transmit hayamiki_lib/view/view_rows_import.anubis +transmit hayamiki_lib/types/hayamiki.anubis +transmit hayamiki_lib/model/utils.anubis +transmit hayamiki_lib/controller/hk_rows_import.anubis +transmit hayamiki_lib/controller/hk_sql_utils.anubis +transmit hayamiki_lib/controller/hk_delete.anubis + +read system/string.anubis +read locale/L3.anubis +read tools/basis.anubis + +read system/convert.anubis + +//read utils.anubis +read locale/L3LanguageInfo.anubis +read xlib/web/CXM_common.anubis +read xlib/web/CXM_web_arg_utils.anubis +read xlib/web/controllers_web_site.anubis +read xlib/web/CXM_multihost_http_server.anubis +read xlib/web/CXM_form.anubis +read xlib/web/CXM_json.anubis +read xlib/web/CXM_web_dump.anubis +read xlib/web/widgets/left_menu.anubis +//read database/users.anubis + + +read xlib/web/widgets/css_helper.anubis +read xlib/web/CXM_page_message.anubis + +//read app/app_constants.anubis +//read config/app_config.anubis + +read hayamiki_lib/controller/hk_controller.anubis + +//read database/vtm_init.anubis + +read xlib/web_controllers/language/language_management.anubis +//read web_controllers/access_and_rights.anubis +//read web_controllers/root/web_action.anubis +read hkc_files_management.anubis + + + +public define WEB_Controller_Result + compute_ajax_edit_table_entry_page + ( + SQLite3DataBase db, + (String) -> String _T, + String lang, + List(Web_arg) lwa, + String table, + String edit_view_name, + HK_Form_action action, + VTM vtm, + String clause, + String fk_clause, + HK_Referer referer + ) = + + with dialog_id = get_String(lwa, "dialog_id", "edit_table_dlg_ajax"), +// println("compute_ajax_edit_table_entry_page: table["+table+"] edit_view_name ["+edit_view_name+"] dialog_id ["+dialog_id+"]"); +// println("clause ["+clause+"] fk_clause["+fk_clause+"]"); + + + if edit_table_content(db, _T, lang, /*web_site_directory,*/ lwa, /*dialog_id,*/ table, edit_view_name, action, vtm, /*clause,*/ fk_clause, referer) is + { + failure then + redirect_to_previous, //compute_page_error(tb, http_ok, error("TABLE_EDITOR_DOESNT_EXIST")), + success(content) then + + with additional_script = +"$('#"+dialog_id+" .datepicker').datetimepicker({lang:'"+lang+"',timepicker:false}); + $('#"+dialog_id+" .datetimepicker').datetimepicker({lang:'"+lang+"', format:'Y-m-d H:i'}); + $('#"+dialog_id+" .timepicker').datetimepicker({lang:'"+lang+"',datepicker:false,format:'H:i',step:5}); + $( \"input[type=submit], button\" ).button();", + +// ajax(json(http_ok, to_html_ajax_content(content, cinfo, additional_script))) + ajax(failure, content, additional_script) + }. + + public define HTTP_Answer + compute_view_table_page + ( + Admin_Tool_Box tb, + Page_message errMsg, + String table, + String view_name, + String action_name, + VTM vtm + ) = + since tb is admin_tool_box( lang, lwa, _T, _, db ), + if view_table_content( db, _T, lang, web_site_directory, table, view_name, action_name, vtm) is + { + failure then compute_page_error(tb, http_ok, error_translate("TABLE_DOESNT_EXIST")), + success(content) then generic_space_page(tb, "", errMsg, content, admin_fisheye_menu, "admin_menu", left_menu(admin_left_menu,"")) + }. + +define (WEB_Session) -> WEB_Controller_Result + ajax_edit_table + ( + SQLite3DataBase db, + VTM _vtm + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + lang = _session.language, + + if web_arg_value(lwa, "table_name") is // table name + { + not_found then redirect_to_previous, + found(table_name) then + //get the name of editor to use + with view_name = get_String(lwa, "view_name", "default"), + with clause = get_String(lwa, "clause", ""), + with fk_clause = get_String(lwa, "fk_filter", ""), + with referer = get_HK_Referer_from_web_arg(lwa, ""), + with db_id = get_DB_id(lwa, "id"), + if db_id is // primary key + { + none then + compute_ajax_edit_table_entry_page(db, _T, lang, lwa, table_name, view_name, new_entry, _vtm, clause, fk_clause, referer), + db_id(id) then + compute_ajax_edit_table_entry_page(db, _T, lang, lwa, table_name, view_name, edit_entry(db_id), _vtm, clause, fk_clause, referer) + } + } +. + +define (WEB_Session) -> WEB_Controller_Result + grid_view_json + ( + SQLite3DataBase db, + VTM _vtm + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + lang = _session.language, + with error_result = ajax(json(http_ok, + json_object([ + json_member("page", json_int(0)), + json_member("total", json_int(0)), + json_member("records", json_int(0)), + json_member("rows",json_array([])) + ]) + )), + + if get_String(lwa, "table_name") is // table name + { + failure then redirect_to_previous, + success(table_name) then + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then + println("Can't get "+table_name+" hk_controller"); + error_result, + success(controller) then + //get the name of editor to use + with view_name = get_String(lwa, "view_name", "default"), + _filter_name = get_String(lwa, "filter_name", ""), + search = get_String(lwa, "_search", "false"), + limit = get_Int(lwa, "rows", 0), + page = get_Int(lwa, "page", 1), + sord = get_String(lwa, "sord", "asc"), + sidx = get_String(lwa, "sidx", "id"), + _clause = get_String(lwa, "clause", "1 = 1"), + referer = get_HK_Referer_from_web_arg(lwa, ""), + + if vtm_get_view(table_name, _vtm.view_list) is + { + failure then redirect_to_previous, + success(vtm_v) then + + with _filter = get_filter_from_name(vtm_v, view_name, _filter_name), + println("_filter name: "+_filter.filter_name); + println("_filter query: "+_filter.filter_string); + with clause = if _filter.filter_string = "" then //filter_string is empty, hence + if _clause = "" then //check if clause is empty + "" + else //return only clause because filter_strinf is empty + _clause + else if _clause = "" then //if clause is empty return only the filter_string + _filter.filter_string + else //in that case the filter_string and clause are not empty + "("+_filter.filter_string+") AND "+_clause, + + println("grid_view_json final clause : ["+clause+"])"); + with number = controller.get_count(db, if clause = "" then "" else "WHERE "+clause), + + with total_page = if number/limit is success(result) then since result is (pages, fraction), pages + if fraction > 0 then 1 else 0 else 1, + with new_page = if total_page < page then total_page else page, + with new_sidx = if sidx = "" then "id" else sidx, + with start = limit * new_page - limit, + ajax(json(http_ok, + json_object([ + json_member("page", json_int(new_page)), + json_member("total", json_int(total_page)), + json_member("records", json_int(number)), + json_member("query_date", json_string(get_current_datetime_ISO)), + json_member("rows", controller.get_rows_json(db, [], true, referer, clause, " ORDER BY "+new_sidx+" "+sord+" LIMIT "+start+", "+limit)) + ]) + )) + }}} +. + +define (WEB_Session) -> WEB_Controller_Result + combo_search + ( + SQLite3DataBase db, + VTM _vtm + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + lang = _session.language, + println("COMBO SEARCH"); + + //construct the error result + with error_result = ajax(json(http_ok, + json_object([ + json_member("cnt_whole", json_int(0)), + json_member("result",json_array([])) + ]) + )), + + if get_String(lwa, "db_table") is // table name + { + failure then + println("db_table argument not found"); + error_result, + success(table_name) then + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then + println("Can't get "+table_name+" hk_controller"); + error_result, + success(controller) then + + //get the page to return + if get_Int(lwa, "page_num") is + { + failure then //initial value because without paging + with pkey_name = get_String(lwa, "pkey_name", "id"), + pkey_val = get_DB_id(lwa, "pkey_val"), + ajax(json(http_ok, controller.get_one_json(db, [], true, pkey_val))), + + success(page) then + with + search_words = get_String_list(lwa, "q_word[]"), + search_fields = get_String_list(lwa, "search_field[]"), + active_filters = get_String_list(lwa, "active_filter[]"), //active filter format is "column_name,id" + limit = get_Int(lwa, "per_page", 10), //limit + and_or = get_String(lwa, "and_or", "OR"), + sidx = get_String(lwa, "sidx", "id"), + referer = get_HK_Referer_from_web_arg(lwa, ""), + //TODO add active filters here + + //active_filters = + with active_filter_clause = + join(" AND ", + map_select((String tuple ) |-> //here we get the tuple "column_name,id" + //slipt by the ',' and gather the column_name and the id + with splited = split_by_token(tuple, ','), + if splited is + { + [] then failure, + [ column_name . t] then + if t is + { + [] then failure, + [id . _] then success(column_name+" = "+id) + } + } + , active_filters)), + + show_string = "__SHOW_STRING__":search_fields, + + //construct the search clause based of the given words and fields + with _search_clause = + join(" "+and_or+" ", + map((String word) + |-> + //here construct like map with the searched word with all fields + "("+join(" OR ", map_select((String field) |-> if field = "__HK_SHOW_STRING__" /* if __HK_SHOW_STRING__ then exclude from search */ then failure else success(field+" LIKE '%"+word+"%'"), search_fields)) + ")" + ,search_words)), + + //finaly construct the full search clause with by concates the words clause and active filters clause + with search_clause = if length(active_filter_clause) > 0 then _search_clause + " AND ("+active_filter_clause+") " else _search_clause, + + println("combo_search final clause : ["+search_clause+"])"); + with number = controller.get_count(db, if search_clause = "" then "" else "WHERE "+search_clause), + //OFFSET + with offset = (page-1) * limit, + //ORDER BY + //order_by = join(", ", l_order_by), + with total_page = if number/limit is success(result) then since result is (pages, fraction), pages + if fraction > 0 then 1 else 0 else 1, + with new_page = if total_page < page then total_page else page, +// with new_sidx = sidx, +// with start = limit * new_page - limit, + ajax(json(http_ok, + json_object([ + json_member("cnt_whole", json_int(number)), + json_member("result", controller.get_rows_json(db, ["id" . search_fields], true, referer, search_clause, " LIMIT "+offset+", "+limit)) + ]) + )) + }}} +. + +define (WEB_Session) -> WEB_Controller_Result + edit_table + ( + SQLite3DataBase db, + VTM _vtm + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + + if get_String(lwa, "table_name") is // table name + { + failure then redirect_to_previous, + success(table_name) then + //get the name of editor to use + with view_name = get_String(lwa, "view_name", "default"), +// with dialog_id = get_String(lwa, "dialog_id", ""), + with clause = get_String(lwa, "clause", ""), + with fk_clause = get_String(lwa, "fk_filter", ""), + with referer = get_HK_Referer_from_web_arg(lwa, ""), + with id = get_DB_id(lwa, "id"), // primary key + + if id is + { + none then + if edit_table_content(db, _T, _session.language, /*web_site_directory,*/ lwa, /*dialog_id,*/ table_name, view_name, new_entry, _vtm, /*clause,*/ fk_clause, referer) is + { + failure then redirect_to_previous, + success(p_content) then + //http_answer(generic_desktop_page(db, _session, product_name, no_left_menu, p_content)) + renderer_content(p_content) + }, + + // state(lang, lwa, logged(account, edit_table_entry(table_name, view_name, new_entry), no_message)), + db_id(_) then + if edit_table_content(db, _T, _session.language, /*web_site_directory,*/ lwa, /*dialog_id,*/ table_name, view_name, edit_entry(id), _vtm, /*clause,*/ fk_clause, referer) is + { + failure then redirect_to_previous, + success(p_content) then + set_Page_Message(_session.fields, no_message); + //http_answer(generic_desktop_page(db, _session, product_name, no_left_menu, p_content)) + renderer_content(_session, p_content) + } + } + } +. + +define (WEB_Session) -> WEB_Controller_Result + view_editor + ( + SQLite3DataBase db, + VTM _vtm, + Bool change_view_name, + Bool change_filter + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + + if get_String(lwa, "table_name") is // table name + { + failure then redirect_to_previous, + success(table_name) then + if vtm_get_view(table_name, _vtm.view_list) is + { + failure then redirect_to_previous, + success(vtm_v) then + with view_name = get_String(lwa, "view_name", "default"), + with + current_filter = get_String(_session.fields, "current_filter", ""), + with filter_name = if change_view_name then + with _f = get_default_filter(vtm_v, view_name), + _f.filter_name + else + get_String(lwa, "filter_name", ""), + + if view_table_content( db, _T, _session.language, /*web_site_directory,*/ table_name, view_name, "edit_table", filter_name, "", no_referer, "", _vtm) is + { + failure then + set_Page_Message(_session.fields, error_translate("TABLE_DOESNT_EXIST")); + redirect_to_previous(_session.fields), //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), + success(p_content) then + //set_Page_Message(_session.fields, no_message); +// replace_String(_session.fields, "current_table", table_name); +// replace_String(_session.fields, "current_view", view_name); +// replace_String(_session.fields, "current_filter", filter_name); +// http_answer(generic_desktop_page(db, _session, product_name, no_left_menu, p_content)) + renderer_content(_session, p_content) + } + } + } +. + +define (WEB_Session) -> WEB_Controller_Result + delete_row + ( + SQLite3DataBase db, + VTM _vtm, + (LogLevel, String) -> One logger + )= + ( + WEB_Session _session + ) |-> + if hk_delete_row(*_session.web_request.lwa, db) is + { + error(error_str) then + set_Page_Message(_session.fields, error_translate(error_str)); + redirect_to_previous(_session.fields), + ok(ok_str) then + logger(logInfo, "delete ok"); + set_Page_Message(_session.fields, ok_translate(ok_str)); + redirect_to_previous(_session.fields), + }. + +define (WEB_Session) -> WEB_Controller_Result + save_row + ( + SQLite3DataBase db, + VTM _vtm, + (LogLevel, String) -> One logger + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + + with table_name = get_String(lwa, "table_name", ""), // table name + with sub_dialog = get_Bool(lwa, "sub_dialog"), + + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then logger(logError, "can't get writer for "+table_name);redirect_to_previous, + success(controller) then + if controller.write_from_fields(db, lwa) is + { + failure then + logger(logError, "can't write into "+table_name+" with current args "+dump_web_arg_values(lwa)); + set_Page_Message(_session.fields, error("Table writer: Error during insert or update")); + redirect_to_previous(_session.fields), + success(_) then + logger(logInfo, "write into "+table_name+"OK"); + //with view_name = get_String(lwa, "view_name", "default"), + if sub_dialog then + ajax(json(http_ok, json_object([json_member("success", json_bool(true))]))) + else + set_Page_Message(_session.fields, no_message); + redirect_to_previous(_session.fields), + //redirect(_session, "hk_c", "view_table") + } + } +. +define (WEB_Session) -> WEB_Controller_Result + get_rows_json + ( + SQLite3DataBase db, + VTM _vtm + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + lang = _session.language, + with error_result = ajax(json(http_ok, + json_object([ + json_member("page_number", json_int(0)), + json_member("total_page", json_int(0)), + json_member("total_rows", json_int(0)), + json_member("rows", json_array([])) + ]) + )), + + if get_String(lwa, "table_name") is // table name + { + failure then redirect_to_previous, + success(table_name) then + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then + println("Can't get "+table_name+" hk_controller"); + error_result, + success(controller) then + //get the name of editor to use + with select_fields = get_String_list(lwa, "select_fields"), +// with view_name = get_String(lwa, "view_name", "default"), +// _filter_name = get_String(lwa, "filter_name", ""), + search = get_String(lwa, "_search", "false"), + limit = get_Int(lwa, "rows", 0), + page = get_Int(lwa, "page", 1), + sord = get_String(lwa, "sord", "asc"), + sidx = get_String(lwa, "sidx", "id"), + clause = get_String(lwa, "clause", "1 = 1"), + referer = get_HK_Referer_from_web_arg(lwa, ""), + +// with _filter = get_filter_from_name(vtm_v, view_name, _filter_name), +// println("_filter name: "+_filter.filter_name); +// println("_filter query: "+_filter.filter_string); +// with clause = if _filter.filter_string = "" then "" else if _clause = "" then _filter.filter_string else "("+_filter.filter_string+") AND "+_clause, + println("get_rows_json final clause : ["+clause+"])"); + with number = controller.get_count(db, if clause = "" then "" else "WHERE "+clause), + + with total_page = if number/limit is success(result) then since result is (pages, fraction), pages + if fraction > 0 then 1 else 0 else 1, + with new_page = if total_page < page then total_page else page, + with new_sidx = if sidx = "" then "id" else sidx, + with start = limit * new_page - limit, + with limit_str = if limit = 0 then "" else " LIMIT "+start+", "+limit, + ajax(json(http_ok, + json_object([ + json_member("page_number",json_int(new_page)), + json_member("total_page", json_int(total_page)), + json_member("total_rows", json_int(number)), + json_member("query_date", json_string(get_current_datetime_ISO)), + json_member("rows", controller.get_rows_json(db, select_fields, false, referer, clause, " ORDER BY "+new_sidx+" "+sord+limit_str)) + ]) + )) + }} +. + +public define Maybe(Int) + update_row + ( + SQLite3DataBase db, + VTM _vtm, + List(Web_arg) _lwa + )= + + with table_name = get_String(_lwa, "table_name", ""), // table name + + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then println("can't get writer for "+table_name);failure, + success(controller) then + //forget(map((HK_Trigger trigger) |-> println("call trigger before update "+trigger.trigger_name+" ON table "+table_name); trigger.trigger_call_back(db, _session), *controller.triggers.before_update)); + + if controller.write_from_fields(db, _lwa) is + { + failure then failure, + success(inserted_idx) then + //replace_Int(_session.fields, "hk_last_insert_idx", inserted_idx); + //forget(map((HK_Trigger trigger) |-> println("call trigger after update "+trigger.trigger_name+" ON table "+table_name); trigger.trigger_call_back(db, _session), *controller.triggers.after_update)); + success(inserted_idx) + } + } +. + + +define (WEB_Session) -> WEB_Controller_Result + update_row + ( + SQLite3DataBase db, + VTM _vtm, + (LogLevel, String) -> One logger + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + _lwa = *_session.web_request.lwa, + + with table_name = get_String(_lwa, "table_name", ""), // table name + with sub_dialog = get_Bool(_lwa, "sub_dialog"), + + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then logger(logError, "can't get writer for "+table_name);redirect_to_previous, + success(controller) then + forget(map((HK_Trigger trigger) |-> logger(logInfo, "call trigger before update "+trigger.trigger_name+" ON table "+table_name); trigger.trigger_call_back(db, _session), *controller.triggers.before_update)); + + if controller.write_from_fields(db, *_session.web_request.lwa) is + { + failure then + logger(logError, "can't write_from_fields for table "+table_name+"\n with following arguments "+dump_web_arg_values(*_session.web_request.lwa)); + set_Page_Message(_session.fields, error("Table writer: Error during insert or update")); + redirect_to_previous(_session.fields), + success(inserted_idx) then + replace_Int(_session.fields, "hk_last_insert_idx", inserted_idx); + forget(map((HK_Trigger trigger) |-> logger(logInfo, "call trigger after update "+trigger.trigger_name+" ON table "+table_name); trigger.trigger_call_back(db, _session), *controller.triggers.after_update)); + + logger(logInfo, "write OK"); + if sub_dialog then + ajax(json(http_ok, json_object([json_member("success", json_bool(true)), json_member("idx", json_int(inserted_idx))]))) + else + //with view_name = get_String(lwa, "view_name", "default"), + set_Page_Message(_session.fields, no_message); + redirect_to_previous(_session.fields), + //redirect(_session, "hk_c", "view_table") + } + } +. + +define (WEB_Session) -> WEB_Controller_Result + get_selector + ( + SQLite3DataBase db, + VTM _vtm + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + + with table_name = get_String(lwa, "table_name", ""), // table name + with sub_dialog = get_Bool(lwa, "sub_dialog"), + with fk_filter = get_String(lwa, "fk_filter", ""), + with selected = get_String(lwa, "selected", ""), + with referer = get_HK_Referer_from_web_arg(lwa, ""), + + if get_hk_controller(_vtm.hk_controllers, table_name) is + { + failure then println("can't get writer for "+table_name);redirect_to_previous, + success(controller) then + + ajax(json(http_ok, to_html_ajax_content(format_choices(controller.get_selector(db, referer, fk_filter), init(selected)), ""))) + + } +. + +define (WEB_Session) -> WEB_Controller_Result + show_apps + ( + SQLite3DataBase db, + HK_Database hk_db + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = _session.web_request.lwa, + web_site_directory = get_web_site_directory(_session), + if show_apps_content( db, hk_db, _T, _session.language, web_site_directory) is + { + failure then + set_Page_Message(_session.fields, error_translate("HK_APPS_ERROR")); + redirect_to_previous(_session.fields), //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), + success(p_content) then + //set_Page_Message(_session.fields, no_message); + renderer_content(_session, p_content) + } +. + +define (WEB_Session) -> WEB_Controller_Result + grid_action + ( + SQLite3DataBase db, + VTM _vtm, + (LogLevel, String) -> One logger + )= + ( + WEB_Session _session + ) |-> + with lwa = *_session.web_request.lwa, + with oper = get_String(lwa, "oper", "N/A"), + + if oper = "del" then + logger(logInfo, "grid: DEL operation requested"); + delete_row(db, _vtm, logger)(_session) + else if oper = "edit" then + logger(logInfo, "grid: EDIT operation requested"); + update_row(db, _vtm, logger)(_session) + else if oper = "add" then + logger(logInfo, "grid: ADD operation requested"); + update_row(db, _vtm, logger)(_session) + else + set_Page_Message(_session.fields, error_translate("GRID_OPERATION_NOT_FOUND")); + redirect_to_previous(_session.fields) //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), +. + +define (WEB_Session) -> WEB_Controller_Result + crud_action + ( + SQLite3DataBase db, + VTM _vtm, + (LogLevel, String) -> One logger + )= + ( + WEB_Session _session + ) |-> + with lwa = *_session.web_request.lwa, + with oper = get_String(lwa, "oper", "N/A"), + + if oper = "create" then + logger(logInfo, "crud: CREATE operation requested"); + update_row(db, _vtm, logger)(_session) + else if oper = "read" then + logger(logInfo, "crud: READ operation requested"); + get_rows_json(db, _vtm)(_session) + else if oper = "update" then + logger(logInfo, "crud: UPDATE operation requested"); + update_row(db, _vtm, logger)(_session) + else if oper = "delete" then + logger(logInfo, "crud: DELETE operation requested"); + delete_row(db, _vtm, logger)(_session) + else + set_Page_Message(_session.fields, error_translate("CRUD OPERATION_NOT_FOUND")); + redirect_to_previous(_session.fields) //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), +. + +define (WEB_Session) -> WEB_Controller_Result + import_rows_dropzone_view + ( + SQLite3DataBase db + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + + if get_String(lwa, "table_name") is + { + failure then + set_Page_Message(_session.fields, error_translate("HK_TABLE_NAME_NOT_FOUND")); + redirect_to_previous(_session.fields), //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), + success(table_name) then +// http_answer(generic_desktop_page(db, _session, product_name, import_zone(table_name, _T))) + renderer_content(import_zone(table_name, _T)) + } +. + +define (WEB_Session) -> WEB_Controller_Result + hkc_import_choose_col + ( + SQLite3DataBase db, + HK_Database hk_db + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + separator = get_String(lwa, "csv_sep", ";"), + cancel_web_action_name = get_WEB_Action_Name(lwa, "cancel_ctrl", "cancel_action"), + file_name = get_String(_session.fields, "upl_file", ""), + if get_String(lwa, "table_name") is + { + failure then + set_Page_Message(_session.fields, error_translate("HK_TABLE_NAME_NOT_FOUND")); + redirect_to_previous(_session.fields), //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), + success(table_name) then + + if get_table(hk_db, table_name) is + { + failure then + set_Page_Message(_session.fields, error_translate("HK_TABLE_NAME_DOESNT_EXISTS")); + redirect_to_previous(_session.fields), //compute_page_error(tb, http_ok, error("TABLE_DOESNT_EXIST")), + success(table) then +// http_answer( +// generic_desktop_page(db, _session, product_name, +// import_choose_col(table_name, get_columns_name_and_TAG(table), separator, file_name, show_dashboard, _T) +// ) + renderer_content(_session, import_choose_col(table_name, get_columns_name_and_TAG(table), separator, file_name, cancel_web_action_name, _T)) + } + } +. + +define (WEB_Session) -> WEB_Controller_Result + hkc_import_file + ( + (LogLevel, String) -> One logger + )= + ( + WEB_Session _session + ) + |-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + //with separator = get_String(lwa, "csv_sep", ";"), + if file_upload_value(lwa,"file") is + { + failure then + set_Page_Message(_session.fields, error_translate("HK_UPLOAD_FILE_NAME_NOT_FOUND")); + redirect_to_previous(_session.fields), + success(upl_file) then + since upl_file is (filename, temp_filepath), + logger(logInfo, "filename="+filename+" / temp_filepath="+temp_filepath); + set_Page_Message(_session.fields, ok_translate("HK_UPLOAD_FILE_NAME_OK")); + replace_String(_session.fields, "upl_file", temp_filepath); + redirect_to_previous(_session.fields) + } +. + +define (WEB_Session) -> WEB_Controller_Result + hkc_import_execute + ( + SQLite3DataBase db, + HK_Database hk_db + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + forget(hkc_import_execute(_session, db, hk_db)); + redirect_to_previous +. + + +define Bool + allow_public + ( + WEB_Session _session + )= + true +. + +public define List(WEB_Action) + make_hk_actions + ( + SQLite3DataBase db, + HK_Database hk_db, + VTM _vtm, + (LogLevel, String) -> One logger + )= + with hk_logger = (LogLevel level, String text) |-> logger(level, "[Hayamiki] "+text), + + [ + //action lors de la demande de création d'un user dans un domaine + //do_change_language, + web_action(hkc_edit_table, https, allow_public, edit_table(db, _vtm)), + web_action(hkc_ajax_edit_table, https, allow_public, ajax_edit_table(db, _vtm)), + web_action(hkc_view_editor, https, allow_public, view_editor(db, _vtm, false, false)), + web_action(hkc_grid_view, https, allow_public, grid_view_json(db, _vtm)), + web_action(hkc_grid_action, https, allow_public, grid_action(db, _vtm, hk_logger)), + web_action(hkc_query, https, allow_public, crud_action(db, _vtm, hk_logger)), + + web_action(hkc_combo_search, https, allow_public, combo_search(db, _vtm)), + web_action(hkc_selector, https, allow_public, get_selector(db, _vtm)), //get dropdown HMTL content + web_action(hkc_list_view, https, allow_public, view_editor(db, _vtm, false, false)), + web_action(hkc_list_view_name, https, allow_public, view_editor(db, _vtm, true, false)), + web_action(hkc_list_view_filter, https, allow_public, view_editor(db, _vtm, false, true)), + web_action(hkc_save_row, https, allow_public, save_row(db, _vtm, hk_logger)), + web_action(hkc_update_row, https, allow_public, update_row(db, _vtm, hk_logger)), + web_action(hkc_cancel, https, allow_public, (WEB_Session _) |-> redirect_to_previous), + web_action(hkc_delete_row, https, allow_public, delete_row(db, _vtm, hk_logger)), + web_action(hkc_show_apps, https, allow_public, show_apps(db, hk_db)), + web_action(hkc_import_dropzone, https, allow_public, import_rows_dropzone_view(db)), + web_action(hkc_import_file, https, allow_public, hkc_import_file(hk_logger)), + web_action(hkc_import_choose_col, https, allow_public, hkc_import_choose_col(db, hk_db)), + web_action(hkc_import_execute, https, allow_public, hkc_import_execute(db, hk_db)), + + web_action(hkc_file_upload, https, allow_public, hkc_upload(db)), + web_action(hkc_file_download, https, allow_public, hkc_download(db)), + ] +. + + diff --git a/src/web_controller/hayamiki_plugin.anubis b/src/web_controller/hayamiki_plugin.anubis new file mode 100644 index 0000000..b7061ce --- /dev/null +++ b/src/web_controller/hayamiki_plugin.anubis @@ -0,0 +1,40 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 18/01/2020 + * Time: 21:02 + * © David RENÉ + */ + +read tools/basis.anubis +read system/logger.anubis +read xlib/web/plugin/plugin.anubis +read xlib/web/types/making_a_web_site.anubis +read xlib/web/types/web_session.anubis +read controller.anubis + +define Maybe(HTML_Partial_Content) + plugin_get_typed_content + ( + SQLite3DataBase db, + WEB_Session _session, + String type + )= + println("plugin_get_typed_content for HYAMIKI type "+type); + if type = "LEFT_MENU" then failure + else if type = "TOOLBAR" then failure + else if type = "CONTROL_PANEL" then failure + else + failure +. + +global define WEB_Plugin + hayamiki_web_plugin_lib + = + web_plugin( + "HAYAMIKI", + "BASE", + plugin_get_controller, + plugin_get_typed_content + ) +. diff --git a/src/web_controller/hkc_files_management.anubis b/src/web_controller/hkc_files_management.anubis new file mode 100644 index 0000000..aeb1a08 --- /dev/null +++ b/src/web_controller/hkc_files_management.anubis @@ -0,0 +1,94 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 20/08/2019 + * Time: 16:47 + * © David RENÉ + */ + +read system/files.anubis +read xlib/web/controllers_web_site.anubis +read database/generated/fs_file.anubis +read xlib/web_controllers/language/language_management.anubis +read xlib/web_controllers/fs/fs_core.anubis +read xlib/web/CXM_json.anubis + +define DB_id + get_new_hkc_id_from_fs + ( + SQLite3DataBase db + ) + = + if get_fs_file_by_clause(db, "res_model = 'hkc' ORDER BY res_id DESC") is + { + failure then db_id(0), + success(fs_file) then db_id(fs_file.res_id + 1) + } +. + +public define (WEB_Session) -> WEB_Controller_Result + hkc_upload + ( + SQLite3DataBase db + )= + ( + WEB_Session _session + )|-> + with _T = make_translate_function(_session), + lwa = *_session.web_request.lwa, + if file_upload_value(lwa,"upload") is + { + failure then + //set_Page_Message(_session.fields, error_translate("HK_UPLOAD_FILE_NAME_NOT_FOUND")); + ajax(json(http_ok, json_object([json_member("uploaded", json_int(0)), + json_member("error", json_object([json_member("message", json_string("File not found"))]))]))), + success(upl_file) then + //uploaded filename and temporary location of this file + since upl_file is (filename, temp_filepath), + println("filename="+filename+" / temp_filepath="+temp_filepath); + with hkc_file_id = get_new_hkc_id_from_fs(db), + with root_dir = app_fs+"hkc/"+to_fs_folder(hkc_file_id), + make_directories(root_dir); + +// with end_dir = current_dir + extract_dir(upload_full_path), + with final_filename = root_dir + filename, + + if move_file(temp_filepath, final_filename) then + //if the file is image create thumbnail +// since get_MIME_from_filename(final_filename) is mime(mime_type, subtype, _), +// (if mime_type = "image" then +// create_thumbnail(root_dir + end_dir, filename, "64x64"); +// create_thumbnail(root_dir + end_dir, filename, "128x128") +// else +// unique); + set_file(db, "hkc", hkc_file_id, filename, "file", filename, "hkc/"+to_fs_folder(hkc_file_id)); + ajax(json(http_ok, json_object([json_member("uploaded", json_int(1)), + json_member("fileName", json_string(filename)), + json_member("url", json_string("?aws_controller=hk_c&aws_action=download&file="+hkc_file_id))]))) + else + println("move_file error from ["+temp_filepath+"] to ["+final_filename+"]"); + ajax(json(http_ok, json_object([json_member("uploaded", json_int(0)), + json_member("error", json_object([json_member("message", json_string("move_file error from temporary location"))]))]))), + + } +. + +public define (WEB_Session) -> WEB_Controller_Result + hkc_download + ( + SQLite3DataBase db, + )= + ( + WEB_Session _session + ) |-> + with _T = make_translate_function(_session), + web_site_public_dir = get_String(_session.fields, "AWS_WEB_SITE_PUBLIC_DIR", ""), + lwa = *_session.web_request.lwa, + file_id = get_DB_id(lwa, "file"), + + if get_file(db, "hkc", file_id, "file") is + { + failure then send_file(web_site_public_dir+"img/missing-file.png", inline), + success(file) then send_file(file, inline) + } +. diff --git a/src/web_controller/types/generated/fs_file.anubis b/src/web_controller/types/generated/fs_file.anubis new file mode 100644 index 0000000..7e17df0 --- /dev/null +++ b/src/web_controller/types/generated/fs_file.anubis @@ -0,0 +1,143 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2020-04-11 + * Time: 10:14:04 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + +transmit xlib/database/db_types.anubis +transmit xlib/database/db_types.anubis + + + +public type Fs_file: + fs_file( + DB_id id, + DB_datetime create_date, + DB_datetime write_date, + String res_model, + String res_name, + Int file_size, + Int res_id, + String description, + String res_field, + String mimetype, + String name, + String url, + String checksum, + String datas_fname, + String path + ) +. + + Fs_file message format + ====================== + + +public define Message + to_Message + ( + Fs_file _fs_file + )= + with _fs_file_message = message((Word32)0), // + forget(add_string(_fs_file_message, "__TYPE__", "Fs_file")); + if _fs_file is + { + //Alternative fs_file + fs_file(_id, _create_date, _write_date, _res_model, _res_name, _file_size, _res_id, _description, _res_field, _mimetype, _name, _url, _checksum, _datas_fname, _path) then + forget(add_string(_fs_file_message, "__TYPE_ALT__", "fs_file")); + // [type = DB_id] fs_file.id + forget(add_message(_fs_file_message, "id", to_Message(_id))); + // [type = DB_datetime] fs_file.create_date + forget(add_message(_fs_file_message, "create_date", to_Message(_create_date))); + // [type = DB_datetime] fs_file.write_date + forget(add_message(_fs_file_message, "write_date", to_Message(_write_date))); + // [type = String] fs_file.res_model + forget(add_string(_fs_file_message, "res_model", _res_model)); + // [type = String] fs_file.res_name + forget(add_string(_fs_file_message, "res_name", _res_name)); + // [type = Int] fs_file.file_size + forget(add_string(_fs_file_message, "file_size", to_String(_file_size))); + // [type = Int] fs_file.res_id + forget(add_string(_fs_file_message, "res_id", to_String(_res_id))); + // [type = String] fs_file.description + forget(add_string(_fs_file_message, "description", _description)); + // [type = String] fs_file.res_field + forget(add_string(_fs_file_message, "res_field", _res_field)); + // [type = String] fs_file.mimetype + forget(add_string(_fs_file_message, "mimetype", _mimetype)); + // [type = String] fs_file.name + forget(add_string(_fs_file_message, "name", _name)); + // [type = String] fs_file.url + forget(add_string(_fs_file_message, "url", _url)); + // [type = String] fs_file.checksum + forget(add_string(_fs_file_message, "checksum", _checksum)); + // [type = String] fs_file.datas_fname + forget(add_string(_fs_file_message, "datas_fname", _datas_fname)); + // [type = String] fs_file.path + forget(add_string(_fs_file_message, "path", _path)), + + }; + _fs_file_message +. + +public define Maybe(Fs_file) + from_Message + ( + Message _fs_file_message + )= + if find_string(_fs_file_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_fs_file_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "Fs_file" then + //Alternative fs_file + if __type_alt__ = "fs_file" then //Alternative fs_file + // [type = DB_id] fs_file.id + if find_message(_fs_file_message, "id") is {failure then failure, success(_id__msg) then + if (Maybe(DB_id))from_Message(_id__msg) is {failure then failure, success(_id_) then + // [type = DB_datetime] fs_file.create_date + if find_message(_fs_file_message, "create_date") is {failure then failure, success(_create_date__msg) then + if (Maybe(DB_datetime))from_Message(_create_date__msg) is {failure then failure, success(_create_date_) then + // [type = DB_datetime] fs_file.write_date + if find_message(_fs_file_message, "write_date") is {failure then failure, success(_write_date__msg) then + if (Maybe(DB_datetime))from_Message(_write_date__msg) is {failure then failure, success(_write_date_) then + // [type = String] fs_file.res_model + if find_string(_fs_file_message, "res_model") is {failure then failure, success(_res_model_) then + // [type = String] fs_file.res_name + if find_string(_fs_file_message, "res_name") is {failure then failure, success(_res_name_) then + // [type = Int] fs_file.file_size + if find_string(_fs_file_message, "file_size") is {failure then failure, success(__file_size_) then + if decimal_scan(__file_size_) is { failure then failure, success(_file_size_) then + // [type = Int] fs_file.res_id + if find_string(_fs_file_message, "res_id") is {failure then failure, success(__res_id_) then + if decimal_scan(__res_id_) is { failure then failure, success(_res_id_) then + // [type = String] fs_file.description + if find_string(_fs_file_message, "description") is {failure then failure, success(_description_) then + // [type = String] fs_file.res_field + if find_string(_fs_file_message, "res_field") is {failure then failure, success(_res_field_) then + // [type = String] fs_file.mimetype + if find_string(_fs_file_message, "mimetype") is {failure then failure, success(_mimetype_) then + // [type = String] fs_file.name + if find_string(_fs_file_message, "name") is {failure then failure, success(_name_) then + // [type = String] fs_file.url + if find_string(_fs_file_message, "url") is {failure then failure, success(_url_) then + // [type = String] fs_file.checksum + if find_string(_fs_file_message, "checksum") is {failure then failure, success(_checksum_) then + // [type = String] fs_file.datas_fname + if find_string(_fs_file_message, "datas_fname") is {failure then failure, success(_datas_fname_) then + // [type = String] fs_file.path + if find_string(_fs_file_message, "path") is {failure then failure, success(_path_) then + + success(fs_file(_id_, _create_date_, _write_date_, _res_model_, _res_name_, _file_size_, _res_id_, _description_, _res_field_, _mimetype_, _name_, _url_, _checksum_, _datas_fname_, _path_)) + }}}}}}}}}}}}}}}}}}}} + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/xlib b/xlib index 42087dc..e432216 160000 --- a/xlib +++ b/xlib @@ -1 +1 @@ -Subproject commit 42087dcf0b412fabb5b67106041c711206c2281f +Subproject commit e4322160bc99742f8283441ca12a823993ab8793 -- libgit2 0.21.4