├── .gitignore ├── app ├── stores │ └── registry.js ├── app.js └── components │ ├── calendar │ ├── calendar.js │ └── calendar.html │ └── calendar-cell │ ├── calendar-cell.html │ └── calendar-cell.js ├── README.md ├── package.json └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /deps/ng 3 | Todo.md 4 | node_modules/ 5 | .*.sw* 6 | .idea 7 | -------------------------------------------------------------------------------- /app/stores/registry.js: -------------------------------------------------------------------------------- 1 | var cells = []; 2 | 3 | export function addCell(cell) { 4 | cells.push(cell); 5 | } 6 | 7 | export function searchAllCells() { 8 | for (var i=0; i ("Oct " + day)); 7 | 8 | @Component({ 9 | selector: 'calendar', 10 | }) 11 | @Template({ 12 | url: System.baseURL+'app/components/calendar/calendar.html', 13 | directives: [ 14 | Foreach, 15 | If, 16 | CalendarCell 17 | ] 18 | }) 19 | export class Calendar { 20 | constructor() { 21 | this.hours = _.range(24); 22 | this.days = DAYS; 23 | this.isLoaded = false; 24 | } 25 | load() { 26 | this.isLoaded = true; 27 | } 28 | searchAll() { 29 | searchAllCells(); 30 | } 31 | dayHeaderClicked() { 32 | alert('dayHeaderClicked()'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/components/calendar-cell/calendar-cell.html: -------------------------------------------------------------------------------- 1 | 31 | 32 |
38 |
39 | ... 40 |
41 |
42 | {{hour}}:00 43 |
44 |
45 |
{{status.searchResults.options}}
46 |
results
47 |
48 |
49 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Angular2 Example 5 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 46 | 47 | 48 | 49 |

Angular2 Example

50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/components/calendar/calendar.html: -------------------------------------------------------------------------------- 1 | 60 | 61 |
62 | 63 | 64 | 65 | 66 | 69 | 70 | 71 | 74 | 75 |
67 | {{day}} 68 |
72 | 73 |
76 |
77 | -------------------------------------------------------------------------------- /app/components/calendar-cell/calendar-cell.js: -------------------------------------------------------------------------------- 1 | import {Component, Foreach, Template, If} from 'angular2/angular2'; 2 | import {addCell} from 'stores/registry'; 3 | import {BindingPropagationConfig} from 'angular2/core'; 4 | 5 | var randomMillis = function() { 6 | //return 0; 7 | return Math.floor(Math.random() * 500); 8 | } 9 | 10 | @Component({ 11 | selector: 'calendar-cell', 12 | bind: { 13 | hour: 'hour', 14 | day: 'day' 15 | } 16 | }) 17 | @Template({ 18 | url: System.baseURL+'app/components/calendar-cell/calendar-cell.html', 19 | directives: [ 20 | Foreach, If 21 | ] 22 | }) 23 | export class CalendarCell { 24 | bpc; 25 | 26 | constructor(bpc:BindingPropagationConfig) { 27 | this.isPure = true; 28 | this.bpc = bpc; 29 | if (this.isPure) this.bpc.shouldBePropagated(); 30 | 31 | addCell(this); 32 | this.status = { 33 | isSearching: false, 34 | searchResults: { 35 | options: null 36 | } 37 | } 38 | } 39 | cellClicked() { 40 | var alreadySearching = this.status.isSearching; 41 | this.status.searchResults.options = null; 42 | this.status.isSearching = !alreadySearching; 43 | if (!alreadySearching) { 44 | // Simulate an AJAX request: 45 | var self = this; 46 | self.isSearching = true; 47 | if (this.isPure) this.bpc.shouldBePropagated(); 48 | setTimeout(() => { 49 | self.status.isSearching = false; 50 | self.status.searchResults.options = Math.floor(Math.random() * 5); 51 | if (this.isPure) this.bpc.shouldBePropagated(); 52 | }, randomMillis()); 53 | } 54 | } 55 | showSpinner() { 56 | return this.status.isSearching; 57 | } 58 | hideSpinner() { 59 | return !this.status.isSearching; 60 | } 61 | showTime() { 62 | return !this.status.isSearching && this.status.searchResults.options === null; 63 | } 64 | showSearchResults() { 65 | return !this.status.isSearching && this.status.searchResults.options !== null; 66 | } 67 | } 68 | 69 | --------------------------------------------------------------------------------