mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-15 09:10:56 +03:00
Missing options are now auto-added to tasks
Added onlyNumber directive for number-only inputs
This commit is contained in:
@@ -93,6 +93,7 @@ import { NotificationsListComponent } from './components/notifications-list/noti
|
||||
import { TaskSettingsComponent } from './components/task-settings/task-settings.component';
|
||||
import { GenerateRssUrlComponent } from './dialogs/generate-rss-url/generate-rss-url.component';
|
||||
import { SortPropertyComponent } from './components/sort-property/sort-property.component';
|
||||
import { OnlyNumberDirective } from './directives/only-number.directive';
|
||||
|
||||
registerLocaleData(es, 'es');
|
||||
|
||||
@@ -143,7 +144,8 @@ registerLocaleData(es, 'es');
|
||||
NotificationsListComponent,
|
||||
TaskSettingsComponent,
|
||||
GenerateRssUrlComponent,
|
||||
SortPropertyComponent
|
||||
SortPropertyComponent,
|
||||
OnlyNumberDirective
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
|
||||
@@ -4,9 +4,15 @@
|
||||
<div *ngIf="task_key === 'delete_old_files'">
|
||||
<mat-form-field color="accent">
|
||||
<mat-label i18n="Delete files older than">Delete files older than</mat-label>
|
||||
<input [(ngModel)]="new_options['threshold_days']" matInput required>
|
||||
<input [(ngModel)]="new_options['threshold_days']" matInput onlyNumber required>
|
||||
<span matTextSuffix>days</span>
|
||||
</mat-form-field>
|
||||
<div>
|
||||
<mat-checkbox [(ngModel)]="new_options['blacklist_files']" i18n="Blacklist deleted files" placeholder="Archive mode must be enabled" placeholder-i18n>Blacklist all files</mat-checkbox>
|
||||
</div>
|
||||
<div>
|
||||
<mat-checkbox [disabled]="new_options['blacklist_files']" [(ngModel)]="new_options['blacklist_subscription_files']" i18n="Blacklist deleted subscription files" placeholder="Archive mode must be enabled" placeholder-i18n>Blacklist deleted subscription files</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
8
src/app/directives/only-number.directive.spec.ts
Normal file
8
src/app/directives/only-number.directive.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { OnlyNumberDirective } from './only-number.directive';
|
||||
|
||||
describe('OnlyNumberDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new OnlyNumberDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
||||
72
src/app/directives/only-number.directive.ts
Normal file
72
src/app/directives/only-number.directive.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
// https://stackoverflow.com/a/58535434/8088021
|
||||
|
||||
import { Directive, ElementRef, HostListener } from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[onlyNumber]'
|
||||
})
|
||||
export class OnlyNumberDirective {
|
||||
|
||||
private navigationKeys = [
|
||||
'Backspace',
|
||||
'Delete',
|
||||
'Tab',
|
||||
'Escape',
|
||||
'Enter',
|
||||
'Home',
|
||||
'End',
|
||||
'ArrowLeft',
|
||||
'ArrowRight',
|
||||
'Clear',
|
||||
'Copy',
|
||||
'Paste'
|
||||
];
|
||||
inputElement: HTMLElement;
|
||||
constructor(public el: ElementRef) {
|
||||
this.inputElement = el.nativeElement;
|
||||
}
|
||||
|
||||
@HostListener('keydown', ['$event'])
|
||||
onKeyDown(e: KeyboardEvent) {
|
||||
if (
|
||||
this.navigationKeys.indexOf(e.key) > -1 || // Allow: navigation keys: backspace, delete, arrows etc.
|
||||
(e.key === 'a' && e.ctrlKey === true) || // Allow: Ctrl+A
|
||||
(e.key === 'c' && e.ctrlKey === true) || // Allow: Ctrl+C
|
||||
(e.key === 'v' && e.ctrlKey === true) || // Allow: Ctrl+V
|
||||
(e.key === 'x' && e.ctrlKey === true) || // Allow: Ctrl+X
|
||||
(e.key === 'a' && e.metaKey === true) || // Allow: Cmd+A (Mac)
|
||||
(e.key === 'c' && e.metaKey === true) || // Allow: Cmd+C (Mac)
|
||||
(e.key === 'v' && e.metaKey === true) || // Allow: Cmd+V (Mac)
|
||||
(e.key === 'x' && e.metaKey === true) // Allow: Cmd+X (Mac)
|
||||
) {
|
||||
// let it happen, don't do anything
|
||||
return;
|
||||
}
|
||||
// Ensure that it is a number and stop the keypress
|
||||
const key = Number(e.key)
|
||||
if (
|
||||
(e.shiftKey || (isNaN(key) && !(e.key === '.')))
|
||||
) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('paste', ['$event'])
|
||||
onPaste(event: ClipboardEvent) {
|
||||
event.preventDefault();
|
||||
const pastedInput: string = event.clipboardData
|
||||
.getData('text/plain')
|
||||
.replace(/\D/g, ''); // get a digit-only string
|
||||
document.execCommand('insertText', false, pastedInput);
|
||||
}
|
||||
|
||||
@HostListener('drop', ['$event'])
|
||||
onDrop(event: DragEvent) {
|
||||
event.preventDefault();
|
||||
const textData = event.dataTransfer.getData('text').replace(/\D/g, '');
|
||||
this.inputElement.focus();
|
||||
document.execCommand('insertText', false, textData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user