Skip to content

Commit

Permalink
reimplement
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 8, 2024
1 parent f48e062 commit eb3ae73
Show file tree
Hide file tree
Showing 129 changed files with 3,314 additions and 2,543 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"node": true,
"es2020": true
},
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"extends": ["plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
Expand All @@ -15,7 +15,6 @@
],
"rules": {
"func-names": "off",
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"import/no-unresolved": "off",
"no-restricted-syntax": [
"error",
Expand Down
2 changes: 1 addition & 1 deletion _backup/generator-angular.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
`
#home-menu-container {@extend .order-0;}
#entity-menu-container {@extend .order-1;}
#${this.tenant.entityLowerCase}-admin-menu-container {@extend .order-3;}
#${this.tenant.entityNameLowerCase}-admin-menu-container {@extend .order-3;}
#admin-menu-container {@extend .order-10;}
#languages-menu-container {@extend .order-11;}
#account-menu-container {@extend .order-12;}
Expand Down
3 changes: 1 addition & 2 deletions _backup/generator-server-entity.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const generator = 'entity-server';
module.exports = {
createGenerator: env => {
const packagePath = env.getPackagePath('jhipster:app');
// eslint-disable-next-line global-require,import/no-dynamic-require
const needleServer = require(`${packagePath}/generators/server/needle-api/needle-server`);

const TenantisedNeedle = class extends needleServer {
Expand Down Expand Up @@ -64,7 +63,7 @@ module.exports = {
customServerCode() {
if (this.tenant) {
this.addConstraintsChangelogToLiquibase(`${this.tenant.changelogDate}-1__user_${this.tenant.entityClass}`);
this.addConstraintsChangelogToLiquibase(`${this.tenant.changelogDate}-2__${this.tenant.entityLowerCase}_user_data`);
this.addConstraintsChangelogToLiquibase(`${this.tenant.changelogDate}-2__${this.tenant.entityNameLowerCase}_user_data`);
this.addConstraintsChangelogToLiquibase(`${this.tenant.changelogDate}-3__user_${this.tenant.entityClass}_constraints`);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const file = data => data.languagesToApply.map(lang => `${data.CLIENT_MAIN_SRC_DIR}i18n/${lang}/user-management.json`);
const file = data => data.languagesToApply.map(lang => `${data.srcMainWebapp}i18n/${lang}/user-management.json`);

const tmpls = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const file = data => data.languagesToApply.map(lang => `${data.CLIENT_MAIN_SRC_DIR}i18n/${lang}/global.json`);
const file = data => data.languagesToApply.map(lang => `${data.srcMainWebapp}i18n/${lang}/global.json`);

const tmpls = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { <%-angularXAppName%>SharedModule } from 'app/shared/shared.module';
@NgModule({
imports: [
<%-angularXAppName%>SharedModule,
/* jhipster-needle-add-<%- tenant.entityLowerCase %>-admin-module - JHipster will add <%- tenant.entityClass %> admin modules here */
/* jhipster-needle-add-<%- tenant.entityNameLowerCase %>-admin-module - JHipster will add <%- tenant.entityClass %> admin modules here */
RouterModule.forChild(
[
<%_ if (!skipUserManagement) { _%>
Expand All @@ -33,7 +33,7 @@ import { <%-angularXAppName%>SharedModule } from 'app/shared/shared.module';
loadChildren: () => import('app/admin/user-management/user-management.module').then(m => m.UserManagementModule)
},
<%_ } _%>
/* jhipster-needle-add-<%- tenant.entityLowerCase %>-admin-route - JHipster will add <%- tenant.entityClass %> admin routes here */
/* jhipster-needle-add-<%- tenant.entityNameLowerCase %>-admin-route - JHipster will add <%- tenant.entityClass %> admin routes here */
]
)
]
Expand Down
3 changes: 3 additions & 0 deletions generators/angular/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ exports[`SubGenerator angular of generator-jhipster-tenantview JHipster blueprin
"src/main/webapp/app/core/auth/auth-jwt.service.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/core/auth/current-tenant.service.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/core/auth/state-storage.service.ts": {
"stateCleared": "modified",
},
Expand Down
11 changes: 7 additions & 4 deletions generators/angular/generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BaseApplicationGenerator from 'generator-jhipster/generators/base-application';
import { patcherTask } from '../../lib/patcher.js';
import { clientSrcTemplatesBlock } from 'generator-jhipster/generators/client/support';
import { patcherTask } from '../tenantview/support/index.js';

export default class extends BaseApplicationGenerator {
constructor(args, opts, features) {
Expand All @@ -14,9 +15,11 @@ export default class extends BaseApplicationGenerator {
return this.asWritingTaskGroup({
async writingTemplateTask({ application }) {
await this.writeFiles({
sections: {
files: [],
},
blocks: [
clientSrcTemplatesBlock({
templates: ['app/core/auth/current-tenant.service.ts'],
}),
],
context: application,
});
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getNode } from '../../../tenantview/support/utils.js';

const file = data => `${data.srcMainWebapp}app/entities/${data.entityFolderName}/detail/${data.entityFileName}-detail.component.html`;

const tmpls = [
{
// Hide tenant if is defined
editFile: data => content => {
const label = getNode(
content,
`[jhiTranslate=${data.frontendAppName}.${data.entityTranslationKey}.${data.tenantRelationshipName}]`,
'parentNode',
);
const [init] = label.range;
const end = label.nextElementSibling.range[1];
return content.slice(0, init) + ' @if (showTenant()) { ' + content.slice(init, end) + '}' + content.slice(end);
},
},
];

export default {
file,
tmpls,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const file = data => `${data.srcMainWebapp}app/entities/${data.entityFolderName}/detail/${data.entityFileName}-detail.component.ts`;

const tmpls = [
{
// Add tenant getter to account
type: 'rewriteFile',
target: "from '@angular/router';",
tmpl: data => `import { inject } from '@angular/core';`,
},
{
// Add imports account
type: 'rewriteFile',
target: "import SharedModule from 'app/shared/shared.module';",
tmpl: "import { AccountService } from 'app/core/auth/account.service';",
},
{
// Add currentAccount field
type: 'replaceContent',
regex: true,
target: /(export class .* {\n(\s*))/,
tmpl: '$1$2showTenant = inject(AccountService).trackShowTenant();\n$2',
},
];

export default {
file,
tmpls,
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getNode } from '../../../tenantview/support/utils.js';

const file = data => `${data.srcMainWebapp}app/entities/${data.entityFolderName}/update/${data.entityFileName}-update.component.html`;

const tmpls = [
{
// Hide the tenant if the current account is from a tenant (field)
editFile: data => content => {
const [init, end] = getNode(content, `[for=field_${data.tenantRelationshipName}]`, 'parentNode.range');
return content.slice(0, init) + ' @if (showTenant()) { ' + content.slice(init, end) + '}' + content.slice(end);
},
},
];

export default {
file,
tmpls,
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const file = data => `${data.srcMainWebapp}app/entities/${data.entityFolderName}/update/${data.entityFileName}-update.component.ts`;

const tmpls = [
{
// Add imports account
type: 'rewriteFile',
target: "import SharedModule from 'app/shared/shared.module';",
tmpl: "import { AccountService } from 'app/core/auth/account.service';",
},
{
// Add currentAccount field
type: 'replaceContent',
regex: true,
target: /(export class .* {\n(\s*))/,
tmpl: '$1$2showTenant = inject(AccountService).trackShowTenant();\n$2',
},
];

export default {
file,
tmpls,
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { parse } from 'node-html-parser';
import { getNode } from '../../../tenantview/support/utils.js';

const file = data => `${data.srcMainWebapp}app/entities/${data.entityFolderName}/list/${data.entityFileName}.component.html`;

const tmpls = [
{
// Hide if currentAccount has a tenant
editFile: data => content => {
const root = parse(content);
const [thInit, thEnd] = getNode(
root,
`[jhiTranslate=${data.frontendAppName}.${data.entityTranslationKey}.${data.tenantRelationshipName}]`,
'parentNode.parentNode.range',
);
const [tdInit, tdEnd] = getNode(
root,
`[\\[routerLink\\]="['/${data.tenantEntity.entityUrl}', ${data.entityInstance}.${data.tenantRelationshipName}.${data.tenantEntity.primaryKey.name}, 'view']"]`,
'parentNode.parentNode.range',
);

return `${content.slice(0, thInit)}
@if (showTenant()) {
${content.slice(thInit, thEnd)}
}
${content.slice(thEnd, tdInit)}
@if (showTenant()) {
${content.slice(tdInit, tdEnd)}
}
${content.slice(tdEnd)}`;
},
},
];
export default {
condition: data => data.tenantAware,
file,
tmpls,
};
Loading

0 comments on commit eb3ae73

Please sign in to comment.