| /// <reference path="../typings/index.d.ts" /> |
| |
| import * as angular from 'angular'; |
| |
| import 'angular-ui-router'; |
| import 'angular-resource'; |
| import 'angular-cookies'; |
| import routesConfig from './routes'; |
| |
| import {main} from './app/main'; |
| |
| import './index.scss'; |
| import {xosCore} from './app/core/index'; |
| import {xosDataSources} from './app/datasources/index'; |
| import {xosViews} from './app/views/index'; |
| import { |
| interceptorConfig, userStatusInterceptor, CredentialsInterceptor, |
| NoHyperlinksInterceptor |
| } from './interceptors'; |
| import {IRuntimeStatesService} from './app/core/services/runtime-states'; |
| import {IModeldefsService, IModeldef} from './app/datasources/rest/modeldefs.rest'; |
| import {IXosCrudData} from './app/views/crud/crud'; |
| import * as _ from 'lodash'; |
| import {IXosNavigationService} from './app/core/services/navigation'; |
| |
| export interface IXosState extends angular.ui.IState { |
| data: IXosCrudData; |
| }; |
| |
| const modeldefToTableCfg = (fields: {name: string, type: string}[]): any[] => { |
| const excluded_fields = [ |
| 'created', |
| 'updated', |
| 'enacted', |
| 'policed', |
| 'backend_register', |
| 'deleted', |
| 'write_protect', |
| 'lazy_blocked', |
| 'no_sync', |
| 'no_policy', |
| 'omf_friendly', |
| 'enabled' |
| ]; |
| const cfg = _.map(fields, (f) => { |
| if (excluded_fields.indexOf(f.name) > -1) { |
| return; |
| } |
| return { |
| label: `${f.name}`, // TODO confert name to label |
| prop: f.name |
| }; |
| }) |
| .filter(v => angular.isDefined(v)); |
| |
| return cfg; |
| }; |
| |
| angular |
| .module('app', [xosCore, xosDataSources, xosViews, 'ui.router', 'ngResource']) |
| .config(routesConfig) |
| .config(interceptorConfig) |
| .factory('UserStatusInterceptor', userStatusInterceptor) |
| .factory('CredentialsInterceptor', CredentialsInterceptor) |
| .factory('NoHyperlinksInterceptor', NoHyperlinksInterceptor) |
| .component('xos', main) |
| .run((ModelDefs: IModeldefsService, RuntimeStates: IRuntimeStatesService, NavigationService: IXosNavigationService) => { |
| // Dinamically add a state |
| RuntimeStates.addState('test', { |
| parent: 'xos', |
| url: 'test', |
| template: 'Test State' |
| }); |
| |
| ModelDefs.get() |
| .then((models: IModeldef[]) => { |
| _.forEach(models, (m: IModeldef) => { |
| const state: IXosState = { |
| parent: 'xos', |
| url: `${m.name.toLowerCase()}s`, // TODO use https://github.com/blakeembrey/pluralize |
| component: 'xosCrud', |
| data: { |
| model: m.name, |
| xosTableCfg: { |
| columns: modeldefToTableCfg(m.fields) |
| } |
| } |
| }; |
| RuntimeStates.addState(`${m.name.toLowerCase()}s`, state); |
| NavigationService.add({label: `${m.name}s`, url: `${m.name.toLowerCase()}s`}); |
| }); |
| }); |
| }); |