Browse Source

#860q2vq2t sortorder

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

41
app/Http/Controllers/ActivityController.php

@ -45,9 +45,9 @@ class ActivityController extends Controller
$dataHeader->type = "header"; $dataHeader->type = "header";
$dataHeader->text = $dataHeader->name; $dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader; $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{ }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){ 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_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->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; $objRow->progress = $objRow->persentase_progress / 100;
if ($objRow->sortorder == 0 || $objRow->sortorder == null) {
$objRow->sortorder = $objRow->id;
}
$objRow->type = $type; $objRow->type = $type;
$finalData[] = $objRow; $finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren); $finalData = array_merge($finalData, $dataChildren);
@ -100,7 +103,7 @@ class ActivityController extends Controller
private function getChildren($gantt_id, $parent_id) private function getChildren($gantt_id, $parent_id)
{ {
$finalData = []; $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){ foreach($data as $objRow){
$objRow->parent = $parent_id; $objRow->parent = $parent_id;
$objRow->text = $objRow->name; $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->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_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->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); $dataChildren = $this->getChildren($gantt_id, $objRow->id);
if($objRow->type_activity=="milestone"){ if($objRow->type_activity=="milestone"){
$objRow->type = $objRow->type_activity; $objRow->type = $objRow->type_activity;
@ -203,6 +209,7 @@ class ActivityController extends Controller
$data['name'] = $request->text; $data['name'] = $request->text;
$data['persentase_progress'] = $request->progress; $data['persentase_progress'] = $request->progress;
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['sortorder'] = Activity::max("sortorder") + 1;
$data['type_activity'] = "task"; $data['type_activity'] = "task";
$parent = $data['parent_id'] ?? null; $parent = $data['parent_id'] ?? null;
@ -247,12 +254,39 @@ class ActivityController extends Controller
if($data->type_activity!='header') if($data->type_activity!='header')
$dataUpdate['type_activity'] = $request->type; $dataUpdate['type_activity'] = $request->type;
if($request->has("target")){
$this->updateOrder($id, $request->target);
}
if(!$data->update($dataUpdate)) if(!$data->update($dataUpdate))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); 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); 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){ public function updateRegular(Request $request, $id){
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); 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['persentase_progress'] = 0;
$input['type_activity'] = $i == 0 ? "header" : "task"; $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)) { if (!$activity = Activity::create($input)) {
Activity::where('version_gantt_id', $data['ganttId'])->delete(); 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', 'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan', 'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id', '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 = [ protected $appends = [

Loading…
Cancel
Save