refactoring
This commit is contained in:
@@ -4,9 +4,9 @@ import { UserProfileComponent } from './user-profile/user-profile.component';
|
||||
import { SettingsCurrencyComponent } from './settings/currency/currency.component';
|
||||
import { SettingsAccountCategoryComponent } from './settings/account/account.category.component';
|
||||
import { SettingsAccountComponent } from './settings/account/account.component';
|
||||
import { SettingsMotionCategoryComponent } from './settings/motion/motion.category.component';
|
||||
import { SettingsMotionComponent } from './settings/motion/motion.component';
|
||||
import { AccountListComponent as AccountComponent } from './accounts/account.list.component';
|
||||
import { SettingsItemCategoryComponent } from './settings/item/item.category.component';
|
||||
import { SettingsItemComponent } from './settings/item/item.component';
|
||||
import { AccountListComponent } from './accounts/account.list.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
@@ -31,16 +31,16 @@ const routes: Routes = [
|
||||
component: SettingsAccountComponent,
|
||||
},
|
||||
{
|
||||
path: 'settings/motion-categories',
|
||||
component: SettingsMotionCategoryComponent,
|
||||
path: 'settings/item-categories',
|
||||
component: SettingsItemCategoryComponent,
|
||||
},
|
||||
{
|
||||
path: 'settings/motions',
|
||||
component: SettingsMotionComponent,
|
||||
path: 'settings/items',
|
||||
component: SettingsItemComponent,
|
||||
},
|
||||
{
|
||||
path: 'account-category/:id',
|
||||
component: AccountComponent,
|
||||
component: AccountListComponent,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ import { SettingsAccountComponent } from './settings/account/account.component';
|
||||
import { SettingsAccountAddComponent } from './settings/account/add.account.component';
|
||||
import { SettingsAccountEditComponent } from './settings/account/edit.account.component';
|
||||
import { CurrencyService } from '../services/currency.service';
|
||||
import { MotionService } from '../services/motion.service';
|
||||
import { SettingsMotionCategoryComponent } from './settings/motion/motion.category.component';
|
||||
import { SettingsMotionComponent } from './settings/motion/motion.component';
|
||||
import { SettingsMotionEditComponent } from './settings/motion/edit.motion.component';
|
||||
import { ItemService } from '../services/item.service';
|
||||
import { SettingsItemCategoryComponent } from './settings/item/item.category.component';
|
||||
import { SettingsItemComponent } from './settings/item/item.component';
|
||||
import { SettingsItemEditComponent } from './settings/item/edit.item.component';
|
||||
import { AccountListComponent } from './accounts/account.list.component';
|
||||
import { AccountComponent } from './accounts/account.component';
|
||||
import { MotionComponent } from './accounts/motion.component';
|
||||
@@ -53,9 +53,9 @@ import { MotionComponent } from './accounts/motion.component';
|
||||
SettingsAccountAddComponent,
|
||||
SettingsAccountEditComponent,
|
||||
|
||||
SettingsMotionCategoryComponent,
|
||||
SettingsMotionComponent,
|
||||
SettingsMotionEditComponent,
|
||||
SettingsItemCategoryComponent,
|
||||
SettingsItemComponent,
|
||||
SettingsItemEditComponent,
|
||||
|
||||
AccountListComponent,
|
||||
AccountComponent,
|
||||
@@ -84,7 +84,7 @@ import { MotionComponent } from './accounts/motion.component';
|
||||
providers: [
|
||||
{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },
|
||||
CurrencyService,
|
||||
MotionService,
|
||||
ItemService,
|
||||
],
|
||||
})
|
||||
export class PagesModule {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
<div class="text-inside">
|
||||
<mat-form-field class="example-full-width">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput value={{motion.name}} formControlName="name" readonly>
|
||||
<input matInput value={{item.name}} formControlName="name" readonly>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
+15
-16
@@ -7,50 +7,49 @@ import { UntypedFormGroup } from '@angular/forms';
|
||||
import { Validators } from '@angular/forms';
|
||||
|
||||
// libs
|
||||
import Swal from 'sweetalert2';
|
||||
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
|
||||
// app
|
||||
import { ApiRoutes } from '../../../api-routes';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { AccountCategoryModel } from '../../../model/account.category.model';
|
||||
import { MotionModel } from '../../../model/motion.model';
|
||||
import { MotionService } from '../../../services/motion.service';
|
||||
import { ItemCategoryModel } from '../../../model/item.category.model';
|
||||
import { ItemModel } from '../../../model/item.model';
|
||||
import { ItemService } from '../../../services/item.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './edit.motion.component.html',
|
||||
styleUrls: ['./edit.motion.component.scss'],
|
||||
templateUrl: './edit.item.component.html',
|
||||
styleUrls: ['./edit.item.component.scss'],
|
||||
})
|
||||
export class SettingsMotionEditComponent {
|
||||
export class SettingsItemEditComponent {
|
||||
public editForm!: UntypedFormGroup;
|
||||
public errorMessage?: string;
|
||||
public categories?: AccountCategoryModel[];
|
||||
public categories?: ItemCategoryModel[];
|
||||
|
||||
constructor(
|
||||
private fb: UntypedFormBuilder,
|
||||
private httpClient: HttpClient,
|
||||
private dialogRef: MatDialogRef<SettingsMotionEditComponent>,
|
||||
private motionService: MotionService,
|
||||
@Inject(MAT_DIALOG_DATA) public motion: MotionModel
|
||||
private dialogRef: MatDialogRef<SettingsItemEditComponent>,
|
||||
private itemService: ItemService,
|
||||
@Inject(MAT_DIALOG_DATA) public item: ItemModel
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.editForm = this.fb.group({
|
||||
id: [
|
||||
this.motion.id,
|
||||
this.item.id,
|
||||
],
|
||||
name: [
|
||||
this.motion.name,
|
||||
this.item.name,
|
||||
[Validators.required],
|
||||
],
|
||||
category: [
|
||||
this.motion.categoryId,
|
||||
this.item.categoryId,
|
||||
[Validators.required],
|
||||
],
|
||||
});
|
||||
|
||||
this.motionService
|
||||
this.itemService
|
||||
.getCategories()
|
||||
.subscribe(x => this.categories = x);
|
||||
}
|
||||
@@ -63,7 +62,7 @@ export class SettingsMotionEditComponent {
|
||||
if (this.editForm.valid) {
|
||||
this.errorMessage = undefined;
|
||||
this.httpClient
|
||||
.put<MotionModel>(ApiRoutes.SettingsMotion.replace(':id', this.motion.id!), this.editForm.value)
|
||||
.put<ItemModel>(ApiRoutes.SettingsItem.replace(':id', this.item.id!), this.editForm.value)
|
||||
.subscribe(response => {
|
||||
this.dialogRef.close({ motion: response, refresh: true });
|
||||
}, error => {
|
||||
+14
-14
@@ -7,14 +7,14 @@ import Swal from 'sweetalert2';
|
||||
|
||||
// app
|
||||
import { ApiRoutes } from '../../../api-routes';
|
||||
import { MotionCategoryModel } from '../../../model/motion.category.model';
|
||||
import { ItemCategoryModel } from '../../../model/item.category.model';
|
||||
|
||||
@Component({
|
||||
templateUrl: './motion.category.component.html',
|
||||
styleUrls: ['./motion.category.component.scss'],
|
||||
templateUrl: './item.category.component.html',
|
||||
styleUrls: ['./item.category.component.scss'],
|
||||
})
|
||||
export class SettingsMotionCategoryComponent {
|
||||
public categories?: MotionCategoryModel[];
|
||||
export class SettingsItemCategoryComponent {
|
||||
public categories?: ItemCategoryModel[];
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
@@ -27,7 +27,7 @@ export class SettingsMotionCategoryComponent {
|
||||
|
||||
private load() {
|
||||
this.httpClient
|
||||
.get<MotionCategoryModel[]>(ApiRoutes.SettingsMotionCategories)
|
||||
.get<ItemCategoryModel[]>(ApiRoutes.SettingsItemCategories)
|
||||
.subscribe(data => {
|
||||
this.categories = data;
|
||||
});
|
||||
@@ -35,7 +35,7 @@ export class SettingsMotionCategoryComponent {
|
||||
|
||||
public add() {
|
||||
Swal.fire({
|
||||
title: 'Motion category name',
|
||||
title: 'Item category name',
|
||||
input: 'text',
|
||||
inputAttributes: {
|
||||
autocapitalize: 'off',
|
||||
@@ -45,7 +45,7 @@ export class SettingsMotionCategoryComponent {
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (name) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.post(ApiRoutes.SettingsMotionCategories, { name: name })
|
||||
this.httpClient.post(ApiRoutes.SettingsItemCategories, { name: name })
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
@@ -63,9 +63,9 @@ export class SettingsMotionCategoryComponent {
|
||||
});
|
||||
}
|
||||
|
||||
public edit(category: MotionCategoryModel) {
|
||||
public edit(category: ItemCategoryModel) {
|
||||
Swal.fire({
|
||||
title: 'Motion category name',
|
||||
title: 'Item category name',
|
||||
input: 'text',
|
||||
inputValue: category.name,
|
||||
inputAttributes: {
|
||||
@@ -76,7 +76,7 @@ export class SettingsMotionCategoryComponent {
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (name) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.put(ApiRoutes.SettingsMotionCategory.replace(':id', category.id!), { name: name })
|
||||
this.httpClient.put(ApiRoutes.SettingsItemCategory.replace(':id', category.id!), { name: name })
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
@@ -94,15 +94,15 @@ export class SettingsMotionCategoryComponent {
|
||||
});
|
||||
}
|
||||
|
||||
public remove(category: MotionCategoryModel) {
|
||||
public remove(category: ItemCategoryModel) {
|
||||
Swal.fire({
|
||||
title: 'Remove motion category ' + category.name,
|
||||
title: 'Remove item category ' + category.name,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Delete',
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (name) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.delete(ApiRoutes.SettingsMotionCategory.replace(':id', category.id!))
|
||||
this.httpClient.delete(ApiRoutes.SettingsItemCategory.replace(':id', category.id!))
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
<div class="content-block">
|
||||
<div class="block-header">
|
||||
<!-- breadcrumb -->
|
||||
<app-breadcrumb [title]="'Blank'" [items]="['Home','Settings']" [active_item]="'Motions'">
|
||||
<app-breadcrumb [title]="'Blank'" [items]="['Home','Settings']" [active_item]="'Items'">
|
||||
</app-breadcrumb>
|
||||
</div>
|
||||
<div class="row">
|
||||
@@ -35,7 +35,7 @@
|
||||
<div class="body table-responsive">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr *ngFor="let item of motions">
|
||||
<tr *ngFor="let item of items">
|
||||
<td>{{item.name}}</td>
|
||||
<td>
|
||||
<button class="btn-space" (click)="edit(item)" mat-raised-button color="primary">
|
||||
+21
-21
@@ -8,24 +8,24 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
// app
|
||||
import { ApiRoutes } from '../../../api-routes';
|
||||
import { SettingsMotionEditComponent } from './edit.motion.component';
|
||||
import { MotionService } from '../../../services/motion.service';
|
||||
import { MotionModel } from '../../../model/motion.model';
|
||||
import { MotionCategoryModel } from '../../../model/motion.category.model';
|
||||
import { SettingsItemEditComponent } from './edit.item.component';
|
||||
import { ItemService } from '../../../services/item.service';
|
||||
import { ItemModel } from '../../../model/item.model';
|
||||
import { ItemCategoryModel } from '../../../model/item.category.model';
|
||||
|
||||
@Component({
|
||||
templateUrl: './motion.component.html',
|
||||
styleUrls: ['./motion.component.scss'],
|
||||
templateUrl: './item.component.html',
|
||||
styleUrls: ['./item.component.scss'],
|
||||
})
|
||||
export class SettingsMotionComponent {
|
||||
public motions?: MotionModel[];
|
||||
public categories?: MotionCategoryModel[];
|
||||
public selectedCategory?: MotionCategoryModel;
|
||||
export class SettingsItemComponent {
|
||||
public items?: ItemModel[];
|
||||
public categories?: ItemCategoryModel[];
|
||||
public selectedCategory?: ItemCategoryModel;
|
||||
|
||||
constructor(
|
||||
private dialogModel: MatDialog,
|
||||
private httpClient: HttpClient,
|
||||
private motionService: MotionService,
|
||||
private itemService: ItemService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export class SettingsMotionComponent {
|
||||
}
|
||||
|
||||
private load(categoryId?: string) {
|
||||
this.motionService.getCategories()
|
||||
this.itemService.getCategories()
|
||||
.subscribe(data => {
|
||||
this.categories = data;
|
||||
var selected = data[0];
|
||||
@@ -49,19 +49,19 @@ export class SettingsMotionComponent {
|
||||
});
|
||||
}
|
||||
|
||||
public selectCategory(category: MotionCategoryModel) {
|
||||
public selectCategory(category: ItemCategoryModel) {
|
||||
this.selectedCategory = category;
|
||||
this.motionService.getMotions(category.id)
|
||||
this.itemService.getItems(category.id)
|
||||
.subscribe(data => {
|
||||
this.motions = data;
|
||||
this.items = data;
|
||||
});
|
||||
}
|
||||
|
||||
public edit(motion: MotionModel) {
|
||||
this.dialogModel.open(SettingsMotionEditComponent, {
|
||||
public edit(item: ItemModel) {
|
||||
this.dialogModel.open(SettingsItemEditComponent, {
|
||||
width: '640px',
|
||||
disableClose: true,
|
||||
data: motion,
|
||||
data: item,
|
||||
}).afterClosed().subscribe(x => {
|
||||
if (x && x.refresh) {
|
||||
console.log(x.motion.categoryId);
|
||||
@@ -70,15 +70,15 @@ export class SettingsMotionComponent {
|
||||
});
|
||||
}
|
||||
|
||||
public remove(category: MotionModel) {
|
||||
public remove(category: ItemModel) {
|
||||
Swal.fire({
|
||||
title: 'Remove motion ' + category.name,
|
||||
title: 'Remove item from ' + category.name,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Delete',
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (name) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.delete(ApiRoutes.SettingsMotionCategory.replace(':id', category.id!))
|
||||
this.httpClient.delete(ApiRoutes.SettingsItemCategory.replace(':id', category.id!))
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
Reference in New Issue
Block a user