File

app/dxa/dxa-entity/views/dist-office-search-views/distributor-search-list/distributor-search-list.component.ts

Implements

OnInit OnChanges

Metadata

selector div[distributor-search-list]
styleUrls ./distributor-search-list.component.scss
templateUrl ./distributor-search-list.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(distOfficeService: DistOfficeSearchService, mapsAPILoader: MapsAPILoader, labelService: LabelService, document)
Parameters :
Name Type Optional
distOfficeService DistOfficeSearchService No
mapsAPILoader MapsAPILoader No
labelService LabelService No
document No

Inputs

distOfficeList
Default value : []
distributorLoading
Type : any
selectedDistributor
Type : any
type
Type : string

Outputs

select
Type : EventEmitter

Methods

Public clickedDistributor
clickedDistributor(id: string)

Emit id to parent component on click.

Parameters :
Name Type Optional
id string No
Returns : void
Public getPanelId
getPanelId(id)

Resolve distributor ID to accordion panel ID

Parameters :
Name Optional
id No
Returns : string
ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public pageJump
pageJump(page)
Parameters :
Name Optional
page No
Returns : void

Properties

address
Type : string
contact
Type : string
distAccordion
Type : NgbAccordion
Decorators :
@ViewChild('distList')
distibutorCategoryLabel
Type : string
Public distOfficeService
Type : DistOfficeSearchService
Public document
Decorators :
@Inject(DOCUMENT)
errorMessage
Type : boolean
errorMessageLabel
Type : string
fax
Type : string
iconActiveUrl
Type : string[]
Default value : [ '/v2/assets/img/change_distributor.png', '/v2/assets/img/skf-truck-icon-active.jpg']
iconUrl
Type : string[]
Default value : [ '/v2/assets/img/skf-truck-icon.svg', '/v2/assets/img/skf-office.png']
isDistributor
Type : boolean
itemsPerPage
Type : number
Default value : 16
Public labelService
Type : LabelService
loadingLabel
Type : string
Public mapsAPILoader
Type : MapsAPILoader
noResultsFound
Type : string
Private noResultsFoundLabelKey
Type : string
Default value : 'noResultsFound'
page
Type : number
Default value : 1
phoneNumber
Type : string
productCategoryLabel
Type : string
resultsLabel
Type : string
showingLabel
Type : string
import { DistOfficeSearchService } from '../dist-office-search.service';
import { MapsAPILoader } from '@agm/core';
import { Component, Input, OnInit, Inject, ViewChild, Output, SimpleChanges, OnChanges, EventEmitter } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { LabelService } from 'src/app/core/services/label-service/label-service.service';
import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap';

@Component({
	selector: 'div[distributor-search-list]',
	templateUrl: './distributor-search-list.component.html',
	styleUrls: ['./distributor-search-list.component.scss']
})
export class DistributorSearchListComponent implements OnInit, OnChanges {

	@Input() distOfficeList = [];
	@Input() distributorLoading: any;
	@Input() selectedDistributor: any;
	@Input() type: string;
	@Output() select = new EventEmitter();

	// initiate the current value of the page for pagination.
	page = 1;
	itemsPerPage = 16;
	private noResultsFoundLabelKey = 'noResultsFound';
	noResultsFound: string;
	loadingLabel: string;
	errorMessageLabel: string;
	// Adding this field to make the prod build work, Needs to be updated by team 1/2 (Axel)
	errorMessage: boolean;
	showingLabel: string;
	resultsLabel: string;
	iconUrl: string[] = [
		'/v2/assets/img/skf-truck-icon.svg',
		'/v2/assets/img/skf-office.png'];
	iconActiveUrl: string[] = [
		'/v2/assets/img/change_distributor.png',
		'/v2/assets/img/skf-truck-icon-active.jpg'];
	address: string;
	contact: string;
	phoneNumber: string;
	fax: string;
	productCategoryLabel: string;
	distibutorCategoryLabel: string;
	isDistributor: boolean;

	@ViewChild('distList') distAccordion: NgbAccordion;

	constructor(
		public distOfficeService: DistOfficeSearchService,
		public mapsAPILoader: MapsAPILoader,
		public labelService: LabelService,
		@Inject(DOCUMENT) public document) { }

	ngOnInit(): void {
		this.labelService.getLabel(this.noResultsFoundLabelKey).then(label => this.noResultsFound = label);
		this.labelService.getLabel('loading').then(label => this.loadingLabel = label);
		this.labelService.getLabel('errorMessage').then(label => this.errorMessageLabel = label);
		this.labelService.getLabel('showing').then(label => this.showingLabel = label);
		this.labelService.getLabel('results').then(label => this.resultsLabel = label);
		this.labelService.getLabel('address').then(label => this.address = label);
		this.labelService.getLabel('contact').then(label => this.contact = label);
		this.labelService.getLabel('phoneNumber').then(label => this.phoneNumber = label);
		this.labelService.getLabel('fax').then(label => this.fax = label);
		this.labelService.getLabel('productCategoryDistOffice').then(label => this.productCategoryLabel = label);
		this.labelService.getLabel('distibutorCategory').then(label => this.distibutorCategoryLabel = label);

		this.isDistributor = this.type === 'Distributor search';
	}

	ngOnChanges(changes: SimpleChanges): void {
		/** Everytime a new list of distributors comes as Input, update state of accordions.
		 * 	If distributor is selected, open in list. Otherwise close all accordions.  */
		if (changes.distOfficeList && changes.distOfficeList.currentValue.length > 0) {
			if (!this.selectedDistributor.id) {
				this.distAccordion.collapseAll();
			} else {
				/** Need this timeout so that the list is completely loaded before opening the accordion, without this there will sometimes be a bug. */
				setTimeout(() => {
					this.distAccordion.expand(this.getPanelId(this.selectedDistributor.id));
				}, 1);
			}
		}
	}

	/** Emit id to parent component on click. */
	public clickedDistributor(id: string) {
		this.select.emit(id);
	}

	/* Jump to a specific page. */
	public pageJump(page) {
		this.page = page;
	}

	/** Resolve distributor ID to accordion panel ID */
	public getPanelId(id) {
		return `distributorHeader_${id}`;
	}
}
<div id="distributor-list">
    <span *ngIf="errorMessage">
        <h2>{{errorMessageLabel}}</h2>
    </span>
    <span *ngIf="(!distributorLoading && distOfficeList?.length === 0)">
        <h2>{{noResultsFound}}</h2>
    </span>
    <div class="distributor-accordion">
        <div class="distributor-results-count" *ngIf="!distributorLoading && distOfficeList?.length > 0">{{showingLabel}} {{distOfficeList.length}} {{resultsLabel}}</div>
        <div class="distributor-results-count" *ngIf="distributorLoading">{{loadingLabel}}</div>
        <ngb-accordion #distList="ngbAccordion" [closeOthers]="true">
            <ng-container *ngIf="distOfficeList?.length > 0">
                <ngb-panel [id]="getPanelId(distributor.id)"
                    *ngFor="let distributor of distOfficeList | paginate: { itemsPerPage: itemsPerPage, currentPage: page }">
                    <ng-template ngbPanelHeader >
                        <button class="distributor-header" [ngClass]="{'active': distList.isExpanded(getPanelId(distributor.id))}"
                            (click)="clickedDistributor(distributor.id)" ngbPanelToggle>
                            <i class="icon-related-truck" *ngIf="isDistributor"
                                [ngClass]="[distList.isExpanded(getPanelId(distributor.id)) ? 'listIconActive' : 'listIcon']"></i>
                            <i class="icon-input-location" *ngIf="!isDistributor"
                                [ngClass]="[distList.isExpanded(getPanelId(distributor.id)) ? 'listIconActive' : 'listIcon']"></i>

                            <div class="d-flex flex-column" >
                                <div class="distributor-name font-weight-bolder">
                                    {{distributor.name}}
                                </div>
                                <div class="distributor-address"
                                    *ngIf="distributor.address_1 && !distList.isExpanded(getPanelId(distributor.id))">
                                    {{distributor.address_1}}
                                </div>
                            </div>
                        </button>
                    </ng-template>
                    <ng-template ngbPanelContent>
                        <div class="row" [ngClass]="{'active': distList.isExpanded(getPanelId(distributor.id))}">
                            <div class="col-3">
                                <img class="dist-skf-logo" src="/v2/assets/img/skf-logo-blue.svg">
                            </div>
                            <div class="col-9">
                                <span class="font-weight-bolder">{{address}}</span>
                                <p class="dist-info">
                                    <span *ngIf="distributor.address_1">{{distributor.address_1}},
                                    </span>
                                    <span *ngIf="distributor.city_name">{{distributor.city_name}},
                                    </span>
                                    <span *ngIf="distributor.state">{{distributor.state}}, </span>
                                    <span *ngIf="distributor.zip_code">{{distributor.zip_code}}, </span>
                                    <span *ngIf="distributor.site">{{distributor.site}}</span>
                                </p>
                            </div>
                        </div>
                        <div class="row" [ngClass]="{'active': distList.isExpanded(getPanelId(distributor.id))}">
                            <div class="col-6">
                                <p class="dist-info" *ngIf="distributor.contact_name || distributor.email">
                                    <span class="d-flex font-weight-bolder text-wrap">{{contact}}</span>
                                    <span class="d-flex">{{distributor.contact_name}}</span>
                                    <a href="mailto:{{distributor.email}}">{{distributor.email}}</a>
                                </p>
                                <p *ngIf="distributor.phone_no">
                                    <span class="d-flex font-weight-bolder">{{phoneNumber}}</span>
                                    <span class="d-flex overflow-hidden text-nowrap">{{distributor.phone_no}}</span>
                                </p>
                                <p *ngIf="distributor.fax_no">
                                    <span class="d-flex font-weight-bolder">{{fax}}</span>
                                    <span class="d-flex overflow-hidden text-nowrap">{{distributor.fax_no}}</span>
                                </p>
                                <p class="dist-info" *ngIf="distributor.homepage">
                                    <a target="_blank" title="Homepage" href="//{{distributor.homepage}}">
                                        {{distributor.homepage}}
                                    </a>
                                </p>
                            </div>
                            <div class="col-6" *ngIf="isDistributor">
                                <p *ngIf="distributor.product_category">
                                    <span class="d-flex"><b>{{productCategoryLabel}}</b></span>
                                    <span class="text-wrap">{{distributor.product_category}}</span>
                                </p>
                                <p *ngIf="distributor.distributor_category">
                                    <span class="d-flex"><b>{{distibutorCategoryLabel}}</b></span>
                                    <span class="text-wrap">{{distributor.distributor_category}}</span>
                                </p>
                            </div>
                        </div>
                        </ng-template>

                </ngb-panel>
            </ng-container>
        </ngb-accordion>
    </div>
    <pagination-controls (pageChange)="pageJump($event)" responsive="true" previousLabel="" nextLabel="" *ngIf="distOfficeList?.length > 0">
    </pagination-controls>
</div>

./distributor-search-list.component.scss

@import "src/app/styles/helpers";

#distributor-list {
    height: 500px;
}

.listIcon{
    color: $blue;
}

.listIconActive{
    color: $green;
}

.text-wrap{
    display: table;
    overflow-wrap: break-word; // Firefox
}

.distributor-accordion {
    display: flex;
    height: 100%;
    flex-direction: column;

    .distributor-results-count {
        margin-bottom: calc-rem(4);
        font-weight: $font-weight-bolder;
    }

    ::ng-deep .accordion {
        height: 100%;
        overflow-y: auto;

        .card {
            border: none;
            border-bottom: calc-rem(1) solid $grey;
            background-color: $white;

            &-header {
                padding: 0;
                background-color: transparent;
                border: none;

                .distributor-header {
                    display: flex;
                    padding: calc-rem(3) calc-rem(10) calc-rem(3) calc-rem(3);
                    width: 100%;
                    border: none;
                    background-color: transparent;
                    margin: 0;

                    &.active {
                        background-color: $off-white;
                        padding-bottom: calc-rem(10);

                        .distributor-name {
                            color: $cool-grey;
                        }

                        &:hover {
                            .distributor-name {
                                text-decoration: none;
                            }
                        }
                    }

                    &:focus {
                        border: none;
                        outline: none;
                    }

                    &:hover {
                        .distributor-name {
                            text-decoration: underline;
                        }
                    }

                    .distributor-name {
                        display: flex;
                        color: $blue;
                    }

                    .distributor-address {
                        display: flex;
                        color: $cool-grey;
                        @include font-size(16);
                    }

                    .icon-related-truck {
                        @include font-size(16);
                        margin-top: calc-rem(2);
                        margin-right: calc-rem(20);
                    }

                    .icon-input-location {
                        @include font-size(25);
                        margin-top: calc-rem(-1);
                        margin-right: calc-rem(15);
                    }
                }
            }

            &-body {
                padding: calc-rem(10);
                padding-top: 0;
                padding-bottom: 0;

                .row {
                    &.active {
                        background-color: $off-white;
                    }

                    .dist-skf-logo {
                        height: calc-rem(15);
                    }
                }
            }
        }
    }
}

::ng-deep #distributor-list .ngx-pagination {
    padding: 0;
    margin: 0;
    margin-top: calc-rem(16);
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""