parent
5006a09f11
commit
2c0e93d882
@ -0,0 +1,24 @@ |
||||
var Fresh = function() { |
||||
function KeepAsset(key) { |
||||
found_one = false; |
||||
assets_files.forEach(value => { |
||||
if (ajax_folder+value.filename+value.ts == key) { |
||||
found_one = true; |
||||
// Note: Do NOT use a BREAK here it will not work
|
||||
// NOR does Return work
|
||||
} |
||||
}); |
||||
return found_one; |
||||
} |
||||
|
||||
let allKeys = Object.keys(localStorage);
|
||||
allKeys.forEach(value => { |
||||
if (! KeepAsset(value)) { |
||||
localStorage.removeItem(value); |
||||
} |
||||
}); |
||||
}; |
||||
|
||||
tts.Router.get('Clear', function() { |
||||
sessionStorage.clear(); |
||||
}); |
||||
@ -0,0 +1,3 @@ |
||||
h2 { |
||||
background-color: green; |
||||
} |
||||
@ -1 +1 @@ |
||||
{"name":"","short_name":"","icons":[{"src":"./assets/favicon/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"./assets/favicon/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} |
||||
{"name":"","short_name":"","icons":[{"src":"./android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"./android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} |
||||
@ -0,0 +1,33 @@ |
||||
<?php |
||||
|
||||
namespace prj\{{.Root}}\controllers\{{.Subfolder}}; |
||||
|
||||
class {{.File}}_ctrl { |
||||
|
||||
public function __construct() { |
||||
\tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') ); |
||||
} |
||||
|
||||
public function {{.Method}}() { |
||||
$input = \prj\{{.Root}}\inputs\{{.Subfolder}}\{{.File}}_in::{{.Method}}(); |
||||
$model = new \prj\{{.Root}}\models\{{.Subfolder}}\{{.File}}_model(\tts\main\registry::get('db')); |
||||
|
||||
$model->init_demo_table(); // Create Table if NOT exists! |
||||
$model->populate(10); // INSERT 10 random rows of data |
||||
|
||||
$success = $model->save_{{.Method}}($input); // Save data from Request Data |
||||
$input['model'] = ($success===true) ? |
||||
$model->get_{{.Method}}(15) : |
||||
$model->get_{{.Method}}(0); |
||||
|
||||
$output = \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}($input); |
||||
|
||||
$html = new \tts\html_document(); |
||||
$view = new \tts\view(); |
||||
$view->set('html', $html); |
||||
$view->set('output', $output); |
||||
$view->set_template('main'); |
||||
$view->include("{{.Subfolder}}/{{.File}}_{{.Method}}_view"); |
||||
$view->render($this); |
||||
} |
||||
} |
||||
@ -0,0 +1,36 @@ |
||||
<?php |
||||
|
||||
namespace prj\{{.Root}}\inputs\{{.Subfolder}}; |
||||
|
||||
use \tts\safer_io as SafeIO; |
||||
use \tts\INPUTS; |
||||
use \tts\FIELD_FILTER; |
||||
use \tts\HTML_FLAG; |
||||
|
||||
class {{.File}}_in { |
||||
|
||||
public static function {{.Method}}(): array { |
||||
$safer_data = SafeIO::sanitize([ |
||||
'first_name' => |
||||
[ |
||||
'input' => INPUTS::post, |
||||
'field' => FIELD_FILTER::raw_string, |
||||
'html' => HTML_FLAG::escape, |
||||
'rule' => 'required|max: 75', // Others: email, valid_email_domain, |
||||
// min, max, between, same, secure (password), alphanumeric |
||||
'message' => ['required' => 'Must fill out first_name!'] |
||||
], |
||||
'last_name' => |
||||
[ |
||||
'input' => INPUTS::post, |
||||
'field' => FIELD_FILTER::raw_string, |
||||
'html' => HTML_FLAG::escape, |
||||
'rule' => 'required|max: 75', |
||||
'message' => ['required' => 'Must fill out last_name!'] |
||||
], |
||||
]); |
||||
|
||||
return $safer_data; // Makes an Array of: fields, html, and errrors |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,72 @@ |
||||
<?php |
||||
|
||||
namespace prj\{{.Root}}\models\{{.Subfolder}}; |
||||
|
||||
class {{.File}}_model { |
||||
private $dbh; |
||||
private $demo_table = "test_names"; |
||||
|
||||
public function __construct($dbh) { |
||||
$this->dbh = $dbh; |
||||
$this->db_helper = new \tts\database\help_save($this->dbh, $this->demo_table); |
||||
} |
||||
|
||||
public function pre_save(): bool { |
||||
$missing = $this->db_helper->get_missing(); |
||||
if (count($missing)) { |
||||
echo "Required fields not set " . implode(",", $missing) . "!"; |
||||
return false; |
||||
} |
||||
|
||||
if ($this->db_helper->dump_diff()) { |
||||
return false; // Opps forgot a field! |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public function init_demo_table(): void { |
||||
$create_table_sql = "CREATE TABLE IF NOT EXISTS `{$this->demo_table}`( |
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
||||
`first_name` TEXT, |
||||
`last_name` TEXT |
||||
)"; |
||||
$this->dbh->query($create_table_sql); |
||||
} |
||||
|
||||
public function populate($rows): void { |
||||
$dummy = new \tts\database\dummy_data($this->dbh); |
||||
$data = [ 'first_name' => \tts\arrays\mocking\rnd_names::get_first_names(), |
||||
'last_name' => \tts\arrays\mocking\rnd_names::get_last_names(), |
||||
]; |
||||
$dummy->add_dummy_data($this->demo_table, $rows, $data); |
||||
} |
||||
|
||||
public function save_{{.Method}}(array $input): bool { |
||||
$set = $this->db_helper->set_members_by_array($input); |
||||
if ($set === false) { |
||||
return false; // Found Validation issues in input |
||||
} |
||||
try { |
||||
$status = $this->db_helper->save($this); |
||||
} catch (\PDOException $e) { |
||||
echo \tts\exceptions\DB_Exception::customMessage($e, "Unable to save changes!"); |
||||
} |
||||
if ($status === $this->db_helper::successful_save) { |
||||
return true; // It saved |
||||
} |
||||
return false; // It did not save |
||||
} |
||||
|
||||
public function get_{{.Method}}(int $number_of_users_to_get = 12): \Generator { |
||||
if ($number_of_users_to_get === 0) { |
||||
return \tts\database\help_load::empty_generator(); |
||||
} |
||||
try { |
||||
$sql = "SELECT * FROM {$this->demo_table} LIMIT {$number_of_users_to_get}"; |
||||
$result = $this->dbh->query($sql); |
||||
return \tts\database\help_load::fetch_lazy($result); |
||||
} catch (\PDOException $e) { |
||||
echo \tts\exceptions\DB_Exception::customMessage($e); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
<?php |
||||
|
||||
namespace prj\{{.Root}}\outputs\{{.Subfolder}}; |
||||
|
||||
class {{.File}}_out { |
||||
|
||||
public static function {{.Method}}(array $input): array { |
||||
|
||||
$first_name = $input['html']['first_name'] ?? ""; |
||||
$last_name = $input['html']['last_name'] ?? ""; |
||||
|
||||
$ret['main'] = ($input['errors']) ? "" : "Hello {$first_name}, {$last_name}!" . PHP_EOL; |
||||
$ret['errors'] = $input['errors']; |
||||
$ret['model'] = $input['model']; |
||||
|
||||
return $ret; |
||||
} |
||||
|
||||
public static function {{.Method}}_show_errors(array $errors): string { |
||||
if ($errors) { |
||||
$message = "Please correct the following errors: "; |
||||
$i = 0; |
||||
foreach($errors as $error) { |
||||
$i++; |
||||
$message .= "<br/>{$i}) " . $error; |
||||
} |
||||
return $message; |
||||
} |
||||
return ""; // No Errors to return here |
||||
} |
||||
|
||||
public static function {{.Method}}_display(\Generator $input): void { |
||||
if (! $input->current()) { |
||||
return; // No Data, so Bail here |
||||
} |
||||
\tts\html::show_table_from_generator( |
||||
['ID', 'First Name', 'Last Name'], |
||||
['id', 'first_name', 'last_name'], |
||||
$input |
||||
); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,20 @@ |
||||
<h2>Sample View file</h2> |
||||
|
||||
<?php |
||||
$route_name_demo = "{{.Subfolder}}/{{.File}}"; |
||||
$method_name_demo_post = "{{.Method}}"; |
||||
|
||||
echo \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}_show_errors($output['errors']); |
||||
?> |
||||
|
||||
<br/><br/> |
||||
<form method="post"> |
||||
<label for="fname">First Name: <input type="text" id="fname" name="first_name" size="15" /></label><br/> |
||||
<label for="lname">Last Name: <input type="text" id="lname" name="last_name" size="15" /></label><br/> |
||||
<input type="submit" /> |
||||
</form> |
||||
|
||||
<br> |
||||
<hr> |
||||
|
||||
<?= \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}_display($output['model']); ?> |
||||
Loading…
Reference in new issue