import { autoinject } from './libs/container' ; import { Metadata , IMetadata , EFileState } from './mining/metadata' ; import { CSS_PREFIX } from './constants' ; import { h } from 'superfine' ; import { Views } from './libs/views' ; export interface IFileProps { id : number ; fullName : string ; name : string ; ext : string ; hash : string ; type : EFileState ; isCommented : boolean ; isActive : boolean ; } @ autoinject export class File { state : IFileProps = { } as IFileProps ; constructor ( private metadata , private views ) { } init ( fullName , id ) { this . updateState ( { fullName , id } ) ; return this ; } updateState ( changes ) { if ( changes . fullName ) { const fileNameParts = changes . fullName . split ( '.' ) ; changes . ext = fileNameParts . length > 0 ? fileNameParts . pop ( ) : '' ; changes . name = fileNameParts . join ( '.' ) ; } if ( changes . id !== undefined ) { const metadata = this . metadata . get ( changes . id ) ; changes . hash = metadata . hash ; changes . type = metadata . type ; changes . isCommented = metadata . commented ; } Object . assign ( this . state , changes ) ; this . views . redrawView ( 'navigation' ) ; return this ; } setActive ( ) { this . updateState ( { isActive : true } ) ; } setInactive ( ) { this . updateState ( { isActive : false } ) ; } render ( ) { const fileClass = `gitlab-tree-plugin__file gitlab-tree-plugin__file--is-${ EFileState [ this . state . type ] . toLocaleLowerCase ( ) } ${ this . state . isActive ? CSS_PREFIX + '__file--is-active' : '' } ${ this . state . isCommented ? CSS_PREFIX + '__file--is-commented' : '' }` ; const iconClass = `fa fa-comments-o ${ CSS_PREFIX }__file__commented-icon` ; return ( < a href = { this . state . hash } class = { fileClass } > { this . state . isCommented ? < i class = { iconClass } > < /i> : ''} < span > { this . state . fullName } < /span> < /a>); } }