Skip to content

Commit

Permalink
Implement setting to select default tag for new issue
Browse files Browse the repository at this point in the history
Fixes #85
  • Loading branch information
satrun77 committed May 10, 2016
1 parent 91f8d96 commit f089cf0
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
17 changes: 17 additions & 0 deletions app/Form/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ protected function fieldDateFormat(Model\Setting $setting)
];
}

/**
* Select status tag for default first status.
*
* @param Model\Setting $setting
*
* @return array
*/
protected function fieldFirstStatusTag(Model\Setting $setting)
{
return [
'type' => 'select',
'label' => 'first_status_tag',
'value' => $setting->value,
'options' => (new Model\Tag())->getStatusTags()->get()->lists('fullname', 'id'),
];
}

/**
* @return array
*/
Expand Down
7 changes: 7 additions & 0 deletions app/Model/Traits/Project/Issue/CrudTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Tinyissue\Model\Project;
use Tinyissue\Model\Project\Issue\Attachment;
use Tinyissue\Model\User;
use Tinyissue\Services\SettingsManager;

/**
* CrudTrait is trait class containing the methods for adding/editing/deleting the Project\Issue model.
Expand Down Expand Up @@ -156,6 +157,12 @@ public function createIssue(array $input)
->where('uploaded_by', '=', $this->user->id)
->update(['issue_id' => $this->id]);

// Add default tag to newly created issue
$defaultTag = app('tinyissue.settings')->getFirstStatusTagId();
if ($defaultTag > 0 && empty($input['tag_status'])) {
$input['tag_status'] = $defaultTag;
}

$this->syncTags($input);

return $this;
Expand Down
10 changes: 10 additions & 0 deletions app/Services/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public function getDateFormat()
return (string) $this->get('date_format');
}

/**
* Returns first status tag id.
*
* @return int
*/
public function getFirstStatusTagId()
{
return (string) $this->get('first_status_tag');
}

/**
* Save a collection of settings.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Tinyissue\Model\Setting;

class AddSettingsFirstStatusTag extends Migration
{
/**
* List of settings to insert.
*
* @var array
*/
protected $data = [
'first_status_tag' => [
'name' => 'first_status_tag',
'value' => 0,
],
];

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach ($this->data as $key => $row) {
$settings = new Setting();
$settings->fill([
'name' => $row['name'],
'value' => $row['value'],
'key' => $key,
])->save();
unset($settings);
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
foreach ($this->data as $key => $row) {
$settings = new Setting();
$setting = $settings->where('key', '=', $key)->first();
if ($setting) {
$setting->delete();
}
unset($settings);
}
}
}
8 changes: 3 additions & 5 deletions resources/views/project/issue/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
@endif

<div class="activity-tags">
@if($issue->isNew())
<label class="label" style="background: green">{!! Html::formatIssueTag('New') !!}</label>
@elseif(!$issue->isOpen())
@if(!$issue->isOpen())
<label class="label" style="background: lightgray">{!! Html::formatIssueTag('Closed') !!}</label>
@endif

@foreach($issue->tags()->with('parent')->get() as $tag)
<label class="label" style="background: {{ $tag->bgcolor or 'gray' }}">{!! Html::formatIssueTag($tag->name, $tag->parent->name) !!}</label>
@foreach($issue->tags as $tag)
<label class="label" style="background: {{ $tag->bgcolor or 'gray' }}">{!! Html::formatIssueTag($tag->name) !!}</label>
@endforeach
</div>

Expand Down

0 comments on commit f089cf0

Please sign in to comment.