Skip to content

Commit

Permalink
Merge pull request #148 from renatomarinho/develop
Browse files Browse the repository at this point in the history
big rafactoring
  • Loading branch information
renatomarinho committed Jan 14, 2017
2 parents ddf36c7 + b4ef007 commit 6d3d28a
Show file tree
Hide file tree
Showing 67 changed files with 600 additions and 645 deletions.
16 changes: 16 additions & 0 deletions app/Classes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace GitScrum\Classes;

use Illuminate\Pagination\LengthAwarePaginator;
use GitScrum\Models\IssueType;
use GitScrum\Models\ConfigIssueEffort;
use Carbon\Carbon;
use Auth;

Expand Down Expand Up @@ -68,6 +70,20 @@ public static function burndown($obj, $subDays = null)
return $arr;
}

public static function issueTypes()
{
return IssueType::where('enabled', 1)
->orderby('position', 'ASC')
->get();
}

public static function issueEfforts()
{
return ConfigIssueEffort::where('enabled', 1)
->orderby('position', 'ASC')
->get();
}

public static function request($url, $auth = true, $customRequest = null, $postFields = null)
{
$user = Auth::user();
Expand Down
66 changes: 17 additions & 49 deletions app/Http/Controllers/IssueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
use GitScrum\Models\UserStory;
use GitScrum\Models\Issue;
use GitScrum\Models\Organization;
use GitScrum\Models\IssueType;
use GitScrum\Models\ConfigStatus;
use GitScrum\Models\ConfigIssueEffort;
use Carbon\Carbon;
use Auth;

Expand Down Expand Up @@ -59,7 +57,7 @@ public function index($slug)

$issues = $issues->sortBy('position')->groupBy('config_status_id');

$configStatus = ConfigStatus::type('issue')->get();
$configStatus = ConfigStatus::type('issues')->get();

if (!is_null($sprint) && !count($sprint)) {
return redirect()->route('sprints.index');
Expand All @@ -71,40 +69,20 @@ public function index($slug)
->with('configStatus', $configStatus);
}

public function create($slug_sprint = null, $slug_user_story = null, $parent_id = null)
public function create($scope, $slug, $parent_id = null)
{
$issue_types = IssueType::where('enabled', 1)
->orderby('position', 'ASC')
->get();

$issue_efforts = ConfigIssueEffort::where('enabled', 1)
->orderby('position', 'ASC')
->get();

$userStory = $productBacklogs = null;

if ((is_null($slug_sprint) || !$slug_sprint) && $slug_user_story) {
$userStory = UserStory::slug($slug_user_story)->first();
$productBacklogs = Auth::user()->productBacklogs($userStory->product_backlog_id);
$usersByOrganization = Organization::find($userStory->productBacklog->organization_id)->users;
} elseif ($slug_sprint) {
$usersByOrganization = Organization::find(Sprint::slug($slug_sprint)->first()
->productBacklog->organization_id)->users;
} else {
$issue = Issue::find($parent_id);
$productBacklogs = $issue->product_backlog_id;
$usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users;
}
$model = 'GitScrum\\Models\\'.$scope;

$obj = $model::slug($slug)->first();
$organization = Organization::find($obj->productBacklog->organization_id);

return view('issues.create')
->with('productBacklogs', $productBacklogs)
->with('userStory', $userStory)
->with('slug', $slug_sprint)
->with('relation', with(new $model)->getTable())
->with('obj', $obj)
->with('organization', $organization)
->with('parent_id', $parent_id)
->with('issue_types', $issue_types)
->with('issue_efforts', $issue_efforts)
->with('usersByOrganization', $usersByOrganization)
->with('action', 'Create');

}

public function store(IssueRequest $request)
Expand Down Expand Up @@ -137,26 +115,16 @@ public function show($slug)

public function edit($slug)
{
$issue = Issue::slug($slug)->first();
$obj = $issue = Issue::slug($slug)->first();

$issue_types = IssueType::where('enabled', 1)
->orderby('position', 'ASC')
->get();
$organization = Organization::find($issue->productBacklog->organization_id);

$issue_efforts = ConfigIssueEffort::where('enabled', 1)
->orderby('position', 'ASC')
->get();

$usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users;

return view('issues.edit')
->with('productBacklogs', $issue->productBacklog->id)
->with('userStory', $issue->userStory)
->with('slug', isset($issue->sprint->slug) ? $issue->sprint->slug : null)
->with('issue_types', $issue_types)
->with('issue_efforts', $issue_efforts)
->with('usersByOrganization', $usersByOrganization)
return view('issues.create')
->with('relation', 'issue')
->with('issue', $issue)
->with('obj', $obj)
->with('organization', $organization)
->with('parent_id', $issue->parent_id)
->with('action', 'Edit');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SprintController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function show($slug)
return redirect()->route('sprints.index');
}

$configStatus = ConfigStatus::type('sprint')->get();
$configStatus = ConfigStatus::type('sprints')->get();

return view('sprints.show')
->with('sprint', $sprint)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function dashboard()
'tbody_sprintBacklog',
'tbody_sprintProductBacklog', ];

$sprints = $sprints->map(function ($sprint) use ($sprintColumns) {
$sprints = $sprints->get()->map(function ($sprint) use ($sprintColumns) {
$sprint['column'] = $sprintColumns;

return $sprint;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserStoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function show($slug)
$userStory = UserStory::slug($slug)
->with('labels')
->first();

return view('user_stories.show')
->with('userStory', $userStory);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/IssueMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ class IssueMiddleware
*/
public function handle($request, Closure $next)
{
/*
try {
if (isset($request->slug)) {
Issue::slug($request->slug)->firstOrFail();
}
} catch (\Exception $e) {
return redirect()->route('user.dashboard');
}
}*/

return $next($request);
}
Expand Down
7 changes: 2 additions & 5 deletions app/Models/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use GitScrum\Scopes\GlobalScope;

class Attachment extends Model
{
use SoftDeletes;
use GlobalScope;

/**
* The database table used by the model.
Expand Down Expand Up @@ -51,11 +53,6 @@ class Attachment extends Model
*/
protected $dates = ['deleted_at'];

protected static function boot()
{
parent::boot();
}

public function attachmentable()
{
return $this->morphTo('attachmentable');
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
namespace GitScrum\Models;

use Illuminate\Database\Eloquent\Model;
use GitScrum\Scopes\GlobalScope;

class Branch extends Model
{
use GlobalScope;
/**
* The database table used by the model.
*
Expand Down
13 changes: 1 addition & 12 deletions app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Carbon\Carbon;
use GitScrum\Scopes\GlobalScope;

class Comment extends Model
{
use SoftDeletes;
use GlobalScope;

/**
* The database table used by the model.
*
Expand Down Expand Up @@ -48,11 +47,6 @@ class Comment extends Model

protected $dates = ['deleted_at'];

protected static function boot()
{
parent::boot();
}

public function user()
{
return $this->belongsTo(\GitScrum\Models\User::class, 'user_id', 'id');
Expand All @@ -68,9 +62,4 @@ public function statuses()
return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
->orderby('created_at', 'DESC');
}

public function getDateforhumansAttribute()
{
return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['created_at'])->diffForHumans();
}
}
54 changes: 4 additions & 50 deletions app/Models/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
namespace GitScrum\Models;

use Illuminate\Database\Eloquent\Model;
use GitScrum\Scopes\CommitScope;
use GitScrum\Scopes\GlobalScope;
use Carbon\Carbon;

class Commit extends Model
{
use GlobalScope;
use CommitScope;
/**
* The database table used by the model.
*
Expand Down Expand Up @@ -73,56 +77,6 @@ public function files()
return $this->hasMany(\GitScrum\Models\CommitFile::class, 'commit_id', 'id');
}

public function totalLines()
{
$lines = $this->files->map(function ($file) {
return count(preg_split('/\R/', $file->raw));
});

return array_sum($lines->all());
}

public function totalAdditions()
{
$additions = $this->files->map(function ($file) {
return $file->additions;
});

return array_sum($additions->all());
}

public function totalChanges()
{
$changes = $this->files->map(function ($file) {
return $file->changes;
});

return array_sum($changes->all());
}

public function totalDeletions()
{
$deletions = $this->files->map(function ($file) {
return $file->deletions;
});

return array_sum($deletions->all());
}

public function totalPHPCS($type = 'ERROR')
{
$errors = $this->files->map(function ($file) use ($type) {
return $file->filePhpcs()->where('type', '=', $type)->groupBy('type')->count();
});

return array_sum($errors->all());
}

public function getDateforhumansAttribute()
{
return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['created_at'])->diffForHumans();
}

public function comments()
{
return $this->morphMany(\GitScrum\Models\Comment::class, 'commentable');
Expand Down
16 changes: 4 additions & 12 deletions app/Models/CommitFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
namespace GitScrum\Models;

use Illuminate\Database\Eloquent\Model;
use GitScrum\Scopes\CommitFileScope;
use GitScrum\Scopes\GlobalScope;

class CommitFile extends Model
{
use CommitFileScope;
use GlobalScope;
/**
* The database table used by the model.
*
Expand Down Expand Up @@ -50,18 +54,6 @@ public function filePhpcs()
return $this->hasMany(\GitScrum\Models\CommitFilePhpc::class, 'commit_file_id', 'id');
}

public function totalLines()
{
$total = preg_split('/\R/', $this->raw);

return count($total);
}

public function totalPHPCS($type = 'ERROR')
{
return $this->filePhpcs()->where('type', '=', $type)->groupBy('type')->count();
}

public function getAdditionsAttribute()
{
return $this->attributes['additions'] !== null ? $this->attributes['additions'] : 0;
Expand Down
2 changes: 2 additions & 0 deletions app/Models/CommitFilePhpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
namespace GitScrum\Models;

use Illuminate\Database\Eloquent\Model;
use GitScrum\Scopes\GlobalScope;

class CommitFilePhpc extends Model
{
use GlobalScope;
/**
* The database table used by the model.
*
Expand Down
2 changes: 2 additions & 0 deletions app/Models/ConfigIssueEffort.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
namespace GitScrum\Models;

use Illuminate\Database\Eloquent\Model;
use GitScrum\Scopes\GlobalScope;

class ConfigIssueEffort extends Model
{
use GlobalScope;
/**
* The database table used by the model.
*
Expand Down
2 changes: 2 additions & 0 deletions app/Models/ConfigPriority.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
namespace GitScrum\Models;

use Illuminate\Database\Eloquent\Model;
use GitScrum\Scopes\GlobalScope;

class ConfigPriority extends Model
{
use GlobalScope;
/**
* The database table used by the model.
*
Expand Down
Loading

0 comments on commit 6d3d28a

Please sign in to comment.