mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-22236] Permission i18n support (#6843)
* localized role pipe * update tests * additional tests * update module * fix package lock * update module settings * try update code * update import * test fixes
This commit is contained in:
66
lib/cli/package-lock.json
generated
66
lib/cli/package-lock.json
generated
@@ -5,9 +5,9 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@alfresco/js-api": {
|
||||
"version": "4.3.0-3278",
|
||||
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-4.3.0-3278.tgz",
|
||||
"integrity": "sha512-rSNfbztQkiiNZ/B3mTazeNUpIjJuxhlzKLfJKa2eEyQNOr/uazNg/LiYQ0pPoTDWexurYfCetlHhd0IW//Qbwg==",
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-4.3.0.tgz",
|
||||
"integrity": "sha512-Q/OeFqQ5uQWG2mGsXBbiG6CKh5MJvdL5h3mkcDqyFHMzZwM+URB082KOlL+6tQN5JgWegHgA3jGZE8EOPviQxw==",
|
||||
"requires": {
|
||||
"event-emitter": "^0.3.5",
|
||||
"minimatch": "3.0.4",
|
||||
@@ -212,6 +212,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"call-bind": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
|
||||
"requires": {
|
||||
"function-bind": "^1.1.1",
|
||||
"get-intrinsic": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"caseless": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
|
||||
@@ -520,9 +529,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"type": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-2.3.0.tgz",
|
||||
"integrity": "sha512-rgPIqOdfK/4J9FhiVrZ3cveAjRRo5rsQBAIhnylX874y1DX/kEKSVdLsnuHB6l1KTjHyU01VjiMBHgU2adejyg=="
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-2.5.0.tgz",
|
||||
"integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -702,6 +711,16 @@
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||
},
|
||||
"get-intrinsic": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
|
||||
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
|
||||
"requires": {
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.3",
|
||||
"has-symbols": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"getpass": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||
@@ -755,6 +774,11 @@
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
||||
},
|
||||
"has-symbols": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
|
||||
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw=="
|
||||
},
|
||||
"hosted-git-info": {
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
|
||||
@@ -1193,6 +1217,11 @@
|
||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ=="
|
||||
},
|
||||
"object-inspect": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz",
|
||||
"integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
@@ -1334,9 +1363,12 @@
|
||||
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.9.6",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz",
|
||||
"integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ=="
|
||||
"version": "6.10.1",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz",
|
||||
"integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==",
|
||||
"requires": {
|
||||
"side-channel": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"read-installed": {
|
||||
"version": "4.0.3",
|
||||
@@ -1492,9 +1524,9 @@
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"semver": {
|
||||
"version": "7.3.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz",
|
||||
"integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==",
|
||||
"version": "7.3.5",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
|
||||
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
|
||||
"requires": {
|
||||
"lru-cache": "^6.0.0"
|
||||
}
|
||||
@@ -1509,6 +1541,16 @@
|
||||
"rechoir": "^0.6.2"
|
||||
}
|
||||
},
|
||||
"side-channel": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
||||
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
||||
"requires": {
|
||||
"call-bind": "^1.0.0",
|
||||
"get-intrinsic": "^1.0.2",
|
||||
"object-inspect": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"slide": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz",
|
||||
|
@@ -33,11 +33,11 @@
|
||||
[placeholder]="entry.data.getValue(entry.row, entry.col)"
|
||||
value="{{entry.data.getValue(entry.row, entry.col)}}"
|
||||
(selectionChange)="saveNewRole($event, entry.row.obj)">
|
||||
<mat-option *ngFor="let role of settableRoles" [value]="role">{{ role }}</mat-option>
|
||||
<mat-option *ngFor="let role of settableRoles" [value]="role">{{ role | adfLocalizedRole }}</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<ng-template #show_only_label>
|
||||
<span>{{entry.data.getValue(entry.row, entry.col)}}</span>
|
||||
<span>{{ entry.data.getValue(entry.row, entry.col) | adfLocalizedRole }}</span>
|
||||
</ng-template>
|
||||
</ng-template>
|
||||
</data-column>
|
||||
|
@@ -31,7 +31,7 @@ import { fakeNodeWithPermissions,
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('PermissionDisplayComponent', () => {
|
||||
describe('PermissionListComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<PermissionListComponent>;
|
||||
let component: PermissionListComponent;
|
||||
@@ -127,10 +127,10 @@ describe('PermissionDisplayComponent', () => {
|
||||
const options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(4);
|
||||
expect(options[0].nativeElement.innerText).toContain('SiteCollaborator');
|
||||
expect(options[1].nativeElement.innerText).toContain('SiteConsumer');
|
||||
expect(options[2].nativeElement.innerText).toContain('SiteContributor');
|
||||
expect(options[3].nativeElement.innerText).toContain('SiteManager');
|
||||
expect(options[0].nativeElement.innerText).toContain('ADF.ROLES.SITECOLLABORATOR');
|
||||
expect(options[1].nativeElement.innerText).toContain('ADF.ROLES.SITECONSUMER');
|
||||
expect(options[2].nativeElement.innerText).toContain('ADF.ROLES.SITECONTRIBUTOR');
|
||||
expect(options[3].nativeElement.innerText).toContain('ADF.ROLES.SITEMANAGER');
|
||||
});
|
||||
});
|
||||
}));
|
||||
@@ -152,11 +152,11 @@ describe('PermissionDisplayComponent', () => {
|
||||
const options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(5);
|
||||
expect(options[0].nativeElement.innerText).toContain('Contributor');
|
||||
expect(options[1].nativeElement.innerText).toContain('Collaborator');
|
||||
expect(options[2].nativeElement.innerText).toContain('Coordinator');
|
||||
expect(options[3].nativeElement.innerText).toContain('Editor');
|
||||
expect(options[4].nativeElement.innerText).toContain('Consumer');
|
||||
expect(options[0].nativeElement.innerText).toContain('ADF.ROLES.CONTRIBUTOR');
|
||||
expect(options[1].nativeElement.innerText).toContain('ADF.ROLES.COLLABORATOR');
|
||||
expect(options[2].nativeElement.innerText).toContain('ADF.ROLES.COORDINATOR');
|
||||
expect(options[3].nativeElement.innerText).toContain('ADF.ROLES.EDITOR');
|
||||
expect(options[4].nativeElement.innerText).toContain('ADF.ROLES.CONSUMER');
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@@ -35,11 +35,11 @@ export class PermissionListComponent implements OnInit {
|
||||
|
||||
/** Emitted when the permission is updated. */
|
||||
@Output()
|
||||
update: EventEmitter<PermissionElement> = new EventEmitter();
|
||||
update = new EventEmitter<PermissionElement>();
|
||||
|
||||
/** Emitted when an error occurs. */
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter();
|
||||
error = new EventEmitter<any>();
|
||||
|
||||
permissionList: PermissionDisplayModel[];
|
||||
settableRoles: any[];
|
||||
@@ -47,7 +47,6 @@ export class PermissionListComponent implements OnInit {
|
||||
|
||||
constructor(private nodeService: NodesApiService,
|
||||
private nodePermissionService: NodePermissionService) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -61,7 +60,7 @@ export class PermissionListComponent implements OnInit {
|
||||
private fetchNodePermissions() {
|
||||
this.nodeService.getNode(this.nodeId).subscribe((node: Node) => {
|
||||
this.actualNode = node;
|
||||
this.permissionList = this.getPermissionList(node);
|
||||
this.permissionList = this.nodePermissionService.getNodePermissions(node);
|
||||
|
||||
this.nodePermissionService.getNodeRoles(node).subscribe((settableList: string[]) => {
|
||||
this.settableRoles = settableList;
|
||||
@@ -69,26 +68,9 @@ export class PermissionListComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private getPermissionList(node: Node): PermissionDisplayModel[] {
|
||||
const allPermissions: PermissionDisplayModel[] = [];
|
||||
if (node?.permissions?.locallySet) {
|
||||
node.permissions.locallySet.map((permissionElement: PermissionElement) => {
|
||||
const permission = new PermissionDisplayModel(permissionElement);
|
||||
allPermissions.push(permission);
|
||||
});
|
||||
}
|
||||
if (node?.permissions?.inherited) {
|
||||
node.permissions.inherited.map((permissionElement: PermissionElement) => {
|
||||
const permissionInherited = new PermissionDisplayModel(permissionElement);
|
||||
permissionInherited.isInherited = true;
|
||||
allPermissions.push(permissionInherited);
|
||||
});
|
||||
}
|
||||
return allPermissions;
|
||||
}
|
||||
|
||||
saveNewRole(event: any, permissionRow: PermissionDisplayModel) {
|
||||
const updatedPermissionRole: PermissionElement = this.buildUpdatedPermission(event.value, permissionRow);
|
||||
const updatedPermissionRole = this.buildUpdatedPermission(event.value, permissionRow);
|
||||
|
||||
this.nodePermissionService.updatePermissionRole(this.actualNode, updatedPermissionRole)
|
||||
.subscribe(() => {
|
||||
this.update.emit(updatedPermissionRole);
|
||||
@@ -96,11 +78,11 @@ export class PermissionListComponent implements OnInit {
|
||||
}
|
||||
|
||||
private buildUpdatedPermission(newRole: string, permissionRow: PermissionDisplayModel): PermissionElement {
|
||||
const permissionRole: PermissionElement = {};
|
||||
permissionRole.accessStatus = permissionRow.accessStatus;
|
||||
permissionRole.name = newRole;
|
||||
permissionRole.authorityId = permissionRow.authorityId;
|
||||
return permissionRole;
|
||||
return {
|
||||
accessStatus: permissionRow.accessStatus,
|
||||
name: newRole,
|
||||
authorityId: permissionRow.authorityId
|
||||
};
|
||||
}
|
||||
|
||||
removePermission(permissionRow: PermissionDisplayModel) {
|
||||
@@ -111,5 +93,4 @@ export class PermissionListComponent implements OnInit {
|
||||
error => this.error.emit(error)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ import { MaterialModule } from '../material.module';
|
||||
import { PermissionListComponent } from './components/permission-list/permission-list.component';
|
||||
import { AddPermissionComponent } from './components/add-permission/add-permission.component';
|
||||
import { AddPermissionDialogComponent } from './components/add-permission/add-permission-dialog.component';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { CoreModule, PipeModule } from '@alfresco/adf-core';
|
||||
import { InheritPermissionDirective } from './components/inherited-button.directive';
|
||||
import { NoPermissionTemplateComponent } from './components/permission-list/no-permission.component';
|
||||
import { AddPermissionPanelComponent } from './components/add-permission/add-permission-panel.component';
|
||||
@@ -35,7 +35,8 @@ import { SearchModule } from '../search/search.module';
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
MaterialModule,
|
||||
SearchModule
|
||||
SearchModule,
|
||||
PipeModule
|
||||
],
|
||||
declarations: [
|
||||
PermissionListComponent,
|
||||
|
@@ -20,6 +20,7 @@ import { Observable, of, from, throwError } from 'rxjs';
|
||||
import { AlfrescoApiService, SearchService, NodesApiService, TranslationService } from '@alfresco/adf-core';
|
||||
import { QueryBody, Node, NodeEntry, PathElement, GroupMemberEntry, GroupMemberPaging, PermissionElement } from '@alfresco/js-api';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { PermissionDisplayModel } from '../models/permission.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -52,6 +53,25 @@ export class NodePermissionService {
|
||||
);
|
||||
}
|
||||
|
||||
getNodePermissions(node: Node): PermissionDisplayModel[] {
|
||||
const result: PermissionDisplayModel[] = [];
|
||||
|
||||
if (node?.permissions?.locallySet) {
|
||||
node.permissions.locallySet.map((permissionElement) => {
|
||||
result.push(new PermissionDisplayModel(permissionElement));
|
||||
});
|
||||
}
|
||||
|
||||
if (node?.permissions?.inherited) {
|
||||
node.permissions.inherited.map((permissionElement) => {
|
||||
const permissionInherited = new PermissionDisplayModel(permissionElement);
|
||||
permissionInherited.isInherited = true;
|
||||
result.push(permissionInherited);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the permission role for a node.
|
||||
* @param node Target node
|
||||
@@ -128,14 +148,13 @@ export class NodePermissionService {
|
||||
|
||||
private transformNodeToPermissionElement(nodes: NodeEntry[], nodeRole: any): PermissionElement[] {
|
||||
return nodes.map((node) => {
|
||||
const newPermissionElement: PermissionElement = <PermissionElement> {
|
||||
return {
|
||||
'authorityId': node.entry.properties['cm:authorityName'] ?
|
||||
node.entry.properties['cm:authorityName'] :
|
||||
node.entry.properties['cm:userName'],
|
||||
'name': nodeRole,
|
||||
'accessStatus': 'ALLOWED'
|
||||
};
|
||||
return newPermissionElement;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,10 +207,11 @@ export class NodePermissionService {
|
||||
|
||||
private buildRetrieveSiteQueryBody(nodePath: PathElement[]): QueryBody {
|
||||
const pathNames = nodePath.map((node: PathElement) => 'name: "' + node.name + '"');
|
||||
const buildedPathNames = pathNames.join(' OR ');
|
||||
const builtPathNames = pathNames.join(' OR ');
|
||||
|
||||
return {
|
||||
'query': {
|
||||
'query': buildedPathNames
|
||||
'query': builtPathNames
|
||||
},
|
||||
'paging': {
|
||||
'maxItems': 100,
|
||||
|
@@ -1,4 +1,18 @@
|
||||
{
|
||||
"ADF": {
|
||||
"ROLES": {
|
||||
"ALL": "All",
|
||||
"CONTRIBUTOR": "Contributor",
|
||||
"COLLABORATOR": "Collaborator",
|
||||
"COORDINATOR": "Coordinator",
|
||||
"EDITOR": "Editor",
|
||||
"CONSUMER": "Consumer",
|
||||
"SITECOLLABORATOR": "Site Collaborator",
|
||||
"SITECONSUMER": "Site Consumer",
|
||||
"SITECONTRIBUTOR": "Site Contributor",
|
||||
"SITEMANAGER": "Site Manager"
|
||||
}
|
||||
},
|
||||
"SAVE": "SAVE",
|
||||
"COMPLETE": "COMPLETE",
|
||||
"CANCEL": "CANCEL",
|
||||
|
50
lib/core/pipes/localized-role.pipe.spec.ts
Normal file
50
lib/core/pipes/localized-role.pipe.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LocalizedRolePipe } from './localized-role.pipe';
|
||||
|
||||
describe('LocalizedRolePipe', () => {
|
||||
let translationService: any;
|
||||
let pipe: LocalizedRolePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
translationService = jasmine.createSpyObj('TranslationService', ['instant']);
|
||||
pipe = new LocalizedRolePipe(translationService);
|
||||
});
|
||||
|
||||
it('should return null', () => {
|
||||
expect(pipe.transform(null)).toBeNull();
|
||||
});
|
||||
|
||||
it('should translate value', () => {
|
||||
translationService.instant.and.returnValue('Consumer');
|
||||
expect(pipe.transform('ADF.ROLES.CONSUMER')).toEqual('Consumer');
|
||||
});
|
||||
|
||||
it('should return the key when translation not present', () => {
|
||||
translationService.instant.and.callFake((value) => {
|
||||
if (value === 'ADF.ROLES.CONSUMER') {
|
||||
return 'Consumer';
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
|
||||
expect(pipe.transform('Contributor')).toBe('ADF.ROLES.CONTRIBUTOR');
|
||||
expect(pipe.transform('Consumer')).toEqual('Consumer');
|
||||
});
|
||||
});
|
39
lib/core/pipes/localized-role.pipe.ts
Normal file
39
lib/core/pipes/localized-role.pipe.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { TranslationService } from '../services/translation.service';
|
||||
|
||||
@Pipe({
|
||||
name: 'adfLocalizedRole'
|
||||
})
|
||||
export class LocalizedRolePipe implements PipeTransform {
|
||||
constructor(private translationService: TranslationService) {
|
||||
}
|
||||
|
||||
transform(value: string): any {
|
||||
if (value) {
|
||||
const key = `ADF.ROLES.${value.toUpperCase()}`;
|
||||
const translation = this.translationService.instant(key);
|
||||
|
||||
if (translation) {
|
||||
return translation;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
@@ -30,10 +30,13 @@ import { FileTypePipe } from './file-type.pipe';
|
||||
import { MultiValuePipe } from './multi-value.pipe';
|
||||
import { LocalizedDatePipe } from './localized-date.pipe';
|
||||
import { DecimalNumberPipe } from './decimal-number.pipe';
|
||||
import { LocalizedRolePipe } from './localized-role.pipe';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule
|
||||
CommonModule,
|
||||
TranslateModule
|
||||
],
|
||||
declarations: [
|
||||
FileSizePipe,
|
||||
@@ -47,7 +50,8 @@ import { DecimalNumberPipe } from './decimal-number.pipe';
|
||||
FileTypePipe,
|
||||
MultiValuePipe,
|
||||
LocalizedDatePipe,
|
||||
DecimalNumberPipe
|
||||
DecimalNumberPipe,
|
||||
LocalizedRolePipe
|
||||
],
|
||||
providers: [
|
||||
FileSizePipe,
|
||||
@@ -60,7 +64,8 @@ import { DecimalNumberPipe } from './decimal-number.pipe';
|
||||
FileTypePipe,
|
||||
MultiValuePipe,
|
||||
LocalizedDatePipe,
|
||||
DecimalNumberPipe
|
||||
DecimalNumberPipe,
|
||||
LocalizedRolePipe
|
||||
],
|
||||
exports: [
|
||||
FileSizePipe,
|
||||
@@ -74,7 +79,8 @@ import { DecimalNumberPipe } from './decimal-number.pipe';
|
||||
FileTypePipe,
|
||||
MultiValuePipe,
|
||||
LocalizedDatePipe,
|
||||
DecimalNumberPipe
|
||||
DecimalNumberPipe,
|
||||
LocalizedRolePipe
|
||||
]
|
||||
})
|
||||
export class PipeModule {
|
||||
|
@@ -27,5 +27,5 @@ export * from './node-name-tooltip.pipe';
|
||||
export * from './text-highlight.pipe';
|
||||
export * from './time-ago.pipe';
|
||||
export * from './user-initial.pipe';
|
||||
|
||||
export * from './localized-role.pipe';
|
||||
export * from './pipe.module';
|
||||
|
Reference in New Issue
Block a user