Skip to content

Commit

Permalink
Added comment icon to file when file was commented.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbonco committed Jan 15, 2017
1 parent f808a64 commit 7665ad2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
6 changes: 5 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
margin-bottom: 10px;
}


.gitlab-tree-plugin-left .folder .holder
{
white-space: nowrap;
Expand Down Expand Up @@ -101,4 +100,9 @@
color: #000;
font-weight: bold;
pointer-events: none;
}

.gitlab-tree-plugin-file-commented-icon
{
margin-right: 7px;
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "GitLab - Tree view for code",
"homepage_url": "https://github.com/tomasbonco/gitlabtree",
"author": "Tomáš Bončo",
"version": "0.0.4.1",
"version": "0.0.5",
"manifest_version": 2,
"description": "Provides folder structure view for code in GitLab.",
"icons": {
Expand Down
28 changes: 23 additions & 5 deletions src/inject/inject.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/inject/inject.js.map

Large diffs are not rendered by default.

45 changes: 40 additions & 5 deletions src/inject/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface IMetadata
type: EFileState; // 'renamed' | 'deleted' | 'edit' | 'new';
hash: string;
filename: string;
commented: boolean;
}

class GitLabTree
Expand Down Expand Up @@ -54,12 +55,12 @@ class GitLabTree

this.metadata = this.obtainMetadata();
if ( this.metadata.length === 0 ) { return; }
const filenames: string[] = this.metadata.map( m => m.filename );
this.obtainCommentedFiles();


// Analyze filenames

this.fileNames = filenames;
this.fileNames = this.metadata.map( m => m.filename );
this.pathPrefix = this.getPrefixPath( this.fileNames );
this.strippedFileNames = this.removePathPrefix( this.fileNames, this.pathPrefix );

Expand Down Expand Up @@ -108,6 +109,7 @@ class GitLabTree
this.rightElement.classList.add( CSS_PREFIX + '-right' );
}


/**
* Collects basic information about files - their names, their hashes, and happend to them.
*
Expand Down Expand Up @@ -136,21 +138,36 @@ class GitLabTree

// Convert type

if ( ~typeRaw.indexOf( 'add-file' )) { type = EFileState.ADDED; }
if ( ~typeRaw.indexOf( 'new-file' )) { type = EFileState.ADDED; }
if ( ~typeRaw.indexOf( 'renamed-file' )) { type = EFileState.RENAMED; }
if ( ~typeRaw.indexOf( 'deleted-file' )) { type = EFileState.DELETED; }


// Save

const fileMetadata: IMetadata = { type, hash, filename };
const fileMetadata: IMetadata = { type, hash, filename, commented: false };
metadata.push( fileMetadata );
}

return metadata;
}


/**
* Adds flag 'commented' in metadata to every file that was commented.
*/
obtainCommentedFiles()
{
const fileHolders = Array.prototype.slice.call( this.fileHolders );

fileHolders.forEach( ( fileHolder, index ) =>
{
const metadata = this.getMetadata( index );
metadata.commented = !! fileHolder.querySelector( '.notes_holder' );
})
}


/**
* Returns metadata by index.
*
Expand Down Expand Up @@ -334,7 +351,8 @@ class GitLabTree
let file: HTMLAnchorElement = document.createElement( 'a' );
file.setAttribute( 'href', metadata.hash );
file.classList.add( 'file' );
file.textContent = name;

// Color

let fileStateClass;
switch ( metadata.type )
Expand All @@ -345,6 +363,23 @@ class GitLabTree
default: fileStateClass = CSS_PREFIX + '-file-updated'; break;
}


// Was file commented?

if ( metadata.commented )
{
let commentElement = document.createElement('i');
commentElement.classList.add( 'fa', 'fa-comments-o', CSS_PREFIX + '-file-commented-icon' );
file.appendChild( commentElement );
}


// Content

const contentElement = document.createElement( 'span' );
contentElement.textContent = name;
file.appendChild( contentElement );

file.classList.add( fileStateClass );
files.push( file );
}
Expand Down

0 comments on commit 7665ad2

Please sign in to comment.