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

Generate admin ui according to the flag value #12738

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b86b9ff
Add with-audit-ui flag
avdev4j Oct 13, 2020
5b60679
[Angular] Remove admin page links in the navbar
avdev4j Oct 13, 2020
a4e9f05
[skip ci] Angular - Generate Admin UI components according to the flag
avdev4j Oct 21, 2020
f4ba20f
[skip ci] Remove Cypress admin test according to the flag
avdev4j Oct 21, 2020
67f0172
Add a test about admin routing.
avdev4j Oct 21, 2020
4b93723
Move from an option to a prompt for admin ui
avdev4j Oct 27, 2020
ae7a353
Avoid to generate admin components when withAdminUi is False
avdev4j Oct 27, 2020
ea8b358
Avoid to generate routes for admin in react app when withAdminUi is f…
avdev4j Oct 27, 2020
d2020de
[React] Remove admin page links in the menu
avdev4j Oct 27, 2020
f814b7b
[React] Remove admin components according to the withAdminUi
avdev4j Oct 27, 2020
f2784a9
[React] Keep Swagger Ui when no admin ui is chosen
avdev4j Nov 2, 2020
1563578
[Angular] Keep Swagger Ui when no admin ui is chosen
avdev4j Nov 2, 2020
a9623bb
merge main branch
avdev4j Nov 3, 2020
a846f07
[Vue] Remove admin components according to the withAdminUi
avdev4j Nov 3, 2020
49b35c6
Don't generate admin ui i18n files according to the flag
avdev4j Nov 3, 2020
f9569bb
Fix tests
avdev4j Nov 3, 2020
cec3227
Change i18n expected files to match with admin UI flag value
avdev4j Nov 3, 2020
9f9d7ec
Add withAdminUi as false for integration-tests
avdev4j Nov 3, 2020
f55b835
Merge branch 'main' into 12090-generate-admin-ui-according-to-flag
avdev4j Nov 8, 2020
d350702
Add JDL WITH_ADMIN_UI support
avdev4j Nov 8, 2020
9dbb9cb
use 'to.be.true' instead of 'to.equal(true)'.
avdev4j Nov 9, 2020
f0da549
Use literal Regexp instead of new Regexp()
avdev4j Nov 9, 2020
3dd77d1
remove blank space
avdev4j Nov 9, 2020
5f855ee
Move to async for client prompts
avdev4j Nov 9, 2020
6845a4f
Rework bootswatch function and add local and online functions
avdev4j Nov 10, 2020
b63a6c8
Use destructuring instead
avdev4j Nov 10, 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
130 changes: 63 additions & 67 deletions generators/client/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ module.exports = {
askForClientThemeVariant,
};

function askForModuleName() {
if (this.jhipsterConfig.baseName) return undefined;
async function askForModuleName() {
if (this.jhipsterConfig.baseName) return;

return this.askModuleName(this);
await this.askModuleName(this);
}

function askForClient() {
if (this.existingProject) return true;
async function askForClient() {
if (this.existingProject) return;

const applicationType = this.applicationType;

Expand All @@ -62,28 +62,27 @@ function askForClient() {
},
];

const PROMPT = {
const answers = await this.prompt({
type: 'list',
name: 'clientFramework',
when: response => applicationType !== 'microservice' && applicationType !== 'uaa',
when: () => applicationType !== 'microservice' && applicationType !== 'uaa',
message: `Which ${chalk.yellow('*Framework*')} would you like to use for the client?`,
choices,
default: clientDefaultConfig.clientFramework,
};

return this.prompt(PROMPT).then(prompt => {
this.clientFramework = this.jhipsterConfig.clientFramework = prompt.clientFramework;
if (this.clientFramework === 'no') {
this.skipClient = this.jhipsterConfig.skipClient = true;
}
});

this.clientFramework = this.jhipsterConfig.clientFramework = answers.clientFramework;
if (this.clientFramework === 'no') {
this.skipClient = this.jhipsterConfig.skipClient = true;
}
}

function askForClientTheme() {
async function askForClientTheme() {
if (this.existingProject) {
return;
}

const self = this;
const skipClient = this.skipClient;
const defaultChoices = [
{
Expand Down Expand Up @@ -113,59 +112,28 @@ function askForClientTheme() {
{ value: 'yeti', name: 'Yeti' },
];

const PROMPT = {
const bootSwatchChoices = await retrieveBootswatchThemes(self).catch(() =>
self.warning('Could not fetch bootswatch themes from API. Using default ones.')
);
const answers = await this.prompt({
type: 'list',
name: 'clientTheme',
when: () => !skipClient,
message: 'Would you like to use a Bootswatch theme (https://bootswatch.com/)?',
choices: defaultChoices,
choices: bootSwatchChoices || defaultChoices,
default: clientDefaultConfig.clientTheme,
};
});

const self = this;
const promptClientTheme = function (PROMPT) {
return self.prompt(PROMPT).then(prompt => {
self.clientTheme = self.jhipsterConfig.clientTheme = prompt.clientTheme;
});
};

const done = this.async();
this.httpsGet(
'https://bootswatch.com/api/4.json',
// eslint-disable-next-line consistent-return
body => {
try {
const { themes } = JSON.parse(body);

PROMPT.choices = [
{
value: 'none',
name: 'Default JHipster',
},
...themes.map(theme => ({
value: theme.name.toLowerCase(),
name: theme.name,
})),
];
} catch (err) {
this.warning('Could not fetch bootswatch themes from API. Using default ones.');
}
done(undefined, promptClientTheme(PROMPT));
},
() => {
this.warning('Could not fetch bootswatch themes from API. Using default ones.');
done(undefined, promptClientTheme(PROMPT));
}
);
this.clientTheme = this.jhipsterConfig.clientTheme = answers.clientTheme;
}

function askForClientThemeVariant() {
async function askForClientThemeVariant() {
if (this.existingProject) {
return undefined;
return;
}
if (this.clientTheme === 'none') {
this.clientThemeVariant = '';
return undefined;
return;
}

const skipClient = this.skipClient;
Expand All @@ -176,36 +144,64 @@ function askForClientThemeVariant() {
{ value: 'light', name: 'Light' },
];

const PROMPT = {
const answers = await this.prompt({
type: 'list',
name: 'clientThemeVariant',
when: () => !skipClient,
message: 'Choose a Bootswatch variant navbar theme (https://bootswatch.com/)?',
choices,
default: clientDefaultConfig.clientThemeVariant,
};

return this.prompt(PROMPT).then(prompt => {
this.clientThemeVariant = this.jhipsterConfig.clientThemeVariant = prompt.clientThemeVariant;
});

this.clientThemeVariant = this.jhipsterConfig.clientThemeVariant = answers.clientThemeVariant;
}

function askForAdminUi() {
async function askForAdminUi() {
if (this.existingProject) {
return undefined;
return;
}

const skipClient = this.skipClient;

const PROMPT = {
const answers = await this.prompt({
type: 'confirm',
name: 'withAdminUi',
when: () => !skipClient,
message: 'Do you want to generate the admin UI?',
default: clientDefaultConfig.withAdminUi,
};
});

this.withAdminUi = this.jhipsterConfig.withAdminUi = answers.withAdminUi;
}

return this.prompt(PROMPT).then(prompt => {
this.withAdminUi = this.jhipsterConfig.withAdminUi = prompt.withAdminUi;
async function retrieveBootswatchThemes(generator) {
return new Promise((resolve, reject) => {
generator.httpsGet(
'https://bootswatch.com/api/4.json',
// eslint-disable-next-line consistent-return
body => {
let choices;
try {
const { themes } = JSON.parse(body);

choices = [
{
value: 'none',
name: 'Default JHipster',
},
...themes.map(theme => ({
value: theme.name.toLowerCase(),
name: theme.name,
})),
];
} catch (err) {
reject();
}
resolve(choices);
},
() => {
reject();
}
);
});
}
52 changes: 24 additions & 28 deletions generators/generator-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1996,35 +1996,31 @@ module.exports = class JHipsterBaseGenerator extends PrivateBase {
*
* @param {object} generator - generator instance to use
*/
askModuleName(generator) {
const done = generator.async();
async askModuleName(generator) {
const defaultAppBaseName = this.getDefaultAppName();
generator
.prompt({
type: 'input',
name: 'baseName',
validate: input => {
if (!/^([a-zA-Z0-9_]*)$/.test(input)) {
return 'Your base name cannot contain special characters or a blank space';
}
if ((generator.applicationType === 'microservice' || generator.applicationType === 'uaa') && /_/.test(input)) {
return 'Your base name cannot contain underscores as this does not meet the URI spec';
}
if (generator.applicationType === 'uaa' && input === 'auth') {
return "Your UAA base name cannot be named 'auth' as it conflicts with the gateway login routes";
}
if (input === 'application') {
return "Your base name cannot be named 'application' as this is a reserved name for Spring Boot";
}
return true;
},
message: 'What is the base name of your application?',
default: defaultAppBaseName,
})
.then(prompt => {
generator.baseName = generator.jhipsterConfig.baseName = prompt.baseName;
done();
});
const answers = await generator.prompt({
type: 'input',
name: 'baseName',
validate: input => {
if (!/^([a-zA-Z0-9_]*)$/.test(input)) {
return 'Your base name cannot contain special characters or a blank space';
}
if ((generator.applicationType === 'microservice' || generator.applicationType === 'uaa') && /_/.test(input)) {
return 'Your base name cannot contain underscores as this does not meet the URI spec';
}
if (generator.applicationType === 'uaa' && input === 'auth') {
return "Your UAA base name cannot be named 'auth' as it conflicts with the gateway login routes";
}
if (input === 'application') {
return "Your base name cannot be named 'application' as this is a reserved name for Spring Boot";
}
return true;
},
message: 'What is the base name of your application?',
default: defaultAppBaseName,
});

generator.baseName = generator.jhipsterConfig.baseName = answers.baseName;
}

/**
Expand Down