Rework of major pages
This commit is contained in:
@@ -1,48 +1,56 @@
|
||||
import { INFO, ConsoleFormattedStream, createLogger as _createLogger, stdSerializers } from "browser-bunyan";
|
||||
import { ListingCriteria } from "../../../../bizmatch-server/src/models/main.model";
|
||||
import { BusinessListing, CommercialPropertyListing } from "../../../../bizmatch-server/src/models/db.model";
|
||||
import { Router } from '@angular/router';
|
||||
import { ConsoleFormattedStream, INFO, createLogger as _createLogger, stdSerializers } from 'browser-bunyan';
|
||||
import { BusinessListing, CommercialPropertyListing } from '../../../../bizmatch-server/src/models/db.model';
|
||||
import { ListingCriteria } from '../../../../bizmatch-server/src/models/main.model';
|
||||
|
||||
export function createGenericObject<T>(): T {
|
||||
// Ein leeres Objekt vom Typ T erstellen
|
||||
const ergebnis: Partial<T> = {};
|
||||
|
||||
// Für ein reales Interface funktioniert diese direkte Iteration nicht,
|
||||
// da Interfaces zur Compile-Zeit entfernt werden. Stattdessen könnten Sie
|
||||
// ein Dummy-Objekt oder spezifische Typtransformationen verwenden.
|
||||
// Hier nur als Pseudocode dargestellt, um die Idee zu vermitteln:
|
||||
for (const key in ergebnis) {
|
||||
ergebnis[key] = null; // oder undefined, je nach Bedarf
|
||||
}
|
||||
|
||||
return ergebnis as T;
|
||||
// Ein leeres Objekt vom Typ T erstellen
|
||||
const ergebnis: Partial<T> = {};
|
||||
|
||||
// Für ein reales Interface funktioniert diese direkte Iteration nicht,
|
||||
// da Interfaces zur Compile-Zeit entfernt werden. Stattdessen könnten Sie
|
||||
// ein Dummy-Objekt oder spezifische Typtransformationen verwenden.
|
||||
// Hier nur als Pseudocode dargestellt, um die Idee zu vermitteln:
|
||||
for (const key in ergebnis) {
|
||||
ergebnis[key] = null; // oder undefined, je nach Bedarf
|
||||
}
|
||||
|
||||
export function createLogger(name:string, level: number = INFO, options:any = {}){
|
||||
return _createLogger({
|
||||
name,
|
||||
streams:[{level, stream: new ConsoleFormattedStream()}],
|
||||
serializers:stdSerializers,
|
||||
src:true,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
return ergebnis as T;
|
||||
}
|
||||
|
||||
export const getSessionStorageHandler = function(path,value,previous,applyData){
|
||||
sessionStorage.setItem('criteria',JSON.stringify(this));
|
||||
}
|
||||
export function createLogger(name: string, level: number = INFO, options: any = {}) {
|
||||
return _createLogger({
|
||||
name,
|
||||
streams: [{ level, stream: new ConsoleFormattedStream() }],
|
||||
serializers: stdSerializers,
|
||||
src: true,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function getCriteriaStateObject(){
|
||||
const initialState = createGenericObject<ListingCriteria>();
|
||||
const storedState = sessionStorage.getItem('criteria');
|
||||
return storedState ? JSON.parse(storedState) : initialState;
|
||||
}
|
||||
export const getSessionStorageHandler = function (path, value, previous, applyData) {
|
||||
sessionStorage.setItem('criteria', JSON.stringify(this));
|
||||
};
|
||||
|
||||
export function getListingType(listing:BusinessListing|CommercialPropertyListing):'business'|'commercialProperty'{
|
||||
return listing?.type<100?'business':'commercialProperty';
|
||||
export function getCriteriaStateObject() {
|
||||
const initialState = createGenericObject<ListingCriteria>();
|
||||
const storedState = sessionStorage.getItem('criteria');
|
||||
return storedState ? JSON.parse(storedState) : initialState;
|
||||
}
|
||||
|
||||
export function getListingType(listing: BusinessListing | CommercialPropertyListing): 'business' | 'commercialProperty' {
|
||||
return listing?.type < 100 ? 'business' : 'commercialProperty';
|
||||
}
|
||||
export function isBusinessListing(listing: BusinessListing | CommercialPropertyListing): listing is BusinessListing {
|
||||
return listing?.type < 100;
|
||||
}
|
||||
export function isCommercialPropertyListing(listing: BusinessListing | CommercialPropertyListing): listing is CommercialPropertyListing {
|
||||
return listing?.type >= 100;
|
||||
}
|
||||
export function routeListingWithState(router: Router, value: string, data: any) {
|
||||
if (value === 'business') {
|
||||
router.navigate(['createBusinessListing'], { state: { data } });
|
||||
} else {
|
||||
router.navigate(['createCommercialPropertyListing'], { state: { data } });
|
||||
}
|
||||
export function isBusinessListing(listing: BusinessListing | CommercialPropertyListing): listing is BusinessListing {
|
||||
return listing?.type < 100;
|
||||
}
|
||||
export function isCommercialPropertyListing(listing: BusinessListing | CommercialPropertyListing): listing is CommercialPropertyListing {
|
||||
return listing?.type >= 100;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user