Skip to content

Commit

Permalink
Add readonly inherited software
Browse files Browse the repository at this point in the history
  • Loading branch information
melegiul committed Jul 26, 2023
1 parent db5c505 commit e1b87e9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
17 changes: 12 additions & 5 deletions src/Controller/SoftwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\SoftwareConfig;
use App\Repository\SoftwareConfigRepository;
use App\Repository\SoftwareRepository;
use App\Repository\TeamRepository;
use App\Service\ApproveService;
use App\Service\AssignService;
use App\Service\CurrentTeamService;
Expand Down Expand Up @@ -228,22 +229,25 @@ public function editSoftware(
AssignService $assignService,
CurrentTeamService $currentTeamService,
SoftwareRepository $softwareRepository,
TeamRepository $teamRepository,
): Response
{
//Request: id: SoftwareID, snack:Snack Notice
$team = $currentTeamService->getCurrentTeam($this->getUser());
$teamPath = $team ? $teamRepository->getPath($team) : null;
$software = $softwareRepository->find($request->get('id'));

if ($securityService->teamDataCheck($software, $team) === false) {
if ($securityService->teamPathDataCheck($software, $teamPath) === false) {
return $this->redirectToRoute('software');
}
$newSoftware = $softwareService->cloneSoftware($software, $this->getUser());
$form = $softwareService->createForm($newSoftware, $team);
$isEditable = $software->getTeam() === $team;
$form = $softwareService->createForm($newSoftware, $team, ['disabled' => !$isEditable]);
$form->handleRequest($request);
$assign = $assignService->createForm($software, $team);
$assign = $assignService->createForm($software, $team, ['disabled' => !$isEditable]);

$errors = array();
if ($form->isSubmitted() && $form->isValid() && $software->getActiv() && !$software->getApproved()) {
if ($form->isSubmitted() && $form->isValid() && $software->getActiv() && !$software->getApproved() && $isEditable) {
$software->setActiv(false);
$newSoftware = $form->getData();

Expand Down Expand Up @@ -276,6 +280,7 @@ public function editSoftware(
'software' => $software,
'activ' => $software->getActiv(),
'snack' => $request->get('snack'),
'isEditable' => $isEditable,
]);
}

Expand All @@ -285,14 +290,16 @@ public function index(
Request $request,
CurrentTeamService $currentTeamService,
SoftwareRepository $softwareRepository,
TeamRepository $teamRepository,
): Response
{
//Request: snack: Snack Notice
$team = $currentTeamService->getCurrentTeam($this->getUser());
if ($securityService->teamCheck($team) === false) {
return $this->redirectToRoute('dashboard');
}
$software = $softwareRepository->findActiveByTeam($team);
$teamPath = $teamRepository->getPath($team);
$software = $softwareRepository->findActiveByTeamPath($teamPath);

return $this->render('software/index.html.twig', [
'data' => $software,
Expand Down
21 changes: 14 additions & 7 deletions src/Service/SoftwareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ public function createConfigForm(SoftwareConfig $softwareConfig): FormInterface
return $form;
}

public function createForm(Software $software, Team $team): FormInterface
public function createForm(Software $software, Team $team, array $options = []): FormInterface
{
$processes = $this->em->getRepository(VVT::class)->findActiveByTeam($team);
$data = $this->em->getRepository(Datenweitergabe::class)->findBy(['team' => $team, 'activ' => true, 'art' => 1]);

$form = $this->formBuilder->create(SoftwareType::class, $software, ['processes' => $processes, 'datenweitergabe' => $data]);

return $form;
if (isset($options['disabled']) && $options['disabled']) {
$teamPath = $this->em->getRepository(Team::class)->getPath($team);
$processes = $this->em->getRepository(VVT::class)->findActiveByTeamPath($teamPath);
$data = $this->em->getRepository(Datenweitergabe::class)->findActiveTransfersByTeamPath($teamPath);
} else {
$processes = $this->em->getRepository(VVT::class)->findActiveByTeam($team);
$data = $this->em->getRepository(Datenweitergabe::class)->findBy(['team' => $team, 'activ' => true, 'art' => 1]);
}

return $this->formBuilder->create(SoftwareType::class, $software, array_merge([
'processes' => $processes,
'datenweitergabe' => $data
], $options));
}

public function newConfig(Software $software): SoftwareConfig
Expand Down
38 changes: 22 additions & 16 deletions templates/software/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<a class="btn btn-amber ml-1 btn-sm " href="{{ path('bericht_software', {'id':software.id, 'all':1}) }}">
<span>{% trans from 'general' %}pdf.createWithHistory{% endtrans %}</span>
</a>
{{ include('base/__approveBtn.html.twig',{'data':software,'dataLink':'software_approve'}) }}
{% if isEditable %}
{{ include('base/__approveBtn.html.twig',{'data':software,'dataLink':'software_approve'}) }}
{% endif %}
{% endif %}

{% endblock %}
Expand All @@ -21,7 +23,9 @@
{{ include('base/__approvedBy.html.twig', {'data':software}) }}
</div>
<div class="col-md-4 text-right">
{{ include('assign/__assign.html.twig',{'data':software,'path':'assign_software'}) }}
{% if isEditable %}
{{ include('assign/__assign.html.twig',{'data':software,'path':'assign_software'}) }}
{% endif %}
</div>
</div>

Expand All @@ -36,29 +40,31 @@
</button>
</h5>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne"
<div id="collapseOne" class="collapse{% if not isEditable %} show{% endif %}" aria-labelledby="headingOne"
data-parent="#accordionExample">
<div class="card-body {% if not activ or software.approved %}disabled{% endif %}">
{{ include('software/__form.html.twig') }}
<p>{% trans from 'general' %}createdBy{% endtrans %}: {{ software.user.email }}</p>
</div>
</div>
</div>
<div class="card z-depth-0 bordered">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link " type="button" data-toggle="collapse"
data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
<h4 class="h4-responsive">{% trans %}config.attached{% endtrans %}</h4>
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body {% if not activ or software.approved %}disabled{% endif %}">
{{ include('software/__config.html.twig') }}
{% if isEditable %}
<div class="card z-depth-0 bordered">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link " type="button" data-toggle="collapse"
data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
<h4 class="h4-responsive">{% trans %}config.attached{% endtrans %}</h4>
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body {% if not activ or software.approved %}disabled{% endif %}">
{{ include('software/__config.html.twig') }}
</div>
</div>
</div>
</div>
{% endif %}
</div>

{% if software.previous %}
Expand Down
4 changes: 4 additions & 0 deletions templates/software/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<th scope="col">{% trans %}licence.word{% endtrans %}</th>
<th scope="col">{% trans %}expiration.date{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}state{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}inheritance.fromTeam{% endtrans %}</th>
</tr>
</thead>
<tbody>
Expand All @@ -48,6 +49,9 @@
{{ d.statusString }}
{% endif %}
</td>
<td{% if d.team != currentTeam %} title="{% trans from 'general' %}inheritance.infoText{% endtrans %}"{% endif %}>
{% if d.team != currentTeam %}{{ d.team }}{% else %}-{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit e1b87e9

Please sign in to comment.