File
Implements
Metadata
selector |
div[product-spec-main] |
styleUrls |
./product-spec-main.component.scss |
templateUrl |
./product-spec-main.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
HostBindings
|
|
Methods
ngOnDestroy
|
ngOnDestroy()
|
|
|
Private
parseJson
|
parseJson(data: any)
|
|
Parameters :
Name |
Type |
Optional |
data |
any
|
No
|
|
Private
searchSubject
|
searchSubject()
|
|
|
noResults
|
Default value : false
|
|
search
|
Type : SearchService
|
|
import { OnInit, Component, Input, OnDestroy, HostBinding } from '@angular/core';
import { SearchFactory, SearchService, HttpParams } from 'skf-search-angular-service';
import { PublicationService } from 'src/app/core/services/publication-service/publication.service';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { IdGeneratorService } from 'src/app/core/services/id-generator.service';
import { AppConfig } from '../../../../../app.config';
interface ProductInfoData {
title: string;
information: string;
}
@Component({
selector: 'div[product-spec-main]',
templateUrl: './product-spec-main.component.html',
styleUrls: ['./product-spec-main.component.scss']
})
export class ProductSpecMainComponent implements OnInit, OnDestroy {
@Input() entity;
data: ProductInfoData;
search: SearchService;
result;
tableId;
sortedColumn;
sortDir;
sortData;
searchSub;
noResults = false;
specId: string;
@HostBinding('class') get class() { return 'col-md-12 space-between'; }
constructor(
private searchFactory: SearchFactory,
private util: UtilService,
private pubService: PublicationService,
private idGenerator: IdGeneratorService
) {
this.specId = this.idGenerator.getId(); // ID for search service instance
this.search = this.searchFactory.get(`product-spec-${this.specId}`, `opc-categories-${AppConfig.settings.searchEnvironment.name}`);
}
ngOnInit() {
this.data = this.parseJson(this.entity);
this.searchSub = this.searchSubject();
// Initial search
this.tableId = this.util.extract(this.entity, 'ProductTableID');
const lang = this.pubService.getLanguage();
const pubId = this.pubService.getPublicationId();
const searchString = `id=${this.tableId}&language=${lang}&source=webpim&site=${pubId}`;
const httpParams = new HttpParams({fromString: searchString});
this.search.doSearchWithParameters({params: httpParams});
}
private searchSubject(): void {
this.search.result.subscribe(res => {
this.result = res;
this.sortData = {
systems: res['systems'],
sortOptions: res['documentList']['sortOptions'],
tableData: null
};
const docs = this.util.extract(res, 'documentList', 'documents');
this.noResults = (docs && docs.length === 0);
});
}
private parseJson(data: any): ProductInfoData {
const parsed: ProductInfoData = {
title: this.util.extract(data, 'Title'),
information: this.util.extract(data, 'Information')
};
return parsed;
}
ngOnDestroy(): void {
// Unsubscribe when component is destroyed
if (this.searchSub) { this.searchSub.unsubscribe(); }
}
}
<h2 class="title" *ngIf="data.title">{{data.title}}</h2>
<div class="product-spec-main" [id]="'result-' + specId" *ngIf="result">
<div class="row">
<div class="col-md-12 toolbelt">
<sort-options *ngIf="result?.documentList" [data]="sortData" [id]="specId"></sort-options>
</div>
<div class="col-lg-3">
<app-facet-list [facets]="result.facets" [stats]="result.stats" [useHierarchy]="false" [id]="specId"></app-facet-list>
</div>
<div class="col-md-12 col-lg-9" *ngIf="!noResults">
<product-table [documentList]="result.documentList" [tableId]="tableId" *ngIf="result.documentList">
</product-table>
<app-pagination [pagination]="result.documentList.pagination" *ngIf="result?.documentList?.pagination"
[id]="specId"></app-pagination>
</div>
<div class="col-md-12 col-lg-9" *ngIf="noResults">
<no-search-result></no-search-result>
</div>
<div class="col-md-12 information" *ngIf="data.information">
<rich-text-field [body]="data.information"> </rich-text-field>
</div>
</div>
</div>
@import "src/app/styles/helpers";
.title {
color: $cool-grey;
}
.information {
padding-top: calc-rem(30);
}
.product-spec-main {
.toolbelt {
display: flex;
flex-direction: row;
justify-content: flex-start;
margin-bottom: calc-rem(35);
align-items: center;
}
}
Legend
Html element with directive