-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from meta-d/develop
Merge develop to main
- Loading branch information
Showing
258 changed files
with
10,775 additions
and
4,652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,25 @@ | ||
import { Store } from './../services/store.service'; | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, Router } from '@angular/router'; | ||
import { first } from 'rxjs/operators'; | ||
import { PermissionsEnum } from '@metad/contracts'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { inject } from '@angular/core' | ||
import { ActivatedRouteSnapshot, Router } from '@angular/router' | ||
import { PermissionsEnum } from '@metad/contracts' | ||
import { combineLatest } from 'rxjs' | ||
import { first, map, tap } from 'rxjs/operators' | ||
import { Store } from './../services/store.service' | ||
|
||
@UntilDestroy() | ||
@Injectable() | ||
export class InviteGuard { | ||
hasPermission = false; | ||
organizationInvitesAllowed = false; | ||
|
||
constructor( | ||
private readonly router: Router, | ||
private readonly store: Store | ||
) {} | ||
|
||
async canActivate(route: ActivatedRouteSnapshot) { | ||
const expectedPermissions: PermissionsEnum[] = | ||
route.data.expectedPermissions; | ||
this.store.userRolePermissions$.pipe(first()).subscribe(() => { | ||
this.hasPermission = expectedPermissions.some((permission) => | ||
this.store.hasPermission(permission) | ||
); | ||
}); | ||
this.store.selectedOrganization$ | ||
.pipe(first(), untilDestroyed(this)) | ||
.subscribe((organization) => { | ||
if (organization) { | ||
this.organizationInvitesAllowed = | ||
organization.invitesAllowed; | ||
} | ||
}); | ||
if (this.organizationInvitesAllowed && this.hasPermission) { | ||
return true; | ||
} | ||
|
||
this.router.navigate(['/']); | ||
return false; | ||
} | ||
export function inviteGuard(route: ActivatedRouteSnapshot) { | ||
const store = inject(Store) | ||
const router = inject(Router) | ||
const expectedPermissions: PermissionsEnum[] = route.data.expectedPermissions | ||
return combineLatest([ | ||
store.userRolePermissions$.pipe( | ||
first(), | ||
map(() => expectedPermissions.some((permission) => store.hasPermission(permission))) | ||
), | ||
store.selectedOrganization$.pipe( | ||
first(), | ||
map((organization) => organization?.invitesAllowed) | ||
) | ||
]).pipe( | ||
map(([hasPermission, invitesAllowed]) => invitesAllowed && hasPermission), | ||
tap((allowed) => allowed || router.navigate(['/'])) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './selector.service' | ||
export * from './theme.service' | ||
export * from './icons' | ||
export * from './translate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { HttpClient } from '@angular/common/http' | ||
import en from '@angular/common/locales/en' | ||
import localeZhExtra from '@angular/common/locales/extra/zh-Hans' | ||
import zh from '@angular/common/locales/zh' | ||
import localeZh from '@angular/common/locales/zh-Hans' | ||
import { ZhHans as AuthZhHans, ZhHant as AuthZhHant } from '@metad/cloud/auth' | ||
import { ZhHans as IAppZhHans, ZhHant as IAppZhHant } from '@metad/cloud/indicator-market/i18n' | ||
import { registerLocaleData as nxRegisterLocaleData, zhHans as CoreZhHans, zhHant as CoreZhHant } from '@metad/core' | ||
import { ZhHans, ZhHant } from '@metad/ocap-angular/i18n' | ||
import { ZhHans as StoryZhHans, ZhHant as StoryZhHant } from '@metad/story/i18n' | ||
import { MissingTranslationHandler, MissingTranslationHandlerParams } from '@ngx-translate/core' | ||
import { TranslateHttpLoader } from '@ngx-translate/http-loader' | ||
import { } from '@metad/core' | ||
import { Observable, map } from 'rxjs' | ||
import { LanguagesEnum } from '../types' | ||
import { registerLocaleData } from '@angular/common' | ||
import { enUS, zhCN, zhHK } from 'date-fns/locale' | ||
|
||
|
||
export const LOCALE_DEFAULT = LanguagesEnum.SimplifiedChinese | ||
registerLocaleData(localeZh, LOCALE_DEFAULT, localeZhExtra) | ||
registerLocaleData(zh) | ||
registerLocaleData(en) | ||
nxRegisterLocaleData(CoreZhHans, LanguagesEnum.SimplifiedChinese) | ||
nxRegisterLocaleData(CoreZhHant, LanguagesEnum.TraditionalChinese) | ||
|
||
class CustomTranslateHttpLoader extends TranslateHttpLoader { | ||
getTranslation(lang: string): Observable<Object> { | ||
let ocapTranslates = {} | ||
switch (lang) { | ||
case LanguagesEnum.Chinese: | ||
case LanguagesEnum.SimplifiedChinese: | ||
ocapTranslates = { | ||
...ZhHans, | ||
...CoreZhHans, | ||
...StoryZhHans, | ||
...AuthZhHans, | ||
...IAppZhHans | ||
} | ||
break | ||
case LanguagesEnum.TraditionalChinese: | ||
ocapTranslates = { | ||
...ZhHant, | ||
...CoreZhHant, | ||
...StoryZhHant, | ||
...AuthZhHant, | ||
...IAppZhHant | ||
} | ||
break | ||
default: | ||
} | ||
return super.getTranslation(lang).pipe( | ||
map((t) => ({ | ||
...t, | ||
...ocapTranslates | ||
})) | ||
) | ||
} | ||
} | ||
|
||
export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader { | ||
return new CustomTranslateHttpLoader(http, `./assets/i18n/`, '.json') | ||
} | ||
|
||
export class MyMissingTranslationHandler implements MissingTranslationHandler { | ||
handle(params: MissingTranslationHandlerParams) { | ||
if (params.interpolateParams) { | ||
return params.interpolateParams['Default'] || params.key | ||
} | ||
return params.key | ||
} | ||
} | ||
|
||
export function mapDateLocale(locale: string) { | ||
switch (locale) { | ||
case 'zh-CN': | ||
case 'zh-Hans': | ||
case 'zh': | ||
return zhCN | ||
case 'zh-Hant': | ||
return zhHK | ||
default: | ||
return enUS | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './lazy-img.directive' | ||
export * from './manage-entity-base' |
52 changes: 52 additions & 0 deletions
52
apps/cloud/src/app/@shared/directives/manage-entity-base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { effect, inject, signal } from '@angular/core' | ||
import { ActivatedRoute, Router } from '@angular/router' | ||
import { IBasePerTenantEntityModel } from '../../@core' | ||
import { TranslationBaseComponent } from '../language/translation-base.component' | ||
|
||
/** | ||
* Extends this class to use manage entity methods | ||
*/ | ||
export abstract class ManageEntityBaseComponent< | ||
T extends IBasePerTenantEntityModel = IBasePerTenantEntityModel | ||
> extends TranslationBaseComponent { | ||
protected readonly router = inject(Router) | ||
protected readonly route = inject(ActivatedRoute) | ||
|
||
openedLinks = signal<T[]>([]) | ||
currentLink = signal<T | null>(null) | ||
|
||
constructor() { | ||
super() | ||
|
||
effect( | ||
() => { | ||
if (this.currentLink()) { | ||
const links = this.openedLinks() | ||
const index = links.findIndex((item) => item.id === this.currentLink().id) | ||
if (index > -1) { | ||
if (links[index] !== this.currentLink()) { | ||
this.openedLinks.set([...links.slice(0, index), this.currentLink(), ...links.slice(index + 1)]) | ||
} | ||
} else { | ||
this.openedLinks.set([...links, this.currentLink()]) | ||
} | ||
} | ||
}, | ||
{ allowSignalWrites: true } | ||
) | ||
} | ||
|
||
trackByEntityId(index: number, item: T) { | ||
return item?.id | ||
} | ||
|
||
setCurrentLink(link: T) { | ||
this.currentLink.set(link) | ||
} | ||
|
||
removeOpenedLink(link: T) { | ||
this.currentLink.set(null) | ||
this.openedLinks.set(this.openedLinks().filter((item) => item.id !== link.id)) | ||
this.router.navigate(['.'], { relativeTo: this.route }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
@apply w-full; | ||
} |
Oops, something went wrong.