Skip to content

Commit

Permalink
feat(app): better names
Browse files Browse the repository at this point in the history
  • Loading branch information
Polyterative committed Feb 9, 2024
1 parent 2280297 commit 9abff3f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/app/components/module-parts/module-detail-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
tap,
withLatestFrom
} from 'rxjs/operators';
import { RackModuleAdderComponent } from 'src/app/components/rack-parts/rack-module-adder/rack-module-adder.component';
import { RackModuleAdderDialogComponent } from 'src/app/components/rack-parts/rack-module-adder/rack-module-adder-dialog.component';
import { UserManagementService } from '../../features/backbone/login/user-management.service';
import { SupabaseService } from '../../features/backend/supabase.service';
import { DbModule } from '../../models/module';
Expand Down Expand Up @@ -151,7 +151,7 @@ export class ModuleDetailDataService {

this.requestAddModuleToRack$
.pipe(
switchMap(x => RackModuleAdderComponent.open(this.dialog, {module: x})
switchMap(x => RackModuleAdderDialogComponent.open(this.dialog, {module: x})
.afterClosed()),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import {
ChangeDetectionStrategy,
Component,
Inject,
OnInit
} from '@angular/core';
import {
UntypedFormControl,
Validators
} from '@angular/forms';
import {
MAT_DIALOG_DATA,
MatDialog,
MatDialogRef
} from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { TimeagoPipe } from 'ngx-timeago';
import { BehaviorSubject, Subject } from 'rxjs';
import { filter, map, share, startWith, switchMap } from 'rxjs/operators';
import {
BehaviorSubject,
Subject
} from 'rxjs';
import {
filter,
map,
share,
startWith,
switchMap
} from 'rxjs/operators';
import { SupabaseService } from 'src/app/features/backend/supabase.service';
import { UserAreaDataService } from 'src/app/features/user-area/user-area-data.service';
import { DbModule } from 'src/app/models/module';
Expand All @@ -13,6 +34,7 @@ import { SubManager } from 'src/app/shared-interproject/directives/subscription-
import { SharedConstants } from 'src/app/shared-interproject/SharedConstants';
import { RackDetailDataService } from '../rack-detail-data.service';


export interface RackModuleAdderOutModel {
}

Expand All @@ -22,15 +44,15 @@ export interface RackModuleAdderInModel {

@Component({
selector: 'app-rack-module-adder',
templateUrl: './rack-module-adder.component.html',
styleUrls: ['./rack-module-adder.component.scss'],
templateUrl: './rack-module-adder-dialog.component.html',
styleUrls: ['./rack-module-adder-dialog.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
UserAreaDataService,
TimeagoPipe
]
})
export class RackModuleAdderComponent extends SubManager implements OnInit {
export class RackModuleAdderDialogComponent extends SubManager implements OnInit {
readonly saveRackedModule$ = new Subject<void>();
data$ = new BehaviorSubject<[]>([]);

Expand All @@ -47,8 +69,8 @@ export class RackModuleAdderComponent extends SubManager implements OnInit {
}
};

static open(dialog: MatDialog, data: RackModuleAdderInModel): MatDialogRef<RackModuleAdderComponent, RackModuleAdderOutModel> {
return dialog.open(RackModuleAdderComponent, {
static open(dialog: MatDialog, data: RackModuleAdderInModel): MatDialogRef<RackModuleAdderDialogComponent, RackModuleAdderOutModel> {
return dialog.open(RackModuleAdderDialogComponent, {
data,
width: '70%',
maxWidth: '40rem'
Expand All @@ -60,25 +82,25 @@ export class RackModuleAdderComponent extends SubManager implements OnInit {
public backend: SupabaseService,
public timeagoPipe: TimeagoPipe,
public userAreaDataService: UserAreaDataService,
public dialogRef: MatDialogRef<RackModuleAdderComponent, RackModuleAdderOutModel>,
public dialogRef: MatDialogRef<RackModuleAdderDialogComponent, RackModuleAdderOutModel>,
public rackDetailDataService: RackDetailDataService,
@Inject(MAT_DIALOG_DATA) public data: RackModuleAdderInModel
) {
super();

this.manageSub(
this.saveRackedModule$
.pipe(
switchMap(x => this.backend.add.rackModule(
this.data.module.id,
this.fields.rack.control.value.id
))
)
.subscribe(value => {
SharedConstants.successSave(this.snackBar);

this.dialogRef.close();
})
.pipe(
switchMap(x => this.backend.add.rackModule(
this.data.module.id,
this.fields.rack.control.value.id
))
)
.subscribe(value => {
SharedConstants.successSave(this.snackBar);
this.dialogRef.close();
})
);

this.userAreaDataService.updateRackData$.next(undefined);
Expand All @@ -92,22 +114,31 @@ export class RackModuleAdderComponent extends SubManager implements OnInit {
return this.userAreaDataService.rackData$.pipe(
filter(x => !!x),
map(x => {
const mapFunction: (row) => { name: string; id: string } = row => {
const mapFunction: (row) => {
name: string;
id: string
} = row => {
const name = `${ row.name } ( ${ row.hp } HP , ${ row.rows } row(s) , ${ this.timeagoPipe.transform(new Date(row.updated)) } )`;

return {
id: row.id.toString(),
name
};
};
const options: { name: string; id: string }[] = x.map(mapFunction);
const options: {
name: string;
id: string
}[] = x.map(mapFunction);

// add lastly updated rack if not already empty
if (options.length > 0) {
const lastUpdatedRack = x.sort((a, b) =>
new Date(b.updated).getTime() - new Date(a.updated).getTime())[0];

const firstRackAsOption: { name: string; id: string } = [lastUpdatedRack].map(mapFunction)[0];
const firstRackAsOption: {
name: string;
id: string
} = [lastUpdatedRack].map(mapFunction)[0];

this.fields.rack.control.patchValue(firstRackAsOption);
}
Expand All @@ -119,4 +150,4 @@ export class RackModuleAdderComponent extends SubManager implements OnInit {
share()
);
}
}
}
6 changes: 3 additions & 3 deletions src/app/components/rack-parts/rack.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { RackDetailDataService } from 'src/app/components/rack-parts/rack-detail
import { RackDetailsComponent } from 'src/app/components/rack-parts/rack-details/rack-details.component';
import { RackEditorComponent } from 'src/app/components/rack-parts/rack-editor/rack-editor.component';
import { RackMinimalComponent } from 'src/app/components/rack-parts/rack-minimal/rack-minimal.component';
import { RackModuleAdderComponent } from 'src/app/components/rack-parts/rack-module-adder/rack-module-adder.component';
import { RackModuleAdderDialogComponent } from 'src/app/components/rack-parts/rack-module-adder/rack-module-adder-dialog.component';
import { SharedAtomsModule } from 'src/app/components/shared-atoms/shared-atoms.module';
import { ModuleBrowserModule } from 'src/app/features/module-browser/module-browser.module';
import { MatFormEntityModule } from 'src/app/shared-interproject/components/@smart/mat-form-entity/mat-form-entity.module';
Expand Down Expand Up @@ -48,7 +48,7 @@ import { StatisticsModule } from "src/app/components/shared-atoms/statistics/sta
RackEditorComponent,
RackMinimalComponent,
RackCreatorComponent,
RackModuleAdderComponent,
RackModuleAdderDialogComponent,
RackDetailsComponent,
TotalHpOfModulesPipe,
RackDetailsRemainingIndicatorComponent,
Expand All @@ -63,7 +63,7 @@ import { StatisticsModule } from "src/app/components/shared-atoms/statistics/sta
RackMinimalComponent,
RackEditorComponent,
RackCreatorComponent,
RackModuleAdderComponent,
RackModuleAdderDialogComponent,
RackDetailsComponent,
RackDetailsRemainingIndicatorComponent,
RackVisualModelComponent
Expand Down
6 changes: 3 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Build information, automatically generated by `ng-info`
const build = {
version: "4.2.3",
timestamp: "Fri Feb 09 2024 11:07:51 GMT+0100 (Ora standard dell’Europa centrale)",
timestamp: "Fri Feb 09 2024 11:53:26 GMT+0100 (Ora standard dell’Europa centrale)",
message: null,
git: {
user: "Polyterative",
branch: "develop",
hash: "a811c2",
fullHash: "a811c286e2afd507b7d44b545065627f451f75c4"
hash: "228029",
fullHash: "2280297164013d554e69b322dae22aaac8d3f231"
}
};

Expand Down

0 comments on commit 9abff3f

Please sign in to comment.