Skip to content

Commit

Permalink
add units
Browse files Browse the repository at this point in the history
  • Loading branch information
Lizvinskyi0202 committed Nov 5, 2024
1 parent 477f87d commit 5e0c8eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export class CastleComponent {
hrefFunc: (doc: Valoriumcastle) => {
return '/building/castle/' + doc._id;
}
},
{
icon: 'person',
hrefFunc: (doc: Valoriumcastle) => {
return '/unit/castle/' + doc._id;
}
}
],
};
Expand Down
14 changes: 12 additions & 2 deletions src/app/modules/valoriumunit/pages/unit/unit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { ValoriumunitService, Valoriumunit } from '../../services/valoriumunit.s
import { FormService } from 'src/app/core/modules/form/form.service';
import { TranslateService } from 'src/app/core/modules/translate/translate.service';
import { FormInterface } from 'src/app/core/modules/form/interfaces/form.interface';
import { Router } from '@angular/router';

@Component({
templateUrl: './unit.component.html',
styleUrls: ['./unit.component.scss'],
})
export class UnitComponent {
castle = this._router.url.includes('/unit/castle/')
? this._router.url.replace('/unit/castle/', '')
: '';
columns = ['name', 'description'];

form: FormInterface = this._form.getForm('unit', {
Expand Down Expand Up @@ -53,6 +57,9 @@ export class UnitComponent {
this._form.modal<Valoriumunit>(this.form, {
label: 'Create',
click: (created: unknown, close: () => void) => {
if (this.castle) {
(created as Valoriumunit).castle = this.castle;
}
this._sv.create(created as Valoriumunit);
close();
},
Expand Down Expand Up @@ -95,14 +102,17 @@ export class UnitComponent {
};

get rows(): Valoriumunit[] {
return this._sv.valoriumunits;
return this.castle
? this._sv.valoriumunitsByWorld[this.castle]
: this._sv.valoriumunits;
}

constructor(
private _sv: ValoriumunitService,
private _translate: TranslateService,
private _alert: AlertService,
private _form: FormService,
private _core: CoreService
private _core: CoreService,
private _router: Router
) {}
}
3 changes: 3 additions & 0 deletions src/app/modules/valoriumunit/pages/unit/unit.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [{
path: '',
component: UnitComponent
},{
path: 'castle/:castle_id',
component: UnitComponent
}];

@NgModule({
Expand Down
20 changes: 7 additions & 13 deletions src/app/modules/valoriumunit/services/valoriumunit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import {
export interface Valoriumunit extends CrudDocument {
name: string;
description: string;
castle: string;
}

@Injectable({
providedIn: 'root',
})
export class ValoriumunitService extends CrudService<Valoriumunit> {
valoriumunits: Valoriumunit[] = [];
valoriumunits: Valoriumunit[] = this.getDocs();

valoriumunitsByWorld: Record<string, Valoriumunit[]> = {};

constructor(
_http: HttpService,
_store: StoreService,
Expand All @@ -33,18 +37,8 @@ export class ValoriumunitService extends CrudService<Valoriumunit> {
_alert,
_core
);
this.get();

this.get().subscribe((valoriumunits: Valoriumunit[]) => this.valoriumunits.push(...valoriumunits));

_core.on('valoriumunit_create').subscribe((valoriumunit: Valoriumunit) => {
this.valoriumunits.push(valoriumunit);
});

_core.on('valoriumunit_delete').subscribe((valoriumunit: Valoriumunit) => {
this.valoriumunits.splice(
this.valoriumunits.findIndex((o) => o._id === valoriumunit._id),
1
);
});
this.filteredDocuments(this.valoriumunitsByWorld, 'castle');
}
}

0 comments on commit 5e0c8eb

Please sign in to comment.