Skip to content

Commit

Permalink
feat: upload
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnih committed Oct 3, 2021
1 parent fa552f6 commit dd63f54
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions projects/ngx-explorer/src/lib/services/example-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { forkJoin, Observable, of } from 'rxjs';
import { DataProvider, NodeContent, TLeaf, TNode } from '../common/types';
import { DataProvider, NodeContent, TNode } from '../common/types';
import { v4 as uuid } from 'uuid';

let mock_folders = [
Expand Down Expand Up @@ -44,6 +44,18 @@ let mock_files = [
})
export class ExampleDataService implements DataProvider {

uploadFiles(nodeInfo: any, files: File[]): Observable<TNode[]> {
const results = [];
for (let i = 0; i < files.length; i++) {
const file = files[i];
const nodePath = nodeInfo ? mock_folders.find(f => f.id === nodeInfo.id).path : '';
const newFile = { id: uuid(), name: file.name, path: nodePath + '/' + file.name, content: file };
mock_files.push(newFile);
results.push(of(newFile));
};
return forkJoin(results);
}

deleteNodes(nodeInfos: TNode[]): Observable<any> {
const results = nodeInfos.map(nodeInfo => {
const path = nodeInfo.path + '/';
Expand All @@ -55,7 +67,7 @@ export class ExampleDataService implements DataProvider {
return forkJoin(results)
}

deleteLeafs(leafInfos: TLeaf[]): Observable<any> {
deleteLeafs(leafInfos: TNode[]): Observable<any> {
const results = leafInfos.map(leafInfo => {
const leaf = mock_files.find(f => f.id === leafInfo.id);
const index = mock_files.indexOf(leaf);
Expand Down Expand Up @@ -98,7 +110,7 @@ export class ExampleDataService implements DataProvider {
return of(node);
}

renameLeaf(leafInfo: TLeaf, newName: string): Observable<TLeaf> {
renameLeaf(leafInfo: TNode, newName: string): Observable<TNode> {
const leaf = mock_files.find(f => f.id === leafInfo.id);
leaf.name = newName;
return of(leaf);
Expand Down

0 comments on commit dd63f54

Please sign in to comment.