From e3ce6d85ef48f69c7c7b73cab56abd42e5fdd98a Mon Sep 17 00:00:00 2001 From: Clemente Raposo Date: Tue, 4 Feb 2020 00:38:51 +0000 Subject: [PATCH] Retrieve Navigation Menu data from API - Add Navigation Api Service - Add Metadata Facade Service - Build Navigation menu using fetched menu items - Fix submenu item link on template - Cleanup code warnings - Remove get method from RecordGQL -- we won't be using GraphQL cache for the moment - Fix classic view karma tests - Fix Filter karma tests - Add set of base jasmine tests for: -- navbar component -- metadata service -- navigation metadata service --- core/app/karma.conf.js | 2 +- .../classic-view.component.spec.ts | 20 +- .../classic-view/classic-view.component.ts | 2 +- .../filter/filter.component.spec.ts | 12 +- .../list-view/list-view.component.spec.ts | 2 - .../app/src/components/navbar/navbar-model.ts | 1 + .../src/components/navbar/navbar.abstract.ts | 342 ++++-------------- .../components/navbar/navbar.component.html | 5 +- .../navbar/navbar.component.spec.ts | 87 ++++- .../src/components/navbar/navbar.component.ts | 27 +- .../api/graphql-api/api.record.get.ts | 36 +- .../src/services/metadata/metadata.service.ts | 18 + .../src/services/metadata/metadata.spec.ts | 74 ++++ .../navigation/navigation.metadata.service.ts | 30 ++ .../navigation/navigation.metadata.spec.ts | 88 +++++ 15 files changed, 413 insertions(+), 333 deletions(-) create mode 100644 core/app/src/services/metadata/metadata.service.ts create mode 100644 core/app/src/services/metadata/metadata.spec.ts create mode 100644 core/app/src/services/metadata/navigation/navigation.metadata.service.ts create mode 100644 core/app/src/services/metadata/navigation/navigation.metadata.spec.ts diff --git a/core/app/karma.conf.js b/core/app/karma.conf.js index 717a3991e..8d7de2f71 100644 --- a/core/app/karma.conf.js +++ b/core/app/karma.conf.js @@ -25,7 +25,7 @@ module.exports = function (config) { colors: true, logLevel: config.LOG_INFO, autoWatch: true, - browsers: ['Chrome'], + browsers: ['Chrome', 'Chromium'], singleRun: false, restartOnFileChange: true }); diff --git a/core/app/src/components/classic-view/classic-view.component.spec.ts b/core/app/src/components/classic-view/classic-view.component.spec.ts index 48be71d74..70ed0c738 100644 --- a/core/app/src/components/classic-view/classic-view.component.spec.ts +++ b/core/app/src/components/classic-view/classic-view.component.spec.ts @@ -5,16 +5,25 @@ import {RouterTestingModule} from '@angular/router/testing'; import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; import {ClassicViewUiComponent} from './classic-view.component'; -import {ApiService} from '../../services/api/api.service'; +import {ApiService} from '@services/api/api.service'; +import {ActivatedRoute} from '@angular/router'; +import {of} from 'rxjs'; describe('ClassicViewUiComponent', () => { let component: ClassicViewUiComponent; let fixture: ComponentFixture; + const route = ({ + data: { view: { html: '

haha

' }}, + snapshot: { + data: { view: { html: '

haha

' }} + } + } as any) as ActivatedRoute; beforeEach(async(() => { TestBed.configureTestingModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], imports: [RouterTestingModule, HttpClientTestingModule, FormsModule], + providers: [{ provide: ActivatedRoute, useValue: route }], declarations: [ClassicViewUiComponent] }) .compileComponents(); @@ -28,6 +37,15 @@ describe('ClassicViewUiComponent', () => { it(`should create`, async(inject([HttpTestingController], (router: RouterTestingModule, http: HttpTestingController, api: ApiService) => { + expect(component).toBeTruthy(); + expect(component.data.view.html).toEqual('

haha

'); + }))); + + it(`should display provided html`, async(inject([HttpTestingController], + (router: RouterTestingModule, http: HttpTestingController, api: ApiService) => { + + const classicElement: HTMLElement = fixture.nativeElement; + expect(classicElement.innerHTML).toContain('

haha

'); }))); }); diff --git a/core/app/src/components/classic-view/classic-view.component.ts b/core/app/src/components/classic-view/classic-view.component.ts index 154698781..369499d80 100644 --- a/core/app/src/components/classic-view/classic-view.component.ts +++ b/core/app/src/components/classic-view/classic-view.component.ts @@ -9,7 +9,7 @@ import {ActivatedRoute} from '@angular/router'; export class ClassicViewUiComponent { data: any; - @ViewChild('dataContainer', {static:true}) dataContainer: ElementRef; + @ViewChild('dataContainer', {static: true}) dataContainer: ElementRef; public element: any; renderHtml(data) { diff --git a/core/app/src/components/filter/filter.component.spec.ts b/core/app/src/components/filter/filter.component.spec.ts index 27c651031..b3021f815 100644 --- a/core/app/src/components/filter/filter.component.spec.ts +++ b/core/app/src/components/filter/filter.component.spec.ts @@ -1,20 +1,20 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing'; -import {FilterViewUiComponent} from './filter-view.component'; +import {FilterUiComponent} from './filter.component'; -describe('FilterViewUiComponent', () => { - let component: FilterViewUiComponent; - let fixture: ComponentFixture; +describe('FilterUiComponent', () => { + let component: FilterUiComponent; + let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [FilterViewUiComponent] + declarations: [FilterUiComponent] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(FilterViewUiComponent); + fixture = TestBed.createComponent(FilterUiComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/core/app/src/components/list-view/list-view.component.spec.ts b/core/app/src/components/list-view/list-view.component.spec.ts index 0946b0779..743048278 100644 --- a/core/app/src/components/list-view/list-view.component.spec.ts +++ b/core/app/src/components/list-view/list-view.component.spec.ts @@ -14,8 +14,6 @@ import {HttpClientModule} from '@angular/common/http'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {ListViewUiComponent} from './list-view.component'; -import {SvgIconUiComponent} from '../svg-icon/svg-icon.component'; -import {ModalViewUiComponent} from '../modal-view/modal-view.component'; let mockRouter: any; diff --git a/core/app/src/components/navbar/navbar-model.ts b/core/app/src/components/navbar/navbar-model.ts index afeba18b8..b822cfcf5 100644 --- a/core/app/src/components/navbar/navbar-model.ts +++ b/core/app/src/components/navbar/navbar-model.ts @@ -11,4 +11,5 @@ export interface NavbarModel { currentUser: CurrentUserModel; all: AllMenuModel; menu: any; + buildMenu(items: any, menuItemThreshold: number): void; } diff --git a/core/app/src/components/navbar/navbar.abstract.ts b/core/app/src/components/navbar/navbar.abstract.ts index fdd2c69d3..db6ea0296 100644 --- a/core/app/src/components/navbar/navbar.abstract.ts +++ b/core/app/src/components/navbar/navbar.abstract.ts @@ -7,27 +7,27 @@ export class NavbarAbstract implements NavbarModel { useGroupTabs = true; globalActions = [ { - 'link': { - 'url': '', - 'label': 'Employees' + link: { + url: '', + label: 'Employees' } }, { - 'link': { - 'url': '', - 'label': 'Admin' + link: { + url: '', + label: 'Admin' } }, { - 'link': { - 'url': '', - 'label': 'Support Forums' + link: { + url: '', + label: 'Support Forums' } }, { - 'link': { - 'url': '', - 'label': 'About' + link: { + url: '', + label: 'About' } } ]; @@ -39,263 +39,65 @@ export class NavbarAbstract implements NavbarModel { modules: [], extra: [], }; - menu = [ - { - "link": { - "label": "Accounts", - "url": '' - }, - "submenu": - [ - { - "link": { - "label": "Create Account", - "url": "", - "iconRef": {"resolved": "home_page"} - }, - "icon": "plus", - "submenu": [], + menu = []; - }, - { - "link": { - "label": "View Account", "url": "/#/Accounts/index" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Accounts", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Contacts", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Contact", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Contact", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Contacts", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Opportunities", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Opportunity", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Opportunity", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Opportunities", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Leads", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Lead", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Lead", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Leads", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Quotes", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Quote", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Quote", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Quotes", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Calendar", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Calendar", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Calendar", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Calendars", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Documents", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Document", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Document", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Documents", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Emails", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Email", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Email", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Emails", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] - }, - { - "link": { "label": "Spots", "url": '' }, "icon": "home_page", - "submenu": - [ - { - "link": { - "label": "Create Spot", - "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "View Spot", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - { - "link": { - "label": "Import Spots", "url": "" - }, - "icon": "plus", - "submenu": [] - }, - ] + public buildMenu(items: {}, threshold: number): void { + const navItems = []; + const moreItems = []; + + if (!items || Object.keys(items).length === 0) { + this.menu = navItems; + this.all.extra = moreItems; } - ]; -} \ No newline at end of file + + let count = 0; + Object.keys(items).forEach(module => { + + if (count <= threshold) { + navItems.push(this.buildMenuItem(module, items[module])); + } else { + moreItems.push(this.buildMenuItem(module, items[module])); + } + + count++; + }); + + this.menu = navItems; + this.all.modules = moreItems; + } + + public buildMenuItem(module: string, label: string): any { + + return { + link: { label, url: `/#/${module}/index` }, icon: 'home_page', + submenu: + [ + { + link: { + label: `Create ${label}`, + url: `/#/${module}/edit` + }, + icon: 'plus', + submenu: [] + }, + { + link: { + label: `View ${label}`, + url: `/#/${module}/list` + }, + icon: 'view', + submenu: [] + }, + { + link: { + label: `Import ${label}`, + url: `/#/${module}/import` + }, + icon: 'upload', + submenu: [] + }, + ] + }; + } + +} diff --git a/core/app/src/components/navbar/navbar.component.html b/core/app/src/components/navbar/navbar.component.html index 4489e8aeb..0c82fdf2e 100644 --- a/core/app/src/components/navbar/navbar.component.html +++ b/core/app/src/components/navbar/navbar.component.html @@ -137,7 +137,10 @@