-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(operations-list-extends-flow): share some common data
- Loading branch information
Showing
11 changed files
with
199 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { NothingFlow } from '../core'; | ||
import { OperationsListFlowOutItemNode } from '../rclone'; | ||
import { NavigationFlowOutNode } from './navigation-flow'; | ||
|
||
export type IManipulate = 'copy' | 'move' | 'del'; | ||
|
||
export interface ClipboardItem { | ||
oper: IManipulate; | ||
key: string; | ||
srcRemote: string; | ||
srcItem: OperationsListFlowOutItemNode; | ||
dst?: NavigationFlowOutNode; | ||
} | ||
|
||
export class Clipboard { | ||
public get values(): ClipboardItem[] { | ||
return Array.from(this.data.values()); | ||
} | ||
|
||
public get size(): number { | ||
return this.data.size; | ||
} | ||
private data = new Map<string, ClipboardItem>(); | ||
|
||
public static genKey(remote: string, path: string) { | ||
return JSON.stringify({ r: remote, p: path }); | ||
} | ||
|
||
public add( | ||
o: IManipulate, | ||
remote: string, | ||
row: OperationsListFlowOutItemNode, | ||
dst?: NavigationFlowOutNode | ||
) { | ||
const key = Clipboard.genKey(remote, row.Path); | ||
this.data.set(key, { | ||
oper: o, | ||
key, | ||
srcItem: { ...row }, | ||
srcRemote: remote, | ||
dst: { ...dst }, | ||
}); | ||
} | ||
|
||
public pop(remote: string, path: string): ClipboardItem { | ||
const key = Clipboard.genKey(remote, path); | ||
if (!this.data.has(key)) return undefined; | ||
const ans = this.data.get(key); | ||
this.data.delete(key); | ||
return ans; | ||
} | ||
|
||
public getManipulation(remote: string, path: string): IManipulate { | ||
const key = Clipboard.genKey(remote, path); | ||
if (!this.data.has(key)) return undefined; | ||
return this.data.get(key).oper; | ||
} | ||
|
||
public countManipulation(o: IManipulate): number { | ||
let cnt = 0; | ||
this.data.forEach(x => (x.oper === o ? cnt++ : null)); | ||
return cnt; | ||
} | ||
|
||
public clear(...opers: IManipulate[]) { | ||
if (opers.length === 0) this.data.clear(); | ||
else | ||
this.values | ||
.filter(x => opers.some(y => x.oper === y)) | ||
.forEach(x => { | ||
this.data.delete(x.key); | ||
}); | ||
} | ||
} | ||
|
||
export interface ClipboardFlowNode { | ||
clipboard: Clipboard; | ||
} | ||
|
||
export abstract class ClipboardFlow extends NothingFlow<ClipboardFlowNode> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './users-flow'; | ||
export * from './navigation-flow'; | ||
export * from './current-user-flow'; | ||
export * from './clipboard-flow'; | ||
export * from './operations-list-extends-flow'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as moment from 'moment'; | ||
import { Observable, of } from 'rxjs'; | ||
import { getIconForFile, getIconForFolder } from 'vscode-icons-js'; | ||
import { FormatBytes } from '../../utils/format-bytes'; | ||
import { BareFlow, CombErr, NothingFlow } from '../core'; | ||
import { | ||
OperationsListFlowInNode, | ||
OperationsListFlowOutItemNode, | ||
OperationsListFlowOutNode, | ||
} from '../rclone'; | ||
import { ClipboardFlowNode, IManipulate } from './clipboard-flow'; | ||
|
||
export interface OperationsListExtendsFlowInNode | ||
extends OperationsListFlowOutNode, | ||
OperationsListFlowInNode, | ||
ClipboardFlowNode {} | ||
|
||
export interface OperationsListExtendsFlowOutItemNode extends OperationsListFlowOutItemNode { | ||
SizeHumanReadable: string; | ||
ModTimeHumanReadable: string; | ||
ModTimeMoment: moment.Moment; | ||
TypeIcon: string; | ||
Manipulation: IManipulate; | ||
} | ||
|
||
export interface OperationsListExtendsFlowOutNode extends OperationsListFlowInNode { | ||
list: OperationsListExtendsFlowOutItemNode[]; | ||
} | ||
|
||
export abstract class OperationsListExtendsFlow extends BareFlow< | ||
OperationsListExtendsFlowInNode, | ||
OperationsListExtendsFlowOutNode | ||
> { | ||
// public prerequest$: Observable<CombErr<OperationsListExtendsFlowInNode>>; | ||
protected request( | ||
pre: CombErr<OperationsListExtendsFlowInNode> | ||
): Observable<CombErr<OperationsListExtendsFlowOutNode>> { | ||
if (pre[1].length !== 0 || pre[1].length !== 0) return pre as any; | ||
const list = pre[0].list.map( | ||
(item): OperationsListExtendsFlowOutItemNode => { | ||
const ModTimeMoment = moment(item.ModTime); | ||
return { | ||
...item, | ||
SizeHumanReadable: FormatBytes(item.Size), | ||
ModTimeMoment, | ||
ModTimeHumanReadable: ModTimeMoment.fromNow(), | ||
Manipulation: pre[0].clipboard.getManipulation(pre[0].remote, item.Path), | ||
TypeIcon: item.IsDir ? getIconForFolder(item.Name) : getIconForFile(item.Name), | ||
}; | ||
} | ||
); | ||
return of([{ ...pre[0], list }, []]); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/app/pages/manager/clipboard/clipboard-remotes-table/clipboard-remotes-table.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.