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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user