mirror of
https://github.com/FJurmanovic/wallet-web.git
synced 2026-02-06 06:08:10 +00:00
wallet edit
This commit is contained in:
@@ -9,6 +9,7 @@ class BaseElement extends HTMLElement {
|
|||||||
private _appMain: AppMainElement;
|
private _appMain: AppMainElement;
|
||||||
public loader: Loader;
|
public loader: Loader;
|
||||||
public elementDisconnectCallbacks: Array<Function> = [];
|
public elementDisconnectCallbacks: Array<Function> = [];
|
||||||
|
public initialized: boolean = false;
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.connectedCallback = this.connectedCallback.bind(this);
|
this.connectedCallback = this.connectedCallback.bind(this);
|
||||||
@@ -86,6 +87,7 @@ class BaseElement extends HTMLElement {
|
|||||||
this.bindEvents('data-action');
|
this.bindEvents('data-action');
|
||||||
this.bindEvents('app-action');
|
this.bindEvents('app-action');
|
||||||
this.updateCallback();
|
this.updateCallback();
|
||||||
|
this.initialized = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class AppLinkElement extends BaseComponentElement {
|
|||||||
@target main: Element;
|
@target main: Element;
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
this.attributeChangedCallback = this.attributeChangedCallback.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
elementConnected = (): void => {
|
elementConnected = (): void => {
|
||||||
@@ -34,6 +35,12 @@ class AppLinkElement extends BaseComponentElement {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
attributeChangedCallback(changed) {
|
||||||
|
if(this.initialized && changed == 'data-title') {
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goTo = (e: Event): void => {
|
goTo = (e: Event): void => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!isTrue(this.goBack) && this.to) {
|
if (!isTrue(this.goBack) && this.to) {
|
||||||
@@ -46,7 +53,8 @@ class AppLinkElement extends BaseComponentElement {
|
|||||||
|
|
||||||
get disabled(): boolean {
|
get disabled(): boolean {
|
||||||
if (isTrue(this.goBack)) {
|
if (isTrue(this.goBack)) {
|
||||||
return this.routerService.emptyState;
|
console.log(this.routerService)
|
||||||
|
return this.routerService?.emptyState;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class AppMenuElement extends BaseComponentElement {
|
|||||||
setWallets = (wallets: Array<any>, totalWallets: number): void => {
|
setWallets = (wallets: Array<any>, totalWallets: number): void => {
|
||||||
this.walletData = wallets;
|
this.walletData = wallets;
|
||||||
this.totalWallets = totalWallets;
|
this.totalWallets = totalWallets;
|
||||||
|
console.log(wallets)
|
||||||
this.update();
|
this.update();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -99,13 +100,15 @@ class AppMenuElement extends BaseComponentElement {
|
|||||||
render = (): TemplateResult => {
|
render = (): TemplateResult => {
|
||||||
const { isAuth, totalWallets, walletData } = this;
|
const { isAuth, totalWallets, walletData } = this;
|
||||||
|
|
||||||
|
console.log(walletData)
|
||||||
|
|
||||||
const regularMenu = (path: string, title: string, action?: string, className?: string): TemplateResult => {
|
const regularMenu = (path: string, title: string, action?: string, className?: string): TemplateResult => {
|
||||||
if (action) {
|
if (action) {
|
||||||
return html`
|
return html`
|
||||||
<menu-item class="${className || ''}" data-path="${path}" data-customaction="${action}">${title}</menu-item>
|
<menu-item class="${className || ''}" data-path="${path}" data-customaction="${action}" data-title="${title}"></menu-item>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
return html`<menu-item class="${className || ''}" data-path="${path}">${title}</menu-item>`;
|
return html`<menu-item class="${className || ''}" data-path="${path}" data-title="${title}"></menu-item>`;
|
||||||
};
|
};
|
||||||
const menuButton = (title: string, action?: string): TemplateResult => {
|
const menuButton = (title: string, action?: string): TemplateResult => {
|
||||||
return html` <div class="menu-item --retract" data-target="menu-item.itemEl">
|
return html` <div class="menu-item --retract" data-target="menu-item.itemEl">
|
||||||
@@ -128,6 +131,7 @@ class AppMenuElement extends BaseComponentElement {
|
|||||||
};
|
};
|
||||||
const renderWallets = (wallets: Array<any>) => {
|
const renderWallets = (wallets: Array<any>) => {
|
||||||
if (isAuth && totalWallets > 0) {
|
if (isAuth && totalWallets > 0) {
|
||||||
|
console.log(wallets[0].name)
|
||||||
return html`<div class="menu-item divider"></div>
|
return html`<div class="menu-item divider"></div>
|
||||||
${wallets.map((wallet) => regularMenu(`/wallet/${wallet.id}`, wallet.name, '', '--wallet'))}`;
|
${wallets.map((wallet) => regularMenu(`/wallet/${wallet.id}`, wallet.name, '', '--wallet'))}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ class AppPaginationElement extends BaseComponentElement {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defaultFetch = () => {
|
||||||
|
const options = {
|
||||||
|
rpp: this.rpp || 10,
|
||||||
|
page: 1
|
||||||
|
}
|
||||||
|
this.executeFetch(options);
|
||||||
|
}
|
||||||
|
|
||||||
setCustomRenderItems = (customRenderItems: () => TemplateResult) => {
|
setCustomRenderItems = (customRenderItems: () => TemplateResult) => {
|
||||||
this.customRenderItems = customRenderItems;
|
this.customRenderItems = customRenderItems;
|
||||||
this.update();
|
this.update();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class MenuItemElement extends BaseComponentElement {
|
|||||||
@target customButton: HTMLDivElement;
|
@target customButton: HTMLDivElement;
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
this.attributeChangedCallback = this.attributeChangedCallback.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public elementConnected = (): void => {
|
public elementConnected = (): void => {
|
||||||
@@ -30,8 +31,14 @@ class MenuItemElement extends BaseComponentElement {
|
|||||||
appMain?.removeEventListener('routechanged', this.update);
|
appMain?.removeEventListener('routechanged', this.update);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
attributeChangedCallback(changed) {
|
||||||
|
if(this.initialized && changed == 'data-title') {
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get current(): boolean {
|
get current(): boolean {
|
||||||
return this.routerService.comparePath(this.path);
|
return this.routerService?.comparePath(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
itemClick = (e) => {
|
itemClick = (e) => {
|
||||||
@@ -41,10 +48,10 @@ class MenuItemElement extends BaseComponentElement {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render = (): TemplateResult => {
|
render = (): TemplateResult => {
|
||||||
|
console.log(this.title)
|
||||||
return html`
|
return html`
|
||||||
<div class="${this.current ? 'selected ' : ''}menu-item" data-target="menu-item.itemEl">
|
<div class="${this.current ? 'selected ' : ''}menu-item" data-target="menu-item.itemEl">
|
||||||
<app-link class="${this.className}" data-to="${this.path}" data-custom-action="click:menu-item#itemClick"
|
<app-link class="${this.className}" data-to="${this.path}" data-custom-action="click:menu-item#itemClick" data-title="${this.title}"></app-link
|
||||||
>${this.title}</app-link
|
|
||||||
>
|
>
|
||||||
${this.customaction
|
${this.customaction
|
||||||
? html`<div data-target="menu-item.customButton" app-action="${this.customaction}">+</div>`
|
? html`<div data-target="menu-item.customButton" app-action="${this.customaction}">+</div>`
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ export * from './subscription-list/SubscriptionListElement';
|
|||||||
export * from './wallet-page/WalletPageElement';
|
export * from './wallet-page/WalletPageElement';
|
||||||
export * from './subscription-edit/SubscriptionEditElement';
|
export * from './subscription-edit/SubscriptionEditElement';
|
||||||
export * from './transaction-edit/TransactionEditElement';
|
export * from './transaction-edit/TransactionEditElement';
|
||||||
|
export * from './wallet-edit/WalletEditElement';
|
||||||
98
src/pages/wallet-edit/WalletEditElement.ts
Normal file
98
src/pages/wallet-edit/WalletEditElement.ts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import { targets, controller, target } from '@github/catalyst';
|
||||||
|
import { html, TemplateResult } from 'core/utils';
|
||||||
|
import { AuthService, WalletService } from 'services/';
|
||||||
|
import { AppDropdownElement, AppFormElement, InputFieldElement } from 'components/';
|
||||||
|
import { BasePageElement } from 'common/';
|
||||||
|
|
||||||
|
@controller
|
||||||
|
class WalletEditElement extends BasePageElement {
|
||||||
|
@targets inputs: Array<InputFieldElement>;
|
||||||
|
@target appForm: AppFormElement;
|
||||||
|
private walletService: WalletService;
|
||||||
|
authService: AuthService;
|
||||||
|
errorMessage: string;
|
||||||
|
walletData: any;
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
title: 'Edit Wallet',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
elementConnected = (): void => {
|
||||||
|
this.walletService = new WalletService(this.appMain?.appService);
|
||||||
|
this.authService = new AuthService(this.appMain.appService);
|
||||||
|
this.walletData = this.getData();
|
||||||
|
this.update();
|
||||||
|
this.getWallet(this.walletData?.id)
|
||||||
|
};
|
||||||
|
|
||||||
|
getWallet = async (id) => {
|
||||||
|
try {
|
||||||
|
const response = await this.walletService.get(id, null);
|
||||||
|
this.appForm.set(response);
|
||||||
|
} catch (err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get nameInput(): InputFieldElement {
|
||||||
|
for (const i in this.inputs) {
|
||||||
|
if (this.inputs[i]?.name == 'name') {
|
||||||
|
return this.inputs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get values(): Object {
|
||||||
|
const formObject: any = {};
|
||||||
|
this.inputs.forEach((input: InputFieldElement) => {
|
||||||
|
const inputType = input.inp;
|
||||||
|
formObject[input.name] = (inputType as HTMLInputElement).value;
|
||||||
|
});
|
||||||
|
return formObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
if (!this.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const response = await this.walletService.put(this.walletData?.id, this.values);
|
||||||
|
|
||||||
|
if (response?.id) {
|
||||||
|
this.appMain.triggerWalletUpdate();
|
||||||
|
this.appMain.pushToast('success', 'Wallet edited successfully!');
|
||||||
|
this.appMain.closeModal();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.errorMessage = 'Unable to edit wallet!';
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
validate(): boolean {
|
||||||
|
let _return = true;
|
||||||
|
this.inputs.forEach((input: InputFieldElement) => {
|
||||||
|
const valid: boolean = input.validate();
|
||||||
|
if (!valid) _return = false;
|
||||||
|
});
|
||||||
|
return _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
render = (): TemplateResult => {
|
||||||
|
return html`
|
||||||
|
<app-form data-custom="wallet-edit#onSubmit" data-has-cancel="true"
|
||||||
|
data-target="wallet-edit.appForm">
|
||||||
|
<input-field
|
||||||
|
data-type="text"
|
||||||
|
data-name="name"
|
||||||
|
data-label="Name"
|
||||||
|
data-targets="wallet-edit.inputs"
|
||||||
|
data-rules="required"
|
||||||
|
></input-field>
|
||||||
|
${this.errorMessage ? html`<div>${this.errorMessage}</div>` : html``}
|
||||||
|
</app-form>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { WalletEditElement };
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { targets, controller, target } from '@github/catalyst';
|
import { targets, controller, target } from '@github/catalyst';
|
||||||
import { html, TemplateResult } from 'core/utils';
|
import { html, TemplateResult } from 'core/utils';
|
||||||
import { AuthService, WalletService } from 'services/';
|
import { AuthService, WalletService } from 'services/';
|
||||||
import { AppPaginationElement, InputFieldElement } from 'components/';
|
import { AppMainElement, AppPaginationElement, InputFieldElement } from 'components/';
|
||||||
import { BasePageElement } from 'common/';
|
import { BasePageElement } from 'common/';
|
||||||
|
|
||||||
@controller
|
@controller
|
||||||
@@ -22,8 +22,17 @@ class WalletListElement extends BasePageElement {
|
|||||||
this.update();
|
this.update();
|
||||||
this.pagination?.setCustomRenderItem(this.renderItem);
|
this.pagination?.setCustomRenderItem(this.renderItem);
|
||||||
this.pagination?.setFetchFunc?.(this.getWallets, true)!;
|
this.pagination?.setFetchFunc?.(this.getWallets, true)!;
|
||||||
|
this.appMain.addEventListener('walletupdate', this.updateToken);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
elementDisconnected = (appMain: AppMainElement) => {
|
||||||
|
appMain?.removeEventListener('walletupdate', this.updateToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
get updateToken() {
|
||||||
|
return this.pagination?.defaultFetch;
|
||||||
|
}
|
||||||
|
|
||||||
getWallets = async (options): Promise<any> => {
|
getWallets = async (options): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
const response = await this.walletService.getAll(options);
|
const response = await this.walletService.getAll(options);
|
||||||
@@ -33,8 +42,22 @@ class WalletListElement extends BasePageElement {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
renderItem = (item): TemplateResult => html`<tr class="col-1">
|
walletEdit = (id) => {
|
||||||
<td><app-link class="wallet-item" data-to="/wallet/${item.id}">${item.name}</app-link></td>
|
const _modal = this.appMain.appModal;
|
||||||
|
if (_modal) {
|
||||||
|
this.appMain.closeModal();
|
||||||
|
} else {
|
||||||
|
this.appMain.createModal('wallet-edit', {
|
||||||
|
id: id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderItem = (item): TemplateResult => html`<tr class="col-wallet">
|
||||||
|
<td><app-link class="wallet-item" data-to="/wallet/${item.id}" data-title="${item.name}"></app-link></td>
|
||||||
|
<td>
|
||||||
|
<span><button @click=${() => this.walletEdit(item.id)}}>Edit</button></span>
|
||||||
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
|
||||||
render = (): TemplateResult => {
|
render = (): TemplateResult => {
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ app-pagination {
|
|||||||
&.col-transactions {
|
&.col-transactions {
|
||||||
grid-template-columns: 1fr 10fr 1fr 1fr;
|
grid-template-columns: 1fr 10fr 1fr 1fr;
|
||||||
}
|
}
|
||||||
|
&.col-wallet {
|
||||||
|
grid-template-columns: 9fr 1fr;
|
||||||
|
}
|
||||||
td,
|
td,
|
||||||
th {
|
th {
|
||||||
margin: 0 12px;
|
margin: 0 12px;
|
||||||
|
|||||||
Reference in New Issue
Block a user