Skip to content

Commit 0083bb7

Browse files
author
Aaron Baker and Christopher Nguyen
committed
more slides + images
1 parent a9c0361 commit 0083bb7

15 files changed

Lines changed: 223 additions & 95 deletions

Angular Patterns.md

Lines changed: 164 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
autoscale: true
2-
footer: © Sharethrough, November XX 2015
2+
footer: © Sharethrough, November 11 2015
33
slidenumbers: false
44

55
# Angular Patterns
66

7+
^ Thank you all for attending
8+
- hoping we can do something like this pretty frequently
9+
710
---
811

912
# Conversion Overview
1013

1114
- Renaming files
1215
- Converting templates
13-
- Front-end routing
14-
- Front-end permissions
1516
- Fetching data from Rails API
1617
- Creating API controllers
18+
- Front-end routing
19+
- Front-end permissions
20+
21+
^ Here are a few things we're gonna go over
22+
- Some in more detail than others, you can always check out my PR for more detail
23+
- or just ask me after this
1724

1825
---
1926

@@ -27,6 +34,9 @@ _becomes_
2734
_becomes_
2835
`deals/data_service.js.coffee`
2936

37+
^ doesn't necessarily have to be index/show, etc.
38+
- just name it after what it's for/ what it does
39+
3040

3141
[^1]: [https://github.com/johnpapa/angular-styleguide#naming](https://github.com/johnpapa/angular-styleguide#naming)
3242

@@ -40,6 +50,7 @@ _becomes_
4050
![inline](rename\ after.png)
4151

4252
^ as you can see, some were already correct, others not
53+
- now lets go over converting the actual templates (next)
4354

4455
---
4556

@@ -50,26 +61,40 @@ _becomes_
5061
^ Notice a few things
5162
- ugly bracket syntax
5263
- can can usage in markup
53-
- hrefs
54-
- in-line rails for model data
64+
- in-line rails for model data (mix with angular too)
5565
- javascript block for bootstrapping data
5666
- render partial syntax
5767
- random double quotes
68+
- hrefs
69+
- and here's where I ended up (next)
5870

5971
---
6072

6173
# Angular Template
6274

6375
![inline](haml\ after.png)
6476

65-
^ Good changes
66-
- more readable attributes
67-
- no ng-controller declaration
68-
- if-can directive
69-
- all rails data lives on controller
70-
- ng-include over render partial
77+
^ more readable attributes using parentheses
7178
- all single quotes unless otherwise needed
79+
- no ng-controller declaration (will address later)
7280
- ui-sref instead of href
81+
- if-can directive
82+
- ng-bind over mustaches
83+
- all rails data lives on controller
84+
- ng-include over render partial (will go over more)
85+
- no more :javascript
86+
- here's how we get data instead (next)
87+
88+
---
89+
90+
# Getting Rails Data
91+
92+
![inline](Deals\ Index\ Controller.png)
93+
94+
^ inject deals data service
95+
- make call, resolve promise and set to instance variable
96+
- what if you need deal before page loads? (We'll get to that later)
97+
- and heres the data service (next)
7398

7499
---
75100

@@ -78,48 +103,59 @@ _becomes_
78103
![inline](Deals\ Data\ Service.png)
79104

80105
^ super simple data service
81-
- could live in bakery.shared, but for now leave here
106+
- could live in bakery.shared, but for now leave here (due to future changes)
82107
- call api endpoint with url with key
108+
- and heres the api controller (next)
83109

84110
---
85111

86112
# Getting Rails Data
87113

88-
![inline](Deals\ Index\ Controller.png)
114+
![inline](Deals\ Api\ Controller.png)
89115

90-
^ inject deals data service
91-
- make call, resolve promise and set to instance variable
92-
- what if you need deal before page loads? We'll get to that later
116+
^ very simple
117+
- includes is for rendering seat name without n+1 queries
118+
- and here are some of those routes that we needed to create
119+
- authorize resource for ensuring user can see deal
93120

94121
---
95122

96-
# ifCan Directive
123+
# Getting Rails Data
124+
125+
![inline](routes-2.png)
126+
![inline](routes-1.png)
97127

98-
If can:
128+
^ Nothing too crazy here
129+
- api internal controller
130+
- globbing for angular routing
131+
- Home controller index action is blank
132+
133+
---
99134

100-
##`%a(if-can='manageDeals' ui-sref='dealsNew') New Deal`
135+
# ifCan Directive
101136

102-
If cannot:
137+
The frankenstein if-else:
103138

104-
##`%span(if-can='!manageDeals') Cannot Text`
139+
![inline](ui-sref.png)
105140

106141
^ would love to hear if someone knows a better way to do this
107142

108143
---
109144

110145
# Angular Partials
111146

112-
In deals/index.nghaml:
147+
In `deals/index.nghaml`:
113148

114149
![inline](ng-include.png)
115150

116-
In deals/bar_table.nghaml:
151+
In `deals/bar_table.nghaml`:
117152

118153
![inline](ng-include-2.png)
119154

120-
^specify the source (directory, name)
155+
^ specify the source (directory, name)
121156
- set internal controller if it is shared in onLoad
122-
- partial now has access to dealsCtrl/metricsCtrl
157+
- partial now has access to dealsCtrl through metricsCtrl
158+
- lets talk about maybe using ui-view in the future?
123159

124160
---
125161

@@ -140,50 +176,54 @@ In case wrapping the partial causes issues:
140176

141177
[^2]: [https://github.com/angular-ui/ui-router](https://github.com/angular-ui/ui-router)
142178

143-
^ lots going on here
179+
^ - remember when I got rid of ng-controller? It's here
144180
- lets focus on deals state first
145181
- url, template, controller, as
146182
- parent
147183
- parent state
148184
- ui-view template
149-
- data permissions
185+
- data permissions (will go over this in a minute)
186+
- lets jump back to front-end permissions
150187

151188
---
152189

153190
# Angular Routing
154191

155-
<br>
192+
New and Show routes:
156193

157-
##`%a(ui-sref='dealsNew') New Deal`
194+
![inline](new-vs-show.png)
158195

159-
^ Will trigger state change
196+
^ two different state routes
197+
- one with no params, the other with a required dealkey param
198+
- both Will trigger state changes, change URL, not reload browser
199+
- you can also pass arbitrary params to routes and handle them on a case-by-case basis
200+
- now lets go over permissions (next)
160201

161202
---
162203

163204
# Angular Routing
164205

165-
<br>
166-
167-
##`%a(ui-sref="dealsShow({ dealKey: deal.key})") Show Deal`
206+
##in `deals/router.js.coffee`:
168207

169-
^ You can send any params through there
208+
![inline](route-permissions.png)
170209

171-
---
210+
##in `shared/permissions.constant.js.coffee`:
172211

173-
# Angular Routing
174-
175-
![inline](route-permissions.png)
176212
![inline](permissions-constant.png)
177213

178-
^ Make sure you have all permissions in the constant file
179-
- if you don't, don't worry, you'll be reminded
214+
^ So, remember that data-permission hash?
215+
- Make sure you have all permissions in the constant file
216+
- if you don't, don't worry, you'll be reminded (next)
180217

181218
---
182219

183220
# Angular Routing
184221

185222
![inline](missing-permission.png)
186223

224+
^ Auth will fail, and you'll get this console error message
225+
- Now lets get into some small implementation details about permissions
226+
187227
---
188228

189229
# Angular Routing
@@ -192,9 +232,12 @@ In case wrapping the partial causes issues:
192232

193233
![inline](permissions-can.png)
194234

195-
^ There's a lot of technical mumbo jumbo that you can read if you have time
235+
^ Heres the basic method that does 90% of the work
236+
- There's a lot of technical details that you're interested
237+
- checks against manage first, since that encompasses all actions of a feature/resource
238+
- maybe feature is the wrong variable name here
196239
- but basically it ends up here, checking against the users cancan abilities
197-
- you can also do custom checking like this
240+
- you can also do custom checking like this (next)
198241

199242
---
200243

@@ -204,9 +247,11 @@ In case wrapping the partial causes issues:
204247

205248
![inline](custom-permission-check.png)
206249

207-
^ See here you can use that can method, or do something custom
208-
- you can modify this file and allow custom attributes or something like that
250+
^ This is part of a switch statement in the main canAccess method
251+
- See here you can use that can method, or do something custom
252+
- you can modify this file and allow custom attributes or something other than key potentially
209253
- checking role or pub key to only allow user to see their own pub content
254+
- and here is where the permission service gets called (next)
210255

211256
---
212257

@@ -215,52 +260,108 @@ In case wrapping the partial causes issues:
215260
![inline](route-auth.png)
216261

217262
^ lots of stuff here again, but it's not super important to understand
263+
- check if logged in, unless state is login (doesn't exist yet)
218264
- basically the parent publisher stuff might be important
219-
- logged in, unless state is login (doesn't exist yet)
220265
- if there is a parent you must be able to see parent
221266
- make sure you can also access curent
222267
- if unauthorized, go to a pseudo 404 page
223268
- prevent default if you are not logged in
224269
- get current user (pseudo log in)
225270
- set user in session, recurse
271+
- one last thing I'd like to mention
226272

227273
---
228274

229-
# State Changes
275+
# Router Resolving
276+
277+
![inline](pre-resolve.png)
278+
279+
^ Router resolving is a very cool concept
280+
- It takes code from this:
230281

231282
---
232283

233-
# Display formulas
284+
# Router Resolving
234285

235-
Easily include mathematical formulas by enclosing TeX commands in `$$` delimiters. Deckset uses [MathJax](http://www.mathjax.org/) to translate TeX commands into beautiful vector graphics.
286+
![inline](post-resolve.png)
236287

237-
Formula support is available as in-app purchase. See the next slide for an example.
288+
^ ...to this
238289

239-
<a name="formulas"></a>
290+
---
291+
292+
# Router Resolving
293+
294+
![inline](route-resolve.png)
295+
296+
^ ...and this
297+
- Use route resolves for data that is required before the page loads
298+
- prevents things like stuff showing up then snapping around once data is loaded
299+
- will cause initial page load to take longer so...
300+
- we need to establish a pattern showing that the page is loading
301+
- but it also gets rid of lots of prepareData calls and jittery pages
240302

241303
---
242304

243-
## Schrödinger equation
305+
# Gotchas and Interestings
306+
307+
Coffeescript + Inline-Edit:
244308

245-
The simplest way to write the time-independent Schrödinger equation is $$H\psi = E\psi$$, however, with the Hamiltonian operator expanded it becomes:
309+
![inline](inline-edit-method.png)
310+
![inline](inline-edit-method-2.png)
246311

247-
$$
248-
-\frac{\hbar^2}{2m} \frac{d^2 \psi}{dx^2} + V\psi = E\psi
249-
$$
312+
^ returning promise made the http request twice
250313

251314
---
252315

253-
# Captioned Images and Videos
316+
# Gotchas and Interestings
254317

255-
![inline](room.jpg)
318+
Boostrap Modals:
256319

257-
Easily create captions using [inline] images/videos with text underneath.
320+
![inline](modal-resolve.png)
321+
322+
^ result callback when modal.close called
323+
- resolve data into it, without using extra unneeded service
324+
- added benefit of it being obvious that the modal needs these values (breaks if not present)
258325

259326
---
260327

261-
# Plus:
328+
# Gotchas and Interestings
329+
330+
Boostrap Modals:
331+
332+
![inline](modal-controller.png)
333+
334+
^ placements and dealKey *must* be resolved into it, even if it is just null
335+
336+
---
337+
338+
# Gotchas and Interestings
339+
340+
Camelizing and Decamelizing $http requests
341+
342+
![inline](camelize-http.png)
343+
344+
^ placements and dealKey *must* be resolved into it, even if it is just null
345+
346+
---
347+
348+
# Further Discussion
349+
350+
- Coffeescript: CS classes vs VM syntax?
351+
- str-directive-name?
352+
- Plan for separating front-end from back-end
353+
- Better handling duplication like metrics-related stuff
354+
- auto-camelize and decamelize http requests
355+
- relying on cancan abilities JSON
356+
- plan for future refactor? giant branches are not fun
357+
358+
---
359+
360+
# References
361+
362+
[John Papa's Styleguide](https://github.com/johnpapa/angular-styleguide)
363+
364+
[AngularUI Router](https://github.com/angular-ui/ui-router)
365+
366+
[Angular Devise](https://github.com/cloudspace/angular_devise)
262367

263-
- PDF export for printed handouts
264-
- Speaker notes and rehearsal mode
265-
- Switch theme and ratio on the fly
266-
- Animated GIFs for cheap wins and LOLs :-)

Deals Api Controller.png

47.9 KB
Loading

camelize-http.png

69.4 KB
Loading

0 commit comments

Comments
 (0)