create apiEnum components
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { TEnumApi } from '../models';
|
||||
|
||||
export const apiEnumTranslates = {
|
||||
goldKarat: '',
|
||||
userStatus: 'وضعیت کاربر',
|
||||
accountRole: 'نقش',
|
||||
accountStatus: 'وضعیت',
|
||||
posStatus: 'وضعیت',
|
||||
posRole: 'نقش',
|
||||
licenseType: 'نوع لایسنس',
|
||||
licenseStatus: 'وضعیت لایسنس',
|
||||
posType: 'نوع پایانه',
|
||||
userType: 'نوع کاربر',
|
||||
accountType: 'نوع کاربر',
|
||||
partnerRole: 'نقش',
|
||||
businessRole: 'نقش',
|
||||
providerRole: 'نقش',
|
||||
unitType: 'واحد اندازهگیری',
|
||||
goodPricingModel: 'مدل محاسبه',
|
||||
} as Record<TEnumApi, string>;
|
||||
@@ -0,0 +1,21 @@
|
||||
const baseUrl = '/api/v1/enums';
|
||||
|
||||
export const ENUMS_API_ROUTES = {
|
||||
goldKarat: `${baseUrl}/gold_karat`,
|
||||
userStatus: `${baseUrl}/user_status`,
|
||||
accountRole: `${baseUrl}/account_role`,
|
||||
accountStatus: `${baseUrl}/account_status`,
|
||||
posStatus: `${baseUrl}/pos_status`,
|
||||
posRole: `${baseUrl}/pos_role`,
|
||||
licenseType: `${baseUrl}/license_type`,
|
||||
licenseStatus: `${baseUrl}/license_status`,
|
||||
posType: `${baseUrl}/pos_type`,
|
||||
userType: `${baseUrl}/user_type`,
|
||||
accountType: `${baseUrl}/account_type`,
|
||||
partnerRole: `${baseUrl}/partner_role`,
|
||||
businessRole: `${baseUrl}/business_role`,
|
||||
providerRole: `${baseUrl}/provider_role`,
|
||||
tokenType: `${baseUrl}/token_type`,
|
||||
unitType: `${baseUrl}/unit_type`,
|
||||
goodPricingModel: `${baseUrl}/good_pricing_model`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiEnumTranslates';
|
||||
export * from './apiRoutes';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './io';
|
||||
export * from './types';
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export interface IApiEnumResponse {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { ENUMS_API_ROUTES } from '../constants/apiRoutes';
|
||||
|
||||
export type TEnumApi = keyof typeof ENUMS_API_ROUTES;
|
||||
@@ -0,0 +1,12 @@
|
||||
<uikit-field [label]="label()" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
|
||||
<p-select
|
||||
[loading]="loading()"
|
||||
[options]="items()"
|
||||
optionLabel="name"
|
||||
optionValue="value"
|
||||
[formControl]="control"
|
||||
[showClear]="showClear"
|
||||
[filter]="true"
|
||||
appendTo="body"
|
||||
/>
|
||||
</uikit-field>
|
||||
@@ -0,0 +1,31 @@
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, computed, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { Select } from 'primeng/select';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AbstractSelectComponent } from '../abstractClasses';
|
||||
import { apiEnumTranslates } from './constants';
|
||||
import { IApiEnumResponse, TEnumApi } from './models';
|
||||
import { EnumsService } from './services';
|
||||
|
||||
@Component({
|
||||
selector: 'app-enum-select',
|
||||
templateUrl: './select.component.html',
|
||||
imports: [UikitFieldComponent, Select, ReactiveFormsModule],
|
||||
})
|
||||
export class EnumSelectComponent extends AbstractSelectComponent<string, IApiEnumResponse[]> {
|
||||
@Input() type!: TEnumApi;
|
||||
@Input() customLabel?: string;
|
||||
|
||||
private readonly service = inject(EnumsService);
|
||||
|
||||
label = computed(() => this.customLabel ?? apiEnumTranslates[this.type]);
|
||||
|
||||
override getDataService(): Observable<IApiEnumResponse[]> {
|
||||
return this.service.getAll(this.type);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ENUMS_API_ROUTES } from './constants/apiRoutes';
|
||||
import { TEnumApi } from './models';
|
||||
import { IApiEnumResponse } from './models/io';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class EnumsService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = ENUMS_API_ROUTES;
|
||||
|
||||
getAll(type: TEnumApi): Observable<IApiEnumResponse[]> {
|
||||
return this.http.get<IApiEnumResponse[]>(this.apiRoutes[type]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user