Skip to content

Commit

Permalink
replace configs service with app settings store & display dynamic con…
Browse files Browse the repository at this point in the history
…tent
  • Loading branch information
esteban-gs committed Jun 17, 2023
1 parent 55cceec commit 25b1d39
Show file tree
Hide file tree
Showing 29 changed files with 431 additions and 237 deletions.
3 changes: 1 addition & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
OnDestroy,
} from "@angular/core";
import { environment } from "../environments/environment";
import { ConfigsService } from "./configs/configs.service";
import { LookupsService } from "./lookups/lookups.service";
import { Router, NavigationEnd } from "@angular/router";
import { MenuItem, Message, MessageService, PrimeNGConfig } from "primeng/api";
Expand All @@ -28,7 +27,7 @@ declare let jQuery: any;
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
providers: [LookupsService, ConfigsService, MessageService],
providers: [LookupsService, MessageService],
})
export class AppComponent implements AfterViewInit, OnInit, OnDestroy {
@ViewChild("layoutContainer", { static: false })
Expand Down
20 changes: 0 additions & 20 deletions src/app/configs/configs.service.spec.ts

This file was deleted.

91 changes: 0 additions & 91 deletions src/app/configs/configs.service.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
</span>
</div>
<div class="p-field p-col-12 p-input-filled" [hidden]="r.key === TERMS_KEY">
<span class="p-float-label">
<textarea
pInputTextarea
[value]="r.description ?? '---'"
[disabled]="true"
id="description"
name="description"
autoResize="autoResize"
></textarea>
<label for="description">Description</label>
</span>
</div>
<div class="p-field p-col-12 p-input-filled">
<span class="p-float-label">
<input
pInputText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ActivatedRoute } from "@angular/router";
import { RouterTestingModule } from "@angular/router/testing";
import { ConfirmationService } from "primeng/api";
import { of } from "rxjs";
import { ConfigsServiceSpy } from "src/app/shared/testing";
import { ConfigsService } from "../../configs.service";
import { AppSettingsStoreServiceSpy } from "src/app/shared/testing";
import { AppSettingsStoreService } from "../../../shared/services/app-settings-store.service";

import { MacheteSettingsEditComponent } from "./machete-settings-edit.component";

Expand All @@ -28,8 +28,8 @@ describe("MacheteSettingsEditComponent", () => {
declarations: [MacheteSettingsEditComponent],
providers: [
{
provide: ConfigsService,
useClass: ConfigsServiceSpy,
provide: AppSettingsStoreServiceSpy,
useClass: AppSettingsStoreService,
},
{
provide: ConfirmationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfirmationService } from "primeng/api";
import { merge, Observable, Subject } from "rxjs";
import { pluck, switchMap, takeWhile, tap } from "rxjs/operators";
import { Config } from "src/app/shared/models/config";
import { ConfigsService } from "../../configs.service";
import { AppSettingsStoreService } from "../../../shared/services/app-settings-store.service";

@Component({
selector: "app-machete-settings-edit",
Expand All @@ -25,14 +25,14 @@ export class MacheteSettingsEditComponent implements OnInit, OnDestroy {
pluck("id"),
switchMap((id: string) => {
this.routeRecordId = id;
return this.configsService.getConfig(this.routeRecordId);
return this.appSettingsStore.getConfig(this.routeRecordId);
})
);

constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private configsService: ConfigsService,
private appSettingsStore: AppSettingsStoreService,
private primeConfirmService: ConfirmationService
) {}

Expand All @@ -52,7 +52,7 @@ export class MacheteSettingsEditComponent implements OnInit, OnDestroy {
}

public save(record: Config): void {
this.configsService
this.appSettingsStore
.update(record)
.pipe(
takeWhile(() => this.isAlive),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { Router } from "@angular/router";
import { ConfigsServiceSpy, RouterSpy } from "src/app/shared/testing";
import { ConfigsService } from "../../configs.service";
import { AppSettingsStoreServiceSpy, RouterSpy } from "src/app/shared/testing";
import { AppSettingsStoreService } from "../../../shared/services/app-settings-store.service";

import { MacheteSettingsListComponent } from "./machete-settings-list.component";

Expand All @@ -13,7 +13,10 @@ describe("MacheteSettingsListComponent", () => {
await TestBed.configureTestingModule({
declarations: [MacheteSettingsListComponent],
providers: [
{ provide: ConfigsService, useClass: ConfigsServiceSpy },
{
provide: AppSettingsStoreService,
useClass: AppSettingsStoreServiceSpy,
},
{ provide: Router, useClass: RouterSpy },
],
}).compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Router } from "@angular/router";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { Config } from "src/app/shared/models/config";
import { ConfigsService } from "../../configs.service";
import { AppSettingsStoreService } from "../../../shared/services/app-settings-store.service";
import { MS_NON_EDITABLE_CONFIGS } from "../shared/machete-settings-constants";

@Component({
Expand All @@ -20,7 +20,10 @@ export class MacheteSettingsListComponent implements OnInit {
"id",
];

constructor(private service: ConfigsService, private router: Router) {}
constructor(
private appSetttingsServ: AppSettingsStoreService,
private router: Router
) {}

async onRowSelect(selectedRecord: Config): Promise<void> {
await this.router.navigate([
Expand All @@ -29,7 +32,7 @@ export class MacheteSettingsListComponent implements OnInit {
}

ngOnInit(): void {
this.configs$ = this.service.getAllConfigs().pipe(
this.configs$ = this.appSetttingsServ.all$.pipe(
map((configs: Config[]) => configs.filter((c) => c.publicConfig)),
map((configs: Config[]) =>
configs.filter((c) => !MS_NON_EDITABLE_CONFIGS.includes(c.key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TableModule } from "primeng/table";
import {
MyWorkOrdersServiceSpy,
RouterSpy,
ConfigsServiceSpy,
AppSettingsStoreServiceSpy,
} from "../../shared/testing";
import {
TransportProvidersServiceSpy,
Expand All @@ -17,9 +17,9 @@ import {
import * as paypal from "paypal-checkout";
import { MyWorkOrdersService } from "../my-work-orders.service";
import { ActivatedRoute, Router } from "@angular/router";
import { ConfigsService } from "../../configs/configs.service";
import { MessageService } from "primeng/api";
import { TransportProvidersService } from "../../online-orders/transport-providers.service";
import { AppSettingsStoreService } from "../../shared/services/app-settings-store.service";

describe("OrderCompleteComponent", () => {
let component: OrderCompleteComponent;
Expand All @@ -42,7 +42,10 @@ describe("OrderCompleteComponent", () => {
provide: MyWorkOrdersService,
useClass: MyWorkOrdersServiceSpy,
},
{ provide: ConfigsService, useClass: ConfigsServiceSpy },
{
provide: AppSettingsStoreService,
useClass: AppSettingsStoreServiceSpy,
},
{ provide: MessageService, useClass: MessageServiceSpy },
{
provide: ActivatedRoute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { WorkOrder } from "../../shared/models/work-order";
import * as paypal from "paypal-checkout";
import { ActivatedRoute, Router } from "@angular/router";
import { MyWorkOrdersService } from "../my-work-orders.service";
import { ConfigsService } from "../../configs/configs.service";
import { TransportProvidersService } from "../../online-orders/transport-providers.service";
import { AppSettingsStoreService } from "../../shared/services/app-settings-store.service";

@Component({
selector: "app-order-complete",
Expand Down Expand Up @@ -80,7 +80,7 @@ export class OrderCompleteComponent implements OnInit, AfterViewChecked {
private transportProviderService: TransportProvidersService,
private route: ActivatedRoute,
private router: Router,
private configsService: ConfigsService
private appSettingsStore: AppSettingsStoreService
) {
console.log(".ctor");
}
Expand All @@ -91,8 +91,8 @@ export class OrderCompleteComponent implements OnInit, AfterViewChecked {
observableCombineLatest([
this.transportProviderService.getTransportProviders(),
this.ordersService.getOrder(orderId),
this.configsService.getConfig("PayPalClientID"),
this.configsService.getConfig("PayPalEnvironment"),
this.appSettingsStore.getConfig("PayPalClientID"),
this.appSettingsStore.getConfig("PayPalEnvironment"),
]).subscribe(
([l, o, id, env]) => {
console.log("ngOnInit:combineLatest received:", l, o, id, env);
Expand Down
11 changes: 7 additions & 4 deletions src/app/online-orders/guards/banner.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import { Injectable } from "@angular/core";
import { CanActivate, Router } from "@angular/router";
import { combineLatest, Observable } from "rxjs";
import { map } from "rxjs/operators";
import { ConfigsService } from "../..//configs/configs.service";
import { AppSettingsStoreService } from "../../shared/services/app-settings-store.service";

@Injectable()
export class BannerGuard implements CanActivate {
constructor(private configsService: ConfigsService, private router: Router) {
constructor(
private appSettingsStore: AppSettingsStoreService,
private router: Router
) {
console.log(".ctor");
}

canActivate(): Observable<boolean> {
return combineLatest([
this.configsService.getConfig("DisableOnlineOrders"),
this.configsService.getConfig("DisableOnlineOrdersBanner"),
this.appSettingsStore.getConfig("DisableOnlineOrders"),
this.appSettingsStore.getConfig("DisableOnlineOrdersBanner"),
]).pipe(
map(
([toggle, banner]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Confirm } from "../shared/models/confirm";
export class IntroConfirmComponent implements OnInit {
confirmChoices = new Array<Confirm>();
confirmStatus = false;
// TODO: Refactor as a service that polls from API

constructor(
private onlineService: OnlineOrdersService,
Expand Down
Loading

0 comments on commit 25b1d39

Please sign in to comment.