From 4849247f787fb5e7e775b6fb919da70c5f64e247 Mon Sep 17 00:00:00 2001 From: luis Date: Tue, 3 Nov 2015 21:42:58 -0500 Subject: [PATCH] upgrade to new reflectable --- .gitignore | 6 ++-- .travis.yml | 5 ++++ bin/controllers/employee_controller.dart | 1 + bin/controllers/persons_controller.dart | 1 + bin/server.dart | 28 ++++++++++++------- lib/main_app.dart | 9 ++---- lib/models/employee.dart | 3 +- lib/models/models.dart | 4 ++- lib/models/person.dart | 3 +- lib/models/user.dart | 3 +- lib/sample_employees/sample_employees.dart | 2 +- .../sample_employees_form.dart | 4 +-- lib/sample_persons/sample_persons.dart | 2 +- lib/sample_persons/sample_persons_form.dart | 5 ++-- pubspec.yaml | 13 ++++++--- test/all.dart | 10 ------- test/login_test.dart | 2 +- web/index.html | 6 ++-- web/main.dart | 13 +++++++++ 19 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 .travis.yml delete mode 100644 test/all.dart create mode 100644 web/main.dart diff --git a/.gitignore b/.gitignore index eff06c3..3f86fd5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -20,3 +17,4 @@ packages pubspec.lock /.settings/** /.project +*.iml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ba28c7a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: dart +dart: + - stable + - dev +script: pub run test diff --git a/bin/controllers/employee_controller.dart b/bin/controllers/employee_controller.dart index fad1898..f4de890 100644 --- a/bin/controllers/employee_controller.dart +++ b/bin/controllers/employee_controller.dart @@ -1,5 +1,6 @@ part of drails_example; +@injectable @AuthorizeRoles(const ['ADMIN']) class EmployeesController { diff --git a/bin/controllers/persons_controller.dart b/bin/controllers/persons_controller.dart index 34e08cb..40f6301 100644 --- a/bin/controllers/persons_controller.dart +++ b/bin/controllers/persons_controller.dart @@ -1,5 +1,6 @@ part of drails_example; +@injectable class PersonsController { Person get(int id) => g_persons[id]; diff --git a/bin/server.dart b/bin/server.dart index ad51a37..04665c9 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -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'; @@ -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]); - -} \ No newline at end of file diff --git a/lib/main_app.dart b/lib/main_app.dart index b9e8c73..fd5812e 100644 --- a/lib/main_app.dart +++ b/lib/main_app.dart @@ -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 `` element. @CustomTag('main-app') class MainApp extends PolymerElement { @@ -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); }); } diff --git a/lib/models/employee.dart b/lib/models/employee.dart index 6aac5df..ea1a7c3 100644 --- a/lib/models/employee.dart +++ b/lib/models/employee.dart @@ -1,5 +1,6 @@ -part of models; +part of dson_sample_app_models; +@serializable class Employee extends Person { num salary; } \ No newline at end of file diff --git a/lib/models/models.dart b/lib/models/models.dart index 2d42bc6..7f05a9a 100644 --- a/lib/models/models.dart +++ b/lib/models/models.dart @@ -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'; diff --git a/lib/models/person.dart b/lib/models/person.dart index 5b04a18..6f8ff1c 100644 --- a/lib/models/person.dart +++ b/lib/models/person.dart @@ -1,5 +1,6 @@ -part of models; +part of dson_sample_app_models; +@serializable class Person { int id; String firstName; diff --git a/lib/models/user.dart b/lib/models/user.dart index cdfccfa..fc0cb02 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -1,5 +1,6 @@ -part of models; +part of dson_sample_app_models; +@serializable class User { int id; String name; diff --git a/lib/sample_employees/sample_employees.dart b/lib/sample_employees/sample_employees.dart index f7be38f..20b7371 100644 --- a/lib/sample_employees/sample_employees.dart +++ b/lib/sample_employees/sample_employees.dart @@ -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')); diff --git a/lib/sample_employees/sample_employees_form.dart b/lib/sample_employees/sample_employees_form.dart index 5c52ce1..b39cd30 100644 --- a/lib/sample_employees/sample_employees_form.dart +++ b/lib/sample_employees/sample_employees_form.dart @@ -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) diff --git a/lib/sample_persons/sample_persons.dart b/lib/sample_persons/sample_persons.dart index ac85ec2..164ec7c 100644 --- a/lib/sample_persons/sample_persons.dart +++ b/lib/sample_persons/sample_persons.dart @@ -21,7 +21,7 @@ class SamplePersons extends PolymerElement { ready() { HttpRequest.getString('persons').then((response) { - persons = toObservable(deserializeList(response, Person)); + persons = toObservable(fromJsonList(response, Person)); }); } diff --git a/lib/sample_persons/sample_persons_form.dart b/lib/sample_persons/sample_persons_form.dart index 8a1f520..8cbf718 100644 --- a/lib/sample_persons/sample_persons_form.dart +++ b/lib/sample_persons/sample_persons_form.dart @@ -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 `` element. @CustomTag('sample-persons-form') @@ -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; }); } diff --git a/pubspec.yaml b/pubspec.yaml index 966dd0b..c1d1f5b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/all.dart b/test/all.dart deleted file mode 100644 index 76bc144..0000000 --- a/test/all.dart +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2015, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - -library all_tests; - -import 'login_test.dart'; - -void main() { - loginTests(); -} diff --git a/test/login_test.dart b/test/login_test.dart index c0ad9db..e6291bd 100644 --- a/test/login_test.dart +++ b/test/login_test.dart @@ -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(); diff --git a/web/index.html b/web/index.html index 00037a6..8b4cabe 100644 --- a/web/index.html +++ b/web/index.html @@ -33,8 +33,8 @@ - - + + @@ -48,6 +48,6 @@ - + diff --git a/web/main.dart b/web/main.dart new file mode 100644 index 0000000..60ab4b2 --- /dev/null +++ b/web/main.dart @@ -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] 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 main() { + print(toJson(new Person()..firstName = 'luis')); + return initPolymer().then((zone) => Polymer.onReady.then((_) => zone)); +}