mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
Linked checkboxes to "download selected" button
This commit is contained in:
@@ -11,7 +11,8 @@ import { ResultTableComponent } from './components/browse/result-table/result-ta
|
|||||||
import { ChartSidebarComponent } from './components/browse/chart-sidebar/chart-sidebar.component';
|
import { ChartSidebarComponent } from './components/browse/chart-sidebar/chart-sidebar.component';
|
||||||
import { ResultTableRowComponent } from './components/browse/result-table/result-table-row/result-table-row.component';
|
import { ResultTableRowComponent } from './components/browse/result-table/result-table-row/result-table-row.component';
|
||||||
import { DownloadsModalComponent } from './components/browse/status-bar/downloads-modal/downloads-modal.component';
|
import { DownloadsModalComponent } from './components/browse/status-bar/downloads-modal/downloads-modal.component';
|
||||||
import { ProgressBarDirective } from './core/directives/progress-bar.directive'
|
import { ProgressBarDirective } from './core/directives/progress-bar.directive';
|
||||||
|
import { CheckboxDirective } from './core/directives/checkbox.directive'
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -24,7 +25,8 @@ import { ProgressBarDirective } from './core/directives/progress-bar.directive'
|
|||||||
ChartSidebarComponent,
|
ChartSidebarComponent,
|
||||||
ResultTableRowComponent,
|
ResultTableRowComponent,
|
||||||
DownloadsModalComponent,
|
DownloadsModalComponent,
|
||||||
ProgressBarDirective
|
ProgressBarDirective,
|
||||||
|
CheckboxDirective
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
|||||||
@@ -2,7 +2,12 @@
|
|||||||
<div class="ui celled two column grid">
|
<div class="ui celled two column grid">
|
||||||
<div id="table-row" class="row">
|
<div id="table-row" class="row">
|
||||||
<div id="table-column" class="column twelve wide">
|
<div id="table-column" class="column twelve wide">
|
||||||
<app-result-table #resultTable (rowClicked)="chartSidebar.onRowClicked($event)"></app-result-table>
|
<app-result-table
|
||||||
|
#resultTable
|
||||||
|
(rowClicked)="chartSidebar.onRowClicked($event)"
|
||||||
|
(songChecked)="statusBar.onSongChecked($event)"
|
||||||
|
(songUnchecked)="statusBar.onSongUnchecked($event)"
|
||||||
|
></app-result-table>
|
||||||
</div>
|
</div>
|
||||||
<div id="sidebar-column" class="column four wide">
|
<div id="sidebar-column" class="column four wide">
|
||||||
<app-chart-sidebar #chartSidebar></app-chart-sidebar>
|
<app-chart-sidebar #chartSidebar></app-chart-sidebar>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<td>
|
<td>
|
||||||
<div class="ui checkbox">
|
<div #checkbox class="ui checkbox">
|
||||||
<input type="checkbox">
|
<input type="checkbox">
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, AfterViewInit, Input } from '@angular/core'
|
import { Component, AfterViewInit, Input, ViewChild, ElementRef, Output, EventEmitter } from '@angular/core'
|
||||||
import { SongResult } from '../../../../../electron/shared/interfaces/search.interface'
|
import { SongResult } from '../../../../../electron/shared/interfaces/search.interface'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -8,10 +8,31 @@ import { SongResult } from '../../../../../electron/shared/interfaces/search.int
|
|||||||
})
|
})
|
||||||
export class ResultTableRowComponent implements AfterViewInit {
|
export class ResultTableRowComponent implements AfterViewInit {
|
||||||
@Input() result: SongResult
|
@Input() result: SongResult
|
||||||
|
@Output() songChecked = new EventEmitter<SongResult>()
|
||||||
|
@Output() songUnchecked = new EventEmitter<SongResult>()
|
||||||
|
|
||||||
|
@ViewChild('checkbox', { static: true }) checkbox: ElementRef
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
$('.ui.checkbox').checkbox()
|
$(this.checkbox.nativeElement).checkbox({
|
||||||
|
onChecked: () => {
|
||||||
|
this.songChecked.emit(this.result)
|
||||||
|
},
|
||||||
|
onUnchecked: () => {
|
||||||
|
this.songUnchecked.emit(this.result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
check(isChecked: boolean) {
|
||||||
|
if (isChecked) {
|
||||||
|
$(this.checkbox.nativeElement).checkbox('check')
|
||||||
|
this.songChecked.emit(this.result)
|
||||||
|
} else {
|
||||||
|
$(this.checkbox.nativeElement).checkbox('uncheck')
|
||||||
|
this.songUnchecked.emit(this.result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<!-- NOTE: it would be nice to make this header sticky, but Fomantic-UI doesn't currently support that -->
|
<!-- NOTE: it would be nice to make this header sticky, but Fomantic-UI doesn't currently support that -->
|
||||||
<tr>
|
<tr>
|
||||||
<th id="checkboxColumn" class="collapsing">
|
<th appCheckbox (checked)="checkAll($event)" id="checkboxColumn" class="collapsing">
|
||||||
<div class="ui checkbox">
|
<div class="ui checkbox">
|
||||||
<input type="checkbox">
|
<input type="checkbox">
|
||||||
</div>
|
</div>
|
||||||
@@ -19,8 +19,11 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr
|
<tr
|
||||||
app-result-table-row
|
app-result-table-row
|
||||||
|
#tableRow
|
||||||
*ngFor="let result of results"
|
*ngFor="let result of results"
|
||||||
(click)="onRowClicked(result)"
|
(click)="onRowClicked(result)"
|
||||||
|
(songChecked)="onSongChecked($event)"
|
||||||
|
(songUnchecked)="onSongUnchecked($event)"
|
||||||
[result]="result"></tr>
|
[result]="result"></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Component, AfterViewInit, Input, Output, EventEmitter } from '@angular/core'
|
import { Component, AfterViewInit, Input, Output, EventEmitter, ViewChildren, QueryList } from '@angular/core'
|
||||||
import { SongResult } from '../../../../electron/shared/interfaces/search.interface'
|
import { SongResult } from '../../../../electron/shared/interfaces/search.interface'
|
||||||
|
import { ResultTableRowComponent } from './result-table-row/result-table-row.component'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-result-table',
|
selector: 'app-result-table',
|
||||||
@@ -10,6 +11,10 @@ export class ResultTableComponent implements AfterViewInit {
|
|||||||
@Input() results: SongResult[]
|
@Input() results: SongResult[]
|
||||||
|
|
||||||
@Output() rowClicked = new EventEmitter<SongResult>()
|
@Output() rowClicked = new EventEmitter<SongResult>()
|
||||||
|
@Output() songChecked = new EventEmitter<SongResult>()
|
||||||
|
@Output() songUnchecked = new EventEmitter<SongResult>()
|
||||||
|
|
||||||
|
@ViewChildren('tableRow') tableRows: QueryList<ResultTableRowComponent>
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
@@ -20,4 +25,16 @@ export class ResultTableComponent implements AfterViewInit {
|
|||||||
onRowClicked(result: SongResult) {
|
onRowClicked(result: SongResult) {
|
||||||
this.rowClicked.emit(result)
|
this.rowClicked.emit(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSongChecked(result: SongResult) {
|
||||||
|
this.songChecked.emit(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
onSongUnchecked(result: SongResult) {
|
||||||
|
this.songUnchecked.emit(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAll(isChecked: boolean) {
|
||||||
|
this.tableRows.forEach(row => row.check(isChecked))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<div class="ui bottom borderless menu">
|
<div class="ui bottom borderless menu">
|
||||||
<div *ngIf="resultCount > 0" class="item">{{resultCount}} Result{{resultCount == 1 ? '' : 's'}}</div>
|
<div *ngIf="resultCount > 0" class="item">{{resultCount}} Result{{resultCount == 1 ? '' : 's'}}</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<button *ngIf="selectedResults.length > 0" class="ui positive button">Download Selected</button>
|
<button *ngIf="selectedResults.length > 0" (click)="downloadSelected()" class="ui positive button">Download Selected</button>
|
||||||
</div>
|
</div>
|
||||||
<a *ngIf="downloading" class="item right" (click)="showDownloads()">
|
<a *ngIf="downloading" class="item right" (click)="showDownloads()">
|
||||||
<div #progressBar appProgressBar [percent]="percent" class="ui progress">
|
<div #progressBar appProgressBar [percent]="percent" class="ui progress">
|
||||||
|
|||||||
@@ -25,4 +25,20 @@ export class StatusBarComponent {
|
|||||||
showDownloads() {
|
showDownloads() {
|
||||||
$('#downloadsModal').modal('show')
|
$('#downloadsModal').modal('show')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSongChecked(result: SongResult) {
|
||||||
|
if (this.selectedResults.findIndex(oldResult => oldResult.id == result.id) == -1) {
|
||||||
|
this.selectedResults.push(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSongUnchecked(result: SongResult) {
|
||||||
|
this.selectedResults = this.selectedResults.filter(oldResult => oldResult.id != result.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadSelected() {
|
||||||
|
// TODO send query to get versions; for any with more than one chart, show modal for confirmation:
|
||||||
|
// "some selected songs have more than one chart: ___" [download all charts for each song] [deselect these songs] [X]
|
||||||
|
console.log(this.selectedResults)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
19
src/app/core/directives/checkbox.directive.ts
Normal file
19
src/app/core/directives/checkbox.directive.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Directive, ElementRef, Output, EventEmitter } from '@angular/core'
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[appCheckbox]'
|
||||||
|
})
|
||||||
|
export class CheckboxDirective {
|
||||||
|
@Output() checked = new EventEmitter<boolean>()
|
||||||
|
|
||||||
|
private _checked = false
|
||||||
|
|
||||||
|
constructor(element: ElementRef) {
|
||||||
|
$(element.nativeElement).checkbox({
|
||||||
|
onChange: () => {
|
||||||
|
this._checked = !this._checked
|
||||||
|
this.checked.emit(this._checked)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,8 +16,6 @@ const mkdir = promisify(_mkdir)
|
|||||||
export class AddDownloadHandler implements IPCEmitHandler<'add-download'> {
|
export class AddDownloadHandler implements IPCEmitHandler<'add-download'> {
|
||||||
event: 'add-download' = 'add-download'
|
event: 'add-download' = 'add-download'
|
||||||
|
|
||||||
//TODO: update percent in a way that makes its progress seem as smooth as possible
|
|
||||||
|
|
||||||
async handler(data: NewDownload) {
|
async handler(data: NewDownload) {
|
||||||
const download: Download = {
|
const download: Download = {
|
||||||
versionID: data.versionID,
|
versionID: data.versionID,
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ export interface Settings {
|
|||||||
export const defaultSettings: Settings = {
|
export const defaultSettings: Settings = {
|
||||||
rateLimitDelay: 31,
|
rateLimitDelay: 31,
|
||||||
theme: 'Default',
|
theme: 'Default',
|
||||||
libraryPath: 'C:/Users/bouviejs/Desktop/Bridge Notes/TestLibrary'
|
libraryPath: 'C:/Users/bouviejs/Desktop/Bridge Notes/TestLibrary' // TODO: default should be undefined
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Represents the download of a single chart
|
* Contains the data required to start downloading a single chart
|
||||||
*/
|
*/
|
||||||
export interface Download {
|
|
||||||
versionID: number
|
|
||||||
title: string
|
|
||||||
header: string
|
|
||||||
description: string
|
|
||||||
percent: number
|
|
||||||
|
|
||||||
//TODO: figure out how to handle user clicking "retry"
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NewDownload {
|
export interface NewDownload {
|
||||||
versionID: number
|
versionID: number
|
||||||
avTagName: string
|
avTagName: string
|
||||||
@@ -19,15 +9,13 @@ export interface NewDownload {
|
|||||||
links: { [type: string]: string }
|
links: { [type: string]: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
export enum DownloadState {
|
* Represents the download progress of a single chart
|
||||||
wait, // Waiting for Google rate limit...
|
*/
|
||||||
request, // [song.ini] Sending request...
|
export interface Download {
|
||||||
warning, // Warning! [song.ini] has been modified recently and may not match how it was displayed in search results. Download anyway?
|
versionID: number
|
||||||
download, // [song.ini] Downloading: 25%
|
title: string
|
||||||
extract, // [archive.zip] Extracting: 44%
|
header: string
|
||||||
transfer, // Copying files to library...
|
description: string
|
||||||
complete // Complete
|
percent: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try again button appears after an error: restarts the stage that failed
|
|
||||||
Reference in New Issue
Block a user