Skip to content

Commit

Permalink
Feature: generic add issue form in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
satrun77 committed Oct 17, 2015
1 parent e75b49a commit 8f14e9c
Show file tree
Hide file tree
Showing 28 changed files with 396 additions and 124 deletions.
38 changes: 19 additions & 19 deletions app/Console/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class Install extends Command
{
const COLOR_GOOD = 'green';
const COLOR_BAD = 'red';
const COLOR_BAD = 'red';
const COLOR_INFO = 'blue';

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function checkEnvironment()
$this->checkPhpExtension($this->dbDrivers, '{module} driver for pdo', false, 'Not Found');

// Whether or not one or more valid drivers were found
$validDrivers = $this->getValidDbDrivers();
$validDrivers = $this->getValidDbDrivers();
$dbDriverStatus = !empty($validDrivers);
if (!$dbDriverStatus) {
$dbDriverTitle = 'Install one of the following pdo drivers ('
Expand Down Expand Up @@ -195,8 +195,8 @@ protected function checkEnvironment()
protected function checkPhpExtension(array &$modules, $labelFormat, $required = true, $failedLabel = 'No')
{
foreach ($modules as $module => $status) {
$title = str_replace(['{module}'], [$module], $labelFormat);
$status = extension_loaded($module);
$title = str_replace(['{module}'], [$module], $labelFormat);
$status = extension_loaded($module);
$modules[$module] = $status;
$this->envRequirementsRow($title, $status, $required, $failedLabel);
}
Expand All @@ -216,8 +216,8 @@ protected function checkPhpExtension(array &$modules, $labelFormat, $required =
*/
protected function envRequirementsRow($label, $status = false, $required = false, $failedLabel = 'No')
{
$statusColor = $status ? static::COLOR_GOOD : ($required ? static::COLOR_BAD : static::COLOR_INFO);
$statusTitle = $status ? 'OK' : $failedLabel;
$statusColor = $status ? static::COLOR_GOOD : ($required ? static::COLOR_BAD : static::COLOR_INFO);
$statusTitle = $status ? 'OK' : $failedLabel;
$this->envRequirements[] = $this->formatTableCells([$label, $statusTitle], $statusColor);
if ($required) {
$this->envStatus = $status;
Expand Down Expand Up @@ -261,13 +261,13 @@ protected function getValidDbDrivers()
protected function isUploadDirectoryPublic()
{
$pathSegments = explode('/', base_path());
$count = count($pathSegments);
$indexes = [];
$count = count($pathSegments);
$indexes = [];
for ($i = 0; $i < $count; ++$i) {
$indexes[] = $i;
$path = implode('/', array_except($pathSegments, $indexes));
$guessUrl = url($path . '/storage/app/uploads');
$curl = curl_init($guessUrl);
$path = implode('/', array_except($pathSegments, $indexes));
$guessUrl = url($path . '/storage/app/uploads');
$curl = curl_init($guessUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_exec($curl);
Expand Down Expand Up @@ -329,12 +329,12 @@ protected function stageOne()
'sysName' => 'Email name used by the Tiny Issue for the email address above',
'timezone' => 'The application timezone. Find your timezone from: http://php.net/manual/en/timezones.php)',
]);
$this->data['key'] = md5(str_random(40));
$this->data['key'] = md5(str_random(40));
$this->data['dbDriver'] = substr($this->data['dbDriver'], 4);

// Create .env from .env.example and populate with user data
$filesystem = $this->getFilesystem();
$content = $filesystem->read('.env.example');
$content = $filesystem->read('.env.example');
if (empty($content)) {
throw new \Exception('Unable to read .env.example to create .env file.');
}
Expand All @@ -348,13 +348,13 @@ protected function stageOne()
$filesystem->put('.env', $content);

// Update the current database connection
$config = \Config::get('database.connections.' . $this->data['dbDriver']);
$config['driver'] = $this->data['dbDriver'];
$config['host'] = $this->data['dbHost'];
$config = \Config::get('database.connections.' . $this->data['dbDriver']);
$config['driver'] = $this->data['dbDriver'];
$config['host'] = $this->data['dbHost'];
$config['database'] = $this->data['dbName'];
$config['username'] = $this->data['dbUser'];
$config['password'] = $this->data['dbPass'];
$config['prefix'] = $this->data['dbPrefix'];
$config['prefix'] = $this->data['dbPrefix'];
\Config::set('database.connections.' . $this->data['dbDriver'], $config);
\Config::set('database.default', $this->data['dbDriver']);

Expand Down Expand Up @@ -394,10 +394,10 @@ protected function askQuestions(array $questions)

foreach ($questions as $name => $question) {
if (is_array($question)) {
$question[1][0] = $labelFormat($question[1][0], $this->data[$name]);
$question[1][0] = $labelFormat($question[1][0], $this->data[$name]);
$this->data[$name] = call_user_func_array([$this, $question[0]], $question[1]);
} else {
$question = $labelFormat($question, $this->data[$name]);
$question = $labelFormat($question, $this->data[$name]);
$this->data[$name] = $this->ask($question, $this->data[$name]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Extensions/Html/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function form(FormInterface $form, array $attrs = [])

// Start a form and add rules
$formType = $form->openType();
$former = Former::$formType();
$former = Former::$formType();
array_walk($attrs, function ($value, $attr) use ($former) {
if ($value === null) {
$former->$attr();
Expand Down Expand Up @@ -87,7 +87,7 @@ public function form(FormInterface $form, array $attrs = [])
public function element($name, array $field)
{
$filterKeys = ['type'];
$attrs = array_diff_key($field, array_flip($filterKeys));
$attrs = array_diff_key($field, array_flip($filterKeys));

// Create field with name
$element = Former::$field['type']($name);
Expand All @@ -113,7 +113,7 @@ public function element($name, array $field)
*/
public function actions(FormInterface $form)
{
$output = '';
$output = '';
$buttons = $form->actions();
if (!empty($buttons)) {
$actions = Former::actions()->addClass('form-actions');
Expand Down
2 changes: 1 addition & 1 deletion app/Extensions/Html/Traits/BlueBoxTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function box($content, $style = 'blue-box', $title = null, $moreLink = nu
public function startBox($style = 'blue-box', $title = null, array $attrs = [])
{
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' . $style : $style;
$output = '<div ' . $this->attributes($attrs) . '><div class="inside-pad">';
$output = '<div ' . $this->attributes($attrs) . '><div class="inside-pad">';

if (!empty($title)) {
if (is_array($title)) {
Expand Down
12 changes: 6 additions & 6 deletions app/Extensions/Html/Traits/DateTimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function age($timestamp)
$timestamp = new \DateTime($timestamp);
}

$timestamp = $timestamp->getTimestamp();
$timestamp = $timestamp->getTimestamp();
$difference = time() - $timestamp;
$periods = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade'];
$lengths = ['60', '60', '24', '7', '4.35', '12', '10'];
$periods = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade'];
$lengths = ['60', '60', '24', '7', '4.35', '12', '10'];
for ($j = 0; $difference >= $lengths[$j]; ++$j) {
$difference /= $lengths[$j];
}
Expand All @@ -70,13 +70,13 @@ public function age($timestamp)
*/
public function duration($seconds)
{
$hours = floor($seconds / 3600);
$hours = floor($seconds / 3600);
$minutes = ($seconds / 60) % 60;
$seconds = $seconds % 60;

$output = '';
$output = '';
$separatorChar = ', ';
$separator = '';
$separator = '';
if ($hours > 0) {
$output .= $hours . ' ' . trans('tinyissue.short_hours');
$separator = $separatorChar;
Expand Down
2 changes: 1 addition & 1 deletion app/Form/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Comment extends FormAbstract
public function setup(array $params)
{
$this->project = $params['project'];
$this->issue = $params['issue'];
$this->issue = $params['issue'];
}

/**
Expand Down
104 changes: 104 additions & 0 deletions app/Form/GlobalIssue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/*
* This file is part of the Tinyissue package.
*
* (c) Mohamed Alsharaf <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tinyissue\Form;

use Tinyissue\Model;

/**
* GlobalIssue is a class to defines fields & rules for adding an issue form
*
* @author Mohamed Alsharaf <[email protected]>
*/
class GlobalIssue extends Issue
{
/**
* List of projects
*
* @var array
*/
protected $projects = [];

/**
* Returns list of logged in user projects
*
* @return array
*/
protected function getProjects()
{
if (!$this->projects) {
$this->projects = \Auth::user()->projects()->get()->lists('name', 'id');
}

return $this->projects;
}

/**
* @param array $params
*
* @return void
*/
public function setup(array $params)
{
$this->project = new Model\Project();
}

/**
* @return array
*/
public function actions()
{
return [
'submit' => 'create_issue',
];
}

/**
* @return array
*/
public function fields()
{
$fields = $this->fieldTitle();

$fields['project'] = [
'type' => 'select',
'label' => 'project',
'options' => $this->getProjects()->all(),
];

$fields += $this->fieldBody();
$fields += $this->fieldTags();

// Only on creating new issue
$fields += $this->fieldUpload();

return $fields;
}

/**
* @return array
*/
public function rules()
{
$rules = parent::rules();
$rules['project'] = 'required|in:' . $this->getProjects()->keys()->implode(',');

return $rules;
}

/**
* @return string
*/
public function getRedirectUrl()
{
return 'projects/new-issue';
}
}
Loading

0 comments on commit 8f14e9c

Please sign in to comment.