first commit

This commit is contained in:
Noor E Ilahi
2026-01-09 12:54:53 +05:30
commit 7ccf44f7da
1070 changed files with 113036 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import Builder from '../builder';
import View from './crud/view';
import Edit from './crud/edit';
import New from './crud/new';
export default class Crud extends Builder {
view = {};
edit = {};
new = {};
constructor(
crudName,
id,
serviceClass,
filters = {},
moduleContext,
defaultPrefix = '',
hasPages = { edit: true, view: true, new: true },
) {
super(moduleContext);
this.moduleContext = moduleContext;
this.crudName = crudName;
this.id = id;
this.serviceClass = typeof serviceClass === 'object' ? serviceClass : new serviceClass();
this.hasEdit = hasPages.edit;
this.hasView = hasPages.view;
this.hasNew = hasPages.new;
this.defaultPrefix = defaultPrefix;
this.routerConfig = [];
this.filters = filters;
if (this.hasView) {
this.view = new View(this);
}
if (this.hasEdit) {
this.edit = new Edit(this);
}
if (this.hasNew) {
this.new = new New(this);
}
}
getRouterConfig() {
const toReturn = [];
if (this.view) {
toReturn.push(this.view.getRouterConfig());
}
if (this.edit) {
toReturn.push(this.edit.getRouterConfig());
}
if (this.new) {
toReturn.push(this.new.getRouterConfig());
}
return toReturn;
}
}

View File

@@ -0,0 +1,12 @@
import set from 'lodash/set';
export default class AbstractCrud {
/**
* @param property
* @param data
* @param routerConfig
*/
addToMetaProperties(property, data, routerConfig) {
set(routerConfig.meta, property, data);
}
}

View File

@@ -0,0 +1,64 @@
import AbstractCrud from './abstractCrud';
export default class Edit extends AbstractCrud {
context = {};
routerConfig = {};
constructor(context) {
super();
this.context = context;
this.routerConfig = {
path: `${context.routerPrefix}${context.defaultPrefix.length ? '/' + context.defaultPrefix : ''}/edit/:id`,
name: this.getEditRouteName(),
component: () => import(/* webpackChunkName: "editview" */ '@/views/Crud/EditView.vue'),
meta: {
auth: true,
service: context.serviceClass,
filters: context.filters,
fields: [],
pageData: {
title: context.crudName,
type: 'edit',
pageControls: [],
},
},
};
}
addPageControls() {
const arg = arguments[0];
this.addToMetaProperties('pageData.pageControls', arg, this.getRouterConfig());
return this;
}
addPageControlsToBottom() {
const arg = arguments[0];
this.addToMetaProperties('pageData.bottomComponents.pageControls', arg, this.getRouterConfig());
return this;
}
addBottomComponents() {
const arg = arguments[0];
this.addToMetaProperties('pageData.bottomComponents.components', arg, this.getRouterConfig());
return this;
}
/**
* @param {Config} fieldConfig
* @returns {Edit}
*/
addField(fieldConfig) {
this.addToMetaProperties('fields', fieldConfig, this.getRouterConfig());
return this;
}
getRouterConfig() {
return this.routerConfig;
}
getEditRouteName() {
return this.context.moduleContext.getModuleRouteName() + `.crud.${this.context.id}.edit`;
}
}

View File

@@ -0,0 +1,56 @@
import AbstractCrud from './abstractCrud';
export default class New extends AbstractCrud {
context = {};
routerConfig = {};
constructor(context) {
super();
this.context = context;
this.routerConfig = {
path: `${context.routerPrefix}${context.defaultPrefix.length ? '/' + context.defaultPrefix : ''}/new`,
name: this.getNewRouteName(),
component: () => import(/* webpackChunkName: "editview" */ '@/views/Crud/EditView.vue'),
meta: {
auth: true,
service: context.serviceClass,
filters: context.filters,
fields: [],
pageData: {
title: context.crudName,
type: 'new',
pageControls: [],
},
},
};
}
/**
*
* @param config
* @returns {New}
*/
addPageControls(config) {
this.addToMetaProperties('pageData.pageControls', config, this.getRouterConfig());
return this;
}
/**
* @param fieldConfig
* @returns {New}
*/
addField(fieldConfig) {
this.addToMetaProperties('fields', fieldConfig, this.getRouterConfig());
return this;
}
getRouterConfig() {
return this.routerConfig;
}
getNewRouteName() {
return this.context.moduleContext.getModuleRouteName() + `.crud.${this.context.id}.new`;
}
}

View File

@@ -0,0 +1,53 @@
import AbstractCrud from './abstractCrud';
export default class View extends AbstractCrud {
context = {};
routerConfig = {};
constructor(context) {
super();
this.context = context;
this.routerConfig = {
path: `${context.routerPrefix}${context.defaultPrefix.length ? '/' + context.defaultPrefix : ''}/view/:id`,
name: this.getViewRouteName(context),
component: () => import(/* webpackChunkName: "itemview" */ '@/views/Crud/ItemView.vue'),
meta: {
auth: true,
service: context.serviceClass,
filters: context.filters,
fields: [],
pageData: {
title: context.crudName,
type: 'view',
pageControls: [],
},
},
};
}
addPageControls() {
const arg = arguments[0];
this.addToMetaProperties('pageData.pageControls', arg, this.getRouterConfig());
return this;
}
/**
* Add field to page
* @param {Object} fieldConfig
* @returns {View}
*/
addField(fieldConfig) {
this.addToMetaProperties('fields', fieldConfig, this.getRouterConfig());
return this;
}
getRouterConfig() {
return this.routerConfig;
}
getViewRouteName() {
return this.context.moduleContext.getModuleRouteName() + `.crud.${this.context.id}.view`;
}
}

View File

@@ -0,0 +1,86 @@
import Builder from '../builder';
import set from 'lodash/set';
export default class Grid extends Builder {
constructor(label, id, serviceClass, moduleContext, gridData = undefined, gridRouterPath = '') {
super(moduleContext);
this.label = label;
this.id = id;
this.routerConfig = {
name: moduleContext.getModuleRouteName() + `.crud.${id}`,
path: this.routerPrefix + '/' + gridRouterPath,
component: () => import(/* webpackChunkName: "gridview" */ '../../views/Crud/GridView.vue'),
meta: {
auth: true,
pageControls: [],
gridData: {
title: label,
columns: [],
filters: [],
filterFields: [],
actions: [],
service: typeof serviceClass === 'object' ? serviceClass : new serviceClass(),
...gridData,
},
},
};
}
addColumn() {
const arg = arguments[0];
this.addToGridData('columns', arg);
return this;
}
addAction() {
const arg = arguments[0];
this.addToGridData('actions', arg);
return this;
}
addFilter() {
const arg = arguments[0];
this.addToGridData('filters', arg);
return this;
}
addFilterField() {
const arg = arguments[0];
this.addToGridData('filterFields', arg);
return this;
}
addToGridData(property, data) {
if (Array.isArray(data)) {
data.forEach(p => {
this.routerConfig.meta.gridData[property].push(p);
});
} else {
this.routerConfig.meta.gridData[property].push(data);
}
}
addToMetaProperties(property, data, routerConfig) {
set(routerConfig.meta, property, data);
}
addPageControls() {
const data = arguments[0];
if (Array.isArray(data)) {
data.forEach(p => {
this.routerConfig.meta.pageControls.push(p);
});
} else {
this.routerConfig.meta.pageControls.push(data);
}
return this;
}
getRouterConfig() {
return this.routerConfig;
}
}

View File

@@ -0,0 +1,24 @@
import isObject from 'lodash/isObject';
export default class NavbarEntry {
constructor({ label, to, displayCondition = () => true, section, icon }) {
if (!isObject(to)) {
throw new Error('[to] instance must be a JavaScript object');
}
this.label = label;
this.to = to;
this.displayCondition = displayCondition;
this.section = section;
this.icon = icon;
}
getData() {
return {
label: this.label,
to: this.to,
displayCondition: this.displayCondition,
section: this.section,
icon: this.icon,
};
}
}

View File

@@ -0,0 +1,74 @@
import { store } from '@/store';
/**
* Section class - create new section with provided params
*
* @param path string - section route path
* @param name string - section route name
* @param meta - section route meta with described fields, service etc
* @param accessCheck - function to check if user has access to work with section content
*/
export default class SettingsSection {
path = '';
name = '';
meta = {};
component = null;
children = [];
accessCheck = null;
section = {};
scope = 'settings';
constructor(
path,
name,
meta,
accessCheck = () => true,
scope = 'settings',
order = 99,
component = null,
children = [],
) {
this.path = path;
this.name = name;
this.meta = meta;
this.component =
component || (() => import(/* webpackChunkName: "settings" */ '@/views/Settings/DynamicSettings.vue'));
this.children = children;
this.accessCheck = accessCheck;
this.scope = scope;
this.order = order;
this.section = {
path: this.path,
name: this.name,
meta: this.meta,
component: this.component,
children: this.children,
accessCheck: this.accessCheck,
scope: this.scope,
order: this.order,
};
}
/**
* Init new section in store
* @returns {Promise<void>}
*/
async initSection() {
await store.dispatch('settings/setSettingSection', this.section);
}
/**
* Get section route, used to create settings child route
* @returns {{path: string, component: null, meta, name: string}}
*/
getRoute() {
return {
path: this.path,
name: this.name,
meta: this.meta,
component: this.component,
children: this.children,
};
}
}