Skip to content

Commit

Permalink
Можно добавлять понятия, добавил измениние title в зависимости от стр…
Browse files Browse the repository at this point in the history
…аницы
  • Loading branch information
delaynore committed Apr 29, 2024
1 parent 9948343 commit 8e5caaf
Show file tree
Hide file tree
Showing 24 changed files with 353 additions and 164 deletions.
98 changes: 98 additions & 0 deletions app/Http/Controllers/ConceptController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Http\Controllers;

use App\Models\Concept;
use App\Models\Dictionary;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class ConceptController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*/
public function create(Dictionary $dictionary)
{

if($dictionary->fk_user_id != auth()->user()->id) {
return abort(404);
}
if (request()->get('parentId') == null) {
return view('concept.create', compact('dictionary'));
}

$parent = Concept::findOrFail(request()->get('parentId'));
return view('concept.create', compact('dictionary', 'parent'));
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request, string $dictionaryId)
{
$request->validate([
'name' => ['required', 'max:50', Rule::notIn(Dictionary::find($dictionaryId)->concepts()->pluck('name'))],
'description' => 'max:500',
'fk_parent_concept_id' => ['uuid',Rule::in(Dictionary::find($dictionaryId)->concepts()->pluck('id'))],
]);

$concept = new Concept([
'name' => $request->name,
'definition' => $request->definition,
'fk_dictionary_id' => $dictionaryId,
'fk_parent_concept_id' => $request->fk_parent_concept_id,
]);

$concept->saveOrFail();

return redirect()->route('dictionary.show', $dictionaryId);
}

/**
* Display the specified resource.
*/
public function show(Concept $concept)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Concept $concept)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, Concept $concept)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request,string $id)
{
dd($request);
$concept = Concept::findOrFail($id);
$dict = $concept->fk_dictionary_id;

$concept->delete();
$concept->saveOrFail();

return redirect(route('dictionary.show'), $dict);
}
}
19 changes: 9 additions & 10 deletions app/Http/Controllers/DictionaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public function store(Request $request) : RedirectResponse
*/
public function show(string $id) : View
{
$dict = Dictionary::where('fk_user_id', '=', auth()->user()->id)->findOrFail($id);
$dictionary = Dictionary::where('fk_user_id', '=', auth()->user()->id)->findOrFail($id);

return view('dictionary.show',
['dict' => $dict,
'concept' => $dict->rootConcept()]);
['dictionary' => $dictionary,
'concepts' => $dictionary->rootConcepts()]);
}

/**
Expand All @@ -75,25 +76,23 @@ public function show(string $id) : View
public function edit(string $id) : View
{
return view('dictionary.edit',
['dict' => Dictionary::where('fk_user_id', '=', auth()->user()->id)->findOrFail($id)]);
['dictionary' => Dictionary::where('fk_user_id', '=', auth()->user()->id)->findOrFail($id)]);
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id) : RedirectResponse
public function update(Request $request, Dictionary $dictionary) : RedirectResponse
{
// $dictionary = Dictionary::where('fk_user_id', '=', auth()->user()->id)->findOrFail($id);
$validated = $request->validate([
'name' => ['required', 'max:50', Rule::notIn(Dictionary::where('fk_user_id', '=', auth()->user()->id)->pluck('name'))],
'name' => ['required', 'max:50', Rule::notIn(Dictionary::where('fk_user_id', '=', auth()->user()->id)->where('id', '!=',$dictionary->id)->pluck('name'))],
'description' => 'max:500',
'visibility' => [new Enum(Visibility::class)],
]);

$dictionary = Dictionary::where('fk_user_id', '=', auth()->user()->id)->findOrFail($id);

$dictionary->name = $validated['name'];
$dictionary->description = $validated['description'];
$dictionary->visibility = $validated['visibility'];
$dictionary->fill($validated);

$dictionary->save();

Expand Down
1 change: 1 addition & 0 deletions app/Models/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function children() : HasMany
'name',
'definition',
'fk_dictionary_id',
'fk_parent_concept_id',
];

protected $casts = [
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function concepts() : HasMany
return $this->hasMany(Concept::class, 'fk_dictionary_id');
}

public function rootConcept() : Concept
public function rootConcepts()
{
// TODO: check if dict is empty
return $this->concepts()->oldest('created_at')->first();
return $this->concepts()->where('fk_parent_concept_id', null)->get();
}

protected $fillable = [
Expand Down
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

/**
* @property string $id
* @property string $name
* @property string $email
*/
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasUuids;
Expand Down
4 changes: 1 addition & 3 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<x-layout.main>
<!-- Session Status -->

<!-- d -->
<x-slot:title>{{ __('Вход') }}</x-slot:title>

<section class="bg-gray-50 dark:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
Expand Down
2 changes: 2 additions & 0 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<x-layout.main>
<x-slot:title>{{ __('Регистрация') }}</x-slot:title>

<section class="bg-gray-50 dark:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<x-shared.logo-title />
Expand Down
2 changes: 2 additions & 0 deletions resources/views/auth/reset-password.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<x-layout.main>
<x-slot:title>{{ __('Сбросить пароль') }}</x-slot:title>

<form method="POST" action="{{ route('password.store') }}">
@csrf

Expand Down
24 changes: 24 additions & 0 deletions resources/views/components/dashboard/sidebar/menu.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="inline-flex rounded-md shadow-sm" role="group">
<a href="{{route('concept.create', ['dictionary' =>$dictionary])}}" class="inline-flex items-center px-2 py-1 text-sm font-medium text-gray-900 bg-white border-t border-b border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white">
<svg class="w-4 h-4 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 7.757v8.486M7.757 12h8.486M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg>
</a>

<button type="button" class="inline-flex items-center px-2 py-1 text-sm font-medium text-gray-900 bg-white border-t border-b border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white">
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 12.25V1m0 11.25a2.25 2.25 0 0 0 0 4.5m0-4.5a2.25 2.25 0 0 1 0 4.5M4 19v-2.25m6-13.5V1m0 2.25a2.25 2.25 0 0 0 0 4.5m0-4.5a2.25 2.25 0 0 1 0 4.5M10 19V7.75m6 4.5V1m0 11.25a2.25 2.25 0 1 0 0 4.5 2.25 2.25 0 0 0 0-4.5ZM16 19v-2" />
</svg>
</button>
<button type="button" class="inline-flex items-center px-2 py-1 text-sm font-medium text-gray-900 bg-white border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white">
<svg class="w-4 h-4 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7.757 12h8.486M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg>
</button>
<button type="button" class="inline-flex items-center px-2 py-1 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-e-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white">
<svg class="w-4 h-4 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 10V4a1 1 0 0 0-1-1H9.914a1 1 0 0 0-.707.293L5.293 7.207A1 1 0 0 0 5 7.914V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2M10 3v4a1 1 0 0 1-1 1H5m5 6h9m0 0-2-2m2 2-2 2" />
</svg>
</button>
<!-- concept delete -->
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<aside class="mt-2 items-center border-r w-64 dark:border-gray-600 border-gray-200 pr-4">
<div class="flex justify-center mb-2">
@include('components.dashboard.sidebar.menu')
</div>
<div class="mt-1 text-sm text-black max-h-lvh overflow-scroll" id="concept-tree">
@includeWhen($concepts, 'components.tree-view.tree-view')
</div>
</aside>
48 changes: 48 additions & 0 deletions resources/views/components/layout/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!-- Управление словарем -->
@props(['dictionary', 'concepts'])

@php
session()->push('dictionary', $dictionary);
@endphp

<x-layout.main>
<x-slot:title>{{ $dictionary->name }}</x-slot:title>
<x-slot name="navigation"></x-slot>
<div class="flex flex-row px-4">
@include('components.dashboard.sidebar.sidebar')
<section class="flex-grow-10 pl-4 pr-4">
<div class="mb-4 border-b border-gray-200 dark:border-gray-700">
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center" id="default-tab" data-tabs-toggle="#default-tab-content" role="tablist">
<li class="me-2" role="presentation">
<button class="inline-block p-4 border-b-2 rounded-t-lg" id="dictionaryionary-tab" data-tabs-target="#dictionaryionary" type="button" role="tab" aria-controls="dictionaryionary" aria-selected="false">dictionaryionary</button>
</li>
<li class="me-2" role="presentation">
<button class="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="concept-tab" data-tabs-target="#concept" type="button" role="tab" aria-controls="concept" aria-selected="false">{{ __('Понятия')}}</button>
</li>
<li class="me-2" role="presentation">
<button class="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="settings-tab" data-tabs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
</li>
<li role="presentation">
<button class="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="export-tab" data-tabs-target="#export" type="button" role="tab" aria-controls="export" aria-selected="false">{{ __('Экспорт')}}</button>
</li>
</ul>
</div>
<div id="default-tab-content">
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="dictionaryionary" role="tabpanel" aria-labelledby="dictionaryionary-tab">
<p class="text-sm text-gray-500 dark:text-gray-400">This is some placeholder content the <strong class="font-medium text-gray-800 dark:text-white">dictionaryionary tab's associated content</strong>. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling.</p>
</div>
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="concept" role="tabpanel" aria-labelledby="concept-tab">
<p class="text-sm text-gray-500 dark:text-gray-400">This is some placeholder content the <strong class="font-medium text-gray-800 dark:text-white">concept tab's associated content</strong>. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling.</p>
</div>
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="settings" role="tabpanel" aria-labelledby="settings-tab">
<p class="text-sm text-gray-500 dark:text-gray-400">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Iure doloremque vero recusandae reprehenderit rem voluptates quas sint possimus nostrum at, facilis quisquam dignissimos. Modi illum velit assumenda vitae dictionarya! Illo.</p>
</div>
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="export" role="tabpanel" aria-labelledby="export-tab">
<p class="text-sm text-gray-500 dark:text-gray-400">
Здесь будет экспорт списка понятий...
</p>
</div>
</div>
</section>
</div>
</x-layout.main>
8 changes: 4 additions & 4 deletions resources/views/components/layout/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">

<title>{{ config('app.name') }}</title>
<title>{{ isset($title) ? $title.' - '.config('app.name') : config('app.name') }}</title>

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
Expand All @@ -31,8 +31,8 @@
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>

<body class="font-sans antialiased">
<div class="flex flex-col min-h-screen bg-gray-100 dark:bg-gray-900">
<body class="font-sans antialiased flex flex-col min-h-screen">
<div class="flex flex-col flex-grow bg-gray-100 dark:bg-gray-900">
@if (isset($navigation))
@include('components.navigation.navbar')
@endif
Expand All @@ -52,7 +52,7 @@
{{ $slot }}
@endif
</main>
<footer>
<footer class="mt-4">
@include('components.footer.footer')
</footer>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/pages/home.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<x-layout.main>
<x-slot:title>{{ __('Главная') }}</x-slot:title>
<x-slot name="navigation"></x-slot>
</x-layout.main>
Loading

0 comments on commit 8e5caaf

Please sign in to comment.