add settings page + config settings
This commit is contained in:
1 parent
b872cd0733
commit
c3294a1ab9
19 files changed
+359
-25
No files matched your search
File renamed without changes.
@@ -0,0 +1 @@
|
||||
<p>settings-api-keys works!</p>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SettingsApiKeysComponent } from './settings-api-keys.component';
|
||||
|
||||
describe('SettingsApiKeysComponent', () => {
|
||||
let component: SettingsApiKeysComponent;
|
||||
let fixture: ComponentFixture<SettingsApiKeysComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SettingsApiKeysComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SettingsApiKeysComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings-api-keys',
|
||||
templateUrl: './settings-api-keys.component.html',
|
||||
styleUrl: './settings-api-keys.component.css'
|
||||
})
|
||||
export class SettingsApiKeysComponent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.is-invalid {
|
||||
border-color: #dc3545;
|
||||
}
|
||||
|
||||
.invalid-feedback {
|
||||
display: block;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<form [formGroup]="settingsForm" (ngSubmit)="onSubmit()">
|
||||
<div class="form-group">
|
||||
<label for="userDataPath">User Data Path</label>
|
||||
<input id="userDataPath" formControlName="userDataPath" type="text" class="form-control"
|
||||
[ngClass]="{'is-invalid': f['userDataPath'].touched && f['userDataPath'].invalid}">
|
||||
<div *ngIf="f['userDataPath'].touched && f['userDataPath'].invalid" class="invalid-feedback">
|
||||
User Data Path is required.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="tmdbApiUrl">TMDB API URL</label>
|
||||
<input id="tmdbApiUrl" formControlName="tmdbApiUrl" type="text" class="form-control"
|
||||
[ngClass]="{'is-invalid': f['tmdbApiUrl'].touched && f['tmdbApiUrl'].invalid}">
|
||||
<div *ngIf="f['tmdbApiUrl'].touched && f['tmdbApiUrl'].invalid" class="invalid-feedback">
|
||||
TMDB API URL is required.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="tmdbApiKey">TMDB API Key</label>
|
||||
<input id="tmdbApiKey" formControlName="tmdbApiKey" type="text" class="form-control"
|
||||
[ngClass]="{'is-invalid': f['tmdbApiKey'].touched && f['tmdbApiKey'].invalid}">
|
||||
<div *ngIf="f['tmdbApiKey'].touched && f['tmdbApiKey'].invalid" class="invalid-feedback">
|
||||
TMDB API Key is required.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="frontPort">Front Port</label>
|
||||
<input id="frontPort" formControlName="frontPort" type="text" class="form-control"
|
||||
[ngClass]="{'is-invalid': f['frontPort'].touched && f['frontPort'].invalid}">
|
||||
<div *ngIf="f['frontPort'].touched && f['frontPort'].invalid" class="invalid-feedback">
|
||||
Front Port is required and must be a number.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="backPort">Back Port</label>
|
||||
<input id="backPort" formControlName="backPort" type="text" class="form-control"
|
||||
[ngClass]="{'is-invalid': f['backPort'].touched && f['backPort'].invalid}">
|
||||
<div *ngIf="f['backPort'].touched && f['backPort'].invalid" class="invalid-feedback">
|
||||
Back Port is required and must be a number.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="portableMode">Portable Mode</label>
|
||||
<input id="portableMode" formControlName="portableMode" type="text" class="form-control"
|
||||
[ngClass]="{'is-invalid': f['portableMode'].touched && f['portableMode'].invalid}">
|
||||
<div *ngIf="f['portableMode'].touched && f['portableMode'].invalid" class="invalid-feedback">
|
||||
Portable Mode is required.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary" [disabled]="settingsForm.invalid">Submit</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.getElementById('userDataPath').addEventListener('click', () => {
|
||||
window.postMessage({
|
||||
type: 'select-dirs'
|
||||
})
|
||||
})
|
||||
</script>
|
||||
+6
-6
@@ -1,18 +1,18 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SettingsComponent } from './settings.component';
|
||||
import { SettingsGeneralComponent } from './settings-general.component';
|
||||
|
||||
describe('SettingsComponent', () => {
|
||||
let component: SettingsComponent;
|
||||
let fixture: ComponentFixture<SettingsComponent>;
|
||||
describe('SettingsGeneralComponent', () => {
|
||||
let component: SettingsGeneralComponent;
|
||||
let fixture: ComponentFixture<SettingsGeneralComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SettingsComponent]
|
||||
imports: [SettingsGeneralComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SettingsComponent);
|
||||
fixture = TestBed.createComponent(SettingsGeneralComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Settings } from '../../../shared/models/settings.model';
|
||||
import { SettingsService } from '../../../core/services/settings.service';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings-general',
|
||||
templateUrl: './settings-general.component.html',
|
||||
styleUrl: './settings-general.component.css',
|
||||
})
|
||||
export class SettingsGeneralComponent implements OnInit {
|
||||
settings: Settings = {} as Settings;
|
||||
settingsForm!: FormGroup;
|
||||
|
||||
constructor(
|
||||
private settingsService: SettingsService,
|
||||
private fb: FormBuilder
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.settingsForm = this.fb.group({
|
||||
userDataPath: [this.settings.userDataPath],
|
||||
tmdbApiUrl: [this.settings.tmdbApiUrl],
|
||||
tmdbApiKey: [this.settings.tmdbApiKey, Validators.required],
|
||||
frontPort: [this.settings.frontPort, Validators.pattern('^[0-9]{4,5}$')],
|
||||
backPort: [
|
||||
this.settings.backPort,
|
||||
[Validators.required, Validators.pattern('^[0-9]{4,5}$')],
|
||||
],
|
||||
portableMode: [this.settings.portableMode],
|
||||
});
|
||||
|
||||
this.settingsService.getSettings().subscribe({
|
||||
next: (s) => {
|
||||
this.settings = s;
|
||||
|
||||
// Update the form with fetched settings
|
||||
this.settingsForm.patchValue({
|
||||
userDataPath: this.settings.userDataPath,
|
||||
tmdbApiUrl: this.settings.tmdbApiUrl,
|
||||
tmdbApiKey: this.settings.tmdbApiKey,
|
||||
frontPort: this.settings.frontPort,
|
||||
backPort: this.settings.backPort,
|
||||
portableMode: this.settings.portableMode,
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Error getting settings...`);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get f() {
|
||||
return this.settingsForm.controls;
|
||||
}
|
||||
|
||||
onSubmit(): void {
|
||||
if (this.settingsForm.valid) {
|
||||
const settings: Settings = this.settingsForm.value;
|
||||
this.settingsService.updateSettings(settings).subscribe({
|
||||
next: (s) => {
|
||||
// TODO: SHOW SUCCESS TOAST
|
||||
console.log(`Settings updated: `);
|
||||
},
|
||||
error: (error) => {
|
||||
// TODO: SHOW ERROR TOAST
|
||||
console.log(`Error updating settings: `, error);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,51 @@
|
||||
<div class="card mb-0" style="height: 82vh;">
|
||||
<div class="card-body">
|
||||
<div id="settingsStepper" class="bs-stepper gap-4 vertical">
|
||||
<!-- ! STEPPER HEADERS -->
|
||||
<div class="bs-stepper-header" role="tablist" style="height: 78vh;">
|
||||
<!-- ? step 1 -->
|
||||
<div class="step" data-target="#test-vl-1" (click)="setStep(1)" [ngClass]="{ 'active': step == 1 }">
|
||||
<div class="step-trigger" role="tab" aria-controls="test-vl-3" aria-selected="true">
|
||||
<div class="bs-stepper-circle"><i class="material-icons-outlined">settings</i></div>
|
||||
<div class="">
|
||||
<h5 class="mb-0 steper-title">Application Settings</h5>
|
||||
<p class="mb-0 steper-sub-title">General application settings</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ? step 1 -->
|
||||
<div class="step" data-target="#test-vl-1" (click)="setStep(2)" [ngClass]="{ 'active': step == 2 }">
|
||||
<div class="step-trigger" role="tab" aria-controls="test-vl-3" aria-selected="true">
|
||||
<div class="bs-stepper-circle"><i class="material-icons-outlined">key</i></div>
|
||||
<div class="">
|
||||
<h5 class="mb-0 steper-title">API keys</h5>
|
||||
<p class="mb-0 steper-sub-title">Setup your API keys</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- ! STEPPER CONTENT -->
|
||||
<div class="bs-stepper-content w-100">
|
||||
<!-- ? step 1 -->
|
||||
<div id="test-vl-3" class="bs-stepper-pane content fade dstepper-block" [ngClass]="{ 'active': step == 1 }"
|
||||
*ngIf="step == 1">
|
||||
<h5 class="mb-1">Application Settings</h5>
|
||||
<p class="mb-4">General application settings</p>
|
||||
<app-settings-general></app-settings-general>
|
||||
</div>
|
||||
|
||||
<!-- ? step 2 -->
|
||||
<div id="test-vl-3" class="bs-stepper-pane content fade dstepper-block" [ngClass]="{ 'active': step == 2 }"
|
||||
*ngIf="step == 2">
|
||||
<h5 class="mb-1">API keys</h5>
|
||||
<p class="mb-4">Setup your API keys</p>
|
||||
<app-settings-api-keys></app-settings-api-keys>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,30 @@
|
||||
import { AfterViewInit, ChangeDetectorRef, Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings-page',
|
||||
templateUrl: './settings-page.component.html',
|
||||
styleUrl: './settings-page.component.css',
|
||||
})
|
||||
export class SettingsPageComponent implements AfterViewInit {
|
||||
// stepper!: Stepper;
|
||||
step: number = 1;
|
||||
|
||||
constructor(private cdRef: ChangeDetectorRef) {}
|
||||
|
||||
ngAfterViewInit() {
|
||||
// const stepperElement = document.querySelector('#settingsStepper');
|
||||
// if (stepperElement) {
|
||||
// this.stepper = new Stepper(stepperElement, {
|
||||
// linear: false,
|
||||
// animation: true,
|
||||
// });
|
||||
// this.cdRef.detectChanges();
|
||||
// } else {
|
||||
// console.error('Stepper element not found!');
|
||||
// }
|
||||
}
|
||||
|
||||
setStep(step: number) {
|
||||
this.step = step;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import { SettingsPageComponent } from './settings-page/settings-page.component';
|
||||
|
||||
// ! /user-collections
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: SettingsPageComponent,
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class SettingsRoutingModule {}
|
||||
@@ -1,4 +0,0 @@
|
||||
<!--breadcrumb-->
|
||||
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||
<div class="breadcrumb-title pe-3">Settings</div>
|
||||
</div>
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.css',
|
||||
})
|
||||
export class SettingsComponent {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { SettingsRoutingModule } from './settings-routing.module';
|
||||
import { SettingsPageComponent } from './settings-page/settings-page.component';
|
||||
import { SettingsGeneralComponent } from './settings-general/settings-general.component';
|
||||
import { SettingsApiKeysComponent } from './settings-api-keys/settings-api-keys.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
SharedModule,
|
||||
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
|
||||
SettingsRoutingModule,
|
||||
|
||||
DragDropModule,
|
||||
],
|
||||
declarations: [
|
||||
SettingsPageComponent,
|
||||
|
||||
SettingsGeneralComponent,
|
||||
SettingsApiKeysComponent,
|
||||
],
|
||||
exports: [],
|
||||
})
|
||||
export class SettingsModule {}
|
||||
Reference in new issue
Block a user