fix
This commit is contained in:
+1
@@ -9,6 +9,7 @@
|
||||
|
||||
<app-file-system-tree-component
|
||||
(folderSelected)="onFolderSelected($event)"
|
||||
[baseUrl]="baseUrl"
|
||||
>
|
||||
</app-file-system-tree-component>
|
||||
</mat-sidenav>
|
||||
|
||||
+9
-2
@@ -1,4 +1,4 @@
|
||||
import {Component, CUSTOM_ELEMENTS_SCHEMA, OnInit, ViewChild} from '@angular/core';
|
||||
import {Component, CUSTOM_ELEMENTS_SCHEMA, Input, OnInit, ViewChild} from '@angular/core';
|
||||
import {DatePipe, NgForOf, NgIf} from '@angular/common';
|
||||
import {
|
||||
MatCell,
|
||||
@@ -83,11 +83,18 @@ export class FileBrowserWithTreeComponent implements OnInit {
|
||||
searchQuery = '';
|
||||
filteredFiles: FileItem[] = [];
|
||||
|
||||
@Input() baseUrl: string = '';
|
||||
|
||||
constructor(
|
||||
private fileService: FileBrowserTreeService,
|
||||
private dialog: MatDialog,
|
||||
private snackBar: MatSnackBar
|
||||
) {}
|
||||
) {
|
||||
if(this.baseUrl.length>0){
|
||||
fileService.baseUrl = this.baseUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadFiles(this.currentPath);
|
||||
|
||||
+29
-13
@@ -7,8 +7,8 @@ import {
|
||||
inject,
|
||||
signal,
|
||||
Output,
|
||||
EventEmitter
|
||||
} from '@angular/core';
|
||||
EventEmitter, Input, OnInit
|
||||
} from '@angular/core';
|
||||
import {BehaviorSubject, merge, Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {MatProgressBarModule} from '@angular/material/progress-bar';
|
||||
@@ -38,19 +38,24 @@ class DynamicFlatNode {
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class DynamicDatabase {
|
||||
|
||||
|
||||
rootNodes:FileItem[] = [];
|
||||
|
||||
constructor(private fileBrowserService: FileBrowserTreeService) {
|
||||
this.getFileItems('/').subscribe(
|
||||
value => {
|
||||
console.log('value', value);
|
||||
this.rootNodes = value;
|
||||
},
|
||||
error => {
|
||||
console.error('Error loading files:', error);
|
||||
}
|
||||
)
|
||||
// this.getFileItems('/').subscribe(
|
||||
// value => {
|
||||
// console.log('value', value);
|
||||
// this.rootNodes = value;
|
||||
// },
|
||||
// error => {
|
||||
// console.error('Error loading files:', error);
|
||||
// }
|
||||
// )
|
||||
|
||||
//this.fileBrowserService.baseUrl
|
||||
}
|
||||
|
||||
setBaseUrl(baseUrl: string) {
|
||||
this.fileBrowserService.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
getFileItems(path:string):Observable<FileItem[]> {
|
||||
@@ -182,7 +187,7 @@ export class DynamicDataSource implements DataSource<DynamicFlatNode> {
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class FileSystemTreeComponent {
|
||||
export class FileSystemTreeComponent implements OnInit{
|
||||
database = inject(DynamicDatabase);
|
||||
treeControl: FlatTreeControl<DynamicFlatNode>;
|
||||
dataSource: DynamicDataSource;
|
||||
@@ -190,12 +195,23 @@ export class FileSystemTreeComponent {
|
||||
|
||||
@Output() folderSelected = new EventEmitter<string>();
|
||||
|
||||
@Input() baseUrl: string = '';
|
||||
|
||||
constructor() {
|
||||
|
||||
|
||||
|
||||
this.treeControl = new FlatTreeControl<DynamicFlatNode>(this.getLevel, this.isExpandable);
|
||||
this.dataSource = new DynamicDataSource(this.treeControl, this.database);
|
||||
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if(this.baseUrl.length>0){
|
||||
this.database.setBaseUrl(this.baseUrl);
|
||||
}
|
||||
|
||||
// Initialize root data
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export const ADMIN_ROUTES: Routes = [
|
||||
{
|
||||
path: 'users',
|
||||
loadComponent: () => import('../admin-module/users.component/users.component').then((c) => c.UsersComponent),
|
||||
data:{title: 'Users', icon:'', nav:true}
|
||||
data:{title: 'Users', icon:'manage_accounts', nav:true}
|
||||
},
|
||||
{
|
||||
path: 'hard-drive-browser',
|
||||
|
||||
+3
-1
@@ -1 +1,3 @@
|
||||
<app-file-browser-with-tree-component></app-file-browser-with-tree-component>
|
||||
<app-file-browser-with-tree-component
|
||||
[baseUrl]="baseUrl"
|
||||
></app-file-browser-with-tree-component>
|
||||
|
||||
+2
@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
|
||||
import {
|
||||
FileBrowserWithTreeComponent
|
||||
} from '../../../components/file-browser-with-tree-component/file-browser-with-tree-component';
|
||||
import {GlobalConstants} from '../../../global-constants';
|
||||
|
||||
@Component({
|
||||
selector: 'app-hard-drive-browser.component',
|
||||
@@ -12,5 +13,6 @@ import {
|
||||
styleUrl: './hard-drive-browser.component.scss'
|
||||
})
|
||||
export class HardDriveBrowserComponent {
|
||||
baseUrl = `${GlobalConstants.API_URL}/admin/file-browser-tree`;
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<app-file-browser-with-tree-component
|
||||
[baseUrl]="baseUrl"
|
||||
></app-file-browser-with-tree-component>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FilesBrowserComponent } from './files-browser.component';
|
||||
|
||||
describe('FilesBrowserComponent', () => {
|
||||
let component: FilesBrowserComponent;
|
||||
let fixture: ComponentFixture<FilesBrowserComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [FilesBrowserComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(FilesBrowserComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {
|
||||
FileBrowserWithTreeComponent
|
||||
} from '../../../components/file-browser-with-tree-component/file-browser-with-tree-component';
|
||||
import {GlobalConstants} from '../../../global-constants';
|
||||
|
||||
@Component({
|
||||
selector: 'app-files-browser.component',
|
||||
imports: [
|
||||
FileBrowserWithTreeComponent
|
||||
],
|
||||
templateUrl: './files-browser.component.html',
|
||||
styleUrl: './files-browser.component.scss'
|
||||
})
|
||||
export class FilesBrowserComponent implements OnInit{
|
||||
baseUrl: string ='';
|
||||
ngOnInit(): void {
|
||||
this.baseUrl= `${GlobalConstants.API_URL}/user/file-browser-tree`;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,6 +31,11 @@ export const USER_ROUTS: Routes = [
|
||||
loadComponent: () => import('../user-module/tutorial-edit.component/tutorial-edit.component').then((c) => c.TutorialEditComponent),
|
||||
data:{title: 'Edit Tutorial'}
|
||||
},
|
||||
{
|
||||
path: 'files-browser',
|
||||
loadComponent: ()=>import('../user-module/files-browser.component/files-browser.component').then((c)=>c.FilesBrowserComponent),
|
||||
data:{title: 'Files Browser', icon:'folder_data', nav:true}
|
||||
},
|
||||
{
|
||||
path: 'ai-models',
|
||||
loadComponent: () => import('../user-module/ai-models.component/ai-models.component').then((c) => c.AiModelsComponent),
|
||||
|
||||
@@ -16,23 +16,16 @@ export interface FileItem {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FileBrowserTreeService {
|
||||
private baseUrl = `${GlobalConstants.API_URL}/file-browser-tree/files`;
|
||||
public baseUrl = `${GlobalConstants.API_URL}/user/file-browser-tree`;
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getFiles(path: string): Observable<FileItem[]> {
|
||||
const encodedPath = encodeURIComponent(path);
|
||||
return this.http.get<FileItem[]>(`${this.baseUrl}?path=${encodedPath}`);
|
||||
return this.http.get<FileItem[]>(`${this.baseUrl}/files?path=${encodedPath}`);
|
||||
}
|
||||
|
||||
// New method to get only folders for tree view
|
||||
getFolders(path: string): Observable<FileItem[]> {
|
||||
const encodedPath = encodeURIComponent(path);
|
||||
return this.http.get<FileItem[]>(`${this.baseUrl}?path=${encodedPath}`)
|
||||
.pipe(
|
||||
map(files => files.filter(file => file.type === 'directory'))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Alternative: dedicated backend endpoint for folders only
|
||||
getFoldersOnly(path: string): Observable<FileItem[]> {
|
||||
|
||||
Reference in New Issue
Block a user