Continued work on install, Continued work on forms module, Started FileSystemStorage class and dependants

This commit is contained in:
xevidos 2020-07-15 00:13:28 -04:00
parent 5ff284bf02
commit 811a67913a
5 changed files with 359 additions and 176 deletions

View File

@ -10,8 +10,11 @@
let _i = this;
this.back_label = "Back";
this.next_label = "Next";
this.page = 0;
this.saving = false;
this.submit_label = "Submit";
this.topics = {};
@ -78,12 +81,6 @@
let total = self.values.length;
let pass = false;
if( ! self.parent.element ) {
console.log( self.parent.element );
return;
}
if( typeof self.subject === "object" ) {
value = self.subject.value;
@ -97,39 +94,21 @@
if( self.values[i].type ) {
self.type = self.values[i].type;
} else {
} else if( self.values[i].action === "change_type" ) {
self.type = self.parent.type;
}
if( value === self.values[i].value || `${value}` === `${self.values[i].value}` ) {
pass = true;
pass = self.values[i];
break;
} else {
pass = false;
}
if( pass ) {
if( self.valid_actions.includes( self.values[i].true ) ) {
self[self.values[i].true]();
} else if( typeof values[i].action === "function" ) {
self.values[i].true();
}
} else {
if( self.valid_actions.includes( self.values[i].false ) ) {
self[self.values[i].false]();
} else if( typeof self.values[i].false === "function" ) {
self.values[i].false();
}
}
}
return pass;
};
this.hide = function() {
@ -225,22 +204,66 @@
this.validation = null;
this.value = "";
this.audit = function( o ) {
let r = false;
if( self.type === "repeatable" ) {
let length = self.value.length;
for( let i = 0;i < length;i++ ) {
self.audit( self.value[i].data );
}
} else {
$.each( self.conditions, function( k, v ) {
if( r !== false ) {
return;
}
r = v.check();
if( r !== false ) {
if( v.valid_actions.includes( r.action ) ) {
v[r.action]();
} else if( typeof r.action === "function" ) {
r.action();
}
return;
}
});
}
};
this.clone = function() {
return _i.m.clone( self );
};
this.conditionals = function() {
let total = self.subscriptions.length;
for( let i = 0;i < total;i++ ) {
let r = false;
$.each( self.conditions, function( k, v ) {
self.subscriptions[i]( self );
}
if( r !== false ) {
return;
}
r = v.check();
});
return r;
};
this.publish = function() {
let total = self.subscriptions.length;
console.log( self );
let total = self.subscriptions.length;
for( let i = 0;i < total;i++ ) {
self.subscriptions[i]( self );
@ -393,6 +416,12 @@
o.update();
}];
if( o.conditions ) {
a.shown_by_default = false;
}
$.each( o, function( key, value ) {
a[key] = value;
@ -411,7 +440,7 @@
a.update = function() {
a.value = !!a.element.prop( "checked" );
a.conditionals();
a.publish();
};
a.render = function() {
@ -430,7 +459,7 @@
let v = codiad.common.get_check_box_values( a.name );
a.value = v;
a.conditionals();
a.publish();
};
a.render = function() {
@ -479,60 +508,6 @@
}
break;
case( a.type === "editor" ):
if( ! a.element ) {
a.element = $( `<textarea></textarea>` );
}
a.element.text( a.value );
a.label += "Please make sure to ( Edit->Select All ) then ( Format->Clear Formatting ) after pasting any content into this editor.";
a.update = function() {
let e = a.element.tinymce();
a.value = e.getContent();
};
a.render = function() {
let _this = a;
let e = a.element.tinymce();
if( ! e ) {
a.element.tinymce({
//theme: 'modern',
width: '100%',
height: 300,
plugins: [
'advlist autolink link image lists charmap print hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table directionality emoticons template paste'
],
content_style: 'body { font-size: 12pt; font-family: "Open Sans", sans-serif; }',
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons',
relative_urls: false,
convert_urls: true,
});
e = a.element.tinymce();
}
if( ! _this.value ) {
_this.value = "";
}
setTimeout( function() {
e.render();
setTimeout( function() {
e.setContent( _this.value );
e.on( "change", _this.update );
}, 500 );
}, 500 );
};
break;
case( a.type === "email" ):
if( ! o.element ) {
@ -782,19 +757,6 @@
};
break;
case( a.type === "ssn" ):
if( ! a.element ) {
a.element = $( `<input type="text" />` );
}
if( ! a.validation ) {
a.validation = _i.validation.validate;
}
break;
case( a.type === "sortable" ):
if( ! a.element ) {
@ -861,7 +823,7 @@
a.update = function() {
a.value = a.element.val();
a.conditionals();
a.publish();
}
}
@ -903,7 +865,7 @@
let c = new _this.conditional( v );
c.parent = value;
if( keys.includes( k ) ) {
if( c.subject === null ) {
@ -920,7 +882,7 @@
}
}
}
c.subject.subscribe( c.check );
c.subject.subscribe( value.audit );
value.conditions[k] = c;
});
});
@ -1223,17 +1185,6 @@
o.render();
}
if( conditions ) {
if( o.parent.type === "repeatable-data" ) {
_this.conditionals( [o.key], o.parent.data );
} else {
_this.conditionals( [o.key], o.parent );
}
}
return o;
},
add_listeners: function( o, element = null ) {
@ -1294,20 +1245,7 @@
return;
}
if( value.type === "repeatable" ) {
let length = value.value.length;
for( let i = 0;i < length;i++ ) {
_this.conditionals( [], value.value[i].data );
}
} else {
$.each( value.conditions, function( k, v ) {
v.check();
});
}
value.audit();
});
this.checking_conditions = false;
},
@ -1367,8 +1305,8 @@
let _this = _i.v;
let controls = _this.controls;
let next = $( `<a class="button">Next</a>` );
let back = $( `<a class="button">Back</a>` );
let next = $( `<button class="button">${_i.next_label}</button>` );
let back = $( `<button class="button">${_i.back_label}</button>` );
controls.html( '' );
@ -1383,7 +1321,7 @@
if( _i.page == _i.get_total_pages() ) {
next.text( "Submit" );
next.text( _i.submit_label );
next.attr( "type", "submit" )
}
@ -1416,6 +1354,15 @@
return;
}
let check = value.conditionals();
console.log( check );
if( check !== false && check.action === "hide" ) {
return;
}
_this.add( value );
});
@ -1423,8 +1370,6 @@
_this.container.append( _this.controls );
_this.render_controls();
_this.update();
_this.conditionals();
_i.publish( "data.onRenderedPage", {
page: id,
view: this,
@ -1467,7 +1412,6 @@
email: /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/,
number: /^(?=.)([+-]?(\d*)(\.(\d+))?)$/,
phone: /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/,
ssn: /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/,
year: /^[0-9]{4}$/,
},
@ -1700,6 +1644,21 @@
o.data = {};
}
if( o.back_label ) {
this.back_label = o.back_label;
}
if( o.next_label ) {
this.next_label = o.next_label;
}
if( o.submit_label ) {
this.submit_label = o.submit_label;
}
let previous = null;
$.each( o.data, async function( key, value ) {

View File

@ -0,0 +1,128 @@
<?php
require_once( "./filesystemstorage/class.data.php" );
class FileSystemStorage {
protected static $instance = null;
function __construct() {}
/**
* Return an instance of this class.
*
* @since ${current_version}
* @return object A single instance of this class.
*/
public static function get_instance() {
if( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
public function get_data( $table, $fields = array(), $filter = null ) {
$path = "./filesystemstorage/$table.inc";
$return = common::get_default_return();
if( is_file( $path ) ) {
$data = file_get_contents( $path );
$c = unserialize( $data );
if( is_callable( $filter ) ) {
try {
$return["data"] = $filter( $c->get_data( $fields ) );
} catch( Throwable $e ) {
$return["status"] = "error";
$return["message"] = "Unable to call filter function.";
$return["error"] = array(
"message" => $e->getMessage(),
"object" => $e,
);
}
} else {
$return["data"] = $c->get_data( $fields );
}
} else {
$return["status"] = "error";
$return["message"] = "The requested table does not exist.";
}
return $return;
}
/**
* Update data stored in a file on the server. In order to stop the file
* from being written by multiple people at the same time, we will provide
* the user with the data from the file while we have a lock on it. Then
* call the user's function as a callback, and write the data returned by
* the aformentioned function and close the file releasing the lock.
*
* @since ${current_version}
* @return object A success or failure message.
*/
public function update_data( $table, $update ) {
$return = common::get_default_return();
$path = "./filesystemstorage/$table.inc";
if( is_file( $path ) ) {
if( is_callable( $update ) ) {
$handle = fopen( $path, "w+" );
if( flock( $handle, LOCK_EX ) ) {
$data = fread( $handle, filesize( $path ) );
$c = unserialize( $data );
try {
$c->set_data( $update( $c->get_data() ) );
} catch( Throwable $e ) {
$return["status"] = "error";
$return["message"] = "Unable to call update function.";
$return["error"] = array(
"message" => $e->getMessage(),
"object" => $e,
);
}
fwrite( $handle, serialize( $c ) );
flock( $handle, LOCK_UN );
fclose( $handle );
$return["status"] = "success";
$return["message"] = "Updated $table.";
} else {
$return["status"] = "error";
$return["message"] = "Unable to obtain a lock on requested file.";
}
} else {
$return["status"] = "error";
$return["message"] = "Update function is not a callable object.";
}
} else {
$return["status"] = "error";
$return["message"] = "The requested table does not exist.";
}
return $return;
}
}
?>

View File

@ -0,0 +1,36 @@
<?php
namespace FileSystemStorage;
class Data {
protected static $instance = null;
public $headers = array();
public $data = array();
function __construct() {}
/**
* Return an instance of this class.
*
* @since ${current_version}
* @return object A single instance of this class.
*/
public static function get_instance() {
if( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
public function query( ) {
}
}
?>

View File

@ -44,30 +44,6 @@ if( isset( $_SESSION['theme'] ) ) {
if( file_exists( THEMES . "/". $theme . "/" . $sheet ) ) {
echo( '<link rel="stylesheet" href="../themes/' . $theme . '/' . $sheet . '?v=' . Update::get_version() . '">' );
} else {
echo( '<link rel="stylesheet" href="../themes/default/' . $sheet . '?v=' . Update::get_version() . '">' );
}
}
// Load Component CSS Files
foreach( $components as $component ) {
if( file_exists( THEMES . "/". $theme . "/" . $component . "/screen.css" ) ) {
echo( '<link rel="stylesheet" href="../themes/' . $theme . '/' . $component . '/screen.css?v=' . Update::get_version() . '">' );
} else {
if( file_exists( "../themes/default/" . $component . "/screen.css" ) ) {
echo( '<link rel="stylesheet" href="../themes/default/' . $component . '/screen.css?v=' . Update::get_version() . '">' );
} else {
if( file_exists( COMPONENTS . "/" . $component . "/screen.css" ) ) {
echo( '<link rel="stylesheet" href="../components/' . $component . '/screen.css?v=' . Update::get_version() . '">' );
}
}
}
}
@ -81,14 +57,21 @@ if( isset( $_SESSION['theme'] ) ) {
?>
<style>
form {
#installation {
left: 50%;
margin-left: -175px;
padding: 35px;
right: 50%;
position: fixed;
top: 30%;
width: 350px;
transform: translate( 50%,-50% );
width: 50%;
}
@media only screen and (max-width: 650px) {
#installation {
width: 80%;
}
}
</style>
<script src="../assets/js/jquery-3.5.1.js"></script>
@ -99,32 +82,103 @@ if( isset( $_SESSION['theme'] ) ) {
<script src="../assets/js/forms.js"></script>
</head>
<body>
<div id="installation"></div>
<div id="installation">
</div>
<script>
( function( global, $ ) {
$( document ).ready( function() {
let dbconditions = {
storage: {
values: [
{
action: "hide",
value: "filesystem",
},
{
action: "show",
value: "mysql",
},
{
action: "show",
value: "pgsql",
}
],
},
};
let d = {
active: {
permissions: {
default: "false",
element: $( '<pre>Checking ...</pre>' ),
label: "Permission Checks: ",
name: "permissions",
type: "custom",
},
storage: {
default: "true",
element: $( '<select></select>' ),
label: "Active On Website: ",
name: "active",
label: "Data Storage Method: ",
name: "storage",
options: {
"Yes": "true",
"No": "false",
"Filesystem": "filesystem",
"MySQL": "mysql",
"PostgreSQL": "pgsql",
},
type: "select",
},
dbhost: {
conditions: $.extend( true, {}, dbconditions ),
default: "localhost",
label: "Database Host: ",
type: "text",
},
dbname: {
conditions: $.extend( true, {}, dbconditions ),
default: "",
label: "Database Name: ",
type: "text",
},
dbuser: {
conditions: $.extend( true, {}, dbconditions ),
default: "",
label: "Database User: ",
type: "text",
},
dbpass: {
conditions: $.extend( true, {}, dbconditions ),
default: "",
label: "Database Password: ",
type: "text",
},
dbpass1: {
conditions: $.extend( true, {}, dbconditions ),
default: "",
label: "Repeat Password: ",
type: "text",
},
};
let form = new codiad.forms({
data: d,
container: $( "#installation" ),
submit_label: "Check Data Storage Method",
});
form.submit = function() {
console.log( "Submitted ..." );
}
});
})( this, jQuery );
</script>

View File

@ -54,6 +54,9 @@ div {
scrollbar-highlight-color:#303030;
scrollbar-shadow-color:#303030;
scrollbar-track-color:#303030;
scrollbar-color: #666 #333;
scrollbar-width: thin;
}
/* GLOBALS */
@ -194,10 +197,11 @@ input:focus, textarea:focus, select:focus {
input[type="checkbox"] {
width: 20px;
position: relative;
position: relative;
margin: 5px 0 0 0; padding: 0;
}
.button,
button {
display: inline-block;
width: auto;
@ -213,27 +217,29 @@ button {
border-bottom: 2px solid #7d7d7d;
}
button:hover {
button:hover,
.button:hover {
color: #333;
background-color: #f3f3f3;
cursor: pointer;
border-bottom: 2px solid #919191;
}
button.btn-left {
.btn-left {
border-radius: 3px 0px 0px 3px;
border-right: none;
}
button.btn-mid {
.btn-mid {
border-radius: 0;
border-right: none;
}
button.btn-right {
.btn-right {
border-radius: 0px 3px 3px 0px;
}
.button .icon,
button .icon {
padding: 0;
padding-right: 5px;