Skip to content

Commit

Permalink
Исправления
Browse files Browse the repository at this point in the history
  • Loading branch information
delaynore committed Jun 9, 2024
1 parent 937b13d commit 4754f02
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 68 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/ConceptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function store(Request $request, string $dictionaryId)
$dictionary = Dictionary::findOrFail($dictionaryId);
Gate::authorize('must-be-owner', $dictionary);
$validated = $request->validate([
'name' => ['required', 'max:255', Rule::notIn(Dictionary::find($dictionaryId)->concepts()->pluck('name'))],
'name' => ['required', 'max:255'],
'definition' => 'max:10000',
'fk_parent_concept_id' => ['uuid', Rule::in(Dictionary::find($dictionaryId)->concepts()->pluck('id'))],
]);
Expand Down Expand Up @@ -130,7 +130,7 @@ public function update(Request $request, Dictionary $dictionary, Concept $concep
{
Gate::authorize('must-be-owner', $concept->dictionary);
$validated = $request->validate([
'name' => ['required', 'max:255', Rule::notIn($dictionary->concepts->where('id', '!=', $concept->id)->pluck('name'))],
'name' => ['required', 'max:255'],
'definition' => 'max:10000',
'parent' => [Rule::excludeIf(empty($request->input('parent'))), 'uuid', Rule::in($dictionary->concepts->pluck('id'))],
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('concepts', function (Blueprint $table) {
$table->dropUnique(['fk_dictionary_id','name']);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('concepts', function (Blueprint $table) {
$table->unique(['fk_dictionary_id','name']);
});
}
};
41 changes: 14 additions & 27 deletions resources/js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ const ContextMenu = (() => {
event.preventDefault();
event.stopPropagation();

const title = contextmenu.querySelector('#conctextmenu-title');
const createParent = contextmenu.querySelector('#conctextmenu-create-parent');
const createBrother = contextmenu.querySelector('#conctextmenu-create-brother');
const editConcept = contextmenu.querySelector('#conctextmenu-edit');
const deleteConcept = contextmenu.querySelector('#conctextmenu-delete');
const openConcept = contextmenu.querySelector('#conctextmenu-open');

const title = contextmenu.querySelector('#contextmenu-title');
const openConcept = contextmenu.querySelector('#contextmenu-open');
if(concept.owner === 'true') {
const createParent = contextmenu.querySelector('#contextmenu-create-parent');
const createBrother = contextmenu.querySelector('#contextmenu-create-brother');
const editConcept = contextmenu.querySelector('#contextmenu-edit');
const deleteConcept = contextmenu.querySelector('#contextmenu-delete');
createParent.href = concept.parent;
createBrother.href = concept.brother;
editConcept.href = concept.edit;
deleteConcept.action = concept.delete;
}
title.textContent = concept.name;
createParent.href = concept.parent;
createBrother.href = concept.brother;
editConcept.href = concept.edit;
deleteConcept.action = concept.delete;
openConcept.action = concept.open;

const x = event.pageX;
Expand Down Expand Up @@ -126,7 +127,8 @@ const ContextMenu = (() => {
brother: li.dataset.createBrother,
edit: li.dataset.edit,
delete: li.dataset.delete,
open: li.dataset.open
open: li.dataset.open,
owner: li.dataset.owner
};
const div = li.querySelector('.lidiv');
div.addEventListener('contextmenu', (event) => handleContextMenu(event, concept));
Expand All @@ -142,21 +144,6 @@ const ContextMenu = (() => {
});
};

const getConceptFromTarget = (target) => {
const li = target.closest('li[data-el="concept"]');
if (li) {
return {
name: li.dataset.name,
parent: li.dataset.createParent,
brother: li.dataset.createBrother,
edit: li.dataset.edit,
delete: li.dataset.delete,
open: li.dataset.open
};
}
return null;
};

return {
initialize
};
Expand Down
62 changes: 36 additions & 26 deletions resources/views/components/dashboard/sidebar/menu.blade.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
<div class="flex overflow-hidden bg-white border divide-x rounded-lg rtl:flex-row-reverse dark:bg-gray-900 dark:border-gray-700 dark:divide-gray-700">
<a href="{{ route('concept.create', $dictionary) }}" data-tooltip-placement="bottom" data-tooltip-target="tooltip-create-concept" class="px-3 py-1 font-medium text-gray-600 transition-colors duration-200 hover:text-blue-600 dark:hover:text-blue-500 sm:px-6 dark:hover:bg-gray-800 dark:text-gray-300 hover:bg-gray-100">
<svg class="w-5 h-5 sm:w-6 sm:h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m3.75 9v6m3-3H9m1.5-12H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
</svg>
</a>
<div id="tooltip-create-concept" role="tooltip" class="absolute z-10 invisible inline-block px-2 py-1 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{__('dashboard.sidebar.menu.create')}}
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
<a href="{{ route('dictionary.export', $dictionary) }}" data-tooltip-placement="bottom" data-tooltip-target="tooltip-export-concepts" class="px-3 py-1 font-medium text-gray-600 transition-colors duration-200 hover:text-blue-600 dark:hover:text-blue-500 sm:px-6 dark:hover:bg-gray-800 dark:text-gray-300 hover:bg-gray-100">
<svg class="w-5 h-5 sm:w-6 sm:h-6" data-slot="icon" aria-hidden="true" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M12 9.75v6.75m0 0-3-3m3 3 3-3m-8.25 6a4.5 4.5 0 0 1-1.41-8.775 5.25 5.25 0 0 1 10.233-2.33 3 3 0 0 1 3.758 3.848A3.752 3.752 0 0 1 18 19.5H6.75Z" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</a>
<div id="tooltip-export-concepts" role="tooltip" class="absolute z-10 invisible inline-block px-2 py-1 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{__('dashboard.sidebar.menu.export')}}
<div class="tooltip-arrow" data-popper-arrow></div>
<div class="flex items-center justify-between w-full">
<div title="{{ $dictionary->name }}" class="max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-lg font-semibold">
{{ $dictionary->name }}
</div>

<div id="collapse-concepts" data-tooltip-placement="bottom" data-tooltip-target="tooltip-collapse-concepts" class="px-3 py-1 font-medium text-gray-600 transition-colors duration-200 cursor-pointer hover:text-blue-600 dark:hover:text-blue-500 sm:px-6 dark:hover:bg-gray-800 dark:text-gray-300 hover:bg-gray-100">
<svg class="w-5 h-5 sm:w-6 sm:h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M15 13.5H9m4.06-7.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" />
</svg>
</div>
<div id="tooltip-collapse-concepts" role="tooltip" class="absolute z-10 invisible inline-block px-2 py-1 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{__('dashboard.sidebar.menu.collapse')}}
<div class="tooltip-arrow" data-popper-arrow></div>
<div class="flex overflow-hidden bg-white border divide-x rounded-lg rtl:flex-row-reverse dark:bg-gray-900 dark:border-gray-700 dark:divide-gray-700">

@can('must-be-owner', $dictionary)

<a href="{{ route('concept.create', $dictionary) }}" data-tooltip-placement="bottom" data-tooltip-target="tooltip-create-concept" class="px-3 py-1 font-medium text-gray-600 transition-colors duration-200 hover:text-blue-600 dark:hover:text-blue-500 dark:hover:bg-gray-800 dark:text-gray-300 hover:bg-gray-100">
<svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m3.75 9v6m3-3H9m1.5-12H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
</svg>
</a>
<div id="tooltip-create-concept" role="tooltip" class="absolute z-10 invisible inline-block px-2 py-1 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{__('dashboard.sidebar.menu.create')}}
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
@endcan
<a href="{{ route('dictionary.export', $dictionary) }}" data-tooltip-placement="bottom" data-tooltip-target="tooltip-export-concepts" class="px-3 py-1 font-medium text-gray-600 transition-colors duration-200 hover:text-blue-600 dark:hover:text-blue-500 dark:hover:bg-gray-800 dark:text-gray-300 hover:bg-gray-100">
<svg class="w-5 h-5" data-slot="icon" aria-hidden="true" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M12 9.75v6.75m0 0-3-3m3 3 3-3m-8.25 6a4.5 4.5 0 0 1-1.41-8.775 5.25 5.25 0 0 1 10.233-2.33 3 3 0 0 1 3.758 3.848A3.752 3.752 0 0 1 18 19.5H6.75Z" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</a>
<div id="tooltip-export-concepts" role="tooltip" class="absolute z-10 invisible inline-block px-2 py-1 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{__('dashboard.sidebar.menu.export')}}
<div class="tooltip-arrow" data-popper-arrow></div>
</div>

<div id="collapse-concepts" data-tooltip-placement="bottom" data-tooltip-target="tooltip-collapse-concepts" class="px-3 py-1 font-medium text-gray-600 transition-colors duration-200 cursor-pointer hover:text-blue-600 dark:hover:text-blue-500 dark:hover:bg-gray-800 dark:text-gray-300 hover:bg-gray-100">
<svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M15 13.5H9m4.06-7.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" />
</svg>
</div>
<div id="tooltip-collapse-concepts" role="tooltip" class="absolute z-10 invisible inline-block px-2 py-1 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{__('dashboard.sidebar.menu.collapse')}}
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<aside class="items-center w-full border-r border-gray-300 max-w-96 min-w-36 dark:border-gray-500">
<div class="px-4 mt-2 text-left text-gray-700 dark:text-gray-200">{{__('entities.dictionary.singular').': '}}<strong>{{$dictionary->name}}</strong></div>
<div class="flex justify-center px-4 py-2 mb-2 border-b border-gray-300 dark:border-gray-500">
@can('must-be-owner', $dictionary)
@include('components.dashboard.sidebar.menu')
@endif
</div>
<div class="w-full px-4 mt-1 overflow-x-scroll text-sm text-black max-h-lvh scroll-smooth" id="concept-tree">
@includeWhen($concepts, 'components.tree-view.tree-view')
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/tree-view/tree-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@endphp

<li data-el="concept" data-id="concept-{{$concept->id}}" class="cursor-pointer"
data-owner="{{$dictionary->fk_user_id === auth()->user()->id ? 'true' : 'false'}}"
data-name="{{$concept->name}}"
data-create-parent="{{route('concept.create', ['dictionary' => $dictionary, 'parentId' => $concept->id])}}"
data-create-brother="{{route('concept.create', ['dictionary' => $dictionary, 'parentId' => $concept->fk_parent_concept_id, 'brotherId' => $concept->id])}}"
Expand Down
14 changes: 6 additions & 8 deletions resources/views/components/tree-view/tree-view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

<div id="contextmenu" class="fixed z-10 hidden bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700">
<div class="py-1 text-gray-700 dark:text-gray-200">
<a id="conctextmenu-title" class="block px-4 py-2 overflow-hidden text-ellipsis hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white dark:text-gray-200"></a>
<a id="contextmenu-title" class="block px-4 py-2 overflow-hidden text-ellipsis hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white dark:text-gray-200"></a>
</div>
@can('must-be-owner', $dictionary)
<div class="py-1 text-gray-700 dark:text-gray-200">
<a id="conctextmenu-create-parent" class="flex items-center justify-between px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">{{__('dashboard.sidebar.concepts.child')}}
<a id="contextmenu-create-parent" class="flex items-center justify-between px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">{{__('dashboard.sidebar.concepts.child')}}
<svg class="w-4 h-4" data-slot="icon" aria-hidden="true" fill="none" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M18 7.5v3m0 0v3m0-3h3m-3 0h-3m-2.25-4.125a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0ZM3 19.235v-.11a6.375 6.375 0 0 1 12.75 0v.109A12.318 12.318 0 0 1 9.374 21c-2.331 0-4.512-.645-6.374-1.766Z" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</a>
<a id="conctextmenu-create-brother" class="flex items-center justify-between px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">{{__('dashboard.sidebar.concepts.brother')}}
<a id="contextmenu-create-brother" class="flex items-center justify-between px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">{{__('dashboard.sidebar.concepts.brother')}}
<svg class="w-4 h-4" data-slot="icon" aria-hidden="true" fill="none" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M12 9v6m3-3H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
Expand All @@ -24,7 +24,7 @@
@endcan
<ul class="py-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="-button">
<li>
<form id="conctextmenu-open" action="" method="get">
<form id="contextmenu-open" action="" method="get">
<button type="submit" class="flex items-center justify-between w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">
{{ __('shared.open') }}
<svg class="w-4 h-4" data-slot="icon" aria-hidden="true" fill="none" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -37,7 +37,7 @@

@can('must-be-owner', $dictionary)
<li>
<a id="conctextmenu-edit" class="flex items-center justify-between px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<a id="contextmenu-edit" class="flex items-center justify-between px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
{{__('shared.edit')}}
<svg class="w-4 h-4" data-slot="icon" aria-hidden="true" fill="none" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" stroke-linecap="round" stroke-linejoin="round"></path>
Expand All @@ -48,7 +48,7 @@
</ul>
@can('must-be-owner', $dictionary)
<div class="py-1 text-gray-700 dark:text-gray-200">
<form id="conctextmenu-delete" action="" method="post">
<form id="contextmenu-delete" action="" method="post">
@csrf
@method('delete')
<button type="submit" class="flex items-center justify-between w-full px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
Expand All @@ -62,9 +62,7 @@
@endcan
</div>

@once
@vite(['resources/js/tree.js'])
@endonce



Expand Down
2 changes: 1 addition & 1 deletion resources/views/dictionary/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="grid gap-4 mb-4">
<div class="col-span-2">
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">{{ __('dictionary-page.create.name.label')}}</label>
<input autofocus type="text" name="name" id="name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" placeholder="{{__('dictionary-page.create.name.placeholder')}}" value="{{old('name')}}" required="">
<input maxlength="50" autofocus type="text" name="name" id="name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" placeholder="{{__('dictionary-page.create.name.placeholder')}}" value="{{old('name')}}" required="">
<x-input-error :messages="$errors->get('name')" class="mt-2" />
</div>
<div class="col-span-2">
Expand Down
Loading

0 comments on commit 4754f02

Please sign in to comment.