Skip to content

Commit

Permalink
Set ui and models
Browse files Browse the repository at this point in the history
  • Loading branch information
rantes committed Aug 5, 2021
1 parent 43ec641 commit 53f1a54
Show file tree
Hide file tree
Showing 56 changed files with 28,015 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
tmp/
*.log
app/webroot/test.html
56 changes: 56 additions & 0 deletions app/controllers/admin_base_trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

trait AdminBaseTrait {
private $_model = '';

private function _init() {
parent::__construct();

$this->layout = 'layout';
$this->helper = ['Sessions','Menu'];
}

public function before_filter() {
// Require_login();
$this->menuLinks = adminMenu();
}

public function deleteregAction() {
$code = HTTP_422;
/** message key is a kinda standard, if an error occurs, message is the same attribute as in exception object */
$response = [
'd' => [],
'message' => ''
];
if (!empty($this->_model) and !empty($this->params['id'])):
$model = Camelize(Singulars($this->_model));

$obj = $this->{$model}->Find((integer)$this->params['id']);
($obj->Delete() and ($code = HTTP_200) and ($response['message'] = 'Success')) or ($response['m'] = (string)$obj->_error);
endif;

http_response_code($code);
$this->respondToAJAX(json_encode($response));
}

public function addregAction() {
$code = HTTP_422;
$response = [
'd' => [],
'message' => 'Error Saving'
];

if(!empty($this->_model) and !empty($_POST[$this->_model])):
$model = Camelize(Singulars($this->_model));
$data = $this->{$model}->Niu($_POST[$this->_model]);
(
$data->Save()
and ($response['d'] = $data and ($response['message'] = 'Success') and $code = HTTP_200)
)
or ($response['message'] = (string)$data->_error);
endif;

http_response_code($code);
$this->respondToAJAX(json_encode($response));
}
}
36 changes: 36 additions & 0 deletions app/controllers/admin_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
require_once INST_PATH.'app/controllers/admin_base_trait.php';
class AdminController extends Page {
use AdminBaseTrait;

public function __construct() {
$this->_init();
}

public function indexAction() {
$this->render = ['text'=>'noop'];
}

public function usersAction() {
$this->users = $this->User->Find();
}

public function deleteuserAction() {
$this->_model = 'user';
$this->deleteregAction();
}

public function useraddregAction() {
$this->_model = 'user';
$this->addregAction();
}

public function useraddeditAction() {
$this->layout = false;
if(empty($this->params['id'])):
$this->data = $this->ProjectGroup->Niu();
else:
$this->data = $this->ProjectGroup->Find($this->params['id']);
endif;
}
}
37 changes: 37 additions & 0 deletions app/controllers/user_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
class UserController extends Page {
public $layout = 'layout';
public $noTemplate = ['create','delete'];
public $helper = ['Menu'];

public function indexAction() {
$_SESSION['admin'] = 1;
$this->menuLinks = adminMenu();
$this->data = $this->User->Find();
}

public function addeditAction() {
if (isset($this->params['id'])):
$this->data = $this->User->Find($this->params['id']);
else:
$this->data = $this->User->Niu();
endif;
}

public function deleteAction() {
if (isset($this->params['id'])):
$this->data = $this->User->Delete($this->params['id']);
endif;

header('Location: '.INST_URI.'user/index/');
}

public function createAction() {
if (isset($_POST['user'])):
$obj = $this->User->Niu($_POST['user']);
$obj->Save() or die($obj->_error);
endif;

header('Location: '.INST_URI.'user/index/');
}
}
38 changes: 38 additions & 0 deletions app/helpers/Menu_Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* @author rantes
*/
class menuEntry {
public $link = '';
public $label = '';
public $items = [];
public $icon = '';
public $target = '_self';
public $hasItems = false;
/**
*
* @param string $link
* @param string $label
* @param array $items
* @param string $icon
* @param string $target
*/
public function __construct($link, $label, $items = [], $icon = '', $target = '_self') {
$this->link = $link;
$this->label = $label;
$this->items = $items;
$this->icon = $icon;
$this->target = $target;

$this->hasItems = !empty($this->items);
}
}


function adminMenu() {
return [
new menuEntry('/admin/index', 'Inicio', null, 'home'),
new menuEntry('/admin/users', 'Usuarios', null, 'user'),
new menuEntry('/admin/logout?logout=1', 'Salir', null, 'exit')
];
}
10 changes: 10 additions & 0 deletions app/helpers/Sessions_Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

function Require_login() {
if (empty($_SESSION['user']) and _ACTION !== 'login' and _ACTION !== 'signin'):
header('Location: /index/login');
return false;
endif;

return true;
}
6 changes: 6 additions & 0 deletions app/models/attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
class Attachment extends ActiveRecord {
function _init_() {

}
}
6 changes: 6 additions & 0 deletions app/models/issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
class Issue extends ActiveRecord {
function _init_() {

}
}
6 changes: 6 additions & 0 deletions app/models/param.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
class Param extends ActiveRecord {
function _init_() {

}
}
43 changes: 43 additions & 0 deletions app/models/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Modelo Usuarios
*
* @author Javier Serrano <[email protected]>
* @version 1.0
* @package Basilisk
* @subpackage Models
*/
class User extends ActiveRecord {
public function _init_(){
$this->before_save = ['sanitize', 'encryptPassword'];

$this->validate = [
'presence_of' => [
['field'=>'firstname','message'=>_('model.error.required.firstname')],
['field'=>'lastname','message'=>_('model.error.required.lastname')],
['field'=>'email','message'=>_('model.error.required.email')],
],
'email' => [
['field'=>'email','message'=>_('model.error.format.email')]
],
'unique' => [
['field'=>'email','message'=>_('model.error.unique.email')]
]
];
}

public function sanitize() {
$this->firstname = htmlentities($this->firstname, ENT_QUOTES, 'UTF-8',false);
$this->lastname = htmlentities($this->lastname, ENT_QUOTES, 'UTF-8',false);
}

public function encryptPassword() {
empty($this->password) or ($this->password = sha1($this->password));
}

public function login($user, $password) {
$user = $this->Find_by_email($user);
// will return 0 or the user id
return ($user->counter() === 1 and $user->password === sha1($password)) * $user->id;
}
}
30 changes: 30 additions & 0 deletions app/views/admin/users.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div>
<div>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>created_at</th>

<th>Actions</th>
</tr>
</thead>
<tbody>
<? foreach($this->users as $row): ?>
<tr>
<td><?=$row->id;?></td>
<td><?=$row->name;?></td>
<td><?=$row->created_at;?></td>

<td>
<a href="<?=INST_URI;?>user/delete/<?=$row->id;?>">delete</a>
<a href="<?=INST_URI;?>user/addedit/<?=$row->id;?>">Edit</a>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
</div>
<a href="<?=INST_URI;?>user/addedit/">Add new...</a>
</div>
81 changes: 69 additions & 12 deletions app/views/layout.phtml
Original file line number Diff line number Diff line change
@@ -1,19 +1,76 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<base href="<?=INST_URI;?>">
<title>Dumbo PHP</title>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<base href="<?=INST_URI;?>">
<title>Basilisk Project Management</title>
<meta name="msapplication-starturl" content="/">
<meta name="theme-color" content="#ff9901">
<meta name="viewport" content="initial-scale=1, width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<meta name="description" content="Basilisk Project Management">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script type="text/javascript">
window.innerWidth = window.outerWidth;
</script>

<style type="text/css">
<? readfile(INST_PATH.'app/webroot/libs/dmb-styles.css'); ?>
<? readfile(INST_PATH.'app/webroot/css/styles.css'); ?>
</style>
</head>
<body>
<header>

</header>
<section class="content">
<?=$this->yield;?>
</section>
<footer>
<p><strong>Powered by DumboPHP</strong></p>
</footer>
<dmb-view class="dmb-view" id="page">
<dmb-header>
<div class="section-group">
<div class="col col2 col2-md col2-sm">
<? if(_ACTION !== 'login' and !empty($_SESSION['admin'])): ?>
<dmb-menu-button menu="#general-menu" legend="Men&uacute; Principal">Menu</dmb-menu-button>
<? endif; ?>
</div>
<div class="col col10 col10-md col10-sm">
<h1 class="site-name"><?=SITE_NAME;?></h1>
</div>
</div>
</dmb-header>
<dmb-content id="page-content">
<?=$this->yield;?>
</dmb-content>
<dmb-footer is="footer" id="page-footer"></dmb-footer>
<? if(_ACTION !== 'login' and !empty($_SESSION['admin'])): ?>
<dmb-panel id="general-menu" class="dmb-panel dmb-menu left">
<dmb-header>
<h3>Men&uacute;</h3>
<dmb-close-panel orientation="left"></dmb-close-panel>
</dmb-header>
<dmb-content>
<? foreach ($this->menuLinks as $entry): ?>
<a class="item item-main" href="<?=$entry->link;?>" target="<?=$entry->target;?>">
<i class="icon icon-<?=$entry->icon;?>"></i>
<?=$entry->label;?>
</a>
<? if ($entry->hasItems): ?>
<? foreach ($entry->items as $subEntry): ?>
<a class="item item-secondary" href="<?=$subEntry->link;?>" target="<?=$entry->target;?>">
<i class="icon icon-<?=$subEntry->icon;?>"></i>
<?=$subEntry->label;?>
</a>
<? endforeach; ?>
<? endif; ?>
<? endforeach; ?>
</dmb-content>
</dmb-panel>
<? endif; ?>
</dmb-view>
<script type="text/javascript">
<? readfile(INST_PATH.'app/webroot/libs/dumbo.min.js'); ?>
<? readfile(INST_PATH.'app/webroot/libs/dmb-factories.min.js'); ?>
<? file_exists(INST_PATH.'app/webroot/js/factories.min.js') and readfile(INST_PATH.'app/webroot/js/factories.min.js'); ?>
<? readfile(INST_PATH.'app/webroot/libs/dmb-components.min.js'); ?>
<? file_exists(INST_PATH.'app/webroot/js/components.min.js') and readfile(INST_PATH.'app/webroot/js/components.min.js'); ?>
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions app/views/user/addedit.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<dmb-form action="/user/create/" dmb-name="user" enctype="application/x-www-form-urlencoded">
<dmb-input dmb-name="user[id]" value="<?=$this->data->id;?>" type="hidden"></dmb-input>
<dmb-input dmb-name="user[name]" label="name" value="<?=$this->data->name;?>" type="text" validate="required"></dmb-input>
<dmb-button type="submit" class="button button-success"><span class="text">Submit</span></dmb-button>
</dmb-form>
Loading

0 comments on commit 53f1a54

Please sign in to comment.