UNPKG

gars_v2

Version:

Geo Assistant Research System

58 lines (53 loc) 1.6 kB
import path from 'path'; import fs from 'fs'; const ext2icon = { '.jpg': 'image', '.svg': 'image', '.png': 'image', '.bmp': 'image', '.gars': 'data' }; function getNodes(srcpath) { return fs.readdirSync(srcpath).map(name => { var filepath = path.join(srcpath, name); var stat = fs.statSync(filepath); var type; if (stat.isDirectory()) { type = 'folder'; } else { var ext = path.extname(name); type = ext2icon[ext] || 'unkown'; } return { name, path: filepath, type }; }); } class View { constructor($container) { this.$view = $('<div>').addClass('folder-view').appendTo($container); } renderItem(file) { return $('<div>') .addClass('item').addClass(file.type) .text(file.name) .click(e => { e.preventDefault(); if (file.type === 'folder') { console.log('finder view onnavigate', file.path); this.onnavigate(file.path); } else { console.log('finder view onopen', file.path); this.onopen(file); } }); } cd(filepath, $container) { var nodes = getNodes(filepath); $container = this.$view.empty(); nodes .map(file => this.renderItem(file)) .forEach($item => this.$view.append($item)); } onnavigate() {} onopen() {} } export default View;