|
| 1 | +library benchmarks.src.naive_infinite_scroll.cells; |
| 2 | + |
| 3 | +import "package:angular2/src/facade/collection.dart" |
| 4 | + show List, ListWrapper, Map; |
| 5 | +import "common.dart" |
| 6 | + show Company, Opportunity, Offering, Account, CustomDate, STATUS_LIST; |
| 7 | +import "package:angular2/directives.dart" show NgFor; |
| 8 | +import "package:angular2/angular2.dart" show Component, Directive, View; |
| 9 | + |
| 10 | +class HasStyle { |
| 11 | + int cellWidth; |
| 12 | + HasStyle() {} |
| 13 | + set width(int w) { |
| 14 | + this.cellWidth = w; |
| 15 | + } |
| 16 | +} |
| 17 | +@Component( |
| 18 | + selector: "company-name", |
| 19 | + properties: const ["width: cell-width", "company"], |
| 20 | + changeDetection: "ON_PUSH_OBSERVE" |
| 21 | +) |
| 22 | +@View( |
| 23 | + directives: const [], |
| 24 | + template: '''<div [style.width.px]="cellWidth">{{company.name}}</div>''' |
| 25 | +) |
| 26 | +class CompanyNameComponent extends HasStyle { |
| 27 | + Company company; |
| 28 | +} |
| 29 | +@Component( |
| 30 | + selector: "opportunity-name", |
| 31 | + properties: const ["width: cell-width", "opportunity"], |
| 32 | + changeDetection: "ON_PUSH_OBSERVE" |
| 33 | +) |
| 34 | +@View( |
| 35 | + directives: const [], |
| 36 | + template: '''<div [style.width.px]="cellWidth">{{opportunity.name}}</div>''' |
| 37 | +) |
| 38 | +class OpportunityNameComponent extends HasStyle { |
| 39 | + Opportunity opportunity; |
| 40 | +} |
| 41 | +@Component( |
| 42 | + selector: "offering-name", |
| 43 | + properties: const ["width: cell-width", "offering"], |
| 44 | + changeDetection: "ON_PUSH_OBSERVE" |
| 45 | +) |
| 46 | +@View( |
| 47 | + directives: const [], |
| 48 | + template: '''<div [style.width.px]="cellWidth">{{offering.name}}</div>''' |
| 49 | +) |
| 50 | +class OfferingNameComponent extends HasStyle { |
| 51 | + Offering offering; |
| 52 | +} |
| 53 | +class Stage { |
| 54 | + String name; |
| 55 | + bool isDisabled; |
| 56 | + String backgroundColor; |
| 57 | + Function apply; |
| 58 | +} |
| 59 | +@Component( |
| 60 | + selector: "stage-buttons", |
| 61 | + properties: const ["width: cell-width", "offering"], |
| 62 | + changeDetection: "ON_PUSH_OBSERVE" |
| 63 | +) |
| 64 | +@View(directives: const [NgFor], template: ''' |
| 65 | + <div [style.width.px]="cellWidth"> |
| 66 | + <button template="ng-for #stage of stages" |
| 67 | + [disabled]="stage.isDisabled" |
| 68 | + [style.background-color]="stage.backgroundColor" |
| 69 | + on-click="setStage(stage)"> |
| 70 | + {{stage.name}} |
| 71 | + </button> |
| 72 | + </div>''') |
| 73 | +class StageButtonsComponent extends HasStyle { |
| 74 | + Offering _offering; |
| 75 | + List<Stage> stages; |
| 76 | + Offering get offering { |
| 77 | + return this._offering; |
| 78 | + } |
| 79 | + set offering(Offering offering) { |
| 80 | + this._offering = offering; |
| 81 | + this._computeStageButtons(); |
| 82 | + } |
| 83 | + setStage(Stage stage) { |
| 84 | + this._offering.status = stage.name; |
| 85 | + this._offering.name = this._offering.name + "!"; |
| 86 | + this._computeStageButtons(); |
| 87 | + } |
| 88 | + _computeStageButtons() { |
| 89 | + var disabled = true; |
| 90 | + this.stages = ListWrapper.clone(STATUS_LIST.map((status) { |
| 91 | + var isCurrent = this._offering.status == status; |
| 92 | + var stage = new Stage(); |
| 93 | + stage.name = status; |
| 94 | + stage.isDisabled = disabled; |
| 95 | + stage.backgroundColor = disabled ? "#DDD" : isCurrent ? "#DDF" : "#FDD"; |
| 96 | + if (isCurrent) { |
| 97 | + disabled = false; |
| 98 | + } |
| 99 | + return stage; |
| 100 | + }).toList()); |
| 101 | + } |
| 102 | +} |
| 103 | +@Component( |
| 104 | + selector: "account-cell", |
| 105 | + properties: const ["width: cell-width", "account"], |
| 106 | + changeDetection: "ON_PUSH_OBSERVE" |
| 107 | +) |
| 108 | +@View(directives: const [], template: ''' |
| 109 | + <div [style.width.px]="cellWidth"> |
| 110 | + <a href="/account/{{account.accountId}}"> |
| 111 | + {{account.accountId}} |
| 112 | + </a> |
| 113 | + </div>''') |
| 114 | +class AccountCellComponent extends HasStyle { |
| 115 | + Account account; |
| 116 | +} |
| 117 | +@Component( |
| 118 | + selector: "formatted-cell", |
| 119 | + properties: const ["width: cell-width", "value"], |
| 120 | + changeDetection: "ON_PUSH_OBSERVE" |
| 121 | +) |
| 122 | +@View( |
| 123 | + directives: const [], |
| 124 | + template: '''<div [style.width.px]="cellWidth">{{formattedValue}}</div>''') |
| 125 | +class FormattedCellComponent extends HasStyle { |
| 126 | + String formattedValue; |
| 127 | + set value(value) { |
| 128 | + if (value is CustomDate) { |
| 129 | + this.formattedValue = |
| 130 | + '''${ value . month}/${ value . day}/${ value . year}'''; |
| 131 | + } else { |
| 132 | + this.formattedValue = value.toString(); |
| 133 | + } |
| 134 | + } |
| 135 | +} |
0 commit comments