Skip to content

Commit

Permalink
upgrade to new reflectable
Browse files Browse the repository at this point in the history
  • Loading branch information
luisvt committed Nov 4, 2015
1 parent f53b911 commit 4849247
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 49 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Don’t commit the following directories created by pub.
build/
packages/
.buildlog
**/packages/
.buildlog
.DS_Store
.idea
.pub/
build/
packages

# Or the files created by dart2js.
*.dart.js
Expand All @@ -20,3 +17,4 @@ packages
pubspec.lock
/.settings/**
/.project
*.iml
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: dart
dart:
- stable
- dev
script: pub run test
1 change: 1 addition & 0 deletions bin/controllers/employee_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of drails_example;

@injectable
@AuthorizeRoles(const ['ADMIN'])
class EmployeesController {

Expand Down
1 change: 1 addition & 0 deletions bin/controllers/persons_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of drails_example;

@injectable
class PersonsController {
Person get(int id) => g_persons[id];

Expand Down
28 changes: 18 additions & 10 deletions bin/server.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library drails_example;

import 'package:drails/drails.dart';
import 'package:drails_di/drails_di.dart';
import 'package:logging/logging.dart';
import 'dart:io';
import 'package:drails_sample_app/models/models.dart';
Expand All @@ -24,20 +25,27 @@ initLogger() {
void main() {
initLogger();

ENV = 'prod';
// ENV = 'prod';

POST['/login'] = (HttpSession session, @RequestBody User user) {
initServer(['drails_example']);
}

@Path('')
@injectable
class LoginController {

@POST
login(HttpSession session, @RequestBody User user) {
var cu = g_users.values.singleWhere((u) => u.name == user.name && u.password == user.password);
if(cu == null) throw Exception;
session['user'] = cu;

return serialize(cu, exclude: 'password');
};

GET['/logout'] = (HttpSession session) {
return toJson(cu, exclude: 'password');
}

@GET
logout(HttpSession session) {
session['user'] = null;
};
}
}

initServer([#drails_example]);

}
9 changes: 3 additions & 6 deletions lib/main_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import 'package:drails_sample_app/models/models.dart';
import 'dart:html';
import 'package:dson/dson.dart';

@MirrorsUsed(targets:const['models'], override:'*')
import 'dart:mirrors';

/// A Polymer `<main-app>` element.
@CustomTag('main-app')
class MainApp extends PolymerElement {
Expand All @@ -24,15 +21,15 @@ class MainApp extends PolymerElement {
});
var usrStr = window.sessionStorage['user'];
if(usrStr != null)
user = deserialize(usrStr, User);
user = fromJson(usrStr, User);
else
user = new User();
}

login(Event e, details, Element target) {
HttpRequest.request("login", method: 'POST', sendData: serialize(user)).then((request) {
HttpRequest.request("login", method: 'POST', sendData: toJson(user)).then((request) {
window.sessionStorage['user'] = request.response;
user = deserialize(request.response, User);
user = fromJson(request.response, User);
});
}

Expand Down
3 changes: 2 additions & 1 deletion lib/models/employee.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of models;
part of dson_sample_app_models;

@serializable
class Employee extends Person {
num salary;
}
4 changes: 3 additions & 1 deletion lib/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
/// The models library.
///
/// This is an awesome library. More dartdocs go here.
library models;
library dson_sample_app_models;

import 'package:dson/dson.dart';

part 'user.dart';
part 'person.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/models/person.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of models;
part of dson_sample_app_models;

@serializable
class Person {
int id;
String firstName;
Expand Down
3 changes: 2 additions & 1 deletion lib/models/user.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of models;
part of dson_sample_app_models;

@serializable
class User {
int id;
String name;
Expand Down
2 changes: 1 addition & 1 deletion lib/sample_employees/sample_employees.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SampleEmployees extends PolymerElement {

ready() {
HttpRequest.getString('employees').then((response) {
employees = toObservable(deserializeList(response, Employee));
employees = toObservable(fromJsonList(response, Employee));
}, onError: (ProgressEvent e) {
if((e.target as HttpRequest).status == 401)
window.dispatchEvent(new CustomEvent('show-login'));
Expand Down
4 changes: 2 additions & 2 deletions lib/sample_employees/sample_employees_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class SampleEmployeesForm extends PolymerElementExt {
}

void saveEmployee(Event e, detail, Element target) {
HttpRequest.request('employees', method: 'POST', sendData: serialize(employeeAux)).then((request) {
fire('employee-saved', detail: deserialize(request.response, Employee));
HttpRequest.request('employees', method: 'POST', sendData: toJson(employeeAux)).then((request) {
fire('employee-saved', detail: fromJson(request.response, Employee));
editing = false;
}, onError: (ProgressEvent re) {
if((re.target as HttpRequest).status == 401)
Expand Down
2 changes: 1 addition & 1 deletion lib/sample_persons/sample_persons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SamplePersons extends PolymerElement {

ready() {
HttpRequest.getString('persons').then((response) {
persons = toObservable(deserializeList(response, Person));
persons = toObservable(fromJsonList(response, Person));
});
}

Expand Down
5 changes: 2 additions & 3 deletions lib/sample_persons/sample_persons_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:drails_sample_app/models/models.dart';
import 'dart:html';
import 'package:dson/dson.dart';
import 'package:drails_sample_app/PolymerElementExt.dart';
import 'package:paper_elements/paper_input.dart';

/// A Polymer `<sample-persons-form>` element.
@CustomTag('sample-persons-form')
Expand Down Expand Up @@ -39,8 +38,8 @@ class SamplePersonsForm extends PolymerElementExt {
}

void savePerson(Event e, detail, Element target) {
HttpRequest.request('persons', method: 'POST', sendData: serialize(personAux)).then((request) {
fire('person-saved', detail: deserialize(request.response, Person));
HttpRequest.request('persons', method: 'POST', sendData: toJson(personAux)).then((request) {
fire('person-saved', detail: fromJson(request.response, Person));
editing = false;
});
}
Expand Down
13 changes: 9 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
browser: any
drails: 0.1.3+3
paper_elements: '>=0.6.1 <0.7.0'
polymer: '>=0.15.4 <0.16.0'
drails: #0.1.3+3
path: ../drails
paper_elements: '^0.7.0'
polymer: '^0.16.0'
sprintf: any
reflectable:
path: ../reflectable/reflectable
dev_dependencies:
unittest: any
transformers:
- reflectable:
entry_points:
- web/main.dart
- polymer:
entry_point: web/index.html
- $dart2js:
$exclude:
- bin/server.dart
- test/all.dart
$include: web/index.html_bootstrap.dart
10 changes: 0 additions & 10 deletions test/all.dart

This file was deleted.

2 changes: 1 addition & 1 deletion test/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library drails_sample_app_test;
import 'package:unittest/unittest.dart';
import '../bin/server.dart' as server;
import 'package:http/http.dart';
import 'package:drails/drails.dart';
import 'package:drails/drails.dart' hide POST;

void main() => loginTests();

Expand Down
6 changes: 3 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<meta name="msapplication-TileImage" content="images/touch/ms-touch-icon-144x144-precomposed.png">
<meta name="msapplication-TileColor" content="#3372DF">

<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="packages/polymer/polymer.html">

<!-- example of using a paper element -->
<link rel="import" href="packages/paper_elements/roboto.html">

Expand All @@ -48,6 +48,6 @@

<main-app></main-app>

<script type="application/dart">export "package:polymer/init.dart";</script>
<script type="application/dart" src="main.dart"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//export "package:polymer/init.dart";
import 'package:dson/dson.dart';
import 'dart:async';
import 'package:polymer/polymer.dart';
import 'package:drails_sample_app/models/models.dart';

/// Returns a [Future<Zone>] that code should be executed in for dirty checking.
/// The returned future will complete once polymer is ready and all @initMethod
/// and @whenPolymerReady functions have been executed.
Future<Zone> main() {
print(toJson(new Person()..firstName = 'luis'));
return initPolymer().then((zone) => Polymer.onReady.then((_) => zone));
}

0 comments on commit 4849247

Please sign in to comment.