Browse Source

Merge branch 'mahdi' of https://gitea.hooradev.ir/mahdihty/liwo into mohammad

pull/2/head
Mohammad Akbari 4 years ago
parent
commit
3ebb402c18
Signed by: akbarjimi GPG Key ID: 55726AEFECE5E683
  1. 2
      app/Http/Controllers/StatisticController.php
  2. 24
      app/Http/Controllers/TaskController.php
  3. 6
      app/Http/Controllers/WorkController.php
  4. 2
      app/Http/Resources/TaskResource.php
  5. 6
      app/Models/Task.php
  6. 2
      app/Models/Work.php
  7. 2
      app/Models/Workflow.php
  8. 2
      database/migrations/2020_08_18_085114_create_tags_table.php

2
app/Http/Controllers/StatisticController.php

@ -43,7 +43,7 @@ class StatisticController extends Controller
$this->addSystems($result, $task);
$this->addTags($result, $task, $tags[$task->id]);
$this->addTags($result, $task, $tags[$task->id] ?? []);
}
return $result;

24
app/Http/Controllers/TaskController.php

@ -6,7 +6,7 @@ use Carbon\Carbon;
use App\Models\Task;
use App\Models\Work;
use App\Models\TagTask;
use App\Rules\maxBound;
use App\Rules\MaxBound;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
@ -30,20 +30,20 @@ class TaskController extends Controller
return $request->filled('group') ?
$tasks->get()->groupBy($request->group)
->map(function ($q) { return $q->keyBy('status_id'); })
: /*response()->json(collect(['now' => Carbon::now()->toDateString()])->merge(*/new TaskCollection($tasks->paginate($per_page));//));
: new TaskCollection($tasks->paginate($per_page));
}
public function indexValidation($request)
{
$bound = 10;
$this->validate($request, [
'filter.project_id' => [new maxBound($bound)] ,
'filter.creator_id' => [new maxBound($bound)] ,
'filter.assignee_id' => [new maxBound($bound)] ,
'filter.system_id' => [new maxBound($bound)] ,
'filter.workflow_id' => [new maxBound($bound)] ,
'filter.status_id' => [new maxBound($bound)] ,
'filter.approver_id' => [new maxBound($bound)] ,
'filter.project_id' => [new MaxBound($bound)] ,
'filter.creator_id' => [new MaxBound($bound)] ,
'filter.assignee_id' => [new MaxBound($bound)] ,
'filter.system_id' => [new MaxBound($bound)] ,
'filter.workflow_id' => [new MaxBound($bound)] ,
'filter.status_id' => [new MaxBound($bound)] ,
'filter.approver_id' => [new MaxBound($bound)] ,
'filter.priority_min' => 'nullable|numeric|between:1,10' ,
'filter.priority_max' => 'nullable|numeric|between:1,10' ,
'filter.ready_to_test' => 'nullable|boolean' ,
@ -55,7 +55,7 @@ class TaskController extends Controller
{
$query = Task::where('business_id', $business);
$taskQ = QueryBuilder::for($query)
->with('tagTask')
// ->with('tags')
->select(DB::raw('tasks.* , (spent_time - estimated_time) as over_spent'))
->allowedFilters([
AllowedFilter::exact('project_id'),
@ -140,7 +140,7 @@ class TaskController extends Controller
public function store($business, $project, Request $request)
{
// permit('projectTasks', ['project_id' => $project]);
permit('projectTasks', ['project_id' => $project]);
$task = Task::create($request->merge(
['business_id' => $business, 'project_id' => $project, 'creator_id' => \auth()->id()]
@ -167,7 +167,7 @@ class TaskController extends Controller
* 1) guest's only can see self task
* 2) user is active in project
*/
public function show($business, $task, $project =null)
public function show($business, $project, $task)
{
$task = Task::findOrFail($task);
$project = $task->project_id;

6
app/Http/Controllers/WorkController.php

@ -124,7 +124,7 @@ class WorkController extends Controller
// 'work_start' => Work::where('task_id', $taskModel->id)->orderBy('started_at')->first()->started_at ?? null,
// 'spent_time' => $taskModel->spent_time + $diff_in_min
// ]);
return $taskModel->load(['tagTask'=> fn($q) => $q->select('id', 'tag_id', 'task_id'), 'works', 'comments']);
return $taskModel->load(['tags', 'works', 'comments']);
}
public function storeValidation($request, $taskModel)
@ -187,7 +187,7 @@ class WorkController extends Controller
// 'work_start' => Work::where('task_id', $taskModel->id)->orderBy('started_at')->first()->started_at ?? null,
// 'spent_time' => ($taskModel->spent_time - $old_diff_in_min) + $new_diff_in_min
// ]);
return $taskModel->load(['tagTask'=> fn($q) => $q->select('id', 'tag_id', 'task_id'), 'works', 'comments']);
return $taskModel->load(['tags', 'works', 'comments']);
}
public function updateValidation($request, $taskModel, $workModel)
@ -237,6 +237,6 @@ class WorkController extends Controller
'work_start' => Work::where('task_id', $taskModel->id)->orderBy('started_at')->first()->started_at ?? null,
'spent_time' => ($taskModel->spent_time - $diff_in_min)
]);
return $taskModel->load(['tagTask'=> fn($q) => $q->select('id', 'tag_id', 'task_id'), 'works','comments']);
return $taskModel->load(['tags', 'works','comments']);
}
}

2
app/Http/Resources/TaskResource.php

@ -21,7 +21,7 @@ class TaskResource extends JsonResource
}
}
$resource['tags'] = $this->tagTask()->pluck('tag_id')->toArray();
$resource['tags'] = $this->tags;
$resource['works'] = $this->works;
$resource['comments'] = $this->comments;

6
app/Models/Task.php

@ -158,12 +158,10 @@ class Task extends Model
public function tags()
{
return $this->belongsToMany(
Tag::class, 'tag_task', 'task_id', 'tag_id',
'id', 'id', __FUNCTION__
)->using(ReportableRelation::class);
return $this->belongsToMany(Tag::class)->using(ReportableRelation::class);
}
// Todo: are we need this relation????
public function tagTask()
{
return $this->hasMany(TagTask::class, 'task_id', 'id');

2
app/Models/Work.php

@ -37,7 +37,7 @@ class Work extends Model
'ended_at' => [
'required', 'date_format:Y-m-d H:i', 'after:'.$started_at,
function ($attribute, $value, $fail) use ($ended_at, $started_at) {
$works = \App\Work::where([
$works = $this::where([
['ended_at', '>', $started_at],
['ended_at', '<', $ended_at],
])->orWhere([

2
app/Models/Workflow.php

@ -38,6 +38,8 @@ class Workflow extends Model
'status_id' => null,
'system_id' => null,
'user_id' => null,
'task_id' => null,
'subject_id' => $this->id,
];
if ($key && isset($values, $key)) {

2
database/migrations/2020_08_18_085114_create_tags_table.php

@ -23,8 +23,10 @@ class CreateTagsTable extends Migration
});
Schema::create('tag_task', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tag_id');
$table->unsignedBigInteger('task_id');
$table->timestamps();
});
}

Loading…
Cancel
Save