Browse Source

ajoute le widget clipboard

master
vincent 2 months ago
parent
commit
7d15bfb04c
5 changed files with 51 additions and 5 deletions
  1. +8
    -0
      assets/controllers/clipboard_controller.js
  2. +1
    -0
      config/packages/twig.yaml
  3. +28
    -0
      src/Service/SourceGenerator.php
  4. +12
    -0
      templates/macro.html.twig
  5. +2
    -5
      templates/task/show.html.twig

+ 8
- 0
assets/controllers/clipboard_controller.js View File

@ -0,0 +1,8 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "source" ]
copy() {
navigator.clipboard.writeText(this.sourceTarget.value)
}
}

+ 1
- 0
config/packages/twig.yaml View File

@ -8,6 +8,7 @@ twig:
- { route: 'app_project', label: 'Projets', icon: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-folder" viewBox="0 0 16 16"><path d="M.54 3.87.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.826a2 2 0 0 1-1.991-1.819l-.637-7a2 2 0 0 1 .342-1.31zM2.19 4a1 1 0 0 0-.996 1.09l.637 7a1 1 0 0 0 .995.91h10.348a1 1 0 0 0 .995-.91l.637-7A1 1 0 0 0 13.81 4zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139q.323-.119.684-.12h5.396z"/></svg>' }
taskLifecycleManager: '@App\Service\TaskLifecycleManager'
geoJsonManager: '@App\Service\GeoJsonManager'
sourceGenerator: '@App\Service\SourceGenerator'
short_title: '%short_title%'
long_title: '%long_title%'


+ 28
- 0
src/Service/SourceGenerator.php View File

@ -0,0 +1,28 @@
<?php
namespace App\Service;
use App\Entity\Task;
class SourceGenerator
{
public function generate(Task $task): string
{
$parts = [];
$project = $task->getProject();
$parts[] = $project->getName();
$parts[] = $task->getName();
foreach(explode(' ', $project->getHashtags()) as $hashtag) {
$parts[] = $hashtag;
}
$source = implode(' ', $parts);
return $source;
}
}

+ 12
- 0
templates/macro.html.twig View File

@ -40,3 +40,15 @@
{% endfor %}
</details>
{% endmacro %}
{% macro clipboard(text) %}
<div class="input-group" data-controller="clipboard">
<input type="text" readonly class="form-control" value="{{ text }}" data-clipboard-target="source" />
<button class="btn btn-outline-secondary" type="button" data-action="clipboard#copy" title="Copier dans le presse-papier">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0z"/>
</svg>
</button>
</div>
{% endmacro %}

+ 2
- 5
templates/task/show.html.twig View File

@ -76,16 +76,13 @@
<tr>
<th scope="row">Commentaire</th>
<td>
{{ project.name }} {{ task.name }}
{% for hashtag in project.hashtags|split(' ') %}
{{ '#' ~ hashtag }}
{% endfor %}
{{ macro.clipboard(sourceGenerator.generate(task)) }}
</td>
</tr>
<tr>
<th scope="row">Source</th>
<td>
{{ project.source }}
{{ macro.clipboard(project.source) }}
</td>
</tr>
</tbody>


Loading…
Cancel
Save