Skip to content
This repository has been archived by the owner on Dec 25, 2021. It is now read-only.

Commit

Permalink
Fixes name display issue for credential types with no manaul translat…
Browse files Browse the repository at this point in the history
…ion entries

Signed-off-by: Akiff Manji <akiff.manji@gmail.com>
  • Loading branch information
amanji committed Sep 1, 2021
1 parent ee94c33 commit ec05984
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/app/cred/form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

<div class="row mt-4" *ngIf="result.data as record">
<div class="col-sm-12" *ngIf="(verify$ | async) as verify">
<h1 class="page-title" id="contentStart" tabindex="-1">{{'name.' + record.credential_type.description | translate}}</h1>
<h1 class="page-title" id="contentStart" tabindex="-1">
{{ translateEntry(record.credential_type.description, "name")}}
</h1>

<div class="row title-links mb-3">
<div class="col">
Expand Down Expand Up @@ -83,7 +85,7 @@ <h5 class="my-0">
<div class="col-sm-12">
<label class="control-label" translate>cred.cred-type</label>
<div class="form-field">
{{'name.' + record.credential_type.description | translate}}
{{ translateEntry(record.credential_type.description, "name")}}
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app/cred/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,8 @@ export class CredFormComponent implements OnInit, OnDestroy, AfterViewInit {
return this._timelineRows;
}

translateEntry(value: string, prefix?: string): string {
return this._dataService.translateEntry(value, prefix);
}

}
4 changes: 2 additions & 2 deletions src/app/cred/list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="cred-detail">
<p class="cred-title">
<a class="body-link cred-link" [routerLink]="cred.topic.extLink('cred', cred.id) | localize">
{{ 'name.' + cred.credential_type.description | translate }}
{{ translateEntry(cred.credential_type.description, "name")}}
</a>
</p>
<p *ngIf="cred.related_topics?.length">
Expand Down Expand Up @@ -45,7 +45,7 @@
<div class="col-sm-4">
<div class="cred-title">
<a class="body-link cred-link" [routerLink]="cred.topic.extLink('cred', cred.id) | localize">
{{ 'name.' + cred.credential_type.description | translate }}
{{ translateEntry(cred.credential_type.description, "name")}}
</a>
</div>
<div class="cred-date" *ngIf="
Expand Down
8 changes: 7 additions & 1 deletion src/app/cred/list.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input } from '@angular/core';
import { Model } from '../data-types';
import { TopicStateService } from 'app/topic/services/topic-state.service';
import { GeneralDataService } from 'app/general-data.service';

@Component({
selector: 'cred-list',
Expand All @@ -22,6 +23,11 @@ export class CredListComponent {
get format(): string {
return this._format;
}
constructor(public stateSvc: TopicStateService){}

constructor(public stateSvc: TopicStateService, public generalDataService: GeneralDataService){}

translateEntry(value: string, prefix?: string): string {
return this.generalDataService.translateEntry(value, prefix);
}

}
2 changes: 1 addition & 1 deletion src/app/cred/timeline-cred.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{'name.' + credential.credential_type.description | translate}}
{{ translateEntry(credential.credential_type.description, "name") }}
<strong *ngIf="related_topic_name">
<span class="fa fa-link"></span> {{related_topic_name}}
</strong>
Expand Down
7 changes: 6 additions & 1 deletion src/app/cred/timeline-cred.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input } from '@angular/core';
import { GeneralDataService } from 'app/general-data.service';
import { Model } from '../data-types';

@Component({
Expand All @@ -8,7 +9,7 @@ import { Model } from '../data-types';
export class TimelineCredComponent {
protected _cred: Model.Credential;

constructor() { }
constructor(private generalDataService: GeneralDataService) { }

get credential() {
return this._cred;
Expand All @@ -30,4 +31,8 @@ export class TimelineCredComponent {
//return this._cred && this._cred.names.length && this._cred.names[0].text;
}

translateEntry(value: string, prefix?: string): string {
return this.generalDataService.translateEntry(value, prefix);
}

}
8 changes: 7 additions & 1 deletion src/app/general-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class GeneralDataService {
};
}
} else if (optname === 'credential_type_id') {
optval.label = this._translate.instant(`name.${optval.label}`)
optval.label = this.translateEntry(optval.label, 'name');
}
if (optidx in options) {
options[optidx].push(optval);
Expand Down Expand Up @@ -400,4 +400,10 @@ export class GeneralDataService {
}),
);
}

translateEntry(value: string, prefix?: string): string {
const key = prefix ? `${prefix}.${value}` : value;
const translated = this._translate.instant(key);
return translated === key ? value : translated;
}
}
3 changes: 2 additions & 1 deletion src/app/search/filters.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ <h3 class="control-label filter-group-label mb-1">{{filter.label | translate}}</
<label *ngFor="let opt of filter.options" class="list-group-item filter-item" [ngClass]="{'list-group-item-primary': opt.active, 'active': opt.focused}">
<div class="form-check">
<input type="checkbox" tabindex="0" [id]="opt.id" class="form-check-input" [value]="opt.value" [checked]="opt.active" (change)="setFilter($event, filter.name, opt.value)" (focus)="opt.focused=true" (blur)="opt.focused=false">
<span class="filter-label">{{opt.label || (opt.tlabel | translate)}}
<span class="filter-label">
{{ translateEntry(opt.tlabel || opt.label, "name") }}
<span class="badge badge-primary badge-pill ml-1" *ngIf="opt.count">{{opt.count | shortNumber}}</span>
</span>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/app/search/filters.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Input } from '@angular/core';
import { Fetch, Filter } from '../data-types';
import { GeneralDataService } from 'app/general-data.service';
import { Filter } from '../data-types';

@Component({
selector: 'search-filters',
Expand All @@ -19,6 +20,8 @@ export class SearchFiltersComponent {
this._loading = val;
}

constructor(private generalDataService: GeneralDataService) {}

get filters$() {
return this._filters.streamVisible;
}
Expand All @@ -35,4 +38,8 @@ export class SearchFiltersComponent {
upd['page'] = '1';
this._filters.update(upd);
}

translateEntry(value: string, prefix?: string): string {
return this.generalDataService.translateEntry(value, prefix);
}
}
8 changes: 3 additions & 5 deletions src/app/shared/components/select/select.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input, forwardRef } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { GeneralDataService } from 'app/general-data.service';

export interface ISelectOption {
value: string | boolean | number;
Expand All @@ -27,7 +27,7 @@ export class SelectComponent implements ControlValueAccessor {

onTouch: (any) => void;

constructor(public translate: TranslateService) { }
constructor(private generalDataService: GeneralDataService) { }

writeValue(value: any): void {
value && this.select.setValue(value);
Expand All @@ -51,8 +51,6 @@ export class SelectComponent implements ControlValueAccessor {
}

translateEntry(value: string, prefix?: string): string {
const key = prefix ? `${prefix}.${value}` : value;
const translated = this.translate.instant(key);
return translated === key ? value : translated;
return this.generalDataService.translateEntry(value, prefix);
}
}

0 comments on commit ec05984

Please sign in to comment.