node package manager

easy-suite

Easy-Suite for Material Design for Angular (and later ionic)

This is the home for Easy-Suite. Built for Angular using Material Design.

Component abstraction to allow easy dynamic pages. Build pages from component or in HTML.

Installation

The latest release of Easy-Suite can be installed from npm

npm install --save easy-suite

Project status

Easy Suite is currently in beta and under active development. During beta, new features will be added regularly and APIs will evolve based on user feedback.

Feature status:

Feature Status
cards Available
tabs Available
button Available
checkbox Available
radio Available
input Available
select Available
selectKeyValue Available
autocomplete Available
datepicker Available
data-table Available

"Available" means that the components or feature is published and available for use, but may still be missing some behaviors or polish.

Getting started

Step 1: Install Easy Suite

npm install --save easy-suite

Step 2: Import the component modules

Import the NgModule:

import {EasyModule} from 'easy-suite';
 
@NgModule({
  ...
  imports: [EasyModule],
  ...
})

Step 3: Hello World

 
import { Component} from '@angular/core';
import { EasyForm, EasyFormService, EasyField, EasyNotification, Colors, ButtonTypes } from 'easy-suite';
 
@Component({
  selector: 'hello-world',
  template: '<easy-form [form]="form"></easy-form>'
})
 
export class HelloWorldComponent {
 
  form: EasyForm;
 
  constructor(public easyFormService: EasyFormService) { 
   this.form = this.easyFormService.createForm();
   this.buildForm();
  } 
 
  buildForm() {
    let container = this.form.addCardContainer("Hello World Title");
 
    container.addInputField('helloWorldInput', 'Hello World');
 
    container.addButtonField('Save', 'Save', () => this.save(), { color: Colors.color_primary, type: ButtonTypes.button_fab, icon: 'done' });
  }
 
  save() {
    let fields = this.form.fields;
 
    let text = fields.filter(x => x.key == "helloWorldInput")[0].value;
 
    alert('Saving ' + text)
    }
 
}

Validation

At runtime field names are validated to ensure only one key is added to the collection.

One of these exceptions can be thrown

FieldWithSameKeyAlreadyExistsException 
FieldWithKeyDoesNotExistException
MultipleFieldsWithSameKeyExistException 

More Methods

Containers :

form.addTabContainer(header: string, options: FieldOptions = {}) form.addCardContainer(header: string, options: FieldOptions = {})

 
Fields:
```ts
container.addInputField(key: string, label: string, options: FieldOptions = {})
container.addAutocompleteField(key: string, label: string, options: Array<KeyValue>)
container.addCheckBoxField(key: string, label: string)
container.addSelectField(key: string, label: string, items: Array<string>
container.addSelectKeyValueField(key: string, label: string, items: Array<string>)
container.addButtonField(key: string, label: string, action: Function, options: FieldOptions = {})
container.addDatePickerField(key: string, label: string)
container.addTableField<T>(key: string)
 

FieldOptions:

export class FieldOptions {
    color?: string
    icon?: string
    type?: string
    format?: string
    showLoader?: boolean
    columnSpan?: number
    value?: any
    key?: string
    label?: string
    required?: boolean
    order?: number
    controlType?: string
    action?: Function
    items?: Array<any>
    xsColumnSize?: string
    smColumnSize?: string
    mdColumnSize?: string
    lgColumnSize?: string
    xlColumnSize?: string
    hide?: boolean;
    maxLength?: number;
    validators?: ValidatorFn[]
    updateAction?: Function;
}

Step 4: Events

All fields expose a subscription property which can be subscribed to for field changes. Use this when fields are dependent on one another or you just need to know when something changes.

Example :

let field = container.addInputField('helloWorldInput', 'Hello World');
 
field.onChange.subscribe(x=>{
    alert(x.value);
});

Step 5 : Handling results

To auto map a dto to the fields collection use the mapFields method on EasyForm NB!!! Ensure the properties on the dto have been assigned values otherwise the properties aren't accessible to TypeScript

export class TestDto {
  name: string = ''; //Default value assigned.
}
 
 this.form.mapFields<TestDto>(this.testDto);

To bind updates directly to a dto use the updateAction Function in the field options

 container.addInputField('helloWorldInput', 'Hello World', {updateAction:(value:string) => foo = value;});

The Form object exposes a fields array. As fields are upated this KeyValue Array is also updated.

 let fields = this.form.fields;
 
 this.field = fields.filter(x => x.key == "helloWorldInput")[0].value;

Step 6 (Optional): Usage as component directives.

  <easy-checkbox [placeholder]="field.label" [(value)]="field.value"></easy-checkbox>
 
  <easy-input [placeholder]="field.label" [(value)]="field.value" (change)="valueChanged()"></easy-input>
 
  <easy-select [placeholder]="field.label" [(selectedValue)]="field.value" [items]="field.items" (selectedValueChange)="valueChanged()"></easy-select>
 
  <easy-select-key-value [placeholder]="field.label" [(selectedValue)]="field.value" [items]="field.items" (selectedValueChange)="valueChanged()"></easy-select-key-value>
 
  <easy-autocomplete [placeholder]="field.label" [items]="field.options"></easy-autocomplete>
 
  <easy-button [color]="field.color" [icon]="field.icon" [type]="field.type" [displayValue]="field.label" [showLoader]="field.showLoader" (onClicked)="executeAction(field.action)"></easy-button>
 
  <easy-table [rows]="field.rows" [columns]="field.columns" [actions]="field.actions"></easy-table>
 
  <easy-date-picker [placeholder]="field.label" [(value)]="field.value"></easy-date-picker>

Appendix: Configuring SystemJS

If your project is using SystemJS for module loading, you will need to add easy-suite to the SystemJS configuration:

System.config({
  // existing configuration options 
  map: {
    // ... 
    'easy-suite': 'npm:easy-suite/src/',
    'easy-core': 'npm:easy-core/src/'
    // ... 
  },
 
  packages: {
    // ... 
      'easy-core': {
        main: 'index.js',
        defaultExtension: 'js'
      },
      'easy-suite': {
        main: 'index.js',
        defaultExtension: 'js'
      }
    // ... 
    }
 
});