Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save widgets reload #140

Open
wants to merge 24 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2e426ee
introduce play method for accerdeon-widgets
stijnvandervegt Jun 19, 2020
2178e78
Use express middleware in openstad auth
stijnvandervegt Jun 19, 2020
f19856a
Fix cookie warning widgets
stijnvandervegt Jun 19, 2020
3b6f13e
apply play method for date-bar-widgets
stijnvandervegt Jun 19, 2020
680394b
extend openstad-widgets instead of apostrophe-widgets
stijnvandervegt Jun 19, 2020
c6fec9e
Merge branch 'development' into feature/save-widgets-reload
stijnvandervegt Jun 24, 2020
f5a6b5d
add play method to slide-widgets
stijnvandervegt Jun 24, 2020
ef23212
add play method to info-bar-widgets
stijnvandervegt Jun 24, 2020
7c03913
Merge branch 'development' into feature/save-widgets-reload
stijnvandervegt Jul 15, 2020
49ace49
add play method in voting.js
stijnvandervegt Jul 15, 2020
8f06f59
add idea-lister to voting.js and enable gridder in play method
stijnvandervegt Jul 15, 2020
a0d6655
add play method for resource form widgets and fix bugs with combinati…
stijnvandervegt Jul 15, 2020
731e132
Merge branch 'development' into feature/save-widgets-reload
stijnvandervegt Jul 29, 2020
413a801
Merge branch 'development' into feature/save-widgets-reload
stijnvandervegt Aug 7, 2020
cfeadca
debug database name
stijnvandervegt Aug 12, 2020
8574d66
log attachment upload error
stijnvandervegt Aug 13, 2020
32f25b5
create attachments folder if not exists
stijnvandervegt Aug 13, 2020
ec504fd
Merge branch 'development' into feature/save-widgets-reload
stijnvandervegt Aug 19, 2020
ea7e04a
add playerData for resource-form-widgets
stijnvandervegt Aug 19, 2020
3fedf5b
Refactor resource-form-widget
stijnvandervegt Aug 19, 2020
825f0fc
fix counter test and refactor counter widget
stijnvandervegt Aug 19, 2020
8c35035
Merge branch 'development' into feature/save-widgets-reload
stijnvandervegt Sep 25, 2020
b6bf8a8
apply play method for arguments and arguments form module
stijnvandervegt Sep 25, 2020
bf3da95
remove console logs
stijnvandervegt Sep 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cms/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function serveSites (req, res, next) {
function serveSite(req, res, siteConfig, forceRestart) {
const runner = Promise.promisify(run);
let dbName = siteConfig.config && siteConfig.config.cms && siteConfig.config.cms.dbName ? siteConfig.config.cms.dbName : '';

// check if the mongodb database exist. The name for databse
return dbExists(dbName).then((exists) => {
// if default DB is set
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/config/contentWidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const contentWidgets = {
},
'cookie-warning': {
adminOnly: true,
hideByDefault: true
hideByDefault: false
},
'date-bar': {},
'idea-form': {
Expand Down
54 changes: 29 additions & 25 deletions packages/cms/lib/modules/accordeon-widgets/public/js/accordeon.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
(function () {
$(document).ready(function () {
$('.accordeon-item .title').on('click', function () {

var $accordeonItem = $(this).closest('.accordeon-item');

if ($accordeonItem.hasClass('closed')) {
// Close all open items
closeItem($('.accordeon-item:not(.closed)'));

// Open the clicked item
openItem($accordeonItem);
} else {
// Close all open items
closeItem($('.accordeon-item:not(.closed)'));
}
});
});

apos.define('accordeon-widgets', {
extend: 'openstad-widgets',
construct: function (self, options) {
self.play = function ($widget, data, options) {

$widget.find('.accordeon-item .title').on('click', function () {

var $accordeonItem = $(this).closest('.accordeon-item');

if ($accordeonItem.hasClass('closed')) {
// Close all open items
closeItem($('.accordeon-item:not(.closed)'));

// Open the clicked item
openItem($accordeonItem);
} else {
// Close all open items
closeItem($widget.find('.accordeon-item:not(.closed)'));
}
});
}

function closeItem($el) {
$el.addClass('closed').find('.description').css({maxHeight: 0});
$el.addClass('closed').find('.description').css({maxHeight: 0});
}

function openItem($el) {
// Get height of description and set it as maxheight on the accordeon item
var height = $el.find('.description p').outerHeight();
$el.removeClass('closed').find('.description').css({maxHeight: height});
// Get height of description and set it as maxheight on the accordeon item
var height = $el.find('.description p').outerHeight();
$el.removeClass('closed').find('.description').css({maxHeight: height});
}
})();
}
});
47 changes: 23 additions & 24 deletions packages/cms/lib/modules/arguments-form-widgets/public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/**
* Show not logged in users the message they have to login
*/
$('.argument-form.not-logged-in textarea').click(function (ev) {
// ev.preventDefault();
// window.location.hash = 'login-required';
apos.define('arguments-form-widgets', {
extend: 'openstad-widgets',
construct: function (self, options) {
self.play = function ($widget, data, options) {
$widget.find('.argument-form').each(function(){
bindArgumentValidation($(this));
});

$widget.on('submit', '.argument-form', function (ev) {
ev.preventDefault();
var $form = $(this);
//clean up, in case already submitted before
self.submit($form);
});
}

self.submit = function($form) {
$form.unbind();
$form.data("validator", null);
bindArgumentValidation($form);
$form.submit();
}
}
});

function bindArgumentValidation ($form){
Expand Down Expand Up @@ -57,21 +74,3 @@ function bindArgumentValidation ($form){
}
});
}

/**
* Handle form validation and submit form with ajax
*/
$(document).ready(function(){
$('.argument-form').each(function(){
bindArgumentValidation($(this));
});
$('body').on('submit', '.argument-form', function (ev) {
ev.preventDefault();
var $form = $(this);
//clean up, in case already submitted before
$form.unbind();
$form.data("validator", null);
bindArgumentValidation($form);
$form.submit();
});
});
96 changes: 52 additions & 44 deletions packages/cms/lib/modules/arguments-widgets/public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
/**
* Make sure after creating the user is scrolled to the comment
*/
window.onload = function() { // using (function {} {})() happens too early
var arguments = $('.argument');
if (arguments.length > 0) {
var hash = window.location.hash;
if (hash.startsWith('#arg') && $(hash).length >0) {
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 600, function() { });
}
}


};

$(document).ready(function() {
$('body').on('click', '.argument-edit, .argument-edit-cancel', function (ev) {
ev.preventDefault();
$(this).closest('.argument').toggleClass('edit-mode');
});

$('body').on('click', '.reaction-edit, .reaction-edit-cancel', function (ev) {
ev.preventDefault();
$(this).closest('.reaction').toggleClass('edit-mode');
});

$('body').on('click', '.reply-click', function (ev) {
ev.preventDefault();

if ($(this).hasClass('logged-in')) {
var $replyForm = $(this).closest('.argument').find('.reply-form');
var $argument = $(this).closest('.argument-container');
var $replyForm = $argument.find('.reply-form');

if ($replyForm.hasClass('active')) {
$replyForm.removeClass('active');
} else {
$replyForm.addClass('active');
$replyForm.find('textarea').focus();
apos.define('arguments-widgets', {
extend: 'openstad-widgets',
construct: function (self, options) {
self.play = function ($widget, data, options) {
var arguments = $widget.find('.argument');
if (arguments.length > 0) {
var hash = window.location.hash;

/**
* Make sure after creating the user is scrolled to the comment
*/
if (hash.startsWith('#arg') && $(hash).length >0) {
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 600, function() { });
}
}
}
})

})
$widget.on('submit', '.argument-form', function (ev) {
ev.preventDefault();
var $form = $(this);
//clean up, in case already submitted before
apos.modules['arguments-form-widgets'].submit($form);
});

$widget.on('click', '.argument-edit, .argument-edit-cancel', function (ev) {
ev.preventDefault();
$(this).closest('.argument').toggleClass('edit-mode');
});

$widget.on('click', '.reaction-edit, .reaction-edit-cancel', function (ev) {
ev.preventDefault();
$(this).closest('.reaction').toggleClass('edit-mode');
});

$widget.on('click', '.reply-click', function (ev) {
ev.preventDefault();

if ($(this).hasClass('logged-in')) {
var $replyForm = $(this).closest('.argument').find('.reply-form');
var $argument = $(this).closest('.argument-container');
var $replyForm = $argument.find('.reply-form');

if ($replyForm.hasClass('active')) {
$replyForm.removeClass('active');
} else {
$replyForm.addClass('active');
$replyForm.find('textarea').focus();
}
}
})
}
}
});
28 changes: 20 additions & 8 deletions packages/cms/lib/modules/attachment-upload/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const multer = require('multer');
const upload = multer();
const multer = require('multer');
const upload = multer();

module.exports = {
extend: 'apostrophe-widgets',
Expand All @@ -14,13 +14,19 @@ module.exports = {

// check user - this module is used by the admin server which has the same SITE_API_KEY
// TODO: this should be done through generic middleware that does a more sensible check
let authHeader = req.headers['x-authorization'];
const authHeader = req.headers['x-authorization'];
if (!authHeader || authHeader != process.env.SITE_API_KEY) return next('Iznogood');

// collect files
let promises = [];
const promises = [];
req.files.forEach((file, i) => {
let path = 'public/uploads/attachments/' + file.originalname;
const attachmentsPath = 'public/uploads/attachments';
const path = `${attachmentsPath}/${file.originalname}`;

if(fs.existsSync(attachmentsPath) === false) {
fs.mkdirSync(attachmentsPath);
}

promises.push(
new Promise( (resolve,reject) => {
// existing files are ignored; it is more then likely the same file
Expand All @@ -31,7 +37,7 @@ module.exports = {
};
console.log('Create file', file.originalname);
fs.writeFile(path, file.buffer, err => {
err ? reject() : resolve()
err ? reject(err) : resolve()
});
});
})
Expand All @@ -42,10 +48,16 @@ module.exports = {
Promise
.all(promises)
.then(result => {
// Todo: create consistent and better api success response
res.json({res: 'ok'})
})
.catch(next)

.catch(error => {
console.error(error);
res.status(500);
// Todo: create consistent and better api error response
res.json({res: 'error'});
})

});
}
}
10 changes: 5 additions & 5 deletions packages/cms/lib/modules/cookie-warning-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
*/
module.exports = {
extend: 'apostrophe-widgets',
extend: 'openstad-widgets',
alias: 'cookieWarning',
label: 'Cookies preference',
addFields: [
Expand Down Expand Up @@ -67,10 +67,10 @@ module.exports = {
/**
* Add the cookieConsent to the req.data object so it ca be used in widget templates for checking before loading
*/
self.apos.app.use(function(req, res, next){
req.data.cookieConsent = req.data.global.useCookieWarning ? req.cookies && req.cookies['cookie-consent'] == 1 : true;
next();
});
self.expressMiddleware = (req, res, next) => {
req.data.cookieConsent = req.data.global.useCookieWarning ? req.cookies && req.cookies['cookie-consent'] == 1 : true;
next();
};

const superLoad = self.load;
self.load = function(req, widgets, next) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apos.define('cookie-warning-widgets', {
extend: 'apostrophe-widgets',
extend: 'openstad-widgets',
construct: function(self, options) {

self.play = function($widget, data, options) {
$widget.find('.cookie-button').click(function(event) {
event.preventDefault();

if(
(self.getCookieConsent() && $(this).data('allow') === true) ||
(!self.getCookieConsent() && $(this).data('allow') === false)
Expand All @@ -32,8 +32,9 @@ apos.define('cookie-warning-widgets', {
}
});

$(document).ready(function() {
apos.utils.onReady(function() {
var cookieConsent = apos.cookieWarning.getCookieConsent();

if (typeof cookieConsent == 'undefined') {
document.getElementById('cookiewarning-container-top') && document.getElementById('cookiewarning-container-top').classList.remove("hidden")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<strong>{{ data.widget.statusText }}</strong> {%if data.cookieConsent %}{{ data.widget.statusAllowText }}{% else %}{{ data.widget.statusDenyText }}{% endif %}<br>
<strong>{{ data.widget.description }}</strong><br>
<a href="#" class="cookie-button cookie-button-{%if data.cookieConsent %}gray{% else %}blue{% endif %}" data-allow="true" title="{{ data.widget.buttonAllowText }}">{{ data.widget.buttonAllowText }}</a>
<a href="#" class="cookie-button cookie-button-{%if data.cookieConsent %}white{% else %}gray{% endif %}" data-allow="false" title="{{ data.widget.buttonDenyText }}>{{ data.widget.buttonDenyText }}</a>
<a href="#" class="cookie-button cookie-button-{%if data.cookieConsent %}white{% else %}gray{% endif %}" data-allow="false" title="{{ data.widget.buttonDenyText }}">{{ data.widget.buttonDenyText }}</a>
</div>
</div>
Loading