angular js in apex - nyougnyoug.org/wp-content/uploads/2014/12/mcghan_angularjs.pdf · title: how...

27

Upload: vanxuyen

Post on 07-Nov-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Angular JS in APEXGetting the Best of Both Worlds

Dan McGhanDatabase EvangelistOracle Database ToolsDecember 11, 2014

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

My Background• Dan McGhan

[email protected]– @dmcghan– danielmcghan.us

• Oracle Database Evangelist– Joined Oracle in December 2014– Focus on JavaScript and HTML5– Extensive background with APEX

Oracle Confidential – Internal/Restricted/Highly Restricted 3

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Agenda

Why Angular?

Brief Angular Overview

APEX & Angular Integration

1

2

3

Oracle Confidential – Internal/Restricted/Highly Restricted 4

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Agenda

Why Angular?

Brief Angular Overview

APEX & Angular Integration

1

2

3

Oracle Confidential – Internal/Restricted/Highly Restricted 5

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

“I call it the law of the instrument, and it may be formulated as follows: Give a small boy a hammer, and he will find that everything he encounters needs pounding”– Abraham Kaplan

Oracle Confidential – Internal/Restricted/Highly Restricted 6

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

My 2014 New Year’s Resolutions• Get MEAN!

– Mongo, Express, Angular, Node

• Learn many other supporting technologies– Git, Grunt, Bower, Bootstrap, Yeoman, and many more

Oracle Confidential – Internal/Restricted/Highly Restricted 7

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

What is Angular?• A JavaScript MVC framework

– Others include Backbone, Ember, & Knockout

• Created by and maintained by Google• Typically used to build SPAs• Requires a “new” way of thinking

Oracle Confidential – Internal/Restricted/Highly Restricted 8

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

“Developing a UI? think state 1st, actions 2nd. Model the UI's state as observable. Then, make actions that update state.”

– Justin B. Meyer, Author of CanJS

Oracle Confidential – Internal/Restricted/Highly Restricted 9

“Everything else calls actions to update state, and listens to state changes. Click -> action > state change -> update UI”

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

• Persisted state– Database server

• Session State/Model– Database server

• APEX

– Middle tier• Java, .NET, etc.

– Client side• Angular, Backbone, etc.

Oracle Confidential – Internal/Restricted/Highly Restricted 10

• Page State– Client side

Application States

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Advantages

• Avoid full page refreshes• Snappier applications• Reduced network traffic

Disadvantages

• Increased development time• Data can’t be trusted

– must re-validate server side

Oracle Confidential – Internal/Restricted/Highly Restricted 11

Client Side Logic

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Complex, highly interactive UI

Oracle Confidential – Internal/Restricted/Highly Restricted 12

When is Client Side Logic Useful?

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Angular: for the occasional page that APEX isn’t great for…

Oracle Confidential – Internal/Restricted/Highly Restricted 13

Why use Angular in APEX?

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Agenda

Why Angular?

Brief Angular Overview

APEX & Angular Integration

1

2

3

Oracle Confidential – Internal/Restricted/Highly Restricted 14

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Ever heard of “How the Other Half Lives”?

Oracle Confidential – Internal/Restricted/Highly Restricted 15

Well today were going to see “How the Other Half Codes”!

Hello NYC!

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Agenda

Why Angular?

Brief Angular Overview

APEX & Angular Integration

1

2

3

Oracle Confidential – Internal/Restricted/Highly Restricted 16

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

APEX Touch Points• Asset files• Page template• Processes/Ajax requests

Oracle Confidential – Internal/Restricted/Highly Restricted 17

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Asset Files• Create a directory on the file system

– /c/todos

• Copy assets from Angular to the file system– /angular-proj/bin/assets -> /c/todos

• Create a substitution string in APEX

Oracle Confidential – Internal/Restricted/Highly Restricted 18

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Page Template 1 of 3• Copy default page template as “Angular Page”

– All “pages” in Angular can reuse this 1 APEX template

• Add ng-app & ng-controller to the HTML

Oracle Confidential – Internal/Restricted/Highly Restricted 19

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Page Template 2 of 3• Add ui-view to HTML

– If you’re using AngularUI Router (otherwise it’s ng-view)

Oracle Confidential – Internal/Restricted/Highly Restricted 20

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Page template 3 of 3• Include JS & CSS from file system

Oracle Confidential – Internal/Restricted/Highly Restricted 21

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Ajax Requests• Use 1 generic Ajax process for all processing

– Acts as a proxy

• Use Angular HTTP interceptor to mask complexity– Example in app-pre-browserify.js

• Standardize all Ajax processes to use PL/JSON– Procedures should have 1 JSON in and 1 JSON out– Example in todo_api.pkb & todo_api.pks

Oracle Confidential – Internal/Restricted/Highly Restricted 22

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted 23

They can play nice together!

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Developing in APEX is incredibly fast. While there are many benefits to JavaScript frameworks, development time will increase.

Oracle Confidential – Internal/Restricted/Highly Restricted 24

WARNING:

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Summary• Angular is very powerful

– Feature rich, large community– Built for testing

• But Angular is also complex– Steep learning curve– Nothing like APEX

• Want to learn more?– Google: angularjs in 60ish minutes

Oracle Confidential – Internal/Restricted/Highly Restricted 25

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Safe Harbor StatementThe following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Oracle Confidential – Internal/Restricted/Highly Restricted 26