예제 #1
0
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function home()
 {
     // Some general statistics
     $notes = Note::all();
     $noteCount = count($notes);
     $references = Reference::all();
     $referenceCount = count($references);
     $tags = Tag::all();
     $tagCount = count($tags);
     $outlines = Outline::all();
     $outlineCount = count($outlines);
     return view('app.main', compact('noteCount', 'referenceCount', 'tagCount', 'outlineCount'));
 }
예제 #2
0
 /**
  *  Remove a note from an outline (without removing the note itself)
  *
  *  @param   int  $outlineId  The outline ID
  *  @param   int  $noteId     The note ID
  *
  *  @return  Response              A JSON encoded response message
  */
 public function getOutlineDetachNote($outlineId, $noteId)
 {
     if (!$outlineId || !$noteId) {
         return response()->json(['message', 'Some ID was empty'], 404);
     }
     $outline = Outline::find($outlineId);
     $outline->notes()->detach($noteId);
     return response()->json(['message', 'Removed note from outliner']);
 }
 public function get($id)
 {
     $outlines = Outline::find($id);
     return $outlines;
 }
예제 #4
0
 /**
  *  Inserts a post into the database
  *
  *  @param   Request  $request
  *
  *  @return  Response
  */
 public function postCreate(Request $request)
 {
     // Insert a note into the db
     // New tags have ID = -1!
     $validator = Validator::make($request->all(), ['title' => 'required|max:255', 'content' => 'required|min:50']);
     if ($validator->fails()) {
         if ($request->outlineId > 0) {
             return redirect('/notes/create/' . $request->outlineId)->withErrors($validator)->withInput();
         } else {
             return redirect('/notes/create')->withErrors($validator)->withInput();
         }
     }
     $note = new Note();
     $note->title = $request->title;
     $note->content = $request->content;
     $note->save();
     // Now fill the join table
     if (count($request->tags) > 0) {
         foreach ($request->tags as $tagname) {
             $tag = Tag::firstOrCreate(["name" => $tagname]);
             $note->tags()->attach($tag->id);
         }
     }
     if (count($request->references) > 0) {
         foreach ($request->references as $referenceId) {
             try {
                 Reference::findOrFail($referenceId);
                 // If this line is executed the model exists
                 $note->references()->attach($referenceId);
             } catch (ModelNotFoundException $e) {
                 // Do nothing
             }
         }
     }
     if ($request->outlineId > 0) {
         $outline = Outline::find($request->outlineId);
         // Which index should we use? Of course the last.
         $noteIndex = count($outline->customFields) + count($outline->notes) + 1;
         // Attach to this outline
         $outline = Outline::find($request->outlineId)->notes()->attach($note, ['index' => $noteIndex]);
         return redirect(url('/notes/create/' . $request->outlineId));
     }
     // Now redirect to note create as the user
     // definitely wants to add another note.
     return redirect(url('/notes/create'));
 }
예제 #5
0
 /**
  *  Removes an outline, detaches its notes and removes its custom fields
  *
  *  @param   integer  $id  Outline id
  *
  *  @return  Response
  */
 public function delete($id)
 {
     try {
         $outline = Outline::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return redirect('/outlines');
     }
     $outline->notes()->detach();
     $outline->customFields()->delete();
     $outline->delete();
     return redirect('/outlines');
 }
예제 #6
0
 /**
  *  Inserts imported and parsed notes into the database
  *
  *  @param   Request  $request
  *
  *  @return  Response
  */
 public function insertImport(Request $request)
 {
     if ($request->createOutline) {
         $outline = new Outline();
         $outline->name = $request->outlineName;
         $outline->description = $request->outlineDescription;
         $outline->save();
         // $index = 0;
     }
     // Just copy the code from NoteController@postCreate
     foreach ($request->title as $index => $title) {
         $note = new Note();
         $note->title = $title;
         $note->content = $request->content[$index];
         $note->save();
         if ($request->createOutline) {
             $outline->notes()->attach($note, ["index" => $index + 1]);
         }
         // Now fill the join table
         // Fix: Sometimes there are just no tags attached to a note
         // and in these situations, Zettlr broke. Now the existence of
         // the variable is previously tested before the length is checked
         if (isset($request->tags[$index]) && count($request->tags[$index]) > 0) {
             if (array_key_exists($index, $request->tags) && count($request->tags[$index]) > 0) {
                 foreach ($request->tags[$index] as $tagname) {
                     $tag = Tag::firstOrCreate(["name" => $tagname]);
                     $note->tags()->attach($tag->id);
                 }
             }
         }
         // $index++;
     }
     if ($request->createOutline) {
         return redirect('/outlines/show/' . $outline->id);
     }
     // Redirect to the main page for now
     return redirect('/');
 }