Skip to content

Commit

Permalink
fix(schematics): fix used translate when not i18n (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Oct 24, 2018
1 parent 0d70d26 commit 93163a9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class StartupService {
resolve(null);
});
}

<% if (i18n) { %>
private viaMockI18n(resolve: any, reject: any) {
this.httpClient
.get(`assets/tmp/i18n/${this.i18n.defaultLang}.json`)
Expand All @@ -84,7 +84,7 @@ export class StartupService {
this.viaMock(resolve, reject);
});
}

<% } %>
private viaMock(resolve: any, reject: any) {
// const tokenData = this.tokenService.get();
// if (!tokenData.token) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Component, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { SettingsService } from '@delon/theme';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';

@Component({
selector: 'header-user',
template: `
<nz-dropdown nzPlacement="bottomRight">
<div class="alain-default__nav-item d-flex align-items-center px-sm" nz-dropdown>
<nz-avatar [nzSrc]="settings.user.avatar" nzSize="small" class="mr-sm"></nz-avatar>
{{settings.user.name}}
</div>
<div nz-menu class="width-sm">
<div nz-menu-item routerLink="/pro/account/center"><i class="anticon anticon-user mr-sm"></i>
<% if (i18n) { %>{{ 'menu.account.center' | translate }}<% } else { %>个人中心<% } %>
</div>
<div nz-menu-item routerLink="/pro/account/settings"><i class="anticon anticon-setting mr-sm"></i>
<% if (i18n) { %>{{ 'menu.account.settings' | translate }}<% } else { %>个人设置<% } %>
</div>
<li nz-menu-divider></li>
<div nz-menu-item (click)="logout()"><i class="anticon anticon-logout mr-sm"></i>
<% if (i18n) { %>{{ 'menu.account.logout' | translate }}<% } else { %>退出登录<% } %>
</div>
</div>
</nz-dropdown>
`,
})
export class HeaderUserComponent {
constructor(
public settings: SettingsService,
private router: Router,
@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
) {}

logout() {
this.tokenService.clear();
this.router.navigateByUrl(this.tokenService.login_url);
}
}
16 changes: 16 additions & 0 deletions packages/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ function removeOrginalFiles() {
};
}

function fixedNg6() {
return (host: Tree) => {
const pkg = getPackage(host);
// all @angular/*
[ 'dependencies', 'devDependencies' ].forEach(type => {
Object.keys(pkg[type]).filter(key => key.startsWith('@angular/')).forEach(key => {
pkg[type][key] = "^6.1.10";
});
});
pkg.devDependencies['@angular-devkit/build-angular'] = '~0.10.2';
pkg.devDependencies['typescript'] = '~2.9.2';
overwritePackage(host, pkg);
};
}

function fixMain() {
return (host: Tree) => {
// fix: main.ts using no hmr file
Expand Down Expand Up @@ -383,6 +398,7 @@ export default function(options: ApplicationOptions): Rule {
removeOrginalFiles(),
addFilesToRoot(options),
fixMain(),
fixedNg6(),
forceLess(),
addStyle(options),
installPackages(),
Expand Down
1 change: 0 additions & 1 deletion scripts/ci/build-schematics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ copyFiles() {
"${1}src/app/layout/default/header/components/icon.component.ts|${2}application/files/src/app/layout/default/header/components/"
"${1}src/app/layout/default/header/components/notify.component.ts|${2}application/files/src/app/layout/default/header/components/"
"${1}src/app/layout/default/header/components/task.component.ts|${2}application/files/src/app/layout/default/header/components/"
"${1}src/app/layout/default/header/components/user.component.ts|${2}application/files/src/app/layout/default/header/components/"
# router
"${1}src/app/routes/callback|${2}application/files/src/app/routes/"
"${1}src/app/routes/exception|${2}application/files/src/app/routes/"
Expand Down

0 comments on commit 93163a9

Please sign in to comment.