init
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<p-dialog header="دستهبندی کالاها" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,35 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
|
||||
import { IGoodCategoriesResponse, IGoodCategoryRequest } from '../../models';
|
||||
import { GuildGoodCategoriesService } from '../../services/goodCategories.service';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild-good-categories-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class GuildGoodCategoryFormComponent extends AbstractFormDialog<
|
||||
IGoodCategoryRequest,
|
||||
IGoodCategoriesResponse
|
||||
> {
|
||||
@Input() guildId!: string;
|
||||
@Input() categoryId?: string;
|
||||
|
||||
private service = inject(GuildGoodCategoriesService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
override submitForm(payload: IGoodCategoryRequest) {
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.guildId!, this.categoryId!, payload);
|
||||
}
|
||||
return this.service.create(this.guildId!, payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت دستهبندیهای کالا'"
|
||||
[addNewCtaLabel]="'افزودن دستهبندی جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="دستهبندی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن دستهبندی جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
[showEdit]="true"
|
||||
[fullHeight]="fullHeight"
|
||||
(onEdit)="onEditClick($event)"
|
||||
(onAdd)="openAddForm()"
|
||||
/>
|
||||
|
||||
<admin-guild-good-categories-form
|
||||
[(visible)]="visibleForm"
|
||||
[initialValues]="selectedItemForEdit() || undefined"
|
||||
[categoryId]="selectedItemForEdit()?.id"
|
||||
[guildId]="guildId"
|
||||
[editMode]="editMode()"
|
||||
(onSubmit)="refresh()"
|
||||
/>
|
||||
@@ -0,0 +1,38 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { IGoodCategoriesResponse } from '../../models';
|
||||
import { GuildGoodCategoriesService } from '../../services/goodCategories.service';
|
||||
import { GuildGoodCategoryFormComponent } from './form.component';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild-good-categories-list',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, GuildGoodCategoryFormComponent],
|
||||
})
|
||||
export class GuildGoodCategoriesListComponent extends AbstractList<IGoodCategoriesResponse> {
|
||||
@Input() guildId!: string;
|
||||
@Input() fullHeight?: boolean;
|
||||
@Input() header: IColumn[] = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'عنوان' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
service = inject(GuildGoodCategoriesService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = this.header;
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll(this.guildId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<p-dialog header="فرم صنف" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true" ()>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-input label="کد" [control]="form.controls.code" name="code" />
|
||||
|
||||
{{ editMode }}
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,68 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IGuildRequest, IGuildResponse } from '../models';
|
||||
import { GuildsService } from '../services/main.service';
|
||||
|
||||
interface T {
|
||||
name: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class GuildFormComponent extends AbstractFormDialog<IGuildRequest, IGuildResponse> {
|
||||
@Input() guildId?: string;
|
||||
private service = inject(GuildsService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [
|
||||
{ value: this.initialValues?.name, disabled: this.submitLoading() },
|
||||
Validators.required,
|
||||
],
|
||||
code: [
|
||||
{ value: this.initialValues?.code, disabled: this.submitLoading() },
|
||||
Validators.required,
|
||||
],
|
||||
});
|
||||
|
||||
override ngOnChanges() {
|
||||
this.form.patchValue(this.initialValues ?? {});
|
||||
if (this.editMode && !this.guildId) {
|
||||
throw 'missing some arguments';
|
||||
}
|
||||
}
|
||||
|
||||
initForm() {
|
||||
// const form = this.fb.group({
|
||||
// name: [
|
||||
// { value: this.initialValues?.name, disabled: !this.initialValues?.name },
|
||||
// Validators.required,
|
||||
// ],
|
||||
// code: [
|
||||
// { value: this.initialValues?.code, disabled: this.submitLoading() },
|
||||
// Validators.required,
|
||||
// ],
|
||||
// });
|
||||
// this.code = form.get<string>('code')!.valueChanges.pipe(
|
||||
// tap((code) => {
|
||||
// const nameControl = form.get('name');
|
||||
// code === '1234' ? nameControl?.disable() : nameControl?.enable();
|
||||
// }),
|
||||
// );
|
||||
// return form;
|
||||
}
|
||||
|
||||
override submitForm(payload: IGuildRequest) {
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.guildId!, payload);
|
||||
}
|
||||
return this.service.create(payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<p-dialog header="فرم صنف" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,35 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
|
||||
import { IGuildGoodRequest, IGuildGoodsResponse } from '../../models';
|
||||
import { GuildGoodsService } from '../../services/goods.service';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild-good-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class GuildGoodCategoryFormComponent extends AbstractFormDialog<
|
||||
IGuildGoodRequest,
|
||||
IGuildGoodsResponse
|
||||
> {
|
||||
@Input() guildId!: string;
|
||||
@Input() categoryId?: string;
|
||||
|
||||
private service = inject(GuildGoodsService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
override submitForm(payload: IGuildGoodRequest) {
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.guildId, this.categoryId!, payload);
|
||||
}
|
||||
return this.service.create(this.guildId, payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<app-page-data-list
|
||||
pageTitle="مدیریت کالاها"
|
||||
[addNewCtaLabel]="'افزودن کالای جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="کالایی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن کالای جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
/>
|
||||
<admin-guild-good-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,40 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { IGuildGoodsResponse } from '../../models';
|
||||
import { GuildGoodsService } from '../../services/goods.service';
|
||||
import { GuildGoodCategoryFormComponent } from './form.component';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild-goods-list',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, GuildGoodCategoryFormComponent],
|
||||
})
|
||||
export class GuildGoodsListComponent extends AbstractList<IGuildGoodsResponse> {
|
||||
@Input() guildId!: string;
|
||||
@Input() fullHeight?: boolean;
|
||||
@Input() header: IColumn[] = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'عنوان' },
|
||||
{ field: 'sku', header: 'شناسهی عمومی' },
|
||||
{ field: 'category', header: 'دستهبندی', type: 'nested', nestedPath: 'name' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
service = inject(GuildGoodsService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = this.header;
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll(this.guildId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = (guildId: string) => `/api/v1/admin/guilds/${guildId}/good_categories`;
|
||||
|
||||
export const GUILD_GOOD_CATEGORIES_API_ROUTES = {
|
||||
list: (guildId: string) => `${baseUrl(guildId)}`,
|
||||
single: (guildId: string, id: string) => `${baseUrl(guildId)}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = (guildId: string) => `/api/v1/admin/guilds/${guildId}/goods`;
|
||||
|
||||
export const GUILD_GOODS_API_ROUTES = {
|
||||
list: (guildId: string) => `${baseUrl(guildId)}`,
|
||||
single: (guildId: string, id: string) => `${baseUrl(guildId)}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/guilds';
|
||||
|
||||
export const GUILDS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,26 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TGuildGoodCategoriesRouteNames = 'goodCategories';
|
||||
|
||||
export const guildGoodCategoriesNamedRoutes: NamedRoutes<TGuildGoodCategoriesRouteNames> = {
|
||||
goodCategories: {
|
||||
path: 'good_categories',
|
||||
loadComponent: () =>
|
||||
import('../../views/categories/list.component').then((m) => m.GuildGoodCategoriesComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'دستهبندیهای کالا',
|
||||
},
|
||||
},
|
||||
// goodCategory: {
|
||||
// path: 'good_categories/:categoryId',
|
||||
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
|
||||
// // @ts-ignore
|
||||
// meta: {
|
||||
// title: 'دستهبندی کالا',
|
||||
// },
|
||||
// },
|
||||
};
|
||||
|
||||
export const GUILD_GOOD_CATEGORIES_ROUTES: Routes = Object.values(guildGoodCategoriesNamedRoutes);
|
||||
@@ -0,0 +1,26 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TGuildGoodsRouteNames = 'goods';
|
||||
|
||||
export const guildGoodsNamedRoutes: NamedRoutes<TGuildGoodsRouteNames> = {
|
||||
goods: {
|
||||
path: 'goods',
|
||||
loadComponent: () =>
|
||||
import('../../views/goods/list.component').then((m) => m.GuildGoodsComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'کالاها',
|
||||
},
|
||||
},
|
||||
// goodCategory: {
|
||||
// path: 'good_categories/:categoryId',
|
||||
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
|
||||
// // @ts-ignore
|
||||
// meta: {
|
||||
// title: 'دستهبندی کالا',
|
||||
// },
|
||||
// },
|
||||
};
|
||||
|
||||
export const GUILD_GOODS_ROUTES: Routes = Object.values(guildGoodsNamedRoutes);
|
||||
@@ -0,0 +1,51 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
import { GUILD_GOOD_CATEGORIES_ROUTES } from './goodCategories';
|
||||
import { GUILD_GOODS_ROUTES } from './goods';
|
||||
|
||||
export type TGuildsRouteNames = 'guilds' | 'guild';
|
||||
|
||||
export const guildsNamedRoutes: NamedRoutes<TGuildsRouteNames> = {
|
||||
guilds: {
|
||||
path: 'guilds',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.GuildsComponent),
|
||||
meta: {
|
||||
title: 'اصناف',
|
||||
pagePath: () => '/super_admin/guilds',
|
||||
},
|
||||
},
|
||||
guild: {
|
||||
path: 'guilds/:guildId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.GuildComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'صنف',
|
||||
pagePath: (guildId: string) => `/super_admin/guilds/${guildId}`,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const GUILDS_ROUTES: Routes = [
|
||||
guildsNamedRoutes.guilds,
|
||||
{
|
||||
path: 'guilds/:guildId',
|
||||
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.GuildComponent),
|
||||
},
|
||||
|
||||
...GUILD_GOOD_CATEGORIES_ROUTES,
|
||||
...GUILD_GOODS_ROUTES,
|
||||
// {
|
||||
// path: 'good_categories/:categoryId',
|
||||
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
|
||||
// // @ts-ignore
|
||||
// meta: {
|
||||
// title: 'دستهبندی کالا',
|
||||
// },
|
||||
// },
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
import ISummary from '@/core/models';
|
||||
|
||||
export interface IGuildGoodsRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
sku: string;
|
||||
category: ISummary;
|
||||
description?: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
export interface IGuildGoodsResponse extends IGuildGoodsRawResponse {}
|
||||
|
||||
export interface IGuildGoodRequest {
|
||||
name: string;
|
||||
sku: string;
|
||||
description?: string;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './goods_io';
|
||||
export * from './io';
|
||||
@@ -0,0 +1,23 @@
|
||||
export interface IGuildRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
code: string;
|
||||
created_at: string;
|
||||
}
|
||||
export interface IGuildResponse extends IGuildRawResponse {}
|
||||
|
||||
export interface IGuildRequest {
|
||||
name: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface IGoodCategoriesRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
}
|
||||
export interface IGoodCategoriesResponse extends IGoodCategoriesRawResponse {}
|
||||
|
||||
export interface IGoodCategoryRequest {
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GUILD_GOOD_CATEGORIES_API_ROUTES } from '../constants/apiRoutes/goodCategories';
|
||||
import {
|
||||
IGoodCategoriesRawResponse,
|
||||
IGoodCategoriesResponse,
|
||||
IGoodCategoryRequest,
|
||||
} from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GuildGoodCategoriesService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = GUILD_GOOD_CATEGORIES_API_ROUTES;
|
||||
|
||||
getAll(guildId: string): Observable<IPaginatedResponse<IGoodCategoriesResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IGoodCategoriesRawResponse>>(
|
||||
this.apiRoutes.list(guildId),
|
||||
);
|
||||
}
|
||||
getSingle(guildId: string, id: string): Observable<IGoodCategoriesResponse> {
|
||||
return this.http.get<IGoodCategoriesRawResponse>(this.apiRoutes.single(guildId, id));
|
||||
}
|
||||
|
||||
create(guildId: string, data: IGoodCategoryRequest): Observable<IGoodCategoriesResponse> {
|
||||
return this.http.post<IGoodCategoriesResponse>(this.apiRoutes.list(guildId), data);
|
||||
}
|
||||
|
||||
update(
|
||||
guildId: string,
|
||||
id: string,
|
||||
data: IGoodCategoryRequest,
|
||||
): Observable<IGoodCategoriesResponse> {
|
||||
return this.http.patch<IGoodCategoriesResponse>(this.apiRoutes.single(guildId, id), data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GUILD_GOODS_API_ROUTES } from '../constants/apiRoutes/goods';
|
||||
import { IGuildGoodRequest, IGuildGoodsRawResponse, IGuildGoodsResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GuildGoodsService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = GUILD_GOODS_API_ROUTES;
|
||||
|
||||
getAll(guildId: string): Observable<IPaginatedResponse<IGuildGoodsResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IGuildGoodsRawResponse>>(this.apiRoutes.list(guildId));
|
||||
}
|
||||
getSingle(guildId: string, id: string): Observable<IGuildGoodsResponse> {
|
||||
return this.http.get<IGuildGoodsRawResponse>(this.apiRoutes.single(guildId, id));
|
||||
}
|
||||
|
||||
create(guildId: string, data: IGuildGoodRequest): Observable<IGuildGoodsResponse> {
|
||||
return this.http.post<IGuildGoodsResponse>(this.apiRoutes.list(guildId), data);
|
||||
}
|
||||
|
||||
update(guildId: string, id: string, data: IGuildGoodRequest): Observable<IGuildGoodsResponse> {
|
||||
return this.http.patch<IGuildGoodsResponse>(this.apiRoutes.single(guildId, id), data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GUILDS_API_ROUTES } from '../constants';
|
||||
import { IGuildRawResponse, IGuildRequest, IGuildResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GuildsService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = GUILDS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IGuildResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IGuildRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(id: string): Observable<IGuildResponse> {
|
||||
return this.http.get<IGuildRawResponse>(this.apiRoutes.single(id));
|
||||
}
|
||||
|
||||
create(data: IGuildRequest): Observable<IGuildResponse> {
|
||||
return this.http.post<IGuildResponse>(this.apiRoutes.list(), data);
|
||||
}
|
||||
|
||||
update(id: string, data: IGuildRequest): Observable<IGuildResponse> {
|
||||
return this.http.patch<IGuildResponse>(this.apiRoutes.single(id), data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { EntityState, EntityStore } from '@/core/state';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { catchError, finalize, throwError } from 'rxjs';
|
||||
import { IGuildResponse } from '../models';
|
||||
import { GuildsService } from '../services/main.service';
|
||||
|
||||
interface GuildState extends EntityState<IGuildResponse> {}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GuildStore extends EntityStore<IGuildResponse, GuildState> {
|
||||
private readonly service = inject(GuildsService);
|
||||
constructor() {
|
||||
super({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
});
|
||||
}
|
||||
|
||||
getData(guildId: string) {
|
||||
this.patchState({ loading: true });
|
||||
this.service
|
||||
.getSingle(guildId)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.patchState({ loading: false });
|
||||
}),
|
||||
catchError(() => {
|
||||
this.patchState({
|
||||
error: '',
|
||||
});
|
||||
return throwError('');
|
||||
}),
|
||||
)
|
||||
.subscribe((entity) => {
|
||||
this.patchState({ entity });
|
||||
});
|
||||
}
|
||||
|
||||
override reset(): void {
|
||||
this.setState({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<admin-guild-good-categories-list [guildId]="guildId()" [fullHeight]="true" />
|
||||
@@ -0,0 +1,14 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { GuildGoodCategoriesListComponent } from '../../components/categories/list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild-good-categories',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [GuildGoodCategoriesListComponent],
|
||||
})
|
||||
export class GuildGoodCategoriesComponent {
|
||||
route = inject(ActivatedRoute);
|
||||
guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<admin-guild-goods-list [guildId]="guildId()" />
|
||||
@@ -0,0 +1,14 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { GuildGoodsListComponent } from '../../components/goods/list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild_goods',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [GuildGoodsListComponent],
|
||||
})
|
||||
export class GuildGoodsComponent {
|
||||
route = inject(ActivatedRoute);
|
||||
guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,15 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت اصناف'"
|
||||
[addNewCtaLabel]="'افزودن صنف جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="صنفی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن صنف جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
(onDetails)="toSinglePage($event)"
|
||||
/>
|
||||
<admin-guild-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,46 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { guildsNamedRoutes } from '../constants';
|
||||
import { IGuildResponse } from '../models';
|
||||
import { GuildsService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guilds',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, GuildFormComponent],
|
||||
})
|
||||
export class GuildsComponent extends AbstractList<IGuildResponse> {
|
||||
private readonly service = inject(GuildsService);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'عنوان' },
|
||||
{ field: 'code', header: 'کد' },
|
||||
{ field: 'businessActivitiesCount', header: 'تعداد فعالیتهای اقتصادی مرتبط' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
] as IColumn[];
|
||||
}
|
||||
|
||||
override getDataRequest(): void | Observable<IPaginatedResponse<IGuildResponse>> {
|
||||
return this.service.getAll();
|
||||
}
|
||||
|
||||
toSinglePage(guild: IGuildResponse) {
|
||||
this.router.navigateByUrl(guildsNamedRoutes.guild.meta.pagePath!(guild.id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<div class="flex flex-col gap-6">
|
||||
<app-card-data cardTitle="اطلاعات صنف" [editable]="true" [(editMode)]="editMode">
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="grid grid-cols-3 gap-4 items-center">
|
||||
<app-key-value label="عنوان صنف" [value]="guild()?.name" />
|
||||
<app-key-value label="کد صنف" [value]="guild()?.code" />
|
||||
</div>
|
||||
</div>
|
||||
</app-card-data>
|
||||
|
||||
<admin-guild-good-categories-list [guildId]="guildId()" />
|
||||
<admin-guild-goods-list [guildId]="guildId()" />
|
||||
|
||||
<admin-guild-form
|
||||
[(visible)]="editMode"
|
||||
[editMode]="true"
|
||||
[guildId]="guildId()"
|
||||
[initialValues]="guild() || undefined"
|
||||
(onSubmit)="getData()"
|
||||
/>
|
||||
</div>
|
||||
@@ -0,0 +1,37 @@
|
||||
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { GuildGoodCategoriesListComponent } from '../components/categories/list.component';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { GuildGoodsListComponent } from '../components/goods/list.component';
|
||||
import { GuildStore } from '../store/guild.store';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-guild',
|
||||
templateUrl: './single.component.html',
|
||||
imports: [
|
||||
AppCardComponent,
|
||||
KeyValueComponent,
|
||||
GuildGoodCategoriesListComponent,
|
||||
GuildGoodsListComponent,
|
||||
GuildFormComponent,
|
||||
],
|
||||
})
|
||||
export class GuildComponent {
|
||||
private readonly store = inject(GuildStore);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
|
||||
readonly guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
|
||||
editMode = signal<boolean>(false);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly guild = computed(() => this.store.entity());
|
||||
|
||||
getData() {
|
||||
this.store.getData(this.guildId());
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<p-dialog
|
||||
header="فرم کاربر"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { ILicenseRequest, ILicenseResponse } from '../models';
|
||||
import { LicensesService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'license-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class LicenseFormComponent extends AbstractFormDialog<ILicenseRequest, ILicenseResponse> {
|
||||
private service = inject(LicensesService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
override submitForm(payload: ILicenseRequest) {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/partners';
|
||||
|
||||
export const LICENSES_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TLicensesRouteNames = 'licenses' | 'license';
|
||||
|
||||
export const licensesNamedRoutes: NamedRoutes<TLicensesRouteNames> = {
|
||||
licenses: {
|
||||
path: 'licenses',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.LicensesComponent),
|
||||
meta: {
|
||||
title: 'لایسنسها',
|
||||
pagePath: () => '/super_admin/licenses',
|
||||
},
|
||||
},
|
||||
license: {
|
||||
path: 'licenses/:licenseId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.LicenseComponent),
|
||||
meta: {
|
||||
title: 'لایسنس',
|
||||
pagePath: () => '/super_admin/licenses/:licenseId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const LICENSES_ROUTES: Routes = Object.values(licensesNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface ILicenseRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
export interface ILicenseResponse extends ILicenseRawResponse {}
|
||||
|
||||
export interface ILicenseRequest {
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { LICENSES_API_ROUTES } from '../constants';
|
||||
import { ILicenseRawResponse, ILicenseRequest, ILicenseResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LicensesService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = LICENSES_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<ILicenseResponse>> {
|
||||
return this.http.get<IPaginatedResponse<ILicenseRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<ILicenseResponse> {
|
||||
return this.http.get<ILicenseRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: ILicenseRequest): Observable<ILicenseResponse> {
|
||||
return this.http.post<ILicenseResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: ILicenseRequest): Observable<ILicenseResponse> {
|
||||
return this.http.patch<ILicenseResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,18 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت لایسنسها'"
|
||||
[addNewCtaLabel]="'افزودن لایسنس جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="لایسنسی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن لایسنس جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
>
|
||||
<!-- <ng-template #role let-data>
|
||||
<catalog-role-tag [role]="data.role" />
|
||||
</ng-template> -->
|
||||
</app-page-data-list>
|
||||
<license-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,31 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { LicenseFormComponent } from '../components/form.component';
|
||||
import { ILicenseResponse } from '../models';
|
||||
import { LicensesService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-licenses',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, LicenseFormComponent],
|
||||
})
|
||||
export class LicensesComponent extends AbstractList<ILicenseResponse> {
|
||||
private readonly service = inject(LicensesService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class=""></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-license',
|
||||
templateUrl: './single.component.html',
|
||||
})
|
||||
export class LicenseComponent {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<p-dialog
|
||||
header="فرم کاربر"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-input label="کد" [control]="form.controls.code" name="code" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,32 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IPartnerRequest, IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'partner-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class GuildFormComponent extends AbstractFormDialog<IPartnerRequest, IPartnerResponse> {
|
||||
private service = inject(PartnersService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: this.fb.control<string>(this.initialValues?.name || '', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
code: this.fb.control<string>(this.initialValues?.code || '', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
});
|
||||
|
||||
override submitForm(payload: IPartnerRequest) {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/partners';
|
||||
|
||||
export const PARTNERS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TPartnersRouteNames = 'partners' | 'partner';
|
||||
|
||||
export const partnersNamedRoutes: NamedRoutes<TPartnersRouteNames> = {
|
||||
partners: {
|
||||
path: 'partners',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.PartnersComponent),
|
||||
meta: {
|
||||
title: 'کاربران',
|
||||
pagePath: () => '/super_admin/partners',
|
||||
},
|
||||
},
|
||||
partner: {
|
||||
path: 'partners/:partnerId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.PartnerComponent),
|
||||
meta: {
|
||||
title: 'کاربر',
|
||||
pagePath: () => '/super_admin/partners/:partnerId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const PARTNERS_ROUTES: Routes = Object.values(partnersNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface IPartnerRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
code: string;
|
||||
}
|
||||
export interface IPartnerResponse extends IPartnerRawResponse {}
|
||||
|
||||
export interface IPartnerRequest {
|
||||
name: string;
|
||||
code: string;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { PARTNERS_API_ROUTES } from '../constants';
|
||||
import { IPartnerRawResponse, IPartnerRequest, IPartnerResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PartnersService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = PARTNERS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IPartnerResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IPartnerRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<IPartnerResponse> {
|
||||
return this.http.get<IPartnerRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: IPartnerRequest): Observable<IPartnerResponse> {
|
||||
return this.http.post<IPartnerResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: IPartnerRequest): Observable<IPartnerResponse> {
|
||||
return this.http.patch<IPartnerResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<uikit-field [label]="label" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
|
||||
<p-select
|
||||
[loading]="loading()"
|
||||
[options]="items()"
|
||||
optionLabel="name"
|
||||
[optionValue]="selectOptionValue"
|
||||
placeholder="انتخاب شریک تجاری"
|
||||
[formControl]="control"
|
||||
[showClear]="showClear"
|
||||
[filter]="true"
|
||||
appendTo="body"
|
||||
>
|
||||
@if (canInsert) {
|
||||
<ng-template #footer>
|
||||
<div class="p-3">
|
||||
<p-button
|
||||
label="افزودن شریک تجاری"
|
||||
fluid
|
||||
severity="secondary"
|
||||
text
|
||||
size="small"
|
||||
icon="pi pi-plus"
|
||||
(onClick)="onOpenForm()"
|
||||
/>
|
||||
</div>
|
||||
</ng-template>
|
||||
}
|
||||
</p-select>
|
||||
<partner-form [(visible)]="isOpenFormDialog" (onSubmit)="refresh()" />
|
||||
</uikit-field>
|
||||
@@ -0,0 +1,32 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { AbstractSelectComponent } from '@/shared/abstractClasses';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { Button } from 'primeng/button';
|
||||
import { Select } from 'primeng/select';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-partner-select',
|
||||
templateUrl: './select.component.html',
|
||||
imports: [UikitFieldComponent, Select, Button, ReactiveFormsModule, GuildFormComponent],
|
||||
})
|
||||
export class InventoryBankAccountSelectComponent extends AbstractSelectComponent<
|
||||
IPartnerResponse,
|
||||
IPaginatedResponse<IPartnerResponse>
|
||||
> {
|
||||
@Input() override showClear: boolean = false;
|
||||
@Input() label: string = '';
|
||||
private readonly service = inject(PartnersService);
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
getDataService() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,18 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت کاربران'"
|
||||
[addNewCtaLabel]="'افزودن کاربر جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="کاربری یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
>
|
||||
<!-- <ng-template #role let-data>
|
||||
<catalog-role-tag [role]="data.role" />
|
||||
</ng-template> -->
|
||||
</app-page-data-list>
|
||||
<partner-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,33 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-users',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, GuildFormComponent],
|
||||
})
|
||||
export class PartnersComponent extends AbstractList<IPartnerResponse> {
|
||||
private readonly service = inject(PartnersService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'نام' },
|
||||
{ field: 'code', header: 'کد' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class=""></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
templateUrl: './single.component.html',
|
||||
})
|
||||
export class PartnerComponent {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<p-dialog
|
||||
header="فرم کاربر"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IProviderRequest, IProviderResponse } from '../models';
|
||||
import { ProvidersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'provider-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class GuildFormComponent extends AbstractFormDialog<IProviderRequest, IProviderResponse> {
|
||||
private service = inject(ProvidersService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
override submitForm(payload: IProviderRequest) {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/providers';
|
||||
|
||||
export const PROVIDERS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TProvidersRouteNames = 'providers' | 'provider';
|
||||
|
||||
export const providersNamedRoutes: NamedRoutes<TProvidersRouteNames> = {
|
||||
providers: {
|
||||
path: 'providers',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.PartnersComponent),
|
||||
meta: {
|
||||
title: 'ارایهدهندگان',
|
||||
pagePath: () => '/super_admin/providers',
|
||||
},
|
||||
},
|
||||
provider: {
|
||||
path: 'providers/:providerId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.ProviderComponent),
|
||||
meta: {
|
||||
title: 'ارایهدهنده',
|
||||
pagePath: () => '/super_admin/providers/:providerId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const PROVIDERS_ROUTES: Routes = Object.values(providersNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface IProviderRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
export interface IProviderResponse extends IProviderRawResponse {}
|
||||
|
||||
export interface IProviderRequest {
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { PROVIDERS_API_ROUTES } from '../constants';
|
||||
import { IProviderRawResponse, IProviderRequest, IProviderResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ProvidersService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = PROVIDERS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IProviderResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IProviderRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<IProviderResponse> {
|
||||
return this.http.get<IProviderRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: IProviderRequest): Observable<IProviderResponse> {
|
||||
return this.http.post<IProviderResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: IProviderRequest): Observable<IProviderResponse> {
|
||||
return this.http.patch<IProviderResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<uikit-field [label]="label" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
|
||||
<p-select
|
||||
[loading]="loading()"
|
||||
[options]="items()"
|
||||
optionLabel="name"
|
||||
[optionValue]="selectOptionValue"
|
||||
placeholder="انتخاب ارایهدهنده"
|
||||
[formControl]="control"
|
||||
[showClear]="showClear"
|
||||
[filter]="true"
|
||||
appendTo="body"
|
||||
>
|
||||
@if (canInsert) {
|
||||
<ng-template #footer>
|
||||
<div class="p-3">
|
||||
<p-button
|
||||
label="افزودن ارایهدهنده"
|
||||
fluid
|
||||
severity="secondary"
|
||||
text
|
||||
size="small"
|
||||
icon="pi pi-plus"
|
||||
(onClick)="onOpenForm()"
|
||||
/>
|
||||
</div>
|
||||
</ng-template>
|
||||
}
|
||||
</p-select>
|
||||
<provider-form [(visible)]="isOpenFormDialog" (onSubmit)="refresh()" />
|
||||
</uikit-field>
|
||||
@@ -0,0 +1,32 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { AbstractSelectComponent } from '@/shared/abstractClasses';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { Button } from 'primeng/button';
|
||||
import { Select } from 'primeng/select';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { IProviderResponse } from '../models';
|
||||
import { ProvidersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-provider-select',
|
||||
templateUrl: './select.component.html',
|
||||
imports: [UikitFieldComponent, Select, Button, ReactiveFormsModule, GuildFormComponent],
|
||||
})
|
||||
export class InventoryBankAccountSelectComponent extends AbstractSelectComponent<
|
||||
IProviderResponse,
|
||||
IPaginatedResponse<IProviderResponse>
|
||||
> {
|
||||
@Input() override showClear: boolean = false;
|
||||
@Input() label: string = '';
|
||||
private readonly service = inject(ProvidersService);
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
getDataService() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,18 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت کاربران'"
|
||||
[addNewCtaLabel]="'افزودن کاربر جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="کاربری یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
>
|
||||
<!-- <ng-template #role let-data>
|
||||
<catalog-role-tag [role]="data.role" />
|
||||
</ng-template> -->
|
||||
</app-page-data-list>
|
||||
<provider-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,32 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { IProviderResponse } from '../models';
|
||||
import { ProvidersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-users',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, GuildFormComponent],
|
||||
})
|
||||
export class PartnersComponent extends AbstractList<IProviderResponse> {
|
||||
private readonly service = inject(ProvidersService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'نام' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class=""></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-provider',
|
||||
templateUrl: './single.component.html',
|
||||
})
|
||||
export class ProviderComponent {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Route } from '@angular/router';
|
||||
import { GUILDS_ROUTES } from './guilds/constants';
|
||||
import { LICENSES_ROUTES } from './licenses/constants';
|
||||
import { PARTNERS_ROUTES } from './partners/constants';
|
||||
import { PROVIDERS_ROUTES } from './providers/constants';
|
||||
import { USERS_ROUTES } from './users/constants';
|
||||
|
||||
export const SUPER_ADMIN_ROUTES = {
|
||||
path: 'super_admin',
|
||||
component: undefined,
|
||||
children: [
|
||||
...USERS_ROUTES,
|
||||
...GUILDS_ROUTES,
|
||||
...PARTNERS_ROUTES,
|
||||
...PROVIDERS_ROUTES,
|
||||
...LICENSES_ROUTES,
|
||||
],
|
||||
} as Route;
|
||||
@@ -0,0 +1,44 @@
|
||||
<p-dialog
|
||||
header="فرم کاربر"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="نام" [control]="form.controls.firstName" name="firstName" />
|
||||
<app-input label="نام خانوادگی" [control]="form.controls.lastName" name="lastName" />
|
||||
<app-input label="شماره موبایل" [control]="form.controls.mobileNumber" name="mobileNumber" type="mobile" />
|
||||
<!-- <catalog-roles-select [control]="form.controls.roleId" /> -->
|
||||
<uikit-field label="رمز عبور" class="" [control]="form.get('password')">
|
||||
<p-password
|
||||
id="password1"
|
||||
name="password"
|
||||
formControlName="password"
|
||||
autocomplete="password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.get('password')?.touched && form.get('password')?.invalid"
|
||||
/>
|
||||
<span class="text-xs mt-2 text-muted-color">
|
||||
رمز باید حداقل ۸ کاراکتر بوده و شامل حداقل یک حرف بزرگ، یک حرف کوچک، یک عدد و یک کاراکتر ویژه باشد.
|
||||
</span>
|
||||
</uikit-field>
|
||||
|
||||
<uikit-field label="تکرار رمز عبور" class="" [control]="form.get('confirmPassword')">
|
||||
<p-password
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
formControlName="confirmPassword"
|
||||
autocomplete="new-password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.get('confirmPassword')?.touched && form.get('confirmPassword')?.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,101 @@
|
||||
import { ToastService } from '@/core/services/toast.service';
|
||||
import { mobileValidator, MustMatch, password } from '@/core/validators';
|
||||
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { Password } from 'primeng/password';
|
||||
import { IUserRequest, IUserResponse } from '../models';
|
||||
import { UsersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'user-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Dialog,
|
||||
InputComponent,
|
||||
FormFooterActionsComponent,
|
||||
// CatalogRolesComponent,
|
||||
UikitFieldComponent,
|
||||
Password,
|
||||
],
|
||||
})
|
||||
export class UserFormComponent {
|
||||
@Input() initialValues?: IUserResponse;
|
||||
|
||||
@Input()
|
||||
set visible(v: boolean) {
|
||||
this.visibleSignal.set(!!v);
|
||||
}
|
||||
get visible() {
|
||||
return this.visibleSignal();
|
||||
}
|
||||
private visibleSignal = signal(false);
|
||||
|
||||
@Output() visibleChange = new EventEmitter<boolean>();
|
||||
@Output() onSubmit = new EventEmitter<IUserResponse>();
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
constructor(
|
||||
private service: UsersService,
|
||||
private toastService: ToastService,
|
||||
) {
|
||||
// effect(() => {
|
||||
// const v = this.visibleSignal();
|
||||
// // this.visibleChange.emit(v);
|
||||
// if (!v) this.form.reset();
|
||||
// });
|
||||
}
|
||||
|
||||
form = this.fb.group(
|
||||
{
|
||||
firstName: [this.initialValues?.firstName || '', [Validators.required]],
|
||||
lastName: [this.initialValues?.lastName || '', [Validators.required]],
|
||||
mobileNumber: [
|
||||
this.initialValues?.mobileNumber || '',
|
||||
[Validators.required, mobileValidator()],
|
||||
],
|
||||
roleId: [this.initialValues?.role.id || null, [Validators.required]],
|
||||
password: ['', [Validators.required, password()]],
|
||||
confirmPassword: ['', [Validators.required]],
|
||||
},
|
||||
{
|
||||
validators: [MustMatch('password', 'confirmPassword')],
|
||||
},
|
||||
);
|
||||
|
||||
submitLoading = signal(false);
|
||||
|
||||
submit() {
|
||||
this.form.markAllAsTouched();
|
||||
if (this.form.valid) {
|
||||
this.form.disable();
|
||||
this.submitLoading.set(true);
|
||||
const { confirmPassword, ...rest } = this.form.value;
|
||||
this.service.create(rest as IUserRequest).subscribe({
|
||||
next: (res) => {
|
||||
this.toastService.success({
|
||||
text: `کاربر ${this.form.value.firstName} با موفقیت ایجاد شد`,
|
||||
});
|
||||
this.close();
|
||||
this.submitLoading.set(false);
|
||||
this.form.enable();
|
||||
this.form.reset();
|
||||
this.onSubmit.emit(res);
|
||||
},
|
||||
error: () => {
|
||||
this.submitLoading.set(false);
|
||||
this.form.enable();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this.visibleChange.emit(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/users';
|
||||
|
||||
export const USERS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (userId: string) => `${baseUrl}/${userId}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TUsersRouteNames = 'users' | 'user';
|
||||
|
||||
export const usersNamedRoutes: NamedRoutes<TUsersRouteNames> = {
|
||||
users: {
|
||||
path: 'users',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.UsersComponent),
|
||||
meta: {
|
||||
title: 'کاربران',
|
||||
pagePath: () => '/super_admin/users',
|
||||
},
|
||||
},
|
||||
user: {
|
||||
path: 'users/:userId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.UserComponent),
|
||||
meta: {
|
||||
title: 'کاربر',
|
||||
pagePath: () => '/super_admin/users/:userId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const USERS_ROUTES: Routes = Object.values(usersNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { IRoleResponse } from '@/shared/catalog/roles';
|
||||
|
||||
export interface IUserRawResponse {
|
||||
mobileNumber: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
id: number;
|
||||
role: IRoleResponse;
|
||||
}
|
||||
export interface IUserResponse extends IUserRawResponse {}
|
||||
|
||||
export interface IUserRequest {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
mobileNumber: string;
|
||||
roleId: number;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { USERS_API_ROUTES } from '../constants';
|
||||
import { IUserRawResponse, IUserRequest, IUserResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UsersService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = USERS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IUserResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IUserRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<IUserResponse> {
|
||||
return this.http.get<IUserRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: IUserRequest): Observable<IUserResponse> {
|
||||
return this.http.post<IUserResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: IUserRequest): Observable<IUserResponse> {
|
||||
return this.http.patch<IUserResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,18 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت کاربران'"
|
||||
[addNewCtaLabel]="'افزودن کاربر جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="کاربری یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
>
|
||||
<!-- <ng-template #role let-data>
|
||||
<catalog-role-tag [role]="data.role" />
|
||||
</ng-template> -->
|
||||
</app-page-data-list>
|
||||
<user-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,34 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { UserFormComponent } from '../components/form.component';
|
||||
import { IUserResponse } from '../models';
|
||||
import { UsersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-users',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, UserFormComponent],
|
||||
})
|
||||
export class UsersComponent extends AbstractList<IUserResponse> {
|
||||
private readonly service = inject(UsersService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'fullname', header: 'نام' },
|
||||
{ field: 'mobile_number', header: 'شماره موبایل' },
|
||||
{ field: 'national_code', header: 'کد ملی' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class=""></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
templateUrl: './single.component.html',
|
||||
})
|
||||
export class UserComponent {
|
||||
constructor() {}
|
||||
}
|
||||
Reference in New Issue
Block a user