Skip to content

Commit

Permalink
added button to template, created stylings, js controller and got js …
Browse files Browse the repository at this point in the history
…to call controller
  • Loading branch information
jeppekroghitk committed Aug 8, 2024
1 parent 4886af4 commit 8131b98
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 2 deletions.
45 changes: 45 additions & 0 deletions assets/controllers/invoice-sync-worklogs_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
updateUrl;
connect() {
console.log('Hello from connect');
this.updateUrl = this.element.dataset.updateUrl;
}

syncWorklogs(e) {
let syncButton = e.target;
syncButton.disabled = true;
syncButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6">\n' +
' <path strokeLinecap="round" strokeLinejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" />\n' +
'</svg>'

fetch(this.updateUrl, {
method: "POST",
mode: "same-origin",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
redirect: "follow",
referrerPolicy: "no-referrer",
})
.then(async (resp) => {
if (!resp.ok) {
resp.json().then((err) => {
syncButton.innerText = `failed: ${err.message}`;
});
} else {
syncButton.innerText = "ok";
}
})
.catch((err) => {
syncButton.innerText = `failed${err.message}`;
syncButton.disabled = false;
})
.finally(() => {
syncButton.disabled = false;
});
}
}
20 changes: 19 additions & 1 deletion assets/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,25 @@
.worklogs-filter-form {
@apply grid gap-3 mb-6 md:grid-cols-4;
}

.worklogs-filter-form-header-group {
@apply flex;
}
.worklogs-filter-form-header-group h1 {
flex: 5;
}
.worklogs-filter-form-header-group #sync-worklogs {
flex: 1;
@apply p-4 h-16 m-auto;
}
.worklogs-filter-form-header-group #sync-worklogs svg {
max-height: 85%;
margin: auto;
animation: spin 2s linear infinite
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.choices__list--dropdown .choices__item--selectable {
padding: 1em !important;
}
Expand Down
58 changes: 58 additions & 0 deletions src/Controller/InvoiceEntryWorklogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,62 @@ public function selectWorklogs(Request $request, InvoiceEntry $invoiceEntry, Wor

return new Response(null, 200);
}

/**
* @throws EconomicsException
*/
#[Route('/{projectId}/sync', name: 'app_invoice_entry_project_worklogs_sync', methods: ['POST'])]
public function sync(): Response
{
die('hgest');
/*$dataProviders = $this->dataProviderRepository->findBy(['enabled' => true]);
foreach ($dataProviders as $dataProvider) {
$projects = $this->projectRepository->findBy(['include' => true, 'dataProvider' => $dataProvider]);
$numberOfProjects = count($projects);
$io->info("Processing worklogs for $numberOfProjects projects that are included (project.include)");
foreach ($projects as $project) {
$io->writeln("Processing worklogs for {$project->getName()}");
$this->dataSynchronizationService->syncWorklogsForProject($project->getId(), function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
$io->progressFinish();
} else {
$io->progressAdvance();
}
}, $dataProvider);
$io->writeln('');
}
}*/



/*try {
$projectId = $project->getId();
if (null == $projectId) {
return new Response('Not found', 404);
}
$dataProvider = $project->getDataProvider();
if (null != $dataProvider) {
$dataSynchronizationService->syncIssuesForProject($projectId, null, $dataProvider);
$dataSynchronizationService->syncWorklogsForProject($projectId, null, $dataProvider);
}
return new JsonResponse([], 200);
} catch (\Throwable $exception) {
return new JsonResponse(
['message' => $exception->getMessage()],
(int) ($exception->getCode() > 0 ? $exception->getCode() : 500)
);
}*/
}
}
1 change: 1 addition & 0 deletions src/Form/InvoiceEntryWorklogFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Model\Invoices\InvoiceEntryWorklogsFilterData;
use App\Repository\InvoiceRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down
7 changes: 6 additions & 1 deletion templates/invoice_entry/worklogs.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
{% block title %}{{ 'worklog.title'|trans }}{% endblock %}

{% block content %}
<h1 class="page-title">{{ 'worklog.title'|trans }}</h1>
{{ dump(invoice.id) }}
<div class="worklogs-filter-form-header-group" {{ stimulus_controller('invoice-sync-worklogs') }} data-update-url="{{ path('app_invoice_entry_project_worklogs_sync', {projectId: invoice.project.id, invoice: invoice.id}) }}">
<h1 class="page-title">{{ 'worklog.title'|trans }}</h1>
<button id="sync-worklogs" {{ stimulus_action('invoice-sync-worklogs', 'syncWorklogs') }} class="button btn-default">{{ 'worklog.sync_worklogs'|trans }}</button>
</div>

{{ form_start(form) }}
<div class="worklogs-filter-form selections" {{ stimulus_controller('choices') }}>
{{ form_rest(form) }}
<button class="button m-5">{{ 'invoices.search'|trans }}</button>
</div>

{{ form_end(form) }}

<div {{ stimulus_controller('entry-select') }} data-submit-endpoint="{{ submitEndpoint }}">
Expand Down
1 change: 1 addition & 0 deletions translations/messages.da.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ worklog:
only_available: "Kun \"frie\" worklogs"
only_available_helptext: "Worklogs der ikke er i en anden fakturalinje."
title_show: "Worklogs"
sync_worklogs: "Synkroniser worklogs"

invoice_entry:
amount: "Antal enheder"
Expand Down

0 comments on commit 8131b98

Please sign in to comment.