|
@@ -16,10 +16,26 @@ use Ramsey\Uuid\Uuid;
|
|
|
|
|
|
class StatTreeLineController extends Controller
|
|
class StatTreeLineController extends Controller
|
|
{
|
|
{
|
|
|
|
+ public function reports()
|
|
|
|
+ {
|
|
|
|
+ $statTreeLines = StatTreeLine::whereNull('stat_tree_id')->get();
|
|
|
|
+ return view('app.stat-tree.stat-tree-line-reports.list', compact('statTreeLines'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function editReport(StatTreeLine $statTreeLine) {
|
|
|
|
+ $allClauses = Clause::orderByRaw('position_index ASC NULLS FIRST')->get();
|
|
|
|
+ return view('app.stat-tree.stat-tree-line-reports.edit', compact('statTreeLine', 'allClauses'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function viewReport(StatTreeLine $statTreeLine) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public function list()
|
|
public function list()
|
|
{
|
|
{
|
|
$statTreeLines = StatTreeLine::all();
|
|
$statTreeLines = StatTreeLine::all();
|
|
- return view('app.stat-tree-lines.list', compact('statTreeLines'));
|
|
|
|
|
|
+ return view('app.stat-tree.stat-tree-lines.list', compact('statTreeLines'));
|
|
}
|
|
}
|
|
public function dashboard(StatTreeLine $statTreeLine)
|
|
public function dashboard(StatTreeLine $statTreeLine)
|
|
{
|
|
{
|
|
@@ -321,4 +337,92 @@ class StatTreeLineController extends Controller
|
|
DB::select("delete from stat_tree_line where id = {$statTreeLine->id}");
|
|
DB::select("delete from stat_tree_line where id = {$statTreeLine->id}");
|
|
return $this->pass();
|
|
return $this->pass();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // eps for reports
|
|
|
|
+ public function createReport(Request $request) {
|
|
|
|
+ $statTreeLine = new StatTreeLine();
|
|
|
|
+ $nextId = DB::select("select nextval('stat_tree_line_id_seq')");
|
|
|
|
+ $statTreeLine->id = $nextId[0]->nextval;
|
|
|
|
+ $statTreeLine->uid = Uuid::uuid4();
|
|
|
|
+ $statTreeLine->title = $request->input('title');
|
|
|
|
+ $statTreeLine->created_at = date('Y-m-d h:i:s');
|
|
|
|
+ $statTreeLine->save();
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
|
|
+ public function removeReport(Request $request) {
|
|
|
|
+ $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
|
|
|
|
+ if(!$statTreeLine) return $this->fail('Stat tree line not found!');
|
|
|
|
+ // TODO: disallow if this has children
|
|
|
|
+ DB::select("delete from stat_tree_line where id = {$statTreeLine->id}");
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
|
|
+ public function updateTitle(Request $request) {
|
|
|
|
+ $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
|
|
|
|
+ if(!$statTreeLine) return $this->fail('Stat tree line not found!');
|
|
|
|
+ $statTreeLine->title = $request->input('title');
|
|
|
|
+ $statTreeLine->save();
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
|
|
+ public function updateModel(Request $request) {
|
|
|
|
+ $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
|
|
|
|
+ if(!$statTreeLine) return $this->fail('Stat tree line not found!');
|
|
|
|
+ $statTreeLine->model = $request->input('model');
|
|
|
|
+ $statTreeLine->save();
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
|
|
+ public function addExistingClause(Request $request) {
|
|
|
|
+ $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
|
|
|
|
+ if(!$statTreeLine) return $this->fail('Stat tree line not found!');
|
|
|
|
+ $clause = Clause::where('uid', $request->input('clauseUid'))->first();
|
|
|
|
+ if(!$clause) return $this->fail('Clause not found!');
|
|
|
|
+
|
|
|
|
+ $nextStatLineClauseId = DB::select("select nextval('stat_tree_line_clause_id_seq')");
|
|
|
|
+ $statTreeLineClause = new StatTreeLineClause;
|
|
|
|
+ $statTreeLineClause->id = $nextStatLineClauseId[0]->nextval;
|
|
|
|
+ $statTreeLineClause->uid = Uuid::uuid4();
|
|
|
|
+ $statTreeLineClause->stat_tree_line_id = $statTreeLine->id;
|
|
|
|
+ $statTreeLineClause->clause_id = $clause->id;
|
|
|
|
+ $statTreeLineClause->clause_label = $clause->label;
|
|
|
|
+ $positionIndex = DB::select("select max(position_index) from stat_tree_line_clause where stat_tree_line_id = {$statTreeLine->id}");
|
|
|
|
+ $statTreeLineClause->position_index = is_numeric($positionIndex[0]->max) ? $positionIndex[0]->max + 1 : 1;
|
|
|
|
+ $statTreeLineClause->save();
|
|
|
|
+
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
|
|
+ public function addNewClause(Request $request) {
|
|
|
|
+ $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
|
|
|
|
+ if(!$statTreeLine) return $this->fail('Stat tree line not found!');
|
|
|
|
+
|
|
|
|
+ $clauseId = DB::select("select nextval('clause_id_seq')");
|
|
|
|
+ $clause = new Clause();
|
|
|
|
+ $clause->id = $clauseId[0]->nextval;
|
|
|
|
+ $clause->uid = Uuid::uuid4();
|
|
|
|
+ $clause->model = $request->input('model');
|
|
|
|
+ $clause->question = $request->input('question');
|
|
|
|
+ $clause->answer = $request->input('answer');
|
|
|
|
+ $clause->label = $request->input('label');
|
|
|
|
+ $clause->clause_text = $request->input('clauseText');
|
|
|
|
+ $positionIndex = DB::select("select max(position_index) from clause");
|
|
|
|
+ $clause->position_index = is_numeric($positionIndex[0]->max) ? $positionIndex[0]->max + 1 : 1;
|
|
|
|
+ $clause->save();
|
|
|
|
+
|
|
|
|
+ $nextStatLineClauseId = DB::select("select nextval('stat_tree_line_clause_id_seq')");
|
|
|
|
+ $statTreeLineClause = new StatTreeLineClause;
|
|
|
|
+ $statTreeLineClause->id = $nextStatLineClauseId[0]->nextval;
|
|
|
|
+ $statTreeLineClause->uid = Uuid::uuid4();
|
|
|
|
+ $statTreeLineClause->stat_tree_line_id = $statTreeLine->id;
|
|
|
|
+ $statTreeLineClause->clause_id = $clause->id;
|
|
|
|
+ $statTreeLineClause->clause_label = $clause->label;
|
|
|
|
+ $positionIndex = DB::select("select max(position_index) from stat_tree_line_clause where stat_tree_line_id = {$statTreeLine->id}");
|
|
|
|
+ $statTreeLineClause->position_index = is_numeric($positionIndex[0]->max) ? $positionIndex[0]->max + 1 : 1;
|
|
|
|
+ $statTreeLineClause->save();
|
|
|
|
+
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
|
|
+ public function removeClause(Request $request) {
|
|
|
|
+ $statTreeLineClause = StatTreeLineClause::where('uid', $request->input('uid'))->first();
|
|
|
|
+ if(!$statTreeLineClause) return $this->fail('Stat tree line not found!');
|
|
|
|
+ DB::select("delete from stat_tree_line_clause where id = {$statTreeLineClause->id}");
|
|
|
|
+ return $this->pass();
|
|
|
|
+ }
|
|
}
|
|
}
|