Skip to content

Commit

Permalink
feat(backend): now using version 2 of the backend library + total ove… (
Browse files Browse the repository at this point in the history
#118)

* feat(backend): now using version 2 of the backend library + total over whole of auth code

* feat(rack): download is image
  • Loading branch information
Polyterative authored Jan 28, 2024
1 parent b13d1ec commit cb41977
Show file tree
Hide file tree
Showing 25 changed files with 3,991 additions and 2,512 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"updateMinors": "npm update --save/--save-dev",
"updateAll": "ncu -u",
"ci": "",
"updateBackendTypes": "npx supabase gen types typescript --project-id sozmatmywjpstwidzlss --schema public > src/backend/database.types.ts",
"testRelease:patch": "standard-version --release-as patch --dry-run && git push --follow-tags origin production",
"release:patch": "standard-version --release-as patch --commit-all && git push --follow-tags origin production",
"release:minor": "standard-version --release-as minor --commit-all && git push --follow-tags origin production",
Expand Down Expand Up @@ -43,7 +44,7 @@
"@ngx-pwa/local-storage": "^13.0.2",
"@sentry/angular": "^7.5.0",
"@sentry/tracing": "^7.5.0",
"@supabase/supabase-js": "^1.35.4",
"@supabase/supabase-js": "^2.39.3",
"angular-animations": "^0.11.0",
"angular-html-parser": "^1.8.0",
"core-js": "^3.23.3",
Expand All @@ -54,6 +55,7 @@
"graphology-layout-force": "^0.2.4",
"graphology-layout-forceatlas2": "^0.8.2",
"graphology-types": "^0.24.3",
"dom-to-image": "^2.6.0",
"lodash": "^4.17.21",
"lottie-web": "^5.9.1",
"luxon": "^2.3.1",
Expand Down Expand Up @@ -84,6 +86,7 @@
"@types/lodash": "^4.14.182",
"@types/luxon": "^2.3.2",
"@types/node": "^18.0.1",
"@types/dom-to-image": "^2.6.0",
"angular-build-info": "^2.0.1",
"copyfiles": "^2.4.1",
"jasmine-core": "^4.0.1",
Expand All @@ -95,7 +98,8 @@
"karma-jasmine-html-reporter": "^1.7.0",
"protractor": "^7.0.0",
"standard-version": "^9.5.0",
"supabase": "^1.136.3",
"ts-node": "^10.7.0",
"typescript": "4.7.4"
}
}
}
182 changes: 91 additions & 91 deletions src/app/components/module-parts/module-detail-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import {
BehaviorSubject,
delay,
merge,
of,
ReplaySubject,
Subject
} from 'rxjs';
} from 'rxjs';
import {
filter,
map,
switchMap,
takeUntil,
tap,
withLatestFrom
} from 'rxjs/operators';
} from 'rxjs/operators';
import { RackModuleAdderComponent } from 'src/app/components/rack-parts/rack-module-adder/rack-module-adder.component';
import { UserManagementService } from '../../features/backbone/login/user-management.service';
import { SupabaseService } from '../../features/backend/supabase.service';
import { DbModule } from '../../models/module';
import { PatchMinimal } from '../../models/patch';
import { RackMinimal } from '../../models/rack';
import { UserManagementService } from '../../features/backbone/login/user-management.service';
import { SupabaseService } from '../../features/backend/supabase.service';
import { DbModule } from '../../models/module';
import { PatchMinimal } from '../../models/patch';
import { RackMinimal } from '../../models/rack';


@Injectable()
export class ModuleDetailDataService {
Expand Down Expand Up @@ -51,17 +52,17 @@ export class ModuleDetailDataService {
) {

this.copyModuleNameAndManufacturer$
.pipe(
withLatestFrom(this.singleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
if (b) {
let text: string = `${ b.name } by ${ b.manufacturer.name }`;
navigator.clipboard.writeText(text);
snackBar.open('Copied: ' + text, undefined, {duration: 3000});
}
});
.pipe(
withLatestFrom(this.singleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
if (b) {
let text: string = `${ b.name } by ${ b.manufacturer.name }`;
navigator.clipboard.writeText(text);
snackBar.open('Copied: ' + text, undefined, {duration: 3000});
}
});

merge(this.userService.loggedUser$, this.updateSingleModuleData$)
.pipe(
Expand All @@ -75,48 +76,48 @@ export class ModuleDetailDataService {

// get module data
this.updateSingleModuleData$
.pipe(
tap(x => this.singleModuleData$.next(undefined)),
switchMap(x => this.backend.get.moduleWithId(x)),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.singleModuleData$.next(x.data));

.pipe(
tap(x => this.singleModuleData$.next(undefined)),
switchMap(x => this.backend.get.moduleWithId(x)),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.singleModuleData$.next(x.data));
// get racks with this module
this.updateSingleModuleData$
.pipe(
tap(x => this.racksWithThisModule$.next(undefined)),
delay(150),
switchMap(x => this.backend.get.racksWithModule(x)),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.racksWithThisModule$.next(x.data.map(y => y.rack)));

.pipe(
tap(x => this.racksWithThisModule$.next(undefined)),
delay(150),
switchMap(x => this.backend.get.racksWithModule(x)),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.racksWithThisModule$.next(x.data.map(y => y.rack)));
// get patches with this module
this.updateSingleModuleData$
.pipe(
tap(x => this.patchesWithThisModule$.next(undefined)),
delay(200),
switchMap(x => this.backend.get.patchesWithModule(x)),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.patchesWithThisModule$.next(x));

.pipe(
tap(x => this.patchesWithThisModule$.next(undefined)),
delay(200),
switchMap(x => this.backend.get.patchesWithModule(x)),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.patchesWithThisModule$.next(x));
// get modules by same manufacturer
this.singleModuleData$
.pipe(
filter(x => !!x && !!x.manufacturer),
tap(x => this.modulesBySameManufacturer$.next(undefined)),
delay(250),
switchMap(singleModuleData => this.backend.get.modulesBySameManufacturer(singleModuleData.manufacturerId)
.pipe(
map(x => x.filter(module => module.id !== singleModuleData.id))
)
),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.modulesBySameManufacturer$.next(x));

.pipe(
filter(x => !!x && !!x.manufacturer),
tap(x => this.modulesBySameManufacturer$.next(undefined)),
delay(250),
switchMap(singleModuleData => this.backend.get.modulesBySameManufacturer(singleModuleData.manufacturerId)
.pipe(
map(x => x.filter(module => module.id !== singleModuleData.id))
)
),
takeUntil(this.destroyEvent$)
)
.subscribe(x => this.modulesBySameManufacturer$.next(x));
// hidden cause circular dependency
// this.updateSingleModuleData$
// .pipe(
Expand All @@ -125,51 +126,50 @@ export class ModuleDetailDataService {
// takeUntil(this.destroyEvent$)
// )
// .subscribe(x => this.modulePatchesList$.next(x.data));

this.addModuleToCollection$
.pipe(
switchMap(x => this.backend.add.userModule(x)),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
snackBar.open('Added', undefined, {duration: 1000});
this.updateSingleModuleData$.next(b);
});
.pipe(
switchMap(x => this.backend.add.userModule(x)),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
snackBar.open('Added', undefined, {duration: 1000});
this.updateSingleModuleData$.next(b);
});

this.removeModuleFromCollection$
.pipe(
switchMap(x => this.backend.delete.userModule(x)),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
snackBar.open('Removed', undefined, {duration: 1000});
this.updateSingleModuleData$.next(b);
});
.pipe(
switchMap(x => this.backend.delete.userModule(x)),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
snackBar.open('Removed', undefined, {duration: 1000});
this.updateSingleModuleData$.next(b);
});

this.requestAddModuleToRack$
.pipe(
switchMap(x => RackModuleAdderComponent.open(this.dialog, {module: x})
.afterClosed()),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
this.updateSingleModuleData$.next(b);
});
.pipe(
switchMap(x => RackModuleAdderComponent.open(this.dialog, {module: x})
.afterClosed()),
withLatestFrom(this.updateSingleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
this.updateSingleModuleData$.next(b);
});

this.singleModuleData$.pipe(
filter(x => !!x),
switchMap(x => this.userService.loggedUser$.pipe(withLatestFrom(of(x)))),
takeUntil(this.destroyEvent$)
)
.subscribe(([user, module]) => {
if (user) {
this.moduleEditingPanelOpenState$.next(!module.isComplete && module.manufacturer.id !== 10000);
}
});

.subscribe(([user, module]) => {
if (user) {
this.moduleEditingPanelOpenState$.next(!module.isComplete && module.manufacturer.id !== 10000);
}
});


}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit
} from '@angular/core';
import {
Observable,
Subject
} from 'rxjs';
import {
map,
takeUntil
} from 'rxjs/operators';
import { UserManagementService } from 'src/app/features/backbone/login/user-management.service';
import { MinimalModule } from 'src/app/models/module';
import { RackDetailDataService } from '../../rack-parts/rack-detail-data.service';
import { ModuleDetailDataService } from '../module-detail-data.service';


@Component({
selector: 'app-module-minimal',
templateUrl: './module-minimal.component.html',
Expand Down Expand Up @@ -65,4 +77,4 @@ export const defaultModuleMinimalViewConfig: ModuleMinimalViewConfig = {
hidePanelsOptions: true,
bigPanelImage: false,
ellipseDescription: true
};
};
Loading

0 comments on commit cb41977

Please sign in to comment.