Skip to content

Commit

Permalink
FORSLAG-84: Fixed progress bar display
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Aug 16, 2023
1 parent 2d5602f commit b2311f0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

* [PR-340](https://github.com/itk-dev/hoeringsportal/pull/340)
Fixed proposal progress bar display
* [PR-337](https://github.com/itk-dev/hoeringsportal/pull/337)
Updated drupal core 9.5.10 and contrib modules
* [PR-332](https://github.com/itk-dev/hoeringsportal/pull/332)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The module supports certain settings in settings.php
$settings['proposal_period_length'] = '+180 days';

// The required votes for a proposal to pass.
$settings['proposal_support_required'] = '5000';
$settings['proposal_support_required'] = 1500;
```

## Mails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function load() {
$entity->save();
$this->addReference('node:citizen_proposal:Proposal1', $entity);

// Add some support.
for ($i = 0; $i < 87; $i++) {
$this->helper->saveSupport(uniqid('', TRUE), $entity, ['user_name' => self::class]);
}

$entity = Node::create([
'type' => 'citizen_proposal',
'title' => 'Borgerforslag nummer 2',
Expand All @@ -88,6 +93,11 @@ public function load() {
$entity->save();
$this->addReference('node:citizen_proposal:Proposal2', $entity);

// Add some support.
for ($i = 0; $i < 3; $i++) {
$this->helper->saveSupport(uniqid('', TRUE), $entity, ['user_name' => self::class]);
}

$entity = Node::create([
'type' => 'citizen_proposal',
'title' => 'Borgerforslag nummer 3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
$node,
[
'user_name' => $form_state->getValue('name'),
'created' => time(),
],
);
$this->messenger()->addStatus($this->getAdminFormStateValue('support_submission_text', $this->t('Thank you for your support.')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function preprocessNode(&$variables): void {
$proposalSupportCount = $this->getProposalSupportCount((int) $node->id());

$variables['proposal_support_count'] = $proposalSupportCount;
$variables['proposal_support_percentage'] = (int) $this->calculateSupportPercentage($proposalSupportCount);
$variables['proposal_support_percentage'] = $this->calculateSupportPercentage($proposalSupportCount);
}

/**
Expand All @@ -217,6 +217,10 @@ public function saveSupport(string $userIdentifier, NodeInterface $node, array $
try {
$values['user_identifier'] = $userIdentifier;
$values['node_id'] = $node->id();
// Set some defaults.
$values += [
'created' => $this->time->getRequestTime(),
];
$this->connection->insert('hoeringsportal_citizen_proposal_support')
->fields($values)
->execute();
Expand Down Expand Up @@ -428,9 +432,9 @@ public function calculateSupportPercentage(int $proposalSupportCount): float {
}

return min(
100,
ceil($proposalSupportCount / $this->getProposalSupportRequired() * 100)
);
100,
$proposalSupportCount / $this->getProposalSupportRequired() * 100
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@
</div>
<div class="activity-supporters">
<div class="pb-1">
<span>{{ 'Number of supporters'|t }}</span>
<strong class="ml-1">{{ proposal_support_count }}</strong>
<span>{{ 'Number of supporters'|t }}</span>: <strong>{{ proposal_support_count }}</strong>
</div>
<div class="support-progress">
<div class="progress">
<div class="progress-bar" style="width:{{ proposal_support_percentage }}%" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar" style="width:{{ proposal_support_percentage|number_format(4, '.', '') }}%" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
Expand Down

0 comments on commit b2311f0

Please sign in to comment.