first commit
This commit is contained in:
62
resources/frontend/core/arch/builder/crud.js
Normal file
62
resources/frontend/core/arch/builder/crud.js
Normal 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;
|
||||
}
|
||||
}
|
||||
12
resources/frontend/core/arch/builder/crud/abstractCrud.js
Normal file
12
resources/frontend/core/arch/builder/crud/abstractCrud.js
Normal 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);
|
||||
}
|
||||
}
|
||||
64
resources/frontend/core/arch/builder/crud/edit.js
Normal file
64
resources/frontend/core/arch/builder/crud/edit.js
Normal 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`;
|
||||
}
|
||||
}
|
||||
56
resources/frontend/core/arch/builder/crud/new.js
Normal file
56
resources/frontend/core/arch/builder/crud/new.js
Normal 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`;
|
||||
}
|
||||
}
|
||||
53
resources/frontend/core/arch/builder/crud/view.js
Normal file
53
resources/frontend/core/arch/builder/crud/view.js
Normal 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`;
|
||||
}
|
||||
}
|
||||
86
resources/frontend/core/arch/builder/grid.js
Normal file
86
resources/frontend/core/arch/builder/grid.js
Normal 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;
|
||||
}
|
||||
}
|
||||
24
resources/frontend/core/arch/builder/navbar.js
Normal file
24
resources/frontend/core/arch/builder/navbar.js
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
74
resources/frontend/core/arch/builder/sections.js
Normal file
74
resources/frontend/core/arch/builder/sections.js
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user