irisa-helpers
v20.0.3
Published
rxjs pipe: changeRouteOnSuccess(router: Router, route: ActivatedRoute, path: string) handleErrors(n: UntypedFormGroup) recordErrors(n: BusinessError[]) streamErrors(n: Subject<BusinessError>) recordState(n: ObservableState)
Readme
rxjs pipe: changeRouteOnSuccess(router: Router, route: ActivatedRoute, path: string) handleErrors(n: UntypedFormGroup) recordErrors(n: BusinessError[]) streamErrors(n: Subject) recordState(n: ObservableState)
example of ObservableState loadState = new ObservableState(); this.loadState.Wait(); this.service.getDate() .pipe(this.recordState()) .subscrbe()
if(this.loadState.IsWait){ //do something }
functions:
toFormData(obj: any, form: FormData = null, namespace: string = null, ignoreList: boolean = false); toHttpParams(obj: any, params: HttpParams = null, namespace: string = null, ignoreList: boolean = false); makeAllControlsTouched(formGroup: UntypedFormGroup);
function wordifyfa(input: string | number, level: number = 0): string function wordifyRials(num: string | number): string function wordifyRialsInTomans(num: string | number): string function wordifyMomentApprox(date: Date | string | null, baseDate?: Date | string | null, suffixBefore: string = "پیش", suffixAfter: string = "بعد", doWordify: boolean = true): string function momentPrecise(date: Date | string | null, baseDate?: Date | string | null, suffixBefore: string = "پیش", suffixAfter: string = "بعد"): string function wordifyMomentPrecise(date: Date | string | null, baseDate?: Date | string | null, suffixBefore: string = "پیش", suffixAfter: string = "بعد", doWordify: boolean = true): string
import { Injectable } from '@angular/core'; import jwt_decode from 'jwt-decode'; import { CookieService } from 'ngx-cookie-service'; import { UserModel } from 'irisa-common-models';
@Injectable({ providedIn: 'root', }) export class SecurityHelper {
static access_token_key = 'access_token'; static refresh_token_key = 'refresh_token'; static exp_time_key = 'exp'; static role_claim_key = 'roles'; static username_claim_key = 'username'; static displayname_claim_key = 'displayname'; public domain: string;
saveAccessToken(token: string): void saveRefreshToken(token: string): void getAccessToken(): string getRefreshToken(): string clearAccessToken() isAuthenticated(): boolean getUserPayload() getUserRoles(): string[] getUserName(): string getDisplayName(): string getUserExpTime(): number getExpTime(token: string): number getPayload(token: string) isUserInRole(rolename: string): boolean hasUserAnyRoles(rolenames: string[]): boolean getUserInfo(): UserModel
}
EncryptionService: {
// ENCRYPTION USING CBC TRIPLE DES encryptUsingTripleDES(res: any, key: string, typeObj: boolean): string
// DECRYPTION USING CBC TRIPLE DES decryptUsingTripleDES(encrypted: string, key: string): string
// ENCRYPTION USING CBC DES encryptUsingDES(res: any, key: string, typeObj: boolean): string
// DECRYPTION USING CBC DES decryptUsingDES(encrypted: string, key: string): string
// ENCRYPTION USING AES encryptUsingAES(res: any, key: string, typeObj: boolean): string
// DECRYPTION USING AES decryptUsingAES(encrypted: string, key: string): string
}
getFileName(contentDisposition: string): string
SignalR service
import { Component, OnDestroy, OnInit } from '@angular/core'; import { glosses } from './glosses'; import { SignalRService } from 'irisa-helpers'; import { NotificationModel } from '../../../shared/models';
@Component({ selector: 'admin-notification', templateUrl: './notification.component.html', styleUrl: './notification.component.scss', standalone: false }) export class AdminNotificationComponent implements OnInit, OnDestroy {
newNotificationsCount = 0; notifications: NotificationModel[] = []; glosses = glosses;
constructor(private signalRService: SignalRService) { }
ngOnInit(): void { this.signalRService.startConnection('AdminNotification', 'Response') .then(() => { this.send('Init'); }) .catch(err => console.error('SignalR connect fail: ', err));
this.signalRService.getResponse('AdminNotification')?.subscribe(response => {
if (response) {
this.notifications = response as NotificationModel[];
this.newNotificationsCount = this.notifications?.filter(notification => notification.isNew).length;
}
});}
onSeenClick() { this.newNotificationsCount = 0; if (this.notifications?.filter(notification => notification.isNew).length) this.send('Seen'); }
send(message: string): void { this.signalRService.sendMessage('AdminNotification', 'Request', message) .catch(err => console.error('Send message error: ', err)); }
ngOnDestroy(): void { this.signalRService.stopConnection('AdminNotification'); }
}
