JHipster yeoman repeating prompt based on option selected - response

Suppose I want to prompt the user to select among a list of database options with "type checkbox":
{
type: 'checkbox',
name: 'databaseType',
message: `Which ${chalk.yellow('*type*')} of database(s) would you like to use?`,
choices: response => {
const databaseOpts = [
{
value: 'mysql',
name: 'MySQL'
},
{
value: 'cassandra',
name: 'Cassandra'
},
{
value: 'mongodb',
name: 'MongoDB'
}
];
return databaseOpts;
},
default: 0
},
After this initial prompt, I want to get the response for whichever option(s) they selected and prompt them again for the name of the database based on their selection(s) then store them:
{
when: response => response.databaseType === 'mysql',
type: 'input',
name: 'selectedMySQL',
message: 'What is the name of your mysql database? ',
default: 'testmysql',
store: true
},
{
when: response => response.databaseType === 'cassandra',
type: 'input',
name: 'selectedCassandra',
message: 'What is the name of your cassandra database? ',
default: 'testcassandra',
store: true
},
{
when: response => response.databaseType === 'mongo',
type: 'input',
name: 'selectedMongo',
message: 'What is the name of your mongo database? ',
default: 'testmongo',
store: true
}
Sample Desired Output:
For example user's choices in databaseOpts: {mysql, mongodb}
It will then ask:
1) What is the name of your mysql database?:
2) What is the name of your mongo database?:
User enters the name(s) respectively which will be stored in selectedMySQL and selectedMongo.
I'm unfamiliar with yeoman syntax, but this is the logic I want to implement. Please help, Thanks.
I tried:
when: response => response.databaseType.databaseOpts === 'mysql'
but it's still skipping the response prompts.

Related

How do I use entity listeners in TypeORM without using decorators?

I'm working on creating a users table. I want to be able to set the password field (which should ideally not be a saved field (not sure if typeorm allows that yet)) and on insert/update I want to look and see if the password field is set, if it is I want to save a new salt and a hashed password to the database instead. I found some thing that showed me how to do it with the #BeforeInsert entity listener, but i'm using javascript without decorators.
user.entity.js:
module.exports = new EntitySchema({
name: "User",
columns: {
id: { primary: true, type: "uuid", generated: "uuid" },
username: { type: "text", unique: true },
password: { type: "text"}, //i'd prefer this to be hashed_password and password to only be used in the listeners
salt: { type: "text" },
email: { type: "text", unique: true },
},
})

Ant Design. How to set form field error message dynamically?

A form field has many asynchronous check rules, since a composited api can check these rules one time by return different result, i do not want to fire so many api request.
the syntax is updated in v4
new syntax is:
setFields. | Set fields status | (fields: FieldData[]) => void
example :
form.setFields([
{
name: 'field-to-update',
errors: ['error-string'],
},
]);
Use form.setFields
Syntax
Function({ fieldName: { value: any, errors: Error } })
Example from here -
this.props.form.setFields({
user: {
value: values.user,
errors: [new Error('forbid ha')],
},
});
When you need to add a custom error message just use validateStatus && help attributes.
For example, you've got an error as loginError (string) in your props:
<Form.Item
{ ...props.loginError && {
help: props.loginError,
validateStatus: 'error',
}}>
{getFieldDecorator('email', {
rules: [
{ required: true, message: 'You have to write the email' },
],
})(
<Input size="large"/>,
)}
</Form.Item>
form.setFields([
{
name: "email", // required
value: "myemail##gmail.com",//optional
errors: ["Invalid email"],
},
]);
I used it in v4.16.11

Set default selected value in extjs6 comboBox

I have made code like below
Ext.define('Abc.store.Indicator', {
extend: 'Ext.data.Store',
alias: 'store.indicator',
fields: ['key', 'value'],
proxy: {
type: 'memory',
reader: {
type: 'array'
}
},
data: [
["ALL", "ALL"],
["Y", "Y"],
["N", "N"]
]
});
Ext.define('Abc.view.main.Indicator', {
extend: 'Ext.form.field.ComboBox',
xtype: 'indicator',
fieldLabel: 'Ind',
name: 'indicator',
displayField: 'value',
valueField: 'key',
store: {
type: 'indicator'
}
});
and in report items i use like
items: [{xtype:'indicator'}]
When user opens the report, i want 'N' to be displayed as default value. How do i do this. I set 'value' key, but when dropdown is opened, selected value is different.
Maybe you can put queryMode: 'local' in the config of 'Abc.view.main.Indicator', or the store will load.
Here is the key code classic/classic/src/form/field/ComboBox.js line 1562
if (lastSelected && selectionModel.selected.length && store.indexOf(lastSelected) > -1) {
itemNode = lastSelected;
}
So the new Store doesn't has the lastSelected which you set.

extjs 4.2 POST data id=0 generates method not allowed - laravel 4

When I send data ( store in codeblock ) to my laravel 4 server I get "method not allowed" and the server returns all methods allowed except POST. When I comment out 'id' in my model, everything works. ( don't want to comment out id)
I tried the writeRecordId:false and writeAllFields:false in my writer property but this doesn't remove the id while sending..
Ext.define('Equipment.store.Equipments', {
extend: 'Ext.data.Store',
model: 'Equipment.model.Equipment',
requires: ['Ext.data.proxy.Rest'],
alias: 'store.Equipments',
proxy: {
type: 'rest',
url: '/json/stock/equipment',
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json'
}
},
groupField: 'location'
});
data send:
{"id":0, "location":"Building123","locationDetails":"office 2","locationIndex":"drawre 5", "description":"item 7"}
I guess I've sorta solved it I think:
Ext.define('Equipment.model.Equipment', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id',
type: 'number',
useNull: true
},
Placing 'useNull: true' along id sets {"id":null, ... in the data which is accepted by the server. Anyone care to comment?

Iterate through properties of current context objects in Dust.js

Given the JSON object:
errors =
{
hashed_password: {
message: 'Validator "Password cannot be blank" failed for path hashed_password',
name: 'ValidatorError',
path: 'hashed_password',
type: 'Password cannot be blank' },
username: {
message: 'Validator "Username cannot be blank" failed for path username',
name: 'ValidatorError',
path: 'username',
type: 'Username cannot be blank' },
email: {
message: 'Validator "Email cannot be blank" failed for path email',
name: 'ValidatorError',
path: 'email',
type: 'Email cannot be blank' },
name: {
message: 'Validator "Name cannot be blank" failed for path name',
name: 'ValidatorError',
path: 'name',
type: 'Name cannot be blank' }
}
How do I iterate through the properties of each "current context" object?
I would think you do something like this:
{#errors}
{#.}
{type}
{/.}
{/errors}
If you really have to put meaningful data into object keys, consider writing a contextual helper, as per:
https://github.com/akdubya/dustjs/issues/9
Dust.js output JSON key
It is not possible to iterate through members of an object in Dust. Part of the reason is that you cannot know the order of the members. Another part is that this is seen as bringing too much logic into Dust.
Instead, you can change the JSON to look more like this:
{
errors: [
{
hashed_password: {
message: 'Validator "Password cannot be blank" failed for path hashed_password',
name: 'ValidatorError',
path: 'hashed_password',
type: 'Password cannot be blank'
}
},
{
username: {
message: 'Validator "Username cannot be blank" failed for path username',
name: 'ValidatorError',
path: 'username',
type: 'Username cannot be blank'
}
},
{
email: {
message: 'Validator "Email cannot be blank" failed for path email',
name: 'ValidatorError',
path: 'email',
type: 'Email cannot be blank'
}
},
{
name: {
message: 'Validator "Name cannot be blank" failed for path name',
name: 'ValidatorError',
path: 'name',
type: 'Name cannot be blank'
}
]
}
You can iterate over an object using a helper.
For example, you could define a helper like this one:
dust.helpers.iter = function(chunk, context, bodies, params) {
var obj = dust.helpers.tap(params.obj, chunk, context);
var iterable = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var value = obj[key];
iterable.push({
'$key': key,
'$value': value,
'$type': typeof value
});
}
}
return chunk.section(iterable, context, bodies);
};
Then, in your template, you would loop through like this:
{#iter obj=errors}
{$value.type}
{/iter}

Resources