Skip to content

Commit

Permalink
Development (#391)
Browse files Browse the repository at this point in the history
* Make it possible to set the href on the counter

* Set counterUrl without lodash lib

* Add a message when the widget is used on a non-idea resource page and when you are logged in as admin, moderator or editor

* Made it so the title can be changed of the succesfull voting message

* Added field to phase-voting-budgeting

* Corrected spelling

* Corrected spelling

* Changed spelling of successful

* Changed spelling of step_3_successful_auth

* changed spelling in label of field

* Added message closed but open for admin / editor / moderator

* Update packages/cms/lib/modules/arguments-block-widgets/index.js

Co-authored-by: Rudi van Hierden <rudi@draad.nl>

* Update packages/cms/lib/modules/arguments-block-widgets/views/widget.html

Co-authored-by: Rudi van Hierden <rudi@draad.nl>

* Aloow for multiple tabs sections on a page

* Make js uglifyable

* Added fallback text because if you did not commit on a preexisting form then the message will not be rendered

* Feature/group tags like mzm (#386)

* Added grouping capabilities to tags on ideas(plannen) on create plannen page

* Added tagid to checbox and label instead of non working option

* specify if theme labels should be shown

* Made it so tags can be grouped by use of extraData.theme

* Changed default of showing labels to false for and made name consistent

* Changed implementation to use type

* Put back cache

* Renamed theme fields to tagType

* Added cache key for if an empty list was fetched

* Added cachekey for empty list

* Bugfix/tags remember choices on edit idea (#389)

* added forgotten groupedTags from cache

* Clean up test code

* Added fallback when choosing static form with dynamic fields

---------

Co-authored-by: Rudi van Hierden <rudi@draad.nl>
Co-authored-by: Niels Vegter <niels@denes.nl>
  • Loading branch information
3 people authored Apr 20, 2023
1 parent fc9fb62 commit 9fdab48
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 80 deletions.
4 changes: 3 additions & 1 deletion packages/cms/lib/modules/arguments-block-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ module.exports = {
const superLoad = self.load;
self.load = function(req, widgets, next) {
widgets.forEach((widget) => {
const data = req.data;

let config = createConfig({
widget: widget,
data: req.data,
data,
});
widget.config = config;
widget.divId = widget.config.divId;
widget.isClosedButRoleAllows = config.isClosed && (data.isAdmin || data.isEditor || data.isModerator);
});

return superLoad(req, widgets, next);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@

<div id="{{data.widget.containerId}}" class="osc-component" style="width: 100%; height: 100%;">

{% if data.activeResource and data.widget.isClosedButRoleAllows %}
<p>Reageren is gesloten, maar je kunt nog reageren vanwege je rol als {{ data.openstadUser.role }}</p>


{% endif %}
{% if data.activeResource and data.activeResource.publishDate %}
<div class="{{data.widget.divId}}" style="width: 100%; height: 100%;"></div>
{% elif (data.isAdmin or data.isEditor or data.isModerator) and data.activeResourceType !== 'idea'%}
<p>Deze widget kan alleen worden gebruikt op pagina`s met een resource waarbij het activeResourceType idea is</p>
{% else %}
<p>Er kunnen geen argumenten worden gegeven op een concept plan</p>
<p>Er kunnen geen argumenten worden gegeven op een concept plan</p>
{% endif %}

</div>
10 changes: 8 additions & 2 deletions packages/cms/lib/modules/begroot-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,18 @@ const fields = [
def: 'Via onderstaande knop kun je op een aparte pagina je persoonlijke stemcode invullen. Wij controleren de stemcode op geldigheid. Als dat gelukt is kom je terug op deze pagina waarna je kunt stemmen. Alle bewoners van Centrum hebben per post een stemcode ontvangen.'
},
{
name: 'step_3_succesfull_auth',
label: 'Step 3: succesfull auth',
name: 'step_3_successful_auth',
label: 'Step 3: successful auth',
type: 'string',
textarea: true,
def: 'Het controleren van je stemcode is gelukt! Je bent bijna klaar. Klik op onderstaande knop om je stem te versturen.'
},
{
name: 'successful_voting_title',
label: 'Message you see when you voted successfully',
type: 'string',
def: 'Gelukt, je hebt gestemd!'
},
{
name: 'thankyou_message',
label: 'Thank you message',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h3 class="icon-header icon-header--blue">
<small>Vul een andere stemcode in</small>
</a>
<div>
{{data.widget.step_3_succesfull_auth}}
{{data.widget.step_3_successful_auth}}
</div>
</div>

Expand Down Expand Up @@ -340,7 +340,7 @@ <h3 class="icon-header icon-header--blue">
</div>
</a>
<div class="mobile-accordion-body">
{{data.widget.step_3_succesfull_auth}}
{{data.widget.step_3_successful_auth}}
</div>
</div>
<br />
Expand All @@ -356,7 +356,7 @@ <h3 class="icon-header icon-header--blue">
<div id="steps-content-6" class="step">
<div class="text">
<div class="checkmark-block-green">
<h4>Gelukt, je hebt gestemd!</h4>
<h4>{{data.widget.successful_voting_title or "Gelukt, je hebt gestemd!"}}</h4>
<br/>
{{data.widget.thankyou_message | sanitize | safe | nlbr}}
{% if data.widget.showNewsletterButton and data.widget.showNewsletterButton == 'yes' %}
Expand Down
10 changes: 9 additions & 1 deletion packages/cms/lib/modules/idea-map-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ module.exports = {
type: 'string',
label: 'Counter text',
},
{
name: 'counterUrl',
type: 'string',
label: 'Counter url',
def: 'plannen',
required: false
},
{
name: 'useMarkerLinks',
type: 'boolean',
Expand Down Expand Up @@ -115,7 +122,7 @@ module.exports = {
{
name: 'counter',
label: 'Counter',
fields: ['displayCounter', 'counterText']
fields: ['displayCounter', 'counterText', 'counterUrl']
},
{
name: 'content',
Expand Down Expand Up @@ -169,6 +176,7 @@ module.exports = {


widgets.forEach((widget) => {
widget.counterUrl = widget.counterUrl || 'plannen';
widget.ideas = req.data.ideas ? req.data.ideas.map((idea) => {
return {
location: idea.location,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro numberPlateButton(name, caption, value, href, color="#004699") %}
{% if href %}
<a href="{{data.siteUrl}}/plannen" class="{{name}}">
<a href="{{data.siteUrl}}/{{href}}" class="{{name}}">
{% else %}
<div class="{{name}}">
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</a>
{% endif %}
{% if (data.widget.displayCounter) %}
{{numberPlateButton.numberPlateButton('no-of-locations', data.widget.counterText, data.ideas.length, '#')}}
{{numberPlateButton.numberPlateButton('no-of-locations', data.widget.counterText, data.ideas.length, data.widget.counterUrl)}}
{% endif %}
</div>
</div>
Expand Down
17 changes: 15 additions & 2 deletions packages/cms/lib/modules/openstad-pages/lib/load-tags.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const rp = require('request-promise');
const _ = require('lodash');
const moment = require('moment'); // returns the new locale, in this case 'de'
const url = require('url');
const internalApiUrl = process.env.INTERNAL_API_URL;
Expand All @@ -17,17 +18,24 @@ module.exports = function (req, res, next) {
*/
if (globalData.siteId) {
let tags;

let retrievedEmpty = false;
// if cacheIdeas is turned on, get ideas from cache
// cacheIdeas is old key, should be refactored,
// preferable we always have caching on

if (globalData.cacheIdeas) {
let cacheKey = 'tags-' + globalData.siteId;
tags = cache.get(cacheKey);
retrievedEmpty = cache.get(globalData.siteId + '-retrieved-tags-empty');
}

if (Array.isArray(tags)) {
req.data.openstadTags = tags;
req.data.groupedOpenstadTags = _.groupBy(tags, function(tag){return tag.type});

next();
} else if(retrievedEmpty) {
req.data.openstadTags = [];
next();
} else {

Expand All @@ -42,9 +50,14 @@ module.exports = function (req, res, next) {
//add tags to to the data object so it's available in templates
//use openstadTags instead of tags to prevent colliding with Apos
req.data.openstadTags = response;
req.data.groupedOpenstadTags = _.groupBy(response, function(tag){return tag.type});

// set the cache
if (globalData.cacheIdeas) {
cache.set(globalData.siteId + '-retrieved-tags-empty', response.length === 0, {
life: cacheLifespan
})

cache.set('tags-' +req.data.global.siteId, response, {
life: cacheLifespan
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
{
name: 'explanation-texts',
label: 'Explanation texts',
fields: ['step_1_intro', 'step_2_intro', 'step_3_intro', 'step_3_succesfull_auth', 'thankyou_message', 'showNewsletterButton', 'newsletterButtonText']
fields: ['step_1_intro', 'step_2_intro', 'step_3_intro', 'step_3_successful_auth','successful_voting_title', 'thankyou_message', 'showNewsletterButton', 'newsletterButtonText']
},
{
name: 'authentication',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,18 @@ const fields = [
def: 'Via onderstaande knop kun je op een aparte pagina je persoonlijke stemcode invullen. Wij controleren de stemcode op geldigheid. Als dat gelukt is kom je terug op deze pagina waarna je kunt stemmen. Alle bewoners van Centrum hebben per post een stemcode ontvangen.'
},
{
name: 'step_3_succesfull_auth',
name: 'step_3_successful_auth',
label: 'Step 3: succesfull auth',
type: 'string',
textarea: true,
def: 'Het controleren van je stemcode is gelukt! Je bent bijna klaar. Klik op onderstaande knop om je stem te versturen.'
},
{
name: 'successful_voting_title',
label: 'Message you see when you voted successfully',
type: 'string',
def: 'Gelukt, je hebt gestemd!'
},
{
name: 'thankyou_message',
label: 'Thank you message',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ <h3 class="icon-header icon-header--blue">
<small>Vul een andere stemcode in</small>
</a>
<div>
{{data.widget.step_3_succesfull_auth}}
{{data.widget.step_3_successful_auth}}
</div>
</div>

Expand Down Expand Up @@ -352,7 +352,7 @@ <h3 class="icon-header icon-header--blue">
</div>
</a>
<div class="mobile-accordion-body">
{{data.widget.step_3_succesfull_auth}}
{{data.widget.step_3_successful_auth}}
</div>
</div>
<br />
Expand All @@ -368,7 +368,7 @@ <h3 class="icon-header icon-header--blue">
<div id="steps-content-6" class="step">
<div class="text">
<div class="checkmark-block-green">
<h4>Gelukt, je hebt gestemd!</h4>
<h4>{{data.widget.successful_voting_title or "Gelukt, je hebt gestemd!"}}</h4>
<br/>
{{data.widget.thankyou_message | sanitize | safe | nlbr}}
{% if data.widget.showNewsletterButton and data.widget.showNewsletterButton == 'yes' %}
Expand Down
6 changes: 6 additions & 0 deletions packages/cms/lib/modules/resource-form-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ module.exports = {
const isReactedTo = activeResource ? (activeResource.yes > 0 || activeResource.no > 0 || activeResource.argumentCount > 0) : false;
const isOwnerOrAdmin = ((!isReactedTo || !widget.hideAdminAfterPublicAction) && isOwner) || req.data.hasModeratorRights;


widget.isTagSelected = function(tagId) {
if(!activeResource || !Array.isArray(activeResource.tags)) return false;
return activeResource.tags.findIndex(t => t.id === tagId) !== -1;
}

widget.mapConfig = self.getMapConfigBuilder(globalData)
.setDefaultSettings({
mapCenterLat: (activeResource && activeResource.location && activeResource.location.coordinates && activeResource.location.coordinates[0]) || globalData.mapCenterLat,
Expand Down
23 changes: 22 additions & 1 deletion packages/cms/lib/modules/resource-form-widgets/lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const fields = [
{
value: 'tags',
label: "Tags (currently only works for ideas)",
showFields: ['fieldKey', 'fieldRequired', 'fieldMin', 'fieldMax']
showFields: ['fieldKey', 'fieldRequired', 'tagType', 'showTagTypeLabels', 'fieldMin', 'fieldMax']
},
{
value: 'raw',
Expand Down Expand Up @@ -296,6 +296,27 @@ const fields = [
type: 'string',
textarea: true
},
{
name: 'tagType',
label: 'Optionally specify the single type (one word) by which to fetch the tags.',
type: 'string'
},
{
name: 'showTagTypeLabels',
label: 'When the above option is empty, select if the corresponding types should be shown or not',
type: 'boolean',
choices: [
{
label: 'Yes',
value: true,
},
{
label: 'No',
value: false,
}
],
def: false
},
{
name: 'notExtraDataKey',
label: 'Save field in root if data object and not in extraData, will only work if column exists in database)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ $(document).ready(function () {

$(form).find('input[type="submit"]').each(function(index, button) {
oldButtonValues.push($(this).val());

if(button.id === "btnSaveAsConcept" && publishField.val()) {
$(this).val('Verzenden...');
} else if(!publishField.val()) {
Expand All @@ -206,6 +205,12 @@ $(document).ready(function () {
success:function(response) {
formHasChanged = false;
var redirect = $(form).find('.form-redirect-uri').val();

// for some reason when you select the dynamic form then the input field with class .form-redirect-uri is not within the form
if(!redirect) {
redirect = document.querySelector('.form-redirect-uri').value;
}

redirect = redirect.replace(':id', response.id);
redirect = window.siteUrl + redirect;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
<div class="checkbox-container">
{% for tag in data.openstadTags %}
<div class="checkbox">
<input
type="checkbox"
name="tags[]"
value="{{tag.id}}"
id="checkbox-{{loop.index}}-{{option.value}}"
{% if field.fieldRequired %}required{% endif %}
{% if field.idea.tags %}checked{% endif %}
/>
<label for="checkbox-{{loop.index}}-{{option.value}}" class="checkbox-label">
{{tag.name}}
</label>
{% if field.tagType
and data.groupedOpenstadTags[field.tagType]
and data.groupedOpenstadTags[field.tagType].length %}

{% for tag in data.groupedOpenstadTags[field.tagType] %}
<div class="checkbox">
<input
type="checkbox"
name="tags[]"
value="{{tag.id}}"
id="checkbox-{{loop.index}}-{{tag.id}}"
{% if field.fieldRequired %}required{% endif %}
{% if field.idea.tags %}checked{% endif %}
/>
<label for="checkbox-{{loop.index}}-{{tag.id}}" class="checkbox-label">{{tag.name}}</label>
</div>
{% endfor %}
{% endif %}
</div>


{% if field.tagType === '' or field.tagType === undefined %}
{% for key, tagList in data.groupedOpenstadTags %}
{% set outer_loop = loop %}

{% if field.showTagTypeLabels %}
{% if outer_loop.length > 1 and key !== 'undefined' %}
<p>{{key}}</p>
{% endif %}

{% if outer_loop.length > 1 and key == 'undefined' %}
<p>Overig</p>
{% endif %}
{% endif %}

{% for tag in tagList %}
<div class="checkbox">
<input
type="checkbox"
name="tags[]"
value="{{tag.id}}"
id="checkbox-{{outer_loop.index}}-{{loop.index}}-{{tag.id}}"
{% if field.fieldRequired %}required{% endif %}
{% if data.widget.isTagSelected(tag.id) %}checked{% endif %}
/>
<label for="checkbox-{{outer_loop.index}}-{{loop.index}}-{{tag.id}}" class="checkbox-label">{{tag.name}}</label>
</div>
{% endfor %}
{% endfor %}
{% endif %}
</div>
2 changes: 2 additions & 0 deletions packages/cms/lib/modules/resource-overview-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ module.exports = {
return Object.assign({}, tag);
}) : [];

widget.groupedOpenstadTags = req.data.groupedOpenstadTags;

let response;

// if cache is turned on, check if current url is available in cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = (self, options) => {
{
name: 'tags',
label: 'Tags',
fields: ['displayTagFilters']
fields: ['displayTagFilters', 'tagType', 'showTagTypeLabels']
},
{
name: 'include_exclude',
Expand Down
Loading

1 comment on commit 9fdab48

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Published new image: openstad/frontend:master-9fdab48

Please sign in to comment.