From 20591ff8117a85296e525de3c9abec30da65e61e Mon Sep 17 00:00:00 2001 From: cbartondock Date: Thu, 11 Nov 2021 22:35:46 -0500 Subject: [PATCH] enabling and disabling from sidebar working --- .todo | 2 + src/models/index.ts | 2 +- src/renderer/components/nav.component.ts | 40 +++++++++++++-- .../components/user-exceptions.component.ts | 7 ++- src/renderer/services/parsers.service.ts | 7 +++ src/renderer/templates/nav.component.html | 49 ++++++++++++++----- 6 files changed, 87 insertions(+), 20 deletions(-) diff --git a/.todo b/.todo index 199a07fbf4..64702e5ab1 100644 --- a/.todo +++ b/.todo @@ -8,6 +8,8 @@ mage"\:\ \"\"\,\n\"defaultIcon\"\:\ \"\"\,/g' {} \; # Fixes Remove close steam if open warning and replace with something better +Steam parser only works for steam apps that are in a category + # Features Add missing artwork filter (2.4) diff --git a/src/models/index.ts b/src/models/index.ts index fe8ec97596..666cbf94c1 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -17,4 +17,4 @@ export * from './x-request.model'; export * from './custom-variables.model'; export * from './user-exceptions.model'; export * from './config-presets.model'; -export * from './error.model' +export * from './error.model'; diff --git a/src/renderer/components/nav.component.ts b/src/renderer/components/nav.component.ts index f85014c07f..e84947d5ec 100644 --- a/src/renderer/components/nav.component.ts +++ b/src/renderer/components/nav.component.ts @@ -1,4 +1,5 @@ -import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; +import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ApplicationRef, OnDestroy } from '@angular/core'; +import { FormBuilder, FormArray, FormGroup, FormControl } from '@angular/forms'; import { ParsersService, LanguageService, UserExceptionsService } from '../services'; import { UserConfiguration } from '../../models'; import { Subscription } from 'rxjs'; @@ -12,23 +13,48 @@ import { APP } from '../../variables'; ], changeDetection: ChangeDetectionStrategy.OnPush }) -export class NavComponent { +export class NavComponent implements OnDestroy { private userConfigurations: { saved: UserConfiguration, current: UserConfiguration }[]; + private numConfigurations: number = -1; private isExceptionsUnsaved: boolean = false; private dummy: boolean = true; private subscriptions: Subscription = new Subscription(); + private navForm: FormGroup; + private navFormItems: FormArray; + constructor( private parsersService: ParsersService, private languageService: LanguageService, private exceptionsService: UserExceptionsService, - private changeRef: ChangeDetectorRef) {} + private changeRef: ChangeDetectorRef, + private appRef: ApplicationRef, + private formBuilder: FormBuilder, + ) {} ngOnInit() { this.subscriptions.add(this.parsersService.getUserConfigurations().subscribe((userConfigurations) => { - this.userConfigurations = userConfigurations; - this.refreshActiveRoute(); + //if(userConfigurations.length != this.numConfigurations) { + this.navForm = this.formBuilder.group({ + parserStatuses: this.formBuilder.array(userConfigurations.map((config: {saved: UserConfiguration, current: UserConfiguration}) => { + let singleton={}; + singleton[config.saved.parserId] = ! config.saved.disabled; + return this.formBuilder.group(singleton); + })) + }); + (this.navForm.get("parserStatuses") as FormArray).controls.forEach((control: FormControl)=>{ + control.valueChanges.subscribe((val: {[parserId: string]: boolean}) => { + console.log("Little Change: ", val) + this.parsersService.changeEnabledStatus(Object.keys(val)[0], Object.values(val)[0]) + }) + }) + this.numConfigurations = userConfigurations.length; + this.userConfigurations = userConfigurations; + //} + + this.appRef.tick() this.changeRef.detectChanges(); + this.refreshActiveRoute(); })); this.subscriptions.add(this.exceptionsService.isUnsavedObservable.subscribe((val:boolean)=>{ this.isExceptionsUnsaved = val; @@ -48,6 +74,10 @@ export class NavComponent { return APP.lang.nav.component; } + getParserControls() { + return (this.navForm.get('parserStatuses') as FormArray).controls; + } + ngOnDestroy() { this.subscriptions.unsubscribe(); } diff --git a/src/renderer/components/user-exceptions.component.ts b/src/renderer/components/user-exceptions.component.ts index 87e7cae1c4..6238600118 100644 --- a/src/renderer/components/user-exceptions.component.ts +++ b/src/renderer/components/user-exceptions.component.ts @@ -1,9 +1,9 @@ -import { Component, ChangeDetectionStrategy, ChangeDetectorRef, AfterViewInit, OnDestroy } from '@angular/core'; +import { Component, ChangeDetectionStrategy, ChangeDetectorRef, OnDestroy } from '@angular/core'; import { ActivatedRoute, Router, RouterLinkActive } from '@angular/router'; import { FormBuilder, FormArray, FormGroup, FormControl } from '@angular/forms'; import { UserExceptions } from '../../models'; import { UserExceptionsService, LoggerService } from '../services'; -import { Subscription, Observable } from "rxjs"; +import { Subscription } from "rxjs"; import { APP } from '../../variables'; import * as _ from 'lodash'; @Component({ @@ -90,6 +90,9 @@ export class ExceptionsComponent implements OnDestroy { this.userExceptions = data.current ? data.current : data.saved; if(!this.exceptionsService.isUnsaved) { this.setForm(); + console.log("how many times we doin that."); + console.log("numexceps: ", this.userExceptions.length); + console.log(this.exceptionsForm); } if(data.current) { this.exceptionsService.setIsUnsaved(true); diff --git a/src/renderer/services/parsers.service.ts b/src/renderer/services/parsers.service.ts index 6415d643bd..b6ca6f2b98 100644 --- a/src/renderer/services/parsers.service.ts +++ b/src/renderer/services/parsers.service.ts @@ -102,6 +102,13 @@ export class ParsersService { this.saveUserConfigurations(); } + changeEnabledStatus(parserId: string, enabled: boolean) { + let updateIndex = this.userConfigurations.getValue().map(e=>e.saved.parserId).indexOf(parserId); + let config = _.cloneDeep(this.userConfigurations.getValue()[updateIndex].saved); + config.disabled = !enabled; + this.updateConfiguration(updateIndex, config); + } + updateConfiguration(index: number, config?: UserConfiguration) { let userConfigurations = this.userConfigurations.getValue(); diff --git a/src/renderer/templates/nav.component.html b/src/renderer/templates/nav.component.html index bc3999604c..4181ac64a0 100644 --- a/src/renderer/templates/nav.component.html +++ b/src/renderer/templates/nav.component.html @@ -7,15 +7,40 @@ {{lang.about}} - - - {{lang.parsers}} -    - - - - - - {{config.saved.configTitle || lang.noTitle}} - - +
+ + + {{lang.parsers}} +    + + + + +
+
+
+ + {{userConfigurations[i].saved.configTitle || lang.noTitle}} + + +
+
+
+ + + +
+
+ + + + + + + + + + + + +