mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-04 10:14:13 +08:00
Enable new list view for a set of modules
This commit is contained in:
parent
cc92e16141
commit
e8112140af
1 changed files with 73 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
import {NgModule} from '@angular/core';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {RouterModule, Routes, UrlMatchResult, UrlSegment} from '@angular/router';
|
||||
import {ClassicViewUiComponent} from '@components/classic-view/classic-view.component';
|
||||
import {ClassicViewResolver} from '@services/classic-view/classic-view.resolver';
|
||||
import {BaseMetadataResolver} from '@services/metadata/base-metadata.resolver';
|
||||
|
@ -7,9 +7,80 @@ import {AuthGuard} from '@services/auth/auth-guard.service';
|
|||
import {ListComponent} from '@views/list/list.component';
|
||||
import {LoginAuthGuard} from '@services/auth/login-auth-guard.service';
|
||||
import {BaseListResolver} from '@services/metadata/base-list.resolver';
|
||||
import { BaseModuleResolver } from '@base/services/metadata/base-module.resolver';
|
||||
import {BaseModuleResolver} from '@base/services/metadata/base-module.resolver';
|
||||
|
||||
/**
|
||||
* @param {[]} segments of url
|
||||
* @returns {object|null} matches
|
||||
*/
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
export function moduleMatcher(segments: UrlSegment[]): UrlMatchResult | null {
|
||||
|
||||
const modules = [
|
||||
'accounts',
|
||||
'contacts',
|
||||
'leads',
|
||||
'opportunities'
|
||||
];
|
||||
|
||||
const action = [
|
||||
'index',
|
||||
'list',
|
||||
];
|
||||
|
||||
if (!segments || segments.length < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let result = {
|
||||
consumed: segments,
|
||||
posParams: {}
|
||||
};
|
||||
|
||||
const checks = [
|
||||
(segment: UrlSegment): boolean => modules.includes(segment.path),
|
||||
(segment: UrlSegment): boolean => action.includes(segment.path)
|
||||
];
|
||||
|
||||
const params = [
|
||||
'module',
|
||||
'action'
|
||||
];
|
||||
|
||||
segments.some((segment, index) => {
|
||||
if (!checks[index]) {
|
||||
return true; // no more segments to check
|
||||
}
|
||||
|
||||
const matches = checks[index](segment);
|
||||
|
||||
if (params[index] && result) {
|
||||
result.posParams[params[index]] = segment;
|
||||
}
|
||||
|
||||
if (!matches) {
|
||||
result = null;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
matcher: moduleMatcher,
|
||||
component: ListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
runGuardsAndResolvers: 'always',
|
||||
resolve: {
|
||||
metadata: BaseListResolver
|
||||
},
|
||||
data: {
|
||||
reuseRoute: false,
|
||||
checkSession: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':module/list-new',
|
||||
component: ListComponent,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue