Skip to content

Commit

Permalink
Merge pull request #416 from openstad/feature/extend-arguments-widget-cp
Browse files Browse the repository at this point in the history
Feature/extend arguments widget cp
  • Loading branch information
rudivanhierden committed Aug 7, 2023
2 parents 3a7cfba + 15e7dfb commit e1a685b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## UNRELEASED
* Allow arguments-widget and arguments-form-widget to be used outside of a resource page by setting the idea ID in the options.
* Add functionality to display multiple images as a slider (with thumbnails) on the resource representation widget
* Make image size configurable for the image widget
* Add global setting to set openstad components cdn url
Expand Down
5 changes: 2 additions & 3 deletions packages/cms/lib/modules/arguments-form-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ module.exports = {
label: 'Arguments form old',
adminOnly: true,
addFields: [
/*
{
name: 'ideaId',
name: 'id',
type: 'string',
label: 'Idea ID (if empty it will try to fetch the ideaId from the URL)',
},*/
},
{
name: 'placeholder',
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
value="Verzenden"
data-modal-text="Log in om een argument te plaatsen, te reageren, of een argument te liken."
/>

<input
type="hidden"
name="ideaId"
{% if not data.widget.ideaId %}
value="{{data.ideaId}}"
{% else %}
{% if not data.widget.id %}
value="{{data.widget.ideaId}}"
{% else %}
value="{{data.widget.id}}"
{% endif %}
/>
<input type="hidden" name="_csrf" value="{{csrfToken}}">
Expand Down
45 changes: 30 additions & 15 deletions packages/cms/lib/modules/arguments-widgets/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
/**
* A widget for displaying a list of arguments it's reactions, and a reaction form
* Needs to be placed on a resource form
* Needs to be placed on a resource form
*/
const rp = require('request-promise');

module.exports = {
extend: 'openstad-widgets',
label: 'Arguments old',
alias: 'arguments',
adminOnly: true,
addFields: [
/*
Not being used for now,
but might in the future
{
name: 'ideaId',
type: 'string',
label: 'Idea ID (if empty it will try to fetch the ideaId from the URL)',
},*/
},
{
name: 'emptyPlaceholder',
type: 'string',
Expand Down Expand Up @@ -86,28 +81,48 @@ module.exports = {
{
name: 'advanced',
label: 'Advanced',
fields: ['replyingEnabled', 'votingEnabled']
fields: ['replyingEnabled', 'votingEnabled', 'ideaId']
}
]);


const superPushAssets = self.pushAssets;
//const auth = "Basic " + new Buffer("xxx:xxx#").toString("base64");

self.pushAssets = function() {
superPushAssets();
self.pushAsset('script', 'main', { when: 'always' });
self.pushAsset('stylesheet', 'main', { when: 'always' });
};

const superLoad = self.load;
self.load = async function (req, widgets, next) {
const promises = widgets.map(async (widget) => {
if (widget.ideaId) {
const resource = await self.apos.openstadApi.getResource(req, req.data.global.siteId, 'idea', widget.ideaId, {includeArguments: 1});
widget.ajaxError = null;
if (resource) {
widget.activeResource = resource
widget.activeResourceType = 'idea';
widget.activeResourceId = resource.id;
}
}
});

await Promise.all(promises);

return superLoad(req, widgets, next);
}

var superOutput = self.output;
self.output = function(widget, options) {
widget.ideaId = options.activeResource ? options.activeResource.id : false;
widget.activeResourceType = options.activeResourceType;
widget.activeResource = options.activeResource ? options.activeResource : {};
widget.activeResourceId = options.activeResource ? options.activeResource.id : false;
if(!widget.ideaId || !widget.activeResource) {
widget.ideaId = options.activeResource ? options.activeResource.id : false;
widget.activeResourceType = options.activeResourceType;
widget.activeResource = options.activeResource ? options.activeResource : {};
widget.activeResourceId = options.activeResource ? options.activeResource.id : false;
}

return superOutput(widget, options);
};

},
}
};

1 comment on commit e1a685b

@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:development-e1a685b

Please sign in to comment.