@ -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;
@ -247,12 +254,39 @@ class ActivityController extends Controller
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);
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);
@ -327,6 +361,7 @@ class ActivityController extends Controller
$input['persentase_progress'] = 0;
$input['type_activity'] = $i == 0 ? "header" : "task";
$input['created_by'] = $this->currentName;
$input['sortorder'] = $activity_row['no'];
if (!$activity = Activity::create($input)) {
Activity::where('version_gantt_id', $data['ganttId'])->delete();