Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
Some dart code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Feb 28, 2014
1 parent f81548d commit b39d557
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 106 deletions.
87 changes: 37 additions & 50 deletions app/dart/backend-app.dart
Expand Up @@ -39,87 +39,74 @@ class FirebaseResultsAdapter {

FirebaseAdapter _results;

FirebaseResultsAdapter() {
this._results = new AngularFire(fb);
}
FirebaseResultsAdapter(): _results = new AngularFire(fb);

getResults() {
return _results;
}
FirebaseAdapter get results => _results;
}

@NgController(
selector: '[system-panel]',
publishAs: 'panel'
)
publishAs: 'panel')
class SystemPanelCtrl {
Scope scope;
final Scope scope;
bool filterOn = false;
FirebaseAdapter results;

SystemPanelCtrl(RouteProvider routeProvider, Scope this.scope, FirebaseResultsAdapter adapter) {
SystemPanelCtrl(RouteProvider routeProvider, this.scope, FirebaseResultsAdapter adapter) {
Map params = routeProvider.parameters;
this.results = adapter.getResults().values;
results = adapter.results.values;
}
}

class SystemEntry {
static statusValues() {
return {
"functional" : "Operations Normal!",
"unpredictable" : "Runs OK ... Sometimes",
"crashing" : "Ughh? What's going on?",
"offline" : "Nope. It's not responding"
};
}

static topicValues() {
return {
"webserver" : "Webserver",
"db" : "Database Engine",
"billing" : "Billing System",
"coffee" : "Coffee Machine"
};
}
static Map<String, String> statusValues() => {
"functional" : "Operations Normal!",
"unpredictable" : "Runs OK ... Sometimes",
"crashing" : "Ughh? What's going on?",
"offline" : "Nope. It's not responding"
};

static Map<String, String> topicValues() => {
"webserver" : "Webserver",
"db" : "Database Engine",
"billing" : "Billing System",
"coffee" : "Coffee Machine"
};

String statusKey, topicKey, status, topic;

SystemEntry(String this.topicKey, String this.statusKey) {
this.topic = SystemEntry.topicValues()[this.topicKey];
this.status = SystemEntry.statusValues()[this.statusKey];
SystemEntry(this.topicKey, this.statusKey) {
topic = SystemEntry.topicValues()[topicKey];
status = SystemEntry.statusValues()[statusKey];
}

export() {
return {
'topicKey' : this.topicKey,
'topic' : this.topic,
'statusKey' : this.statusKey,
'status' : this.status
};
}
export() => {
'topicKey' : this.topicKey,
'topic' : this.topic,
'statusKey' : this.statusKey,
'status' : this.status
};
}

@NgController(
selector: '[entry-form-ctrl]',
publishAs: 'form'
)
publishAs: 'form')
class NewEntryFormCtrl {

Scope _scope;
NgForm _form;
Router _router;
final Scope _scope;
final NgForm _form;
final Router _router;

FirebaseAdapter _results;
String topicKey;
String statusKey;

String statuses;
String topics;

NewEntryFormCtrl(Router this._router, Scope this._scope, NgForm this._form, FirebaseResultsAdapter adapter) {
this.topics = this.formatAsOptions(SystemEntry.topicValues());
this.statuses = this.formatAsOptions(SystemEntry.statusValues());
this._results = adapter.getResults();
NewEntryFormCtrl(this._router, this._scope, this._form, FirebaseResultsAdapter adapter) {
topics = this.formatAsOptions(SystemEntry.topicValues());
statuses = this.formatAsOptions(SystemEntry.statusValues());
_results = adapter.results;
}

formatAsOptions(Map items) {
Expand All @@ -134,7 +121,7 @@ class NewEntryFormCtrl {
}

submit() {
SystemEntry entry = new SystemEntry(this.topicKey, this.statusKey);
SystemEntry entry = new SystemEntry(topicKey, statusKey);
print(entry.export());
this._results.add(entry.export());
this._router.gotoUrl('home');
Expand Down
15 changes: 7 additions & 8 deletions app/dart/examples.dart
Expand Up @@ -82,16 +82,16 @@ class TabsComponent {

void select(var pane) {
for (var i = 0; i < panes.length; i++) {
this.panes[i].selected = false;
panes[i].selected = false;
}
pane.selected = true;
}

void addPane(PaneComponent pane) {
if (this.panes.length == 0) {
this.select(pane);
if (panes.length.isEmpty) {
select(pane);
}
this.panes.add(pane);
panes.add(pane);
}
}

Expand All @@ -101,8 +101,7 @@ class TabsComponent {
cssUrl: 'pane.css',
applyAuthorStyles: true,
publishAs: 'pane',
map: const {'title' : '@'}
)
map: const {'title' : '@'})
class PaneComponent {
String title = '';
bool selected = false;
Expand All @@ -121,14 +120,14 @@ class BeerCounter {

BeerCounter() {
if (Intl.defaultLocale.toString() == 'sk_SK') {
this.getMessage = (beer_count) => Intl.plural(
getMessage = (beer_count) => Intl.plural(
beer_count,
zero: '\u017Eiadne pivo',
one: '$beer_count pivo',
few: '$beer_count piv\u00E1',
other: '$beer_count p\u00EDv');
} else {
this.getMessage = (beer_count) => Intl.plural(
getMessage = (beer_count) => Intl.plural(
beer_count,
zero: 'no beers',
one: '$beer_count beer',
Expand Down
83 changes: 35 additions & 48 deletions app/demo/index.html
Expand Up @@ -576,76 +576,63 @@ <h2>Todo</h2>

FirebaseAdapter _results;

FirebaseResultsAdapter() {
this._results = new AngularFire(fb);
}
FirebaseResultsAdapter(): _results = new AngularFire(fb);

getResults() {
return _results;
}
FirebaseAdapter get result => _results;
}

@NgController(
selector: '[system-panel]',
publishAs: 'panel'
)
selector: '[system-panel]',
publishAs: 'panel')
class SystemPanelCtrl {
Scope scope;
final Scope scope;
bool filterOn = false;
FirebaseAdapter results;

SystemPanelCtrl(RouteProvider routeProvider, Scope this.scope,
FirebaseResultsAdapter adapter) {
Map params = routeProvider.parameters;
this.results = adapter.getResults().values;
results = adapter.results.values;
}
}

class SystemEntry {
static statusValues() {
return {
"functional" : "Operations Normal!",
"unpredictable" : "Runs OK ... Sometimes",
"crashing" : "Ughh? What's going on?",
"offline" : "Nope. It's not responding"
};
}

static topicValues() {
return {
"webserver" : "Webserver",
"db" : "Database Engine",
"billing" : "Billing System",
"coffee" : "Coffee Machine"
};
}
static Map<String, String> statusValues() =>
"functional" : "Operations Normal!",
"unpredictable" : "Runs OK ... Sometimes",
"crashing" : "Ughh? What's going on?",
"offline" : "Nope. It's not responding"
};

static Map<String, String> topicValues() => {
"webserver" : "Webserver",
"db" : "Database Engine",
"billing" : "Billing System",
"coffee" : "Coffee Machine"
};

String statusKey, topicKey, status, topic;

SystemEntry(String this.topicKey, String this.statusKey) {
this.topic = SystemEntry.topicValues()[this.topicKey];
this.status = SystemEntry.statusValues()[this.statusKey];
SystemEntry(this.topicKey, this.statusKey) {
topic = SystemEntry.topicValues()[topicKey];
status = SystemEntry.statusValues()[statusKey];
}

export() {
return {
'topicKey' : this.topicKey,
'topic' : this.topic,
'statusKey' : this.statusKey,
'status' : this.status
};
}
Map<String, String> export() => {
'topicKey' : this.topicKey,
'topic' : this.topic,
'statusKey' : this.statusKey,
'status' : this.status
};
}

@NgController(
selector: '[entry-form-ctrl]',
publishAs: 'form'
)
publishAs: 'form')
class NewEntryFormCtrl {

Scope _scope;
NgForm _form;
Router _router;
final Scope _scope;
final NgForm _form;
final Router _router;

FirebaseAdapter _results;
String topicKey;
Expand Down Expand Up @@ -673,10 +660,10 @@ <h2>Todo</h2>
}

submit() {
SystemEntry entry = new SystemEntry(this.topicKey, this.statusKey);
SystemEntry entry = new SystemEntry(topicKey, statusKey);
print(entry.export());
this._results.add(entry.export());
this._router.gotoUrl('home');
_results.add(entry.export());
_router.gotoUrl('home');
}
}
</script>
Expand Down

0 comments on commit b39d557

Please sign in to comment.