Skip to content

Commit

Permalink
Added filebudgets to detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoJokhan committed Sep 12, 2023
1 parent fff20c7 commit b9a3a8f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
38 changes: 34 additions & 4 deletions packages/cms/lib/modules/resource-form-widgets/lib/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const eventEmitter = require('../../../../events').emitter;
const multer = require('multer');
const upload = multer();
const fs = require('fs');
const fetch = require('node-fetch');

module.exports = async function(self, options) {

Expand All @@ -23,6 +24,7 @@ module.exports = async function(self, options) {
const siteId = req.data.global.siteId;

const postUrl = `${apiUrl}/api/site/${siteId}/${req.body.resourceEndPoint}`;
const getUrl = `${apiUrl}/api/site/${siteId}/${req.body.resourceEndPoint}/${req.body.resourceId}`;

/**
* Format headerr
Expand Down Expand Up @@ -67,14 +69,42 @@ module.exports = async function(self, options) {
});

const results = await Promise.all(promises);
try {
const files = results.map(file =>
Object.assign({}, {...file, url: file.url.replace("public", siteUrl)}));


const httpHeaders = {
'Accept': 'application/json',
'Content-Type': 'application/json',
};

if (req.session.jwt) {
httpHeaders['X-Authorization'] = `Bearer ${req.session.jwt}`;
}

const response = await fetch(getUrl, {
headers: httpHeaders
});

if(response.ok) {
const idea = await response.json();
try {
let files = results.map(file =>
Object.assign({}, {...file, url: file.url.replace("public", siteUrl)}));

if(idea.extraData && idea.extraData.budgetDocuments) {
try {
const existingIdeaBudgets = JSON.parse(idea.extraData.budgetDocuments);
files = files.concat(existingIdeaBudgets);
} catch(e) {

}
}

data.extraData.budgetDocuments = JSON.stringify(files);
}catch(e) {
console.error("Budget documenten konden niet worden geupload");
}
}
}
}

//format image
if (data.image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@
}
}

.filepond-uploaded-items {
.filepond-uploaded-item {
display: flex;
padding: 8px;
justify-content: center;
align-items: center;
background-color: #f1f0ef;
margin-bottom: 8px;

a {
text-align: center;
Expand All @@ -147,7 +148,11 @@
}

button {
border-radius: 50%;
border: none;
opacity: .5;
}
button:hover {
opacity: 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ <h2>

{% if activeResource.extraData.budgetDocuments %}
{% for budget in activeResource.extraData.budgetDocuments %}
<div class="filepond-uploaded-items">
<div class="filepond-uploaded-item">
<a href="{{budget.url}}" target="_blank">
<p>{{budget.name}}</p>
</a>

<button type="button" onclick="deleteBudgetDocument('{{budget.name}}', '{{activeResource.id}}', '{{data.siteUrl}}')">
<span class="glyphicon glyphicon-remove-sign"></span>
<button type="button" onclick="deleteBudgetDocument('{{budget.name}}', '{{activeResource.id}}', '{{data.siteUrl}}')">
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXgiPjxwYXRoIGQ9Ik0xOCA2IDYgMTgiLz48cGF0aCBkPSJtNiA2IDEyIDEyIi8+PC9zdmc+"/>
</button>
</div>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ module.exports = {
widget.pageType = options.pageType;
widget.activeResourceType = options.activeResourceType;
widget.activeResource = options.activeResource ? options.activeResource : {};

if(widget.activeResource && widget.activeResource.extraData && widget.activeResource.extraData.budgetDocuments) {
try {
widget.activeResource.extraData.budgetDocuments = JSON.parse(widget.activeResource.extraData.budgetDocuments);
} catch (error) {
}
}


widget.activeResourceId = options.activeResource ? options.activeResource.id : false;

//Todo, find a nice way of adding functions per display / resource type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ <h1>{{idea.title}}</h1>
{% include 'includes/openstad-map.html' %}
</div>
{% endif %}


{% if idea.budget %}
<h3>Budget</h3>
<p>€{{(idea.budget or '') | sanitize | safe | nlbr }}</p>

{% if idea.extraData.budgetDocuments %}
{% for budget in idea.extraData.budgetDocuments %}
<div class="filepond-uploaded-items">
<a href="{{budget.url}}" target="_blank">
<p>{{budget.name}}</p>
</a>
</div>
{% endfor %}
{% endif %}
{% endif %}


</div> <!-- #primary -->

<div class="secondary">
Expand Down

0 comments on commit b9a3a8f

Please sign in to comment.