Skip to content

Commit

Permalink
Allow setting internal tags directly in the proposed procedure overvi…
Browse files Browse the repository at this point in the history
…ew page
  • Loading branch information
CatoTH committed Nov 1, 2023
1 parent 3478110 commit 80bb0bd
Show file tree
Hide file tree
Showing 32 changed files with 208 additions and 78 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Vertion 4.13.1 [not released yet]

- As admin, is now possible to edit the list of internal (proposed procedure) tags, just like the public ones.
- Proposed procedure tags can now be assigned directly in the procedure overview page.

## Version 4.13.0 (2023-10-29)

Expand Down
2 changes: 1 addition & 1 deletion config/urls.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$adminUserPaths = 'save|poll|add-single-init|add-single|add-multiple-ww|add-multiple-email|search-groups';
$adminPaths = 'consultation|appearance|consultationextended|translation|translation-motion-type|siteaccess|siteconsultations|openslidesusers';
$adminPaths .= '|theming|files|proposed-procedure|ods-proposed-procedure|check-updates|goto-update';
$adminPpPaths = 'index-ajax|ods|save-motion-comment|save-amendment-comment|save-motion-visible|save-amendment-visible|save-responsibility';
$adminPpPaths = 'index-ajax|ods|save-motion-comment|save-amendment-comment|save-motion-visible|save-amendment-visible|save-responsibility|save-tags';

$urlRules = [
$domadmin => 'admin/index',
Expand Down
30 changes: 2 additions & 28 deletions controllers/AmendmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
RestApiExceptionResponse,
RestApiResponse};
use app\components\{HTMLTools, Tools, UrlHelper};
use app\models\db\{Amendment,
AmendmentAdminComment,
AmendmentSupporter,
ConsultationLog,
ConsultationSettingsTag,
ISupporter,
Motion,
User};
use app\models\db\{Amendment, AmendmentAdminComment, AmendmentSupporter, ConsultationLog, ISupporter, Motion, User};
use app\models\events\AmendmentEvent;
use app\models\exceptions\{FormError, MailNotSent, ResponseException};
use app\models\forms\{AmendmentEditForm, ProposedChangeForm};
Expand Down Expand Up @@ -479,26 +472,7 @@ public function actionSaveProposalStatus(string $motionSlug, int $amendmentId):
$amendment->proposalComment = $this->getHttpRequest()->post('proposalComment', '');
}

$oldTags = $amendment->getProposedProcedureTags();
$newTags = [];
$changed = false;
foreach ($this->getHttpRequest()->post('tags', []) as $newTag) {
$tag = $amendment->getMyConsultation()->getExistingTagOrCreate(ConsultationSettingsTag::TYPE_PROPOSED_PROCEDURE, $newTag, 0);
if (!isset($oldTags[$tag->getNormalizedName()])) {
$amendment->link('tags', $tag);
$changed = true;
}
$newTags[] = ConsultationSettingsTag::normalizeName($newTag);
}
foreach ($oldTags as $tagKey => $tag) {
if (!in_array($tagKey, $newTags)) {
$amendment->unlink('tags', $tag, true);
$changed = true;
}
}
if ($changed) {
$ppChanges->setProposalTagsHaveChanged(array_keys($oldTags), $newTags);
}
$amendment->setProposedProcedureTags($this->getHttpRequest()->post('tags', []), $ppChanges);

if ($canChangeProposalUnlimitedly) {
$proposalExplanationPre = $amendment->proposalExplanation;
Expand Down
21 changes: 1 addition & 20 deletions controllers/MotionActionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,26 +497,7 @@ public function actionSaveProposalStatus(string $motionSlug): ResponseInterface
$motion->proposalComment = $this->getHttpRequest()->post('proposalComment', '');
}

$oldTags = $motion->getProposedProcedureTags();
$newTags = [];
$changed = false;
foreach ($this->getHttpRequest()->post('tags', []) as $newTag) {
$tag = $motion->getMyConsultation()->getExistingTagOrCreate(ConsultationSettingsTag::TYPE_PROPOSED_PROCEDURE, $newTag, 0);
if (!isset($oldTags[$tag->getNormalizedName()])) {
$motion->link('tags', $tag);
$changed = true;
}
$newTags[] = ConsultationSettingsTag::normalizeName($newTag);
}
foreach ($oldTags as $tagKey => $tag) {
if (!in_array($tagKey, $newTags)) {
$motion->unlink('tags', $tag, true);
$changed = true;
}
}
if ($changed) {
$ppChanges->setProposalTagsHaveChanged(array_keys($oldTags), $newTags);
}
$motion->setProposedProcedureTags($this->getHttpRequest()->post('tags', []), $ppChanges);

if ($canChangeProposalUnlimitedly) {
$proposalExplanationPre = $motion->proposalExplanation;
Expand Down
41 changes: 35 additions & 6 deletions controllers/admin/ProposedProcedureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace app\controllers\admin;

use app\models\consultationLog\ProposedProcedureChange;
use app\models\exceptions\{FormError, ResponseException};
use app\models\http\{BinaryFileResponse, HtmlResponse, JsonResponse};
use app\models\settings\Privileges;
use app\components\{HTMLTools, Tools};
use app\models\db\{AmendmentAdminComment, Consultation, IMotion, MotionAdminComment, User};
use app\models\db\{AmendmentAdminComment, Consultation, ConsultationLog, IMotion, Motion, MotionAdminComment, User};
use app\models\proposedProcedure\Factory;

class ProposedProcedureController extends AdminBase
Expand Down Expand Up @@ -205,9 +207,8 @@ public function actionSaveAmendmentVisible(): JsonResponse
]);
}

public function actionSaveResponsibility(string $type, string $id): JsonResponse
private function loadIMotion(string $type, string $id): IMotion
{
/** @var null|IMotion $imotion */
$imotion = null;
switch ($type) {
case 'motion':
Expand All @@ -218,12 +219,19 @@ public function actionSaveResponsibility(string $type, string $id): JsonResponse
break;
}
if (!$imotion) {
return new JsonResponse([
throw new ResponseException(new JsonResponse([
'success' => false,
'error' => 'Could not open amendment',
]);
'error' => 'Could not open ' . $type,
]));
}

return $imotion;
}

public function actionSaveResponsibility(string $type, string $id): JsonResponse
{
$imotion = $this->loadIMotion($type, $id);

if ($this->getPostValue('comment') !== null) {
$imotion->responsibilityComment = $this->getPostValue('comment');
$imotion->save();
Expand All @@ -241,4 +249,25 @@ public function actionSaveResponsibility(string $type, string $id): JsonResponse
'success' => true
]);
}

public function actionSaveTags(string $type, string $id): JsonResponse
{
$imotion = $this->loadIMotion($type, $id);
if (!isset($this->getPostValues()['tags'])) {
throw new FormError('Missing tags');
}

$tags = $this->getPostValues()['tags'];

$ppChanges = new ProposedProcedureChange(null);
$imotion->setProposedProcedureTags($tags, $ppChanges);
if ($ppChanges->hasChanges()) {
$changeType = (is_a($imotion, Motion::class) ? ConsultationLog::MOTION_SET_PROPOSAL : ConsultationLog::AMENDMENT_SET_PROPOSAL);
ConsultationLog::logCurrUser($imotion->getMyConsultation(), $changeType, $imotion->id, $ppChanges->jsonSerialize());
}

return new JsonResponse([
'success' => true
]);
}
}
1 change: 1 addition & 0 deletions messages/de/amend.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
'proposal_refer_to' => 'Überweisen an',
'proposal_custom_str' => 'Sonstiger Status',
'proposal_tags' => 'Interne Schlagworte',
'proposal_edit_tags' => 'Schlagworte bearbeiten',
'proposal_obsoleted_by' => 'Erledigt durch',
'proposal_moved_to_other_motion' => 'Ersatz-Änderungsantrag',
'proposal_moved_to_other_motion_h' => 'Muss aktuell noch von Hand angelegt und auf den Status "Vorgeschlagene Verschiebung von anderem Antrag" gesetzt werden, um hier aufzutauchen.',
Expand Down
1 change: 1 addition & 0 deletions messages/en/amend.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
'proposal_refer_to' => 'Referred to',
'proposal_custom_str' => 'Custom status',
'proposal_tags' => 'Internal tags',
'proposal_edit_tags' => 'Edit tags',
'proposal_obsoleted_by' => 'Handled by',
'proposal_modified_accepted' => 'Modification',
'proposal_comment_title' => 'Internal comment',
Expand Down
29 changes: 28 additions & 1 deletion models/db/IMotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,33 @@ public function setTags(int $type, array $newList): void
}
}

/**
* @param string[] $newList
*/
public function setProposedProcedureTags(array $newList, ProposedProcedureChange $ppChanges): void
{
$oldTags = $this->getProposedProcedureTags();
$newTags = [];
$changed = false;
foreach ($newList as $newTag) {
$tag = $this->getMyConsultation()->getExistingTagOrCreate(ConsultationSettingsTag::TYPE_PROPOSED_PROCEDURE, $newTag, 0);
if (!isset($oldTags[$tag->getNormalizedName()])) {
$this->link('tags', $tag);
$changed = true;
}
$newTags[] = ConsultationSettingsTag::normalizeName($newTag);
}
foreach ($oldTags as $tagKey => $tag) {
if (!in_array($tagKey, $newTags)) {
$this->unlink('tags', $tag, true);
$changed = true;
}
}
if ($changed) {
$ppChanges->setProposalTagsHaveChanged(array_keys($oldTags), $newTags);
}
}

public function isVisible(): bool
{
if (!$this->getMyConsultation()) {
Expand Down Expand Up @@ -257,7 +284,7 @@ public function isResolution(): bool
{
return in_array($this->status, [static::STATUS_RESOLUTION_FINAL, static::STATUS_RESOLUTION_PRELIMINARY]);
}

public function isProposalPublic(): bool
{
if (!$this->proposalVisibleFrom) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/dbwv/assets/layout-dbwv.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/dbwv/assets/layout-dbwv.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/egp/assets/layout-egp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/egp/assets/layout-egp.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/green_layout/assets/layout-green_layout.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/green_layout/assets/layout-green_layout.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci1.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci1.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci2.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci2.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci3.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci3.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/neos/assets/layout-neos.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/neos/assets/layout-neos.css.map

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions views/admin/proposed-procedure/_index_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
}
}

$allTags = $consultation->getSortedTags(\app\models\db\ConsultationSettingsTag::TYPE_PROPOSED_PROCEDURE);

// Hint: there are probably a lot more motions/amendments than tags. So to limit the amount of queries,
// it's faster to iterate over the tags than to iterate over motions/amendments.
$getRelevantItemsFromBlock = function(AgendaVoting $votingBlock) use ($taggedMotionIds, $taggedAmendmentIds): array
Expand Down Expand Up @@ -91,6 +93,7 @@
<div class="content">
<?php
foreach ($proposedItem->votingBlocks as $votingBlock) {
/** @var \app\models\db\IVotingItem[] $items */
$items = $getRelevantItemsFromBlock($votingBlock);
if (count($items) === 0) {
continue;
Expand Down Expand Up @@ -130,9 +133,11 @@

if (is_a($item, Amendment::class)) {
$setVisibleUrl = UrlHelper::createUrl('admin/proposed-procedure/save-amendment-visible');
$saveTagsUrl = UrlHelper::createUrl(['admin/proposed-procedure/save-tags', 'type' => 'amendment', 'id' => $item->id]);
$type = 'amendment';
} else {
$setVisibleUrl = UrlHelper::createUrl('admin/proposed-procedure/save-motion-visible');
$saveTagsUrl = UrlHelper::createUrl(['admin/proposed-procedure/save-tags', 'type' => 'motion', 'id' => $item->id]);
$type = 'motion';
}

Expand Down Expand Up @@ -188,14 +193,48 @@
<?php
echo $this->render('_status_icons', ['entry' => $item, 'show_visibility' => false]);
echo Agenda::formatProposedProcedure($item, Agenda::FORMAT_HTML);

$selectedTags = [];
if (count($item->getProposedProcedureTags()) > 0) {
$tags = [];
foreach ($item->getProposedProcedureTags() as $tag) {
$tags[] = Html::encode($tag->title);
$selectedTags[] = $tag->id;
}
echo '<small style="color: grey;">' . implode(', ', $tags) . '</small>';
echo '<div class="tagNames">';
echo implode(', ', $tags);
echo '<button class="btn btn-sm btn-link tagEditOpener" type="button" title="' . Yii::t('amend', 'proposal_edit_tags') . '">';
echo '<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>';
echo '</button>';
echo '</div>';
} else {
echo '<div class="noTags">';
echo '<button class="btn btn-sm btn-link tagEditOpener" type="button">';
echo '<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>';
echo ' ' . Yii::t('amend', 'proposal_edit_tags');
echo '</button>';
echo '</div>';
}
?></td>
?>
<div class="selectize-wrapper tagsSelector hidden">
<select class="proposalTagsSelect" name="proposalTags[]" multiple="multiple" id="proposalTagsSelect">
<?php
foreach ($allTags as $tag) {
echo '<option name="' . Html::encode($tag->title) . '"';
if (in_array($tag->id, $selectedTags)) {
echo ' selected';
}
echo '>' . Html::encode($tag->title) . '</option>';
}
?>
</select>
<div class="proposalTagsSelectHolder">
<button type="button" class="tagsSaver btn btn-primary" data-save-url="<?= Html::encode($saveTagsUrl) ?>">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
</button>
</div>
</div>
</td>
<td class="visible">
<input type="checkbox" name="visible"
title="<?= Yii::t('con', 'proposal_table_visible') ?>"
Expand Down
1 change: 1 addition & 0 deletions views/admin/proposed-procedure/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
$layout->addBreadcrumb(Yii::t('admin', 'bread_list'), UrlHelper::createUrl('/admin/motion-list/index'));
$layout->addBreadcrumb(Yii::t('con', 'proposal_bc'));
$layout->loadBootstrapToggle();
$layout->loadSelectize();
$layout->addCSS('css/backend.css');

echo '<h1>' . Html::encode($this->title) . '</h1>';
Expand Down
25 changes: 25 additions & 0 deletions web/css/_proposed_procedure.scss
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,31 @@
}
}
}

.tagNames {
color: grey;
font-size: 0.8em;

.btn {
opacity: 0.5;
}
}
.noTags {
opacity: 0;
&:hover {
opacity: 0.5;
}
.btn {
font-weight: normal;
}
}
.tagsSelector {
display: flex;
width: 100%;
.proposalTagsSelect {
flex-grow: 1;
}
}
}

.agreeToProposal {
Expand Down
2 changes: 1 addition & 1 deletion web/css/layout-classic.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/css/layout-classic.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/css/layout-dbjr.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/css/layout-dbjr.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 80bb0bd

Please sign in to comment.