not-found page, #85, client logging

This commit is contained in:
2024-08-13 19:06:32 +02:00
parent 1f8febc479
commit a8bb163acf
15 changed files with 233 additions and 185 deletions

View File

@@ -1,93 +1,11 @@
import { Router } from '@angular/router';
import { ConsoleFormattedStream, INFO, createLogger as _createLogger, stdSerializers } from 'browser-bunyan';
import { jwtDecode } from 'jwt-decode';
import onChange from 'on-change';
import { User } from '../../../../bizmatch-server/src/models/db.model';
import { BusinessListingCriteria, CommercialPropertyListingCriteria, JwtToken, KeycloakUser, MailInfo, UserListingCriteria } from '../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../environments/environment';
// export function createDefaultUser(email: string, firstname: string, lastname: string): User {
// return {
// id: undefined,
// email,
// firstname,
// lastname,
// phoneNumber: '',
// description: '',
// companyName: '',
// companyOverview: '',
// companyWebsite: '',
// companyLocation: '',
// offeredServices: '',
// areasServed: [],
// hasProfile: false,
// hasCompanyLogo: false,
// licensedIn: [],
// gender: undefined,
// customerType: undefined,
// customerSubType: undefined,
// created: new Date(),
// updated: new Date(),
// };
// }
// export function createDefaultCommercialPropertyListing(): CommercialPropertyListing {
// return {
// id: undefined,
// serialId: undefined,
// email: '',
// type: null,
// title: '',
// description: '',
// city: '',
// state: '',
// price: null,
// favoritesForUser: [],
// hideImage: false,
// draft: false,
// zipCode: null,
// county: '',
// imageOrder: [],
// imagePath: '',
// created: null,
// updated: null,
// visits: null,
// lastVisit: null,
// latitude: null,
// longitude: null,
// listingsCategory: 'commercialProperty',
// };
// }
// export function createDefaultBusinessListing(): BusinessListing {
// return {
// id: undefined,
// email: '',
// type: null,
// title: '',
// description: '',
// city: '',
// state: '',
// price: null,
// favoritesForUser: [],
// draft: false,
// realEstateIncluded: false,
// leasedLocation: false,
// franchiseResale: false,
// salesRevenue: null,
// cashFlow: null,
// supportAndTraining: '',
// employees: null,
// established: null,
// internalListingNumber: null,
// reasonForSale: '',
// brokerLicencing: '',
// internals: '',
// created: null,
// updated: null,
// visits: null,
// lastVisit: null,
// latitude: null,
// longitude: null,
// listingsCategory: 'business',
// };
// }
export function createEmptyBusinessListingCriteria(): BusinessListingCriteria {
return {
start: 0,
@@ -153,6 +71,66 @@ export function createEmptyUserListingCriteria(): UserListingCriteria {
radius: null,
};
}
export function resetBusinessListingCriteria(criteria: BusinessListingCriteria) {
criteria.start = 0;
criteria.length = 0;
criteria.page = 0;
criteria.state = null;
criteria.city = null;
criteria.types = [];
criteria.prompt = '';
criteria.criteriaType = 'businessListings';
criteria.minPrice = null;
criteria.maxPrice = null;
criteria.minRevenue = null;
criteria.maxRevenue = null;
criteria.minCashFlow = null;
criteria.maxCashFlow = null;
criteria.minNumberEmployees = null;
criteria.maxNumberEmployees = null;
criteria.establishedSince = null;
criteria.establishedUntil = null;
criteria.realEstateChecked = false;
criteria.leasedLocation = false;
criteria.franchiseResale = false;
criteria.title = '';
criteria.brokerName = '';
criteria.searchType = 'exact';
criteria.radius = null;
}
export function resetCommercialPropertyListingCriteria(criteria: CommercialPropertyListingCriteria) {
criteria.start = 0;
criteria.length = 0;
criteria.page = 0;
criteria.state = null;
criteria.city = null;
criteria.types = [];
criteria.prompt = '';
criteria.criteriaType = 'commercialPropertyListings';
criteria.minPrice = null;
criteria.maxPrice = null;
criteria.title = '';
criteria.searchType = 'exact';
criteria.radius = null;
}
export function resetUserListingCriteria(criteria: UserListingCriteria) {
criteria.start = 0;
criteria.length = 0;
criteria.page = 0;
criteria.city = null;
criteria.types = [];
criteria.prompt = '';
criteria.criteriaType = 'brokerListings';
criteria.brokerName = '';
criteria.companyName = '';
criteria.counties = [];
criteria.state = '';
criteria.searchType = 'exact';
criteria.radius = null;
}
export function createMailInfo(user: User): MailInfo {
return {
sender: { name: `${user.firstname} ${user.lastname}`, email: user.email, phoneNumber: user.phoneNumber, state: user.companyLocation?.state, comments: null },
@@ -178,9 +156,7 @@ export function formatPhoneNumber(phone: string): string {
}
return phone;
}
// export const getSessionStorageHandler = function (path, value, previous, applyData) {
// sessionStorage.setItem(applyData, JSON.stringify(this));
// };
export const getSessionStorageHandler = function (criteriaType, path, value, previous, applyData) {
sessionStorage.setItem(`${criteriaType}_criteria`, JSON.stringify(this));
console.log('Zusätzlicher Parameter:', criteriaType);
@@ -191,19 +167,6 @@ export const getSessionStorageHandlerWrapper = param => {
};
};
export function getCriteriaStateObject(criteriaType: 'businessListings' | 'commercialPropertyListings' | 'brokerListings') {
let initialState;
if (criteriaType === 'businessListings') {
initialState = createEmptyBusinessListingCriteria();
} else if (criteriaType === 'commercialPropertyListings') {
initialState = createEmptyCommercialPropertyListingCriteria();
} else {
initialState = createEmptyUserListingCriteria();
}
const storedState = sessionStorage.getItem(`${criteriaType}`);
return storedState ? JSON.parse(storedState) : initialState;
}
export function routeListingWithState(router: Router, value: string, data: any) {
if (value === 'business') {
router.navigate(['createBusinessListing'], { state: { data } });
@@ -248,70 +211,6 @@ export function getDialogWidth(dimensions): string {
return dialogWidth;
}
import { initFlowbite } from 'flowbite';
import onChange from 'on-change';
import { Subject, concatMap, delay, of } from 'rxjs';
import { User } from '../../../../bizmatch-server/src/models/db.model';
import { environment } from '../../environments/environment';
const flowbiteQueue = new Subject<() => void>();
flowbiteQueue.pipe(concatMap(item => of(item).pipe(delay(100)))).subscribe(x => {
x();
});
export function Flowbite() {
return function (target: any) {
const originalOnInit = target.prototype.ngOnInit;
target.prototype.ngOnInit = function () {
if (originalOnInit) {
originalOnInit.apply(this);
}
initFlowbiteFix();
};
};
}
export function initFlowbiteFix() {
flowbiteQueue.next(() => {
const elements = Array.from(document.querySelectorAll('*'));
const flowbiteElements: Element[] = [];
const initializedElements = Array.from(document.querySelectorAll('[flowbite-initialized]'));
for (const element of elements) {
const attributes = Array.from(element.attributes);
for (const attribute of attributes) {
if (attribute.name.startsWith('data-') && !initializedElements.includes(element)) {
flowbiteElements.push(element);
break;
}
}
}
for (const element of flowbiteElements) {
element.setAttribute('flowbite-initialized', '');
}
initFlowbite();
for (const element of flowbiteElements) {
const attributes: { name: string; value: string }[] = Array.from(element.attributes);
const dataAttributes = attributes.filter(attribute => attribute.name.startsWith('data-'));
for (const attribute of dataAttributes) {
element.setAttribute(attribute.name.replace('data-', 'fb-'), attribute.value);
element.removeAttribute(attribute.name);
}
}
});
}
// export function arraysEqual(arr1: any[], arr2: any[]): boolean {
// if (arr1.length !== arr2.length) return false;
// for (let i = 0; i < arr1.length; i++) {
// if (arr1[i] !== arr2[i]) return false;
// }
// return true;
// }
export function compareObjects<T extends object>(obj1: T, obj2: T, ignoreProperties: (keyof T)[] = []): number {
let differences = 0;
const keys = Object.keys(obj1) as Array<keyof T>;
@@ -380,10 +279,29 @@ function arraysEqual(arr1: any[] | null | undefined, arr2: any[] | null | undefi
}
return true;
}
export function assignProperties(target, source) {
for (let key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
return target;
}
// -----------------------------
// Criteria Proxy
// -----------------------------
export function getCriteriaStateObject(criteriaType: 'businessListings' | 'commercialPropertyListings' | 'brokerListings') {
let initialState;
if (criteriaType === 'businessListings') {
initialState = createEmptyBusinessListingCriteria();
} else if (criteriaType === 'commercialPropertyListings') {
initialState = createEmptyCommercialPropertyListingCriteria();
} else {
initialState = createEmptyUserListingCriteria();
}
const storedState = sessionStorage.getItem(`${criteriaType}`);
return storedState ? JSON.parse(storedState) : initialState;
}
export function getCriteriaProxy(path: string, component: any): BusinessListingCriteria | CommercialPropertyListingCriteria | UserListingCriteria {
if ('businessListings' === path) {
return createEnhancedProxy(getCriteriaStateObject('businessListings'), component);