From f089cf055d3c35d1459f1f75d84a4eb7d0f3dbf2 Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Tue, 10 May 2016 23:03:14 +1200 Subject: [PATCH] Implement setting to select default tag for new issue Fixes #85 --- app/Form/Settings.php | 17 ++++++ app/Model/Traits/Project/Issue/CrudTrait.php | 7 +++ app/Services/SettingsManager.php | 10 ++++ ...0_222358_add_settings_first_status_tag.php | 54 +++++++++++++++++++ resources/views/project/issue/index.blade.php | 8 ++- 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2016_05_10_222358_add_settings_first_status_tag.php diff --git a/app/Form/Settings.php b/app/Form/Settings.php index 03dfa3020..afcfb8be5 100644 --- a/app/Form/Settings.php +++ b/app/Form/Settings.php @@ -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 */ diff --git a/app/Model/Traits/Project/Issue/CrudTrait.php b/app/Model/Traits/Project/Issue/CrudTrait.php index 322913f00..a82327fb9 100644 --- a/app/Model/Traits/Project/Issue/CrudTrait.php +++ b/app/Model/Traits/Project/Issue/CrudTrait.php @@ -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. @@ -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; diff --git a/app/Services/SettingsManager.php b/app/Services/SettingsManager.php index a3eab063d..eac4c6a92 100644 --- a/app/Services/SettingsManager.php +++ b/app/Services/SettingsManager.php @@ -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. * diff --git a/database/migrations/2016_05_10_222358_add_settings_first_status_tag.php b/database/migrations/2016_05_10_222358_add_settings_first_status_tag.php new file mode 100644 index 000000000..0d5302e80 --- /dev/null +++ b/database/migrations/2016_05_10_222358_add_settings_first_status_tag.php @@ -0,0 +1,54 @@ + [ + '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); + } + } +} diff --git a/resources/views/project/issue/index.blade.php b/resources/views/project/issue/index.blade.php index ce85dee61..579b73512 100644 --- a/resources/views/project/issue/index.blade.php +++ b/resources/views/project/issue/index.blade.php @@ -32,14 +32,12 @@ @endif
- @if($issue->isNew()) - - @elseif(!$issue->isOpen()) + @if(!$issue->isOpen()) @endif - @foreach($issue->tags()->with('parent')->get() as $tag) - + @foreach($issue->tags as $tag) + @endforeach