|
@@ -11,6 +11,7 @@ use Cookie;
|
|
|
|
|
|
use App\Models\Note;
|
|
|
use App\Models\Client;
|
|
|
+use App\Models\Section;
|
|
|
use App\Models\SectionTemplate;
|
|
|
|
|
|
class NoteController extends Controller
|
|
@@ -34,13 +35,17 @@ class NoteController extends Controller
|
|
|
|
|
|
public function sectionCreateForm($note_uid, $section_template_uid, Request $request)
|
|
|
{
|
|
|
-
|
|
|
$note = Note::where('uid', $note_uid)->first();
|
|
|
-
|
|
|
$sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
|
|
|
-
|
|
|
$section = null; // convenience
|
|
|
+ include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
|
|
|
+ }
|
|
|
|
|
|
+ public function sectionUpdateForm($section_uid, Request $request)
|
|
|
+ {
|
|
|
+ $section = Section::where('uid', $section_uid)->first();
|
|
|
+ $note = Note::where('id', $section->note_id)->first();
|
|
|
+ $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
|
|
|
include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
|
|
|
}
|
|
|
|
|
@@ -61,8 +66,8 @@ class NoteController extends Controller
|
|
|
$note = Note::where('uid', $note_uid)->first();
|
|
|
$sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
|
|
|
} else {
|
|
|
- $note = $section->note();
|
|
|
- $sectionTemplate = $section->sectionTemplate();
|
|
|
+ $note = Note::where('id', $section->note_id)->first();
|
|
|
+ $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
|
|
|
}
|
|
|
|
|
|
$newContentData = [];
|
|
@@ -72,16 +77,21 @@ class NoteController extends Controller
|
|
|
// if UPDATE, $section, and $request
|
|
|
include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
|
|
|
|
|
|
- $newContentData = ['dog' => 'bark', 'cat' => 'meow'];
|
|
|
// now, create summaryHtml appropriate
|
|
|
ob_start();
|
|
|
- echo 'this is not going to scream anywhere.';
|
|
|
include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
|
|
|
$newSummaryHtml = ob_get_contents();
|
|
|
ob_end_clean();
|
|
|
|
|
|
if($section){
|
|
|
// call Java to update section
|
|
|
+ $data = [
|
|
|
+ 'uid' => $section->uid,
|
|
|
+ 'contentData' => json_encode($newContentData),
|
|
|
+ 'summaryHtml' => $newSummaryHtml
|
|
|
+ ];
|
|
|
+ $response = $this->calljava($request, '/api/section/update', $data);
|
|
|
+ //TODO: handle if response->success == false
|
|
|
}else{
|
|
|
// call Java to create section
|
|
|
$data = [
|
|
@@ -90,12 +100,18 @@ class NoteController extends Controller
|
|
|
'contentData' => json_encode($newContentData),
|
|
|
'summaryHtml' => $newSummaryHtml
|
|
|
];
|
|
|
- $url = env('BACKEND_URL', 'http://localhost:8080') . '/api/section/create';
|
|
|
- $response = Http::asForm()
|
|
|
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
- ->post($url, $data)
|
|
|
- ->json();
|
|
|
- dd($response);
|
|
|
+ $response = $this->callJava($request, '/api/section/create', $data);
|
|
|
+ //TODO: handle if response->success == false
|
|
|
}
|
|
|
+ return redirect(route('render-note',$note->uid));
|
|
|
+ }
|
|
|
+
|
|
|
+ private function callJava($request, $endPoint, $data){
|
|
|
+ $url = env('BACKEND_URL', 'http://localhost:8080') . $endPoint;
|
|
|
+ $response = Http::asForm()
|
|
|
+ ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
+ ->post($url, $data)
|
|
|
+ ->json();
|
|
|
+ return $response;
|
|
|
}
|
|
|
}
|