all files / app/utils/ column.ts

56.14% Statements 32/57
75% Branches 6/8
14.29% Functions 2/14
56.36% Lines 31/55
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                    1×           8× 8× 8× 8× 8× 8× 8× 8× 8×   8× 8×     8× 8× 8× 8× 8× 8×     1×         1×         1×         1×         1×         1×         1×         1×         1×         1×         1×         1×         1×      
/* Copyright CloudLinux Zug GmbH 2010-2017 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */
 
import { ConvertFormat } from './types';
import { Tool } from '../model/tool';
 
export interface ColumnProperties {
    name: string;
    descr: string;
    group?: string;
    convertToFormat: ConvertFormat;
    hidden?: boolean;
    showEditOrValue?: boolean;
}
 
export class Column {
    name: string;
    descr: string;
    hidden: boolean;
    group: string;
    icon: string;
    tooltip: string = '';
    sortable: boolean = true;
    showEditOrValue: boolean = true;
    alignClass: string = '';
    additionCssClass: string = '';
    action: Function = null;
    button: Tool = null;
    isSwitcher: boolean = false;
    hasRunningStatus: boolean = false;
    convertToFormat: ConvertFormat;
    span: number = 1;
    isVisible: boolean = true;
 
    constructor(params: ColumnProperties){
        this.name = params.name;
        this.descr = params.descr;
        this.convertToFormat = params.convertToFormat;
        this.hidden = params.hidden || false;
        this.group = params.group || null;
        this.showEditOrValue = params.showEditOrValue || false;
    }
 
    setAlign(align: TypeOfAlignment = null) {
        this.alignClass = align + '-align';
        return this;
    }
 
    setAdditionCssClass(addClass: string) {
        this.additionCssClass = addClass;
        return this;
    }
 
    setIcon(icon: string) {
        this.icon = icon;
        return this;
    }
 
    setTooltip(tooltip: string) {
        this.tooltip = tooltip;
        return this;
    }
 
    setButton(button: Tool) {
        this.button = button;
        return this;
    }
 
    sortableDisable() {
        this.sortable = false;
        return this;
    }
 
    setFormat(format: ConvertFormat) {
        this.convertToFormat = format;
        return this;
    }
 
    hide() {
        this.hidden = true;
        return this;
    }
 
    show() {
        this.hidden = false;
        return this;
    }
 
    setAction(action: Function) {
        this.action = action;
        return this;
    }
 
    makeSwitcher() {
        this.isSwitcher = true;
        return this;
    }
 
    makeRunningStatus() {
        this.hasRunningStatus = true;
        return this;
    }
 
}
 
export type TypeOfAlignment = 'left' | 'center' | 'right' | null;