All files / src/navigationcontrols Breadcrumbs.ts

100% Statements 15/15
100% Branches 4/4
100% Functions 3/3
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39          1x         1x   1x     1x           1x 13x 10x   3x   6x 6x 6x           3x      
/**
 * @module NavigationControls
 * 
 */ /** */
 
import { bindable, customElement, computedFrom } from 'aurelia-framework';
import { Content } from 'sn-client-js';
 
 
@customElement('breadcrumbs')
export class Breadcrumbs {
    @bindable
    public Selection: Content;
 
    @bindable
    PathChange: ({path: string}) => void;
 
 
 
 
    @computedFrom('Selection')
    public get Segments(): {name: string, path: string}[]{
        if (!this.Selection || !this.Selection.Path){
            return [];
        }
        const returns: {name: string, path: string}[] = [];
 
        this.Selection.Path.split('/').filter(s => s.length > 0).forEach((segment, index, array) => {
            const segmentPath = '/' + array.slice(0, index + 1).join('/');
            returns.push({
                name: segment,
                path: segmentPath
            });
        });
 
        return returns;
    }
 
}