mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
Add validation to background field
This commit is contained in:
parent
7811d60efb
commit
f85d499bbf
10 changed files with 130 additions and 25 deletions
|
@ -15,9 +15,35 @@ module.exports = {
|
|||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
},
|
||||
// TODO: add validation
|
||||
background: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (_.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Project.BACKGROUND_TYPES.includes(value.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
value.type === 'gradient' &&
|
||||
_.size(value) === 2 &&
|
||||
Project.BACKGROUND_GRADIENTS.includes(value.name)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value.type === 'image' && _.size(value) === 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
},
|
||||
backgroundImage: {
|
||||
type: 'json',
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = {
|
|||
type: 'json',
|
||||
custom: (value) =>
|
||||
_.isPlainObject(value) &&
|
||||
/* _.isUndefined(value.background) || _.isNull(value.background) && */
|
||||
(_.isUndefined(value.background) || _.isPlainObject(value.background)) &&
|
||||
(_.isUndefined(value.backgroundImage) || _.isNull(value.backgroundImage)),
|
||||
required: true,
|
||||
},
|
||||
|
@ -20,6 +20,10 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
invalidParams: {},
|
||||
},
|
||||
|
||||
async fn(inputs, exits) {
|
||||
if (!_.isUndefined(inputs.values.backgroundImage)) {
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
@ -33,9 +37,37 @@ module.exports = {
|
|||
inputs.values.background = {
|
||||
type: 'image',
|
||||
};
|
||||
} else if (
|
||||
_.isNull(inputs.values.backgroundImageDirname) &&
|
||||
inputs.record.background &&
|
||||
inputs.record.background.type === 'image'
|
||||
) {
|
||||
inputs.values.background = null; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
|
||||
const project = await Project.updateOne(inputs.record.id).set(inputs.values);
|
||||
let project;
|
||||
if (inputs.values.background && inputs.values.background.type === 'image') {
|
||||
if (_.isNull(inputs.values.backgroundImageDirname)) {
|
||||
throw 'invalidParams';
|
||||
}
|
||||
|
||||
if (_.isUndefined(inputs.values.backgroundImageDirname)) {
|
||||
project = await Project.updateOne({
|
||||
id: inputs.record.id,
|
||||
backgroundImageDirname: {
|
||||
'!=': null,
|
||||
},
|
||||
}).set(inputs.values);
|
||||
|
||||
if (!project) {
|
||||
delete inputs.values.background; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
project = await Project.updateOne(inputs.record.id).set(inputs.values);
|
||||
}
|
||||
|
||||
if (project) {
|
||||
if (
|
||||
|
|
|
@ -5,7 +5,40 @@
|
|||
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
|
||||
*/
|
||||
|
||||
const BACKGROUND_TYPES = ['gradient', 'image'];
|
||||
|
||||
const BACKGROUND_GRADIENTS = [
|
||||
'old-lime',
|
||||
'ocean-dive',
|
||||
'tzepesch-style',
|
||||
'jungle-mesh',
|
||||
'strawberry-dust',
|
||||
'purple-rose',
|
||||
'sun-scream',
|
||||
'warm-rust',
|
||||
'sky-change',
|
||||
'green-eyes',
|
||||
'blue-xchange',
|
||||
'blood-orange',
|
||||
'sour-peel',
|
||||
'green-ninja',
|
||||
'algae-green',
|
||||
'coral-reef',
|
||||
'steel-grey',
|
||||
'heat-waves',
|
||||
'velvet-lounge',
|
||||
'purple-rain',
|
||||
'blue-steel',
|
||||
'blueish-curve',
|
||||
'prism-light',
|
||||
'green-mist',
|
||||
'red-curtain',
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
BACKGROUND_TYPES,
|
||||
BACKGROUND_GRADIENTS,
|
||||
|
||||
attributes: {
|
||||
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
|
||||
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue