Skip to content

Commit

Permalink
Merge pull request #13 from OpenForgeProject/no-report-files-found
Browse files Browse the repository at this point in the history
fix report files functions
  • Loading branch information
dermatz authored Dec 9, 2024
2 parents fd5db01 + 650397c commit 29ed266
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Change Log
# Changelog

All notable changes to the "magento-log-viewer" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

## [1.7.1] - 2024-12-09

### Added
- Added a message when there are no report files.
- Support for Node.js 18.x in GitHub Actions
- Automated tests for releases using GitHub Workflows

### Fixed
- Fixed an issue where the status bar item was being created multiple times.

## [1.7.0] - 2024-12-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento-log-viewer",
"displayName": "Magento Log Viewer",
"description": "A Visual Studio Code extension to view and manage Magento log files.",
"version": "1.7.0",
"version": "1.7.1",
"publisher": "MathiasElle",
"icon": "resources/logo.png",
"repository": {
Expand Down
34 changes: 31 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ export function updateBadge(treeView: vscode.TreeView<unknown>, logViewerProvide
vscode.commands.executeCommand('setContext', 'magentoLogViewer.hasLogFiles', totalEntries > 0);

// Update status bar item
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
statusBarItem.text = `Magento Log-Entries: ${totalEntries}`;
statusBarItem.show();
LogViewerProvider.statusBarItem.text = `Magento Log-Entries: ${totalEntries}`;
};

logViewerProvider.onDidChangeTreeData(updateBadgeCount);
Expand Down Expand Up @@ -288,3 +286,33 @@ export function getIconForReport(filePath: string): vscode.ThemeIcon {
return new vscode.ThemeIcon('file');
}
}

export function getReportItems(dir: string): LogItem[] {
if (!pathExists(dir)) {
return [];
}

const items: LogItem[] = [];
const files = fs.readdirSync(dir);

files.forEach(file => {
const filePath = path.join(dir, file);
if (fs.lstatSync(filePath).isDirectory()) {
const subItems = getReportItems(filePath);
if (subItems.length > 0) {
items.push(...subItems);
}
} else if (fs.lstatSync(filePath).isFile()) {
const title = parseReportTitle(filePath);
const reportFile = new LogItem(title, vscode.TreeItemCollapsibleState.None, {
command: 'magento-log-viewer.openFile',
title: 'Open Report File',
arguments: [filePath]
});
reportFile.iconPath = getIconForReport(filePath);
items.push(reportFile);
}
});

return items;
}
17 changes: 11 additions & 6 deletions src/logViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { pathExists, getLineCount, getIconForLogLevel, getLogItems, parseReportT
export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vscode.Disposable {
private _onDidChangeTreeData: vscode.EventEmitter<LogItem | undefined | void> = new vscode.EventEmitter<LogItem | undefined | void>();
readonly onDidChangeTreeData: vscode.Event<LogItem | undefined | void> = this._onDidChangeTreeData.event;
private statusBarItem: vscode.StatusBarItem;
public static statusBarItem: vscode.StatusBarItem;
private groupByMessage: boolean;

constructor(private workspaceRoot: string) {
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
this.statusBarItem.command = 'magento-log-viewer.refreshLogFiles';
this.statusBarItem.show();
if (!LogViewerProvider.statusBarItem) {
LogViewerProvider.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
LogViewerProvider.statusBarItem.command = 'magento-log-viewer.refreshLogFiles';
LogViewerProvider.statusBarItem.show();
}
this.groupByMessage = vscode.workspace.getConfiguration('magentoLogViewer').get<boolean>('groupByMessage', true);
this.updateBadge();
this.updateRefreshButtonVisibility();
Expand Down Expand Up @@ -191,11 +193,11 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
const logPath = path.join(this.workspaceRoot, 'var', 'log');
const logFiles = this.getLogFilesWithoutUpdatingBadge(logPath);
const totalEntries = logFiles.reduce((count, file) => count + parseInt(file.description?.match(/\d+/)?.[0] || '0', 10), 0);
this.statusBarItem.text = `Magento Log-Entries: ${totalEntries}`;
LogViewerProvider.statusBarItem.text = `Magento Log-Entries: ${totalEntries}`;
}

dispose() {
this.statusBarItem.dispose();
// Do not dispose the status bar item here to avoid multiple creations
}
}

Expand Down Expand Up @@ -230,6 +232,9 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
} else {
const reportPath = path.join(this.workspaceRoot, 'var', 'report');
const reportItems = this.getLogItems(reportPath, 'Reports');
if (reportItems.length === 0) {
return Promise.resolve([new LogItem('No report files found', vscode.TreeItemCollapsibleState.None)]);
}
return Promise.resolve(reportItems);
}
}
Expand Down

0 comments on commit 29ed266

Please sign in to comment.