Add new plugins: WIP, Suggestions, Reviews

This commit is contained in:
Joey Kimsey
2024-12-11 08:00:06 -05:00
parent 6a6fe4171f
commit a8a99b37e3
41 changed files with 2079 additions and 0 deletions

View File

@ -0,0 +1,102 @@
<?php
/**
* app/plugins/wip/controllers/admin/wip.php
*
* This is the projects admin controller.
*
* @package TP Wip
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers\Admin;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Models\Projects;
class Wip extends AdminController {
public static $projects;
public function __construct() {
parent::__construct();
self::$projects = new Projects;
self::$title = 'Admin - Projects';
$view = Navigation::activePageSelect( 'nav.admin', '/admin/wip' );
Components::set( 'ADMINNAV', $view );
}
public function index( $data = null ) {
Views::view( 'wip.admin.list', self::$projects->listPaginated() );
}
public function create( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'wip.admin.create' );
}
if ( !Forms::check( 'newProject' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return $this->index();
}
$result = self::$projects->create( Input::post( 'title' ), Input::post( 'description' ), Input::post( 'progress' ), Input::post( 'startDate' ) );
if ( $result ) {
Issues::add( 'success', 'Your projects has been created.' );
return $this->index();
} else {
Issues::add( 'error', [ 'There was an unknown error submitting your data.' => Check::userErrors() ] );
return $this->index();
}
}
public function edit( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'wip.admin.edit', self::$projects->findById( $data ) );
}
if ( !Forms::check( 'editProject' ) ) {
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
return $this->index();
}
$fields = [
'title' => Input::post( 'title' ),
'description' => Input::post( 'description' ),
'progress' => Input::post( 'progress' ),
'startDate' => Input::post( 'startDate' ),
];
if ( self::$projects->update( $data, $fields ) ) {
Issues::add( 'success', 'Projects Updated.' );
return $this->index();
}
Issues::add( 'error', 'There was an error with your request.' );
$this->index();
}
public function view( $data = null ) {
$projectData = self::$projects->findById( $data );
if ( $projectData !== false ) {
return Views::view( 'wip.admin.view', $projectData );
}
Issues::add( 'error', 'Projects not found.' );
$this->index();
}
public function delete( $data = null ) {
if ( $data == null ) {
if ( Input::exists( 'P_' ) ) {
$data = Input::post( 'P_' );
}
}
if ( !self::$projects->delete( (array) $data ) ) {
Issues::add( 'error', 'There was an error with your request.' );
} else {
Issues::add( 'success', 'Projects has been deleted' );
}
$this->index();
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* app/plugins/wip/controllers/wip.php
*
* This is the bug reports controller.
*
* @package TP Wip
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Models\Projects;
class Wip extends Controller {
protected static $projects;
public function index() {
self::$projects = new Projects;
self::$title = '{SITENAME} - Works in Progress';
self::$pageDescription = 'Its not the longest wip in the world, but I\'m certainly proud of it.';
$projects = self::$projects->listPaginated();
if ( false == $projects ) {
Issues::add( 'error', 'Well, this is embarrassing, surely he wouldn\'t just have no wip..... right.... Dave? ... erm Joey?' );
return;
} else {
Views::view( 'wip.wip', self::$projects->listPaginated() );
}
}
}

79
app/plugins/wip/forms.php Normal file
View File

@ -0,0 +1,79 @@
<?php
/**
* app/plugins/wip/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @package TP Wip
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins\Wip;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
class WipForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'newProject', __CLASS__, 'newProject' );
self::addHandler( 'editProject', __CLASS__, 'editProject' );
}
/**
* Validates the new project post form.
*
* @return {bool}
*/
public static function newProject() {
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'description' ) ) {
self::addUserError( 'You must specify description' );
return false;
}
if ( !Input::exists( 'progress' ) ) {
self::addUserError( 'You must specify progress' );
return false;
}
if ( !Input::exists( 'startDate' ) ) {
self::addUserError( 'You must specify startDate' );
return false;
}
return true;
}
/**
* Validates the edit project post form.
*
* @return {bool}
*/
public static function editProject() {
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'description' ) ) {
self::addUserError( 'You must specify description' );
return false;
}
if ( !Input::exists( 'progress' ) ) {
self::addUserError( 'You must specify progress' );
return false;
}
if ( !Input::exists( 'startDate' ) ) {
self::addUserError( 'You must specify startDate' );
return false;
}
return true;
}
}
new WipForms;

View File

@ -0,0 +1,85 @@
<?php
/**
* app/plugins/wip/models/projects.php
*
* This class is used for the manipulation of the projects database table.
*
* @package TP WIP
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Models;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\Plugins\Wip as Plugin;
class Projects extends DatabaseModel {
public $tableName = 'projects';
public $databaseMatrix = [
[ 'title', 'varchar', '128' ],
[ 'description', 'text', '' ],
[ 'progress', 'int', '3' ],
[ 'startDate', 'varchar', '32' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
public function create( $title, $description, $progress, $startDate ) {
if ( !$this->plugin->checkEnabled() ) {
Debug::info( 'Wip is disabled in the config.' );
return false;
}
$fields = [
'title' => $title,
'description' => $description,
'progress' => $progress,
'startDate' => $startDate,
];
if ( !self::$db->insert( $this->tableName, $fields ) ) {
Debug::info( 'Projects::create - failed to insert to db' );
return false;
}
return self::$db->lastId();
}
public function update( $id, $fields ) {
if ( !Check::id( $id ) ) {
Debug::info( 'Project:update: illegal ID.' );
return false;
}
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
// new CustomException( 'projectUpdate' );
Debug::error( "Project:update: $id not updated: $fields" );
return false;
}
return true;
}
public function filter( $postArray, $params = [] ) {
foreach ( $postArray as $instance ) {
if ( !is_object( $instance ) ) {
$instance = $postArray;
$end = true;
}
$instance->prettyStart = $instance->startDate;
$out[] = $instance;
if ( !empty( $end ) ) {
$out = $out[0];
break;
}
}
return $out;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* app/plugins/wip/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Wip
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins;
use TheTempusProject\Classes\Plugin;
class Wip extends Plugin {
public $pluginName = 'TP Wip';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin which adds management for a wip.';
public $configName = 'wip';
public $configMatrix = [
'enabled' => [
'type' => 'radio',
'pretty' => 'Enable the wip Feature.',
'default' => true,
],
];
public $main_links = [
[
'text' => 'WIP',
'url' => '{ROOT_URL}wip/index',
],
];
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-support"></i> Wip',
'url' => '{ROOT_URL}admin/wip',
],
];
}

View File

@ -0,0 +1,16 @@
<h2>Create Project</h2>
<form action="#" method="POST">
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" required><br><br>
<label for="progress">Progress:</label><br>
<input type="text" id="progress" name="progress" required><br><br>
<label for="startDate">Start Month/Year:</label><br>
<input type="month" id="startDate" name="startDate" required><br><br>
<label for="description">Description:</label><br>
<textarea id="description" name="description" rows="20" cols="50" required></textarea><br><br>
<input type="submit" name="submit" value="Submit">
</form>

View File

@ -0,0 +1,16 @@
<h2>Edit Project</h2>
<form action="#" method="POST">
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" value="{title}" required><br><br>
<label for="progress">Progress:</label><br>
<input type="text" id="progress" name="progress" value="{progress}" required><br><br>
<label for="startDate">Start Month/Year:</label><br>
<input type="month" id="startDate" name="startDate" value="{startDate}" required><br><br>
<label for="description">Description:</label><br>
<textarea id="description" name="description" rows="20" cols="50" required>{description}</textarea><br><br>
<input type="submit" name="submit" value="Submit">
</form>

View File

@ -0,0 +1,41 @@
<legend>Works in Progress</legend>
{PAGINATION}
<form action="{ROOT_URL}admin/wip/delete" method="post">
<table class="table table-striped">
<thead>
<tr>
<th style="width: 30%">Title</th>
<th style="width: 20%">Progress</th>
<th style="width: 20%">Start Date</th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
<th style="width: 10%">
<INPUT type="checkbox" onchange="checkAll(this)" name="check.b" value="P_[]"/>
</th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td><a href="{ROOT_URL}admin/wip/view/{ID}">{title}</a></td>
<td>{progress}</td>
<td>{startDate}</td>
<td><a href="{ROOT_URL}admin/wip/edit/{ID}" class="btn btn-sm btn-warning" role="button"><i class="glyphicon glyphicon-edit"></i></a></td>
<td><a href="{ROOT_URL}admin/wip/delete/{ID}" class="btn btn-sm btn-danger" role="button"><i class="glyphicon glyphicon-trash"></i></a></td>
<td>
<input type="checkbox" value="{ID}" name="P_[]">
</td>
</tr>
{/LOOP}
{ALT}
<tr>
<td colspan="7">
No results to show.
</td>
</tr>
{/ALT}
</tbody>
</table>
<a href="{ROOT_URL}admin/wip/create" class="btn btn-sm btn-primary" role="button">Create</a>
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>

View File

@ -0,0 +1,8 @@
<legend>WIP</legend>
<div class="wip-project">
<h3 class="wip-project-title">{name}</h3>
<p><b>{position}</b> from <i>{prettyStart}</i> to <i>{prettyEnd}</i></p>
<div class="well">
{details}
</div>
</div>

View File

@ -0,0 +1,19 @@
<h1>Work in Progress</h1>
<hr>
{LOOP}
<div class="wip-project">
<h3 class="wip-project-title">{title}</h3>
<p><b>Started: </b><i>{prettyStart}</i></p>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {progress}%" aria-valuenow="{progress}" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="well">
{description}
</div>
</div>
{/LOOP}
{ALT}
<div class="wip-project">
<p>None Found</p>
</div>
{/ALT}