refactor: extend base settings add class to edit
This commit is contained in:
@@ -5,7 +5,7 @@ import { ActionBtn } from '../action-btn/action-btn';
|
|||||||
import { TranslatePipe } from '@ngx-translate/core';
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
|
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
|
||||||
import { ChainSettings } from '../../services/chain-settings';
|
import { ChainSettings } from '../../services/chain-settings';
|
||||||
import { SettingsBaseAdd } from '../settings-base-add/settings-base-add';
|
import { SettingsBaseAddEdit } from '../settings-base-add-edit/settings-base-add-edit';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-chain-add',
|
selector: 'app-chain-add',
|
||||||
@@ -14,15 +14,17 @@ import { SettingsBaseAdd } from '../settings-base-add/settings-base-add';
|
|||||||
TranslatePipe,
|
TranslatePipe,
|
||||||
UpperfirstPipe,
|
UpperfirstPipe,
|
||||||
],
|
],
|
||||||
templateUrl: './../settings-base-add/settings-base-add.html',
|
templateUrl: './../settings-base-add-edit/settings-base-add-edit.html',
|
||||||
styleUrl: './../settings-base-add/settings-base-add.scss',
|
styleUrl: './../settings-base-add-edit/settings-base-add-edit.scss',
|
||||||
})
|
})
|
||||||
export class ChainAdd extends SettingsBaseAdd {
|
export class ChainAdd extends SettingsBaseAddEdit {
|
||||||
private readonly chainSettings = inject(ChainSettings);
|
private readonly chainSettings = inject(ChainSettings);
|
||||||
|
|
||||||
readonly form = new ChainFormGroup();
|
readonly form = new ChainFormGroup();
|
||||||
|
btnText = 'common.save';
|
||||||
title = 'settings.chain.new_chain';
|
title = 'settings.chain.new_chain';
|
||||||
|
|
||||||
async save() {
|
async submit() {
|
||||||
const name = this.form.controls.name.value;
|
const name = this.form.controls.name.value;
|
||||||
const img = this.form.controls.image.value;
|
const img = this.form.controls.image.value;
|
||||||
//TODO: the sqlite bridge can't handle null as param
|
//TODO: the sqlite bridge can't handle null as param
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<h3>{{title|translate|upperfirst}}</h3>
|
||||||
|
<ng-content></ng-content>
|
||||||
|
<app-action-btn
|
||||||
|
(click)="submit()"
|
||||||
|
(keydown)="submit()"
|
||||||
|
[disabled]="this.disabled"
|
||||||
|
class="top-auto"
|
||||||
|
text="{{btnText|translate|upperfirst}}"
|
||||||
|
/>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { FormGroup } from '@angular/forms';
|
||||||
|
|
||||||
|
export abstract class SettingsBaseAddEdit {
|
||||||
|
abstract btnText: string;
|
||||||
|
abstract title: string;
|
||||||
|
abstract form: FormGroup;
|
||||||
|
|
||||||
|
protected abstract submit(): Promise<void>
|
||||||
|
|
||||||
|
get disabled() {
|
||||||
|
return this.form.invalid || this.form.pristine;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<h3>{{title|translate|upperfirst}}</h3>
|
|
||||||
<ng-content></ng-content>
|
|
||||||
<app-action-btn
|
|
||||||
(click)="save()"
|
|
||||||
[disabled]="this.form.invalid"
|
|
||||||
class="top-auto"
|
|
||||||
text="{{'common.save'|translate|upperfirst}}"
|
|
||||||
/>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { FormGroup } from '@angular/forms';
|
|
||||||
|
|
||||||
export abstract class SettingsBaseAdd {
|
|
||||||
abstract title: string;
|
|
||||||
abstract form: FormGroup;
|
|
||||||
|
|
||||||
protected abstract save(): Promise<void>
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user