All files / src/components/subcomponents _treeView.vue

93.33% Statements 14/15
100% Branches 6/6
50% Functions 1/2
93.33% Lines 14/15
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                                                                                3x                               1x     16x     1x 1x     1x       17x   17x 8x   17x 9x     17x 1x   17x                                                                                                                                          
 
<template>
    <div class="col-12">
        <ul class="scoped-root-list">
            <li v-for="(folder,cnt) in folders" :key="folder.key" :class="getHtmlClasses(folder)">
                <div class="ls-flex ls-flex-row" :id="folder.key" @click.stop="selectFolder(folder)">
                    <div class="ls-flex-item grow-1 text-center">
                        <i
                            :class="$store.state.currentFolder == folder.folder ? 'fa fa-folder-open fa-lg' : 'fa fa-folder fa-lg'"
                        ></i>
                    </div>
                    <div class="ls-flex-item grow-6">
                        <span class="scope-apply-hover">{{folder.shortName}}</span>
                    </div>
                    <div class="ls-flex-item grow-1 text-right">
                        <button
                            v-if="folder.children.length > 0"
                            class="btn btn-xs btn-default toggle-collapse-children"
                            @click.stop="toggleCollapse(folder.key)"
                        >
                            <i
                                :class=" isCollapsed(folder.key) ? 'fa fa-caret-down fa-lg' : 'fa fa-caret-up fa-lg'"
                            ></i>
                        </button>
                    </div>
                </div>
                <treeview
                    :key="folder.folder+'-children'"
                    v-show="folder.children.length > 0 && !isCollapsed(folder.key)"
                    :folders="folder.children"
                    :loading="loading"
                    :preset-folder="presetFolder"
                    @setLoading="setLoading"
                />
            </li>
        </ul>
    </div>
</template>
 
<script>
import applyLoader from '../../mixins/applyLoader';
 
export default {
    name: "treeview",
  mixins: [applyLoader],
    props: {
        folders: {
            type: [Object, Array],
            default: () => {
                return [];
            }
        },
        presetFolder: {type: String|null, default: null},
    },
    methods: {
        toggleCollapse(folderKey) {
            this.$store.commit('toggleCollapseFolder', folderKey);
        },
        isCollapsed(folderKey) {
            return this.$store.state.uncollapsedFolders.indexOf(folderKey) == -1
        },
        selectFolder(folderObject) {
            this.loadingState = true;
            this.$store
                .dispatch("folderSelected", folderObject)
                .then(result => {
                    this.loadingState = false;
                });
        },
        getHtmlClasses(folder) {
            let classes =
                "ls-flex ls-flex-row scoped-tree-folder ls-space bottom-5";
            if (folder.children.length > 0) {
                classes += " scoped-has-children text-bold";
            }
            if (this.$store.state.currentFolder == folder.folder) {
                classes += " scoped-selected";
            }
 
            if (this.presetFolder == folder.folder) {
                classes += " FileManager--preselected-folder";
            }
            return classes;
        }
    }
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.FileManager--preselected-folder {
    background:rgba(220, 220, 220, 0.5);
}
.scoped-root-list {
    position: relative;
    padding-left: 18px;
    padding-top: 18px;
    &:before {
        content: "\2510";
        width: 100%;
        text-align: left;
        font-size: 18px;
        font-weight: bold;
        position: absolute;
        left: 0;
        top: 0;
    }
}
.scope-apply-hover {
    transition: all 0.4s ease;
    border-bottom: 0px solid black;
 
    &:hover {
        border-bottom: 1px solid black;
    }
}
.scoped-tree-folder {
    font-size: 16px;
    margin: 5px 1px;
    cursor: pointer;
    flex-wrap: wrap;
    border: 0;
    box-shadow: 3px 2px 3px #dedede;
    padding: 1.2rem;
 
    &:before {
        content: "\22A2";
        text-align: left;
        width: 1.2rem;
        position: absolute;
        font-size: 18px;
        font-weight: bold;
        left: 5px;
    }
    &div:first-of-type {
        padding-left: 0.3rem;
    }
    &.scoped-has-children {
        border-left: 3px solid rgba(120, 120, 120, 0.5);
    }
    &.scoped-selected {
        &:before {
            content: "\22A2>";
        }
        & > div > .scope-apply-hover {
            padding-left: 1.5rem;
            font-weight: bold;
        }
    }
}
</style>