2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50:56 +00:00

feat: add link navigation

- getCreateRoute -> getFormRoute
- update formRoute listconfig
This commit is contained in:
18alantom 2023-03-03 17:50:16 +05:30
parent 7ed392654a
commit 539157d122
15 changed files with 50 additions and 53 deletions

View File

@ -87,7 +87,7 @@ export interface ColumnConfig {
export type ListViewColumn = string | ColumnConfig;
export interface ListViewSettings {
formRoute?: (doc: Doc) => RouteLocationRaw;
formRoute?: (name: string) => RouteLocationRaw;
columns?: ListViewColumn[];
}

View File

@ -112,7 +112,7 @@ export class Item extends Doc {
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/Item/${name}`,
formRoute: (name) => `/edit/Item/${name}`,
columns: ['name', 'unit', 'tax', 'rate'],
};
}

View File

@ -65,7 +65,7 @@ export class JournalEntry extends Transactional {
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/JournalEntry/${name}`,
formRoute: (name) => `/edit/JournalEntry/${name}`,
columns: [
'name',
{

View File

@ -617,7 +617,7 @@ export class Payment extends Transactional {
static getListViewSettings(fyo: Fyo): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/Payment/${name}`,
formRoute: (name) => `/edit/Payment/${name}`,
columns: ['name', getDocStatusListColumn(), 'party', 'date', 'amount'],
};
}

View File

@ -37,7 +37,7 @@ export class PurchaseInvoice extends Invoice {
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/PurchaseInvoice/${name}`,
formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
columns: [
'name',
getTransactionStatusColumn(),

View File

@ -37,7 +37,7 @@ export class SalesInvoice extends Invoice {
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/SalesInvoice/${name}`,
formRoute: (name) => `/edit/SalesInvoice/${name}`,
columns: [
'name',
getTransactionStatusColumn(),

View File

@ -8,7 +8,7 @@ export class PurchaseReceipt extends StockTransfer {
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/PurchaseReceipt/${name}`,
formRoute: (name) => `/edit/PurchaseReceipt/${name}`,
columns: [
'name',
getTransactionStatusColumn(),

View File

@ -8,7 +8,7 @@ export class Shipment extends StockTransfer {
static getListViewSettings(): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/Shipment/${name}`,
formRoute: (name) => `/edit/Shipment/${name}`,
columns: [
'name',
getTransactionStatusColumn(),

View File

@ -81,7 +81,7 @@ export class StockMovement extends Transfer {
static getListViewSettings(fyo: Fyo): ListViewSettings {
return {
formRoute: ({ name }) => `/edit/StockMovement/${name}`,
formRoute: (name) => `/edit/StockMovement/${name}`,
columns: [
'name',
getDocStatusListColumn(),

View File

@ -68,6 +68,7 @@ import { getOptionList } from 'fyo/utils';
import { FieldTypeEnum } from 'schemas/types';
import Dropdown from 'src/components/Dropdown.vue';
import { fuzzyMatch } from 'src/utils';
import { getFormRoute, routeTo } from 'src/utils/ui';
import Base from './Base.vue';
export default {
@ -138,7 +139,7 @@ export default {
},
},
methods: {
routeToLinkedDoc() {
async routeToLinkedDoc() {
let schemaName = this.df?.target;
const name = this.value;
@ -151,7 +152,8 @@ export default {
return;
}
console.log(`routing to: ${schemaName}.${name}`);
const route = getFormRoute(schemaName, name);
await routeTo(route);
},
setLinkValue(value) {
this.linkValue = value;

View File

@ -55,8 +55,7 @@
<script lang="ts">
import { Money } from 'pesa';
import { getCreateRoute } from 'src/router';
import { routeTo } from 'src/utils/ui';
import { getFormRoute, routeTo } from 'src/utils/ui';
import { defineComponent, PropType } from 'vue';
import Button from '../Button.vue';
import StatusBadge from '../StatusBadge.vue';
@ -90,7 +89,7 @@ export default defineComponent({
return 'Saved';
},
async openEntry(name: string) {
const route = getCreateRoute(this.linked.schemaName, name);
const route = getFormRoute(this.linked.schemaName, name);
await routeTo(route);
},
},

View File

@ -100,7 +100,7 @@ export default {
const doc = await this.fyo.doc.getDoc(this.schemaName, name);
if (this.listConfig.formRoute) {
return await routeTo(this.listConfig.formRoute(doc));
return await routeTo(this.listConfig.formRoute(name));
}
const { routeFilter } = getRouteData({ doc });
@ -137,7 +137,7 @@ export default {
};
if (this.listConfig.formRoute) {
path = this.listConfig.formRoute(doc);
path = this.listConfig.formRoute(doc.name);
}
if (typeof path === 'object') {

View File

@ -141,28 +141,6 @@ const routes: RouteRecordRaw[] = [
},
];
export function getCreateRoute(
schemaName: string,
name: string
): RouteLocationRaw {
if (
[
ModelNameEnum.SalesInvoice,
ModelNameEnum.PurchaseInvoice,
ModelNameEnum.JournalEntry,
ModelNameEnum.Shipment,
ModelNameEnum.PurchaseReceipt,
ModelNameEnum.StockMovement,
ModelNameEnum.Payment,
ModelNameEnum.Item,
].includes(schemaName as ModelNameEnum)
) {
return `/edit/${schemaName}/${name}`;
}
return `/list/${schemaName}?edit=1&schemaName=${schemaName}&name=${name}`;
}
const router = createRouter({ routes, history: createWebHistory() });
export default router;

View File

@ -4,13 +4,12 @@ import { groupBy } from 'lodash';
import { ModelNameEnum } from 'models/types';
import { reports } from 'reports';
import { OptionField } from 'schemas/types';
import { getCreateRoute } from 'src/router';
import { createFilters, routeFilters } from 'src/utils/filters';
import { GetAllOptions } from 'utils/db/types';
import { safeParseFloat } from 'utils/index';
import { RouteLocationRaw } from 'vue-router';
import { fuzzyMatch } from '.';
import { routeTo } from './ui';
import { getFormRoute, routeTo } from './ui';
export const searchGroups = ['Docs', 'List', 'Create', 'Report', 'Page'];
enum SearchGroupEnum {
@ -73,17 +72,6 @@ export function getGroupLabelMap() {
};
}
async function openQuickEditDoc(schemaName: string, fyo: Fyo) {
await routeTo(`/list/${schemaName}`);
const doc = await fyo.doc.getNewDoc(schemaName);
const { openQuickEdit } = await import('src/utils/ui');
await openQuickEdit({
schemaName,
name: doc.name as string,
});
}
async function openFormEditDoc(schemaName: string, fyo: Fyo) {
const doc = fyo.doc.getNewDoc(schemaName);
const name = doc.name;
@ -735,10 +723,10 @@ export class Search {
_getRouteFromKeyword(keyword: Keyword): RouteLocationRaw {
const { parent, parentSchemaName, schemaName } = keyword.meta;
if (parent && parentSchemaName) {
return getCreateRoute(parentSchemaName as string, parent as string);
return getFormRoute(parentSchemaName as string, parent as string);
}
return getCreateRoute(schemaName as string, keyword.values[0]);
return getFormRoute(schemaName as string, keyword.values[0]);
}
_getGroupedKeywords() {

View File

@ -420,3 +420,33 @@ export function getFieldsGroupedByTabAndSection(
return grouped;
}
export function getFormRoute(
schemaName: string,
name: string
): RouteLocationRaw {
const route = fyo.models[schemaName]
?.getListViewSettings(fyo)
?.formRoute?.(name);
if (typeof route === 'string') {
return route;
}
if (
[
ModelNameEnum.SalesInvoice,
ModelNameEnum.PurchaseInvoice,
ModelNameEnum.JournalEntry,
ModelNameEnum.Shipment,
ModelNameEnum.PurchaseReceipt,
ModelNameEnum.StockMovement,
ModelNameEnum.Payment,
ModelNameEnum.Item,
].includes(schemaName as ModelNameEnum)
) {
return `/edit/${schemaName}/${name}`;
}
return `/list/${schemaName}?edit=1&schemaName=${schemaName}&name=${name}`;
}