Browse Source

#860q2vq2t sortorder

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
9851f12cfc
  1. 43
      app/Http/Controllers/ActivityController.php
  2. 2
      app/Models/Activity.php

43
app/Http/Controllers/ActivityController.php

@ -45,9 +45,9 @@ class ActivityController extends Controller
$dataHeader->type = "header";
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get();
}else{
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
}
foreach($data as $objRow){
@ -68,6 +68,9 @@ class ActivityController extends Controller
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->progress = $objRow->persentase_progress / 100;
if ($objRow->sortorder == 0 || $objRow->sortorder == null) {
$objRow->sortorder = $objRow->id;
}
$objRow->type = $type;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
@ -100,7 +103,7 @@ class ActivityController extends Controller
private function getChildren($gantt_id, $parent_id)
{
$finalData = [];
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach($data as $objRow){
$objRow->parent = $parent_id;
$objRow->text = $objRow->name;
@ -111,6 +114,9 @@ class ActivityController extends Controller
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
if ($objRow->sortorder == 0 || $objRow->sortorder == null) {
$objRow->sortorder = $objRow->id;
}
$dataChildren = $this->getChildren($gantt_id, $objRow->id);
if($objRow->type_activity=="milestone"){
$objRow->type = $objRow->type_activity;
@ -203,6 +209,7 @@ class ActivityController extends Controller
$data['name'] = $request->text;
$data['persentase_progress'] = $request->progress;
$data['created_by'] = $this->currentName;
$data['sortorder'] = Activity::max("sortorder") + 1;
$data['type_activity'] = "task";
$parent = $data['parent_id'] ?? null;
@ -246,6 +253,10 @@ class ActivityController extends Controller
$dataUpdate['updated_by'] = $this->currentName;
if($data->type_activity!='header')
$dataUpdate['type_activity'] = $request->type;
if($request->has("target")){
$this->updateOrder($id, $request->target);
}
if(!$data->update($dataUpdate))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400);
@ -253,6 +264,29 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200);
}
private function updateOrder($taskId, $target){
$nextTask = false;
$targetId = $target;
if(strpos($target, "next:") === 0){
$targetId = substr($target, strlen("next:"));
$nextTask = true;
}
if($targetId == "null")
return;
$targetOrder = Activity::find($targetId)->sortorder;
if($nextTask)
$targetOrder++;
Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder");
$updatedTask = Activity::find($taskId);
$updatedTask->sortorder = $targetOrder;
$updatedTask->save();
}
public function updateRegular(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -326,7 +360,8 @@ class ActivityController extends Controller
$input['bobot_planning'] = $activity_row['weight'];
$input['persentase_progress'] = 0;
$input['type_activity'] = $i == 0 ? "header" : "task";
$input['created_by'] = $this->currentName;
$input['created_by'] = $this->currentName;
$input['sortorder'] = $activity_row['no'];
if (!$activity = Activity::create($input)) {
Activity::where('version_gantt_id', $data['ganttId'])->delete();

2
app/Models/Activity.php

@ -26,7 +26,7 @@ class Activity extends Model
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id',
'created_at', 'created_by', 'updated_at', 'updated_by'
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder'
];
protected $appends = [

Loading…
Cancel
Save