Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File priority for torrents #140

Merged
merged 12 commits into from
Oct 11, 2021
Prev Previous commit
Next Next commit
checkbox beside each file and folder
  • Loading branch information
bill-ahmed committed Oct 11, 2021
commit cc834540c7812c0e1e3a4e5e2c5bd5118c93ec1e
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
<!-- This is the tree node template for leaf nodes -->
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
<li *ngIf="isParentRendered(node)" class="file-node mat-tree-node">
<mat-checkbox *ngIf="allowSetPriority" class="toggle_checkbox" (change)="handleCheckboxClick(node)" [checked]="node.priority !== 0"></mat-checkbox>

<!-- use a disabled button to provide padding for tree leaf -->
<button mat-icon-button disabled><mat-icon color="accent">file_copy</mat-icon></button>
<div class="node-info">
@@ -38,36 +40,40 @@
<!-- This is the tree node template for expandable nodes -->
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasChild">
<li *ngIf="isParentRendered(node)" class="directory-node">
<div (click)="toggleNode(node)" matRipple matTreeNodeToggle class="mat-tree-node">
<button mat-icon-button matTreeNodeToggle id="expand_folder_button"
[attr.aria-label]="'toggle ' + node.name">
<mat-icon class="mat-icon-rtl-mirror">
{{isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
<div class="node-info">
<div class="node-title">
{{node.name}}
</div>
<div style="display: flex; flex-direction: row; align-items: center;">
<mat-checkbox *ngIf="allowSetPriority" class="toggle_checkbox" (change)="handleCheckboxClick(node)" [checked]="node.priority !== 0"></mat-checkbox>

<div class="priority_selection" *ngIf="allowSetPriority" (click)="$event.stopPropagation()">
<mat-form-field>
<mat-label>Choose priority</mat-label>
<mat-select (selectionChange)="handleFilePriorityChange(node)" (openedChange)="handleFilePriorityToggled()" [(value)]="node.priority">
<mat-option *ngFor="let item of file_priorities" [value]="item">
{{ file_priorities_mapping[item] }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div (click)="toggleNode(node)" matRipple matTreeNodeToggle class="mat-tree-node">
<button mat-icon-button matTreeNodeToggle id="expand_folder_button"
[attr.aria-label]="'toggle ' + node.name">
<mat-icon class="mat-icon-rtl-mirror">
{{isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
<div class="node-info">
<div class="node-title">
{{node.name}}
</div>

<div class="grow">
<div id="progress" *ngIf="showProgress">
Done: {{getNodeProgress(node)}}%
<div class="priority_selection" *ngIf="allowSetPriority" (click)="$event.stopPropagation()">
<mat-form-field>
<mat-label>Choose priority</mat-label>
<mat-select (selectionChange)="handleFilePriorityChange(node)" (openedChange)="handleFilePriorityToggled()" [(value)]="node.priority">
<mat-option *ngFor="let item of file_priorities" [value]="item">
{{ file_priorities_mapping[item] }}
</mat-option>
</mat-select>
</mat-form-field>
</div>

<div id="fileSize">
{{getNodeSize(node)}}
<div class="grow">
<div id="progress" *ngIf="showProgress">
Done: {{getNodeProgress(node)}}%
</div>

<div id="fileSize">
{{getNodeSize(node)}}
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@
pointer-events: none;
}

.toggle_checkbox {
margin: 0 10px 0 20px;
}

.node-info {
display: flex;
flex-direction: row;
Original file line number Diff line number Diff line change
@@ -59,6 +59,12 @@ export class FileSystemTreeExplorerComponent implements OnChanges {
if(changes.allowSetPriority) { this.allowSetPriority = changes.allowSetPriority.currentValue }
}

handleCheckboxClick(node: SerializedNode) {
let o = node.progress;
node.progress = o === 0 ? 1 : 0

this.onPriorityChange.emit(node);
}
handleFilePriorityChange(node: SerializedNode) { this.onPriorityChange.emit(node); }
handleFilePriorityToggled() { this.onPriorityChangeToggled.emit(''); }

Original file line number Diff line number Diff line change
@@ -208,6 +208,9 @@ export class TorrentDataStoreService {
if(new Date(tor.completion_on * 1000) < TorrentDataStoreService.CREATED_AT_THRESHOLD) {
tor.completion_on = TorrentDataStoreService.FUTURE_MOST_DATE.valueOf() / 1000
}

// Ensure progress is between 0 and 1
tor.progress = Math.max(0, Math.min(1, tor.progress));
}

/** Update server status in changelog */