This commit is contained in:
2024-05-15 17:35:04 -05:00
parent 474d7c63d5
commit f51a298227
39 changed files with 333 additions and 260 deletions

View File

@@ -1,32 +1,33 @@
import { Location } from '@angular/common';
import { Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { filter } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class HistoryService {
private history: string[] = [];
private previousUrl: string | undefined;
private currentUrl: string | undefined;
constructor(private router: Router) {
this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
this.history.push(event.urlAfterRedirects);
}
constructor(private router: Router, private location: Location) {
this.setupRouterListener();
}
private setupRouterListener(): void {
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
this.previousUrl = this.currentUrl;
this.currentUrl = event.urlAfterRedirects;
});
}
public getHistory(): string[] {
return this.history;
get canGoBack(): boolean {
return !!this.previousUrl;
}
public canGoBack(): boolean {
return this.history.length > 1;
}
public goBack(): void {
if (this.canGoBack()) {
this.history.pop();
this.router.navigateByUrl(this.history[this.history.length - 1]);
goBack(): void {
if (this.canGoBack) {
this.location.back();
}
}
}

View File

@@ -1,39 +1,38 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { lastValueFrom } from 'rxjs';
import { ImageType } from '../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ImageService {
private apiBaseUrl = environment.apiBaseUrl;
constructor(private http: HttpClient) { }
constructor(private http: HttpClient) {}
uploadImage(imageBlob: Blob,type:'uploadPropertyPicture'|'uploadCompanyLogo'|'uploadProfile',id:string) {
const uploadUrl = `${this.apiBaseUrl}/bizmatch/image/${type}/${id}`;
uploadImage(imageBlob: Blob, type: 'uploadPropertyPicture' | 'uploadCompanyLogo' | 'uploadProfile', imagePath: string) {
const uploadUrl = `${this.apiBaseUrl}/bizmatch/image/${type}/${imagePath}`;
const formData = new FormData();
formData.append('file', imageBlob, 'image.png');
return this.http.post(uploadUrl, formData,{
return this.http.post(uploadUrl, formData, {
// headers: this.headers,
//reportProgress: true,
observe: 'events',
observe: 'events',
});
}
async deleteUserImage(userid:string,type:ImageType,name?:string){
async deleteUserImage(userid: string, type: ImageType, name?: string) {
return await lastValueFrom(this.http.delete<[]>(`${this.apiBaseUrl}/bizmatch/image/${type.delete}${userid}`));
}
async deleteListingImage(listingid:string,name?:string){
async deleteListingImage(listingid: string, name?: string) {
return await lastValueFrom(this.http.delete<[]>(`${this.apiBaseUrl}/bizmatch/image/propertyPicture/${listingid}/${name}`));
}
async getProfileImagesForUsers(userids:string[]){
async getProfileImagesForUsers(userids: string[]) {
return await lastValueFrom(this.http.get<[]>(`${this.apiBaseUrl}/bizmatch/image/profileImages/${userids.join(',')}`));
}
async getCompanyLogosForUsers(userids:string[]){
async getCompanyLogosForUsers(userids: string[]) {
return await lastValueFrom(this.http.get<[]>(`${this.apiBaseUrl}/bizmatch/image/companyLogos/${userids.join(',')}`));
}
}

View File

@@ -4,7 +4,7 @@ import { jwtDecode } from 'jwt-decode';
import { Observable, distinctUntilChanged, filter, from, lastValueFrom, map } from 'rxjs';
import urlcat from 'urlcat';
import { User } from '../../../../bizmatch-server/src/models/db.model';
import { JwtToken, ListingCriteria, ResponseUsersArray } from '../../../../bizmatch-server/src/models/main.model';
import { JwtToken, KeycloakUser, ListingCriteria, ResponseUsersArray, StatesResult } from '../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../environments/environment';
import { KeycloakService } from './keycloak.service';
@@ -16,8 +16,8 @@ export class UserService {
// -----------------------------
// Keycloak services
// -----------------------------
private user$ = new Observable<User>();
private user: User;
private user$ = new Observable<KeycloakUser>();
private user: KeycloakUser;
public $isLoggedIn: Signal<boolean>;
constructor(public keycloak: KeycloakService, private http: HttpClient) {
this.user$ = from(this.keycloak.getToken()).pipe(
@@ -56,12 +56,12 @@ export class UserService {
this.user = this.map2User(token);
}
private map2User(jwt: string): User {
private map2User(jwt: string): KeycloakUser {
const token = jwtDecode<JwtToken>(jwt);
return {
id: token.user_id,
firstname: token.given_name,
lastname: token.family_name,
firstName: token.given_name,
lastName: token.family_name,
email: token.email,
};
}
@@ -69,10 +69,10 @@ export class UserService {
isLoggedIn(): boolean {
return this.$isLoggedIn();
}
getKeycloakUser(): User {
getKeycloakUser(): KeycloakUser {
return this.user;
}
getUserObservable(): Observable<User> {
getUserObservable(): Observable<KeycloakUser> {
return this.user$;
}
async getId(): Promise<string> {
@@ -119,4 +119,7 @@ export class UserService {
async search(criteria?: ListingCriteria): Promise<ResponseUsersArray> {
return await lastValueFrom(this.http.post<ResponseUsersArray>(`${this.apiBaseUrl}/bizmatch/user/search`, criteria));
}
async getAllStates(): Promise<any> {
return await lastValueFrom(this.http.get<StatesResult[]>(`${this.apiBaseUrl}/bizmatch/user/states/all`));
}
}