UNPKG

@hicoder/angular-cli

Version:

Angular UI componenets and service generator. It works with the mean-rest-express package to generate the end to end web application. The input to this generator is the Mongoose schema defined for the express application. mean-rest-express exposes the Res

69 lines (59 loc) 2.8 kB
import { Component, OnInit, Input } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Injector } from '@angular/core'; import { <%-SchemaName%>ListComponent } from './<%-schemaName%>-list.component'; import { <%-SchemaName%>Service } from '../<%-schemaName%>.service'; @Component({ <%- include(`/widgets/list/component.template.custom.ts`)%> }) export class <%-SchemaName%><%-ComponentClassName%>Component extends <%-SchemaName%>ListComponent implements OnInit { public override clickItemAction: string = '<%-listViewObj.clickItemAction%>'; public override cardHasLink: boolean = <%-listViewObj.cardHasLink%>; public override cardHasSelect: boolean = <%-listViewObj.cardHasSelect%>; public override includeSubDetail: boolean = <%-listViewObj.includeSubDetail%>; public override canUpdate: boolean = <%-listViewObj.canUpdate%>; public override canDelete: boolean = <%-listViewObj.canDelete%>; public override canArchive: boolean = <%-listViewObj.canArchive%>; public override canCheck: boolean = <%-listViewObj.canCheck%>; public override itemMultiSelect: boolean = <%-listViewObj.itemMultiSelect%>; public override majorUi: boolean = <%-listViewObj.majorUi%>; public parentSchema: string = ''; public parentItemId: string = ''; constructor( public override <%-schemaName%>Service: <%-SchemaName%>Service, public override injector: Injector, public override route: ActivatedRoute, ) { super(<%-schemaName%>Service, injector, route); this.listViews = [ <%for (let widget of widgetDef.views) {%>'<%-widget%>', <%}%>]; this.listViewFilter = '<%-widgetDef.views[0]%>'; } override ngOnInit() { this.queryOnNgInit = false; // don't do query on the super class. super.ngOnInit(); this.listCategory1 = {}; // no do query based on category; this.listCategory2 = {}; // no do query based on category; let ref = this.getParentRouteRefField(); this.parentSchema = this.referenceFieldsReverseMap[ref]; if (!this.inputData) { this.parentItemId = this.getParentRouteItemId(); } else { this.parentItemId = this.inputData; } if (!this.parentItemId) { console.error(`Failed to find parentItemId in sub list component: ${this.schemaName}`); return; } let id = this.parentItemId; // this is to initialize the detail that will be used for search condition selection this.parentData = {}; if (this.arrayFields.some(x=>x[0] == ref)) { this.parentData[ref] = {'selection':[{'_id': id}] }; this.detail[ref] = {'selection':[{'_id': id}] }; //search on array list } else { this.parentData[ref] = {'_id': id }; this.detail[ref] = {'_id': id }; //make this as the search context } this.searchList(); } }