1.0.196 • Published 6 years ago

crud-restful v1.0.196

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

crud-restful - UNDER DEVELOPMENT

UNDER DEVELOPMENT

This component aims to facilitate the construction of user interfaces in Angular 2. This component provides high-level interface components using PrimeNG. The use of this component generates a great gain of productivity and flexibility in the construction of the interfaces. All components are created at runtime based on Decorators and Metadatas that provides information such as field positioning, combos content and component configuration.

Libraries dependencies

Installation of dependencies:

  1. PrimeNG: http://www.primefaces.org/primeng/#/setup
  2. jQuery : https://www.npmjs.com/package/jquery
  3. ng2-translate : https://www.npmjs.com/package/ng2-translate
  4. moment : https://www.npmjs.com/package/moment
  5. font-awesome : https://www.npmjs.com/package/font-awesome

Library installation

To install this library, run:

$ npm install crud-restful --save

How to use

Describe your model with Decorators and Metadatas. Example:

import { Configure, Id, InputType, MultiSelect, Chips, Select, Calendar, Checkboxes, Table } from '../index';

@Table({
	clazz : 'Login',
    name : 'tableUser',
    url : '/data/login.json',  
    rows : 10,
    paginator : true,
    pageLinks : 3,
    sortField : 'id',
    sortOrder : 1,   
    order : 0,
    emptyMessageKey : 'MESSAGE.NO_DATA',
    autoHide : true
})
@Configure({
    clazz : 'Login',
    i18nPath : './assets/i18n'
})
export class Login {
    @InputType({
    	clazz : 'Login',
        name : 'Id',
        type : 'text',
        readOnly : true,
        disabled : true,
        autoWidth : true,
        order : 1,
        tableColumn : 0,
        sortable : true
    })    
    id : number;

    @InputType({
    	clazz : 'Login',
        name : 'Email',
        translateKey : 'EMAIL',
        type : 'text',
        autoWidth : true,
        order : 2,
        tableColumn : 2,
        sortable : true,
        required : true,
        requiredMessageKey : 'MESSAGE.FIELD_REQUIRED',
        regexp : "/^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i",
        regexpMessage : 'Email is invalid'
    })            
    name : string;
    
    @InputType({
    	clazz : 'Login',
        name : 'Full Name',
        translateKey : 'FULLNAME',
        type : 'text',
        autoWidth : true,
        order : 3,
        tableColumn : 1,
        sortable : true,
        required : true,
        requiredMessageKey : 'MESSAGE.FIELD_REQUIRED',
        style : 'color: blue;font-style: italic;'
    })    
    fullname : string;   
}

Result:

alt tag

Import in your module:

import {CrudModule} from 'crud-restful/index';

In your HTML template:

<crud [clazz]="'Login'" [model]="login" [broadcast]="broadcast" [buttons]="'Save,Remove,Cancel'" (onSave)="handleOnSave($event)" (onRemove)="handleOnRemove($event)" (onCancel)="handleOnCancel()" (onOk)="handleOnOk($event)" [onTableLoaded]="onTableLoaded" [onTableRowSelected]="onTableRowSelected"></crud>

In the component, initialize your object model with default values (if necessary) and handle the events:

    .
    .
    .

    @ViewChild(CrudComponent) crudComponent : CrudComponent;
    broadcast: EventEmitter<any> = new EventEmitter<any>();
    onTableLoaded: EventEmitter<any> = new EventEmitter<any>();
    login : Login;

    constructor() {
        this.login = new Login();
        this.login.id = 1;
        this.login.email = 'cmargulhano@gmail.com';
        this.login.fullname = 'Cláudio Margulhano';

        this.onTableLoaded.subscribe(() => {
            console.log('table loaded');
        })

        this.onTableRowSelected.subscribe((event : any) => {
            console.log(event);
        });

        this.onNewItem.subscribe((event : any) => {
            console.log(event);
        });
    }
    
    handleOnSave(login : Login) {
        console.log('Save');
        console.log(login);
    }
    
    handleOnRemove(login : Login) {
        console.log('Remove');
        console.log(login);
    }

    handleOnCancel() {
        console.log('Cancel');
    }

    handleOnOk(login : Login) {
        console.log(login);
    }

    refreshTable() {
        this.broadcast.emit();
    }

    i18n() {
        this.translate.use('pt-br');
        this.crudComponent.notify();
    }    

    changeEmail () {
        this.broadcast.emit('{"email" : "cmargulhano@hotmail.com"}');
    }
    .
    .
    .

Playground of components: http://localhost:8080

git clone https://github.com/cmargulhano/crud-restful.git
npm install
npm start

Helper functions

To hide / show table:

this.crudComponent.showTable('none'); // hide
this.crudComponent.showTable('flex'); // show

To hide / show buttons:

this.crudComponent.showOkButton = false; // true to show
this.crudComponent.showSaveButton = false; 
this.crudComponent.showRemoveButton = false;
this.crudComponent.showCancelButton = false;

Components

Table - class decorator

Example:

@Table({
	clazz : 'Login',
    name : 'tableUser',
    url : '/data/login.json', 
    rows : 10,
    paginator : true,
    pageLinks : 3,
    sortField : 'id',
    sortOrder : 1,   
    order : 0,
    emptyMessageKey : 'MESSAGE.NO_DATA',
    autoHide : true
})
export class Login {
    .
    .
    .
    @InputType({
    	clazz : 'Login',
        name : 'Email',
        translateKey : 'EMAIL',
        type : 'text',
        autoWidth : true,
        order : 2,
        tableColumn : 2,
        sortable : true,
        required : true,
        requiredMessageKey : 'MESSAGE.FIELD_REQUIRED',
        regexp : "/^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i",
        regexpMessage : 'Email is invalid',
        style : 'color: blue;font-style: italic;'
    })            
    name : string;
    .
    .
    .
}

The decorator @InputType needs to inform news parameters for the table component: tableColumn parameter defines the order of column in the table. sortable parameter defines if the column will be sortable.

InputType - property decorator

Examples:

@InputType({
	clazz : 'Login',
    name : 'Email',
    translateKey : 'EMAIL',
    type : 'text',
    autoWidth : true,
    order : 2,
    tableColumn : 2,
    sortable : true,
    required : true,
    requiredMessageKey : 'MESSAGE.FIELD_REQUIRED',
    regexp : "/^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i",
    regexpMessage : 'Email is invalid',
    style : 'color: blue;font-style: italic;'
})            
email : string;

@InputType({
	clazz : 'Login',
    name : 'Phone Number',
    type : 'text',
    autoWidth : true,
    order : 4,
    tableColumn : 3,
    sortable : true,
    required : false,
    requiredMessageKey : 'MESSAGE.FIELD_REQUIRED',
    style : 'color: pink;'
    mask : '(99) 999-9999'
})    
phonenumber : string;

MultiSelect - property decorator

Example:

@MultiSelect({
	clazz : 'Scheduling',
    url : '/data/report.json', 
    modelSelect : 'reportList',        
    modelSelectClazz : Report, 
    modelSelectValue : 'id',
    modelSelectLabel : 'name',
    disabled : true,
    order : 4
})
public reports: Report[];

Chips - property decorator

@Chips({
	clazz : 'Scheduling',
    name : 'Email',
    disabled : false,
    autoWidth : true,       
    regexp : "/^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i",
    regexpMessage : 'Email is invalid'        
    order : 5
})
public mails: string[];

Select - property decorator

Example:

@Select({
	clazz : 'Scheduling',
    values : [{"value" : 1, "label" : "Value 1"}, {"value" : 2, "label" : "Value 2"}, {"value" : 3, "label" : "Value 3"}],
    defaultValue : 2,
    order : 5
})
public period: string;

Calendar - property decorator

Example:

Using string object:

@Calendar({
	clazz : 'Scheduling',
    disabled : false,
    autoWidth : true,
    order : 7,
    format : 'DD/MM/YYYY'
})
public date : string;

You can also use Date object instead of string:

@Calendar({
	clazz : 'Scheduling',
    disabled : false,
    autoWidth : true,
    order : 7,
    format : 'DD/MM/YYYY'
})
public date : Date;

Posible formats:

  1. DD/MM/YYYY
  2. MM/DD/YYYY
  3. YYYY/MM/DD

Checkboxes - property decorator

Example:

@Checkboxes({
	clazz : 'Scheduling',
    name : 'Itens:',
    disabled : false,
    autoWidth : true,
    defaultValue : 1,
    order : 10,
    values : [new Item(1, 'Value 1', true),
              new Item(2, 'Value 2', false),
              new Item(3, 'Value 3', true)]
})
public itensCheckboxes : Item[];

Radioboxes - property decorator

Example:

@Radioboxes({
	clazz : 'Scheduling',
    name : 'Itens:',
    disabled : false,
    autoWidth : true,
    defaultValue : 1,
    order : 10,
    values : [new Item(1, 'Value 1', true),
              new Item(2, 'Value 2', false)],
    target : 'selectedRadiobox'
})
public itensRadioboxes : Item[];

public selectedRadiobox : number;

Scheduling (under development)

Dual List Box (under development)

Internationalization

Crud-restful uses Ng2-translate component to translate the interface.

Configuration

By default, Crud-restful will search for files in assets/i18n/*.json. If you want you can customize this behavior by changing the path (attribute i18nPath) of the files with the decorator @Config, example:

@Configure({
    clazz : 'Login',
    i18nPath : './assets/i18n'
})

All decorators have the translateKey parameter which refers to the translation key of the json file. The exception is the @Table decorator that has the parameter emptyMessageKey that refers to the "Records not found" message.

If you change the used language of Ng2-Translate you need to refresh the translation in your App. Example:

export class App {
    @ViewChild(CrudComponent) crudComponent : CrudComponent;

    refreshI18N() {
        this.translate.use('pt-br');
        this.crudComponent.notify();
    }
...

Auth

If you need, you can use bearer tokens in HTTP requests, for example:

import { Configuration } from 'crud-restful/index';
Configuration.token = 'bearer 96549c0e-dab8-4d05-9d62-33cbd320b152';

License

MIT © Claudio Margulhano

1.0.196

6 years ago

1.0.195

6 years ago

1.0.191

6 years ago

1.0.190

6 years ago

1.0.189

6 years ago

1.0.188

6 years ago

1.0.187

6 years ago

1.0.186

6 years ago

1.0.185

6 years ago

1.0.184

6 years ago

1.0.182

6 years ago

1.0.178

7 years ago

1.0.177

7 years ago

1.0.176

7 years ago

1.0.175

7 years ago

1.0.174

7 years ago

1.0.173

7 years ago

1.0.172

7 years ago

1.0.171

7 years ago

1.0.170

7 years ago

1.0.169

7 years ago

1.0.168

7 years ago

1.0.167

7 years ago

1.0.166

7 years ago

1.0.165

7 years ago

1.0.164

7 years ago

1.0.163

7 years ago

1.0.162

7 years ago

1.0.161

7 years ago

1.0.160

7 years ago

1.0.159

7 years ago

1.0.158

7 years ago

1.0.157

7 years ago

1.0.156

7 years ago

1.0.155

7 years ago

1.0.154

7 years ago

1.0.153

7 years ago

1.0.152

7 years ago

1.0.151

7 years ago

1.0.150

7 years ago

1.0.149

7 years ago

1.0.148

7 years ago

1.0.147

7 years ago

1.0.146

7 years ago

1.0.145

7 years ago

1.0.144

7 years ago

1.0.143

7 years ago

1.0.142

7 years ago

1.0.141

7 years ago

1.0.140

7 years ago

1.0.139

7 years ago

1.0.138

7 years ago

1.0.137

7 years ago

1.0.136

7 years ago

1.0.135

7 years ago

1.0.134

7 years ago

1.0.133

7 years ago

1.0.132

7 years ago

1.0.131

7 years ago

1.0.130

7 years ago

1.0.129

7 years ago

1.0.128

7 years ago

1.0.127

7 years ago

1.0.126

7 years ago

1.0.125

7 years ago

1.0.124

7 years ago

1.0.123

7 years ago

1.0.122

7 years ago

1.0.121

7 years ago

1.0.119

7 years ago

1.0.118

7 years ago

1.0.117

7 years ago

1.0.116

7 years ago

1.0.115

7 years ago

1.0.114

7 years ago

1.0.113

7 years ago

1.0.112

7 years ago

1.0.111

7 years ago

1.0.110

7 years ago

1.0.109

7 years ago

1.0.108

7 years ago

1.0.107

7 years ago

1.0.106

7 years ago

1.0.105

7 years ago

1.0.104

7 years ago

1.0.103

7 years ago

1.0.102

7 years ago

1.0.101

7 years ago

1.0.100

7 years ago

1.0.99

7 years ago

1.0.98

7 years ago

1.0.97

7 years ago

1.0.96

7 years ago

1.0.95

7 years ago

1.0.94

7 years ago

1.0.93

7 years ago

1.0.92

7 years ago

1.0.91

7 years ago

1.0.90

7 years ago

1.0.89

7 years ago

1.0.88

7 years ago

1.0.87

7 years ago

1.0.86

7 years ago

1.0.85

7 years ago

1.0.84

7 years ago

1.0.83

7 years ago

1.0.82

7 years ago

1.0.81

7 years ago

1.0.80

7 years ago

1.0.79

7 years ago

1.0.78

7 years ago

1.0.77

7 years ago

1.0.76

7 years ago

1.0.75

7 years ago

1.0.74

7 years ago

1.0.73

7 years ago

1.0.72

7 years ago

1.0.71

7 years ago

1.0.70

7 years ago

1.0.69

7 years ago

1.0.68

7 years ago

1.0.67

7 years ago

1.0.66

7 years ago

1.0.65

7 years ago

1.0.64

7 years ago

1.0.63

7 years ago

1.0.62

7 years ago

1.0.61

7 years ago

1.0.59

7 years ago

1.0.57

7 years ago

1.0.56

7 years ago

1.0.55

7 years ago

1.0.54

7 years ago

1.0.53

7 years ago

1.0.52

7 years ago

1.0.51

7 years ago

1.0.50

7 years ago

1.0.49

7 years ago

1.0.48

7 years ago

1.0.47

7 years ago

1.0.46

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.42

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.17.0

7 years ago

0.16.0

7 years ago

0.15.0

7 years ago

0.14.0

7 years ago

0.13.0

7 years ago

0.12.0

7 years ago

0.11.0

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago