diff --git a/client/collection_view.coffee b/client/collection_view.coffee index 0623e17..590b3cd 100644 --- a/client/collection_view.coffee +++ b/client/collection_view.coffee @@ -27,7 +27,7 @@ get_filter_query = (collection) -> resubscribe = (name) -> # Stop the old subscription and resubscribe with the new filter/sort subscription_name = "_houston_#{name}" - Houston._paginated_subscription.stop() + Houston._paginated_subscription?.stop() Houston._paginated_subscription = Meteor.subscribeWithPagination subscription_name, get_sort_by(), get_filter_query(Houston._get_collection(name)), @@ -48,17 +48,17 @@ Template._houston_collection_view.helpers num_of_records: -> collection_count(@name) or "no" pluralize: -> 's' unless collection_count(@name) == 1 rows: -> - collection = @name - documents = this?.find(get_filter_query(Houston._get_collection(collection)), {sort: get_sort_by()}).fetch() - _.map documents, (d) -> - d.collection = collection + collection = Houston._get_collection(@name) + documents = collection?.find(get_filter_query(collection), {sort: get_sort_by()}).fetch() + _.map documents, (d) => + d.collection = @name d._id = d._id._str or d._id return d values_in_order: -> fields_in_order = get_collection_view_fields(@collection) names_in_order = _.clone fields_in_order values = (Houston._nested_field_lookup(@, field.name) for field in fields_in_order[1..]) # skip _id - ({field_value: field_value.toString(), field_name, collection: @collection} for [field_value, {name:field_name}] in _.zip values, names_in_order[1..]) + ({field_value: field_value.toString(), field_name, @collection} for [field_value, {name: field_name}] in _.zip values, names_in_order[1..]) filter_value: -> if Houston._session('field_selectors') and Houston._session('field_selectors')[@] Houston._session('field_selectors')[@] diff --git a/client/collection_view.html b/client/collection_view.html index e0c74cd..609a6d5 100644 --- a/client/collection_view.html +++ b/client/collection_view.html @@ -92,7 +92,7 @@

{{#each rows }} - {{_id}} {{#each values_in_order}} diff --git a/client/db_view.coffee b/client/db_view.coffee index 3de30c4..df95e41 100644 --- a/client/db_view.coffee +++ b/client/db_view.coffee @@ -7,10 +7,14 @@ filterCollections = (query, collections) -> else collections + Template._houston_db_view.helpers - collections: -> @collections + collections: -> Houston._collections.collections filtered_collections: -> - filterCollections(Houston._session('search'), @collections.find().fetch()) + filterCollections( + Houston._session('search'), + Houston._collections.collections.find().fetch() + ) Template._houston_db_view.events # trigger meteor session invalidation, definitely a hack diff --git a/client/document_view.coffee b/client/document_view.coffee index d0ff919..4f84246 100644 --- a/client/document_view.coffee +++ b/client/document_view.coffee @@ -19,10 +19,11 @@ Template._houston_document_view.events 'click #houston-save': (e) -> e.preventDefault() update_dict = {} + collection = Houston._get_collection(@name) for field in $('.houston-field') field_name = field.name.split(' ')[0] unless field_name is '_id' - update_dict[field_name] = Houston._convert_to_correct_type(field_name, field.value, @collection) + update_dict[field_name] = Houston._convert_to_correct_type(field_name, field.value, collection) Houston._call("#{@name}_update", @document._id, $set: update_dict, Houston._show_flash) 'click #houston-delete': (e) -> diff --git a/client/master_layout.html b/client/master_layout.html index fdd8ce3..3fa6759 100644 --- a/client/master_layout.html +++ b/client/master_layout.html @@ -13,7 +13,8 @@ {{> _houston_sidenav}}
- {{> yield}} + {{> Template.dynamic template=template data=data}} + {{> _houston_flash_message }}
diff --git a/client/router.coffee b/client/router.coffee index 43a9bfb..29d000e 100644 --- a/client/router.coffee +++ b/client/router.coffee @@ -25,7 +25,7 @@ Houston._houstonize_route = (name) -> Houston._houstonize(name)[1..] Houston._go = (route_name, options) -> - Router.go Houston._houstonize_route(route_name), options + FlowRouter.go Houston._houstonize_route(route_name), options houston_route = (route_name, options) => @@ -37,12 +37,16 @@ houston_route = (route_name, options) => subscriptions = if options.subs then options.subs(this.params) else [] subscriptions.push Houston._subscribe('admin_user') subscriptions - Router.route "#{Houston._ROOT_ROUTE}#{options.houston_path}", options + options.action = (params) -> + # keep iron-router style this.params working via .call + data = options.data?.call({params}) + BlazeLayout.render options.layoutTemplate, + {template: options.template, data} + FlowRouter.route "#{Houston._ROOT_ROUTE}#{options.houston_path}", options houston_route 'home', houston_path: '/' template: 'db_view' - data: -> collections: Houston._collections.collections waitOn: -> Houston._collections houston_route 'login', @@ -60,7 +64,7 @@ houston_route 'custom_template', houston_route 'collection', houston_path: "/:collection_name" - data: -> Houston._get_collection(@params.collection_name) + data: -> {name: @params.collection_name} subs: (params) -> [setup_collection(params.collection_name)] template: 'collection_view' @@ -70,7 +74,7 @@ houston_route 'document', @subscription = setup_collection(@params.collection, @params._id) collection = Houston._get_collection(@params.collection) document = collection.findOne _id: @params._id - {document, collection, name: @params.collection} + {document, name: @params.collection} template: 'document_view' # ######## @@ -79,34 +83,38 @@ houston_route 'document', mustBeAdmin = -> if !Meteor.user() if Meteor.loggingIn() - @render 'houstonLoading' + console.log "logging in, TODO(AMK) do a nice job" else Houston._go 'login' else - if @ready() and not Houston._user_is_admin Meteor.userId() + console.log "should check if ready I guess... TODO(AMK) " + if not Houston._user_is_admin Meteor.userId() Houston._go 'login' - else - @next() # If the host app doesn't have a router, their html may show up hide_non_admin_stuff = -> $('body').css('visibility', 'hidden').children().hide() $('body>.houston').show() - @next() remove_host_css = -> $('link[rel="stylesheet"]').remove() - @next() BASE_HOUSTON_ROUTES = (Houston._houstonize_route(name) for name in ['home', 'collection', 'document', 'change_password', 'custom_template']) ALL_HOUSTON_ROUTES = BASE_HOUSTON_ROUTES.concat([Houston._houstonize_route('login')]) -Router.onBeforeAction mustBeAdmin, only: BASE_HOUSTON_ROUTES -Router.onBeforeAction hide_non_admin_stuff, only: ALL_HOUSTON_ROUTES -Router.onBeforeAction remove_host_css, only: ALL_HOUSTON_ROUTES - -onRouteNotFound = Router.onRouteNotFound -Router.onRouteNotFound = (args...) -> - non_houston_routes = _.filter(Router.routes, (route) -> route.name.indexOf('houston_') != 0) - if non_houston_routes.length > 0 - onRouteNotFound.apply Router, args - else - console.log "Note: Houston is suppressing Iron-Router errors because we don't think you are using it." +FlowRouter.triggers.enter([mustBeAdmin], only: BASE_HOUSTON_ROUTES) +FlowRouter.triggers.enter( + [hide_non_admin_stuff, remove_host_css], + only: ALL_HOUSTON_ROUTES) + +Template.registerHelper 'pathFor', (route, args) -> + FlowRouter.path(route, args.hash) + +originalNotFound = FlowRouter.notFound +FlowRouter.notFound = + action: (args...) -> + non_houston_routes = _.filter( + FlowRouter._routes, + (route) -> route.name? and route.name.indexOf('houston_') != 0) + if non_houston_routes.length > 0 + originalNotFound.action(args...) + else + console.log "Note: Houston is suppressing Iron-Router errors because we don't think you are using it." diff --git a/package.js b/package.js index 491f0b6..3e95362 100644 --- a/package.js +++ b/package.js @@ -24,7 +24,10 @@ Package.on_use(function(api) { ////////////////////////////////////////////////////////////////// // Third-party package dependencies ////////////////////////////////////////////////////////////////// - api.use('iron:router@1.0.1', 'client'); + + api.use('kadira:flow-router@2.8.0', 'client'); + api.use('kadira:blaze-layout@2.2.0', 'client'); + api.use('tmeasday:paginated-subscription@0.2.4', 'client'); api.use('dburles:mongo-collection-instances@0.3.4', ['client', 'server']); diff --git a/test/route-test-app/.meteor/.finished-upgraders b/test/route-test-app/.meteor/.finished-upgraders new file mode 100644 index 0000000..61ee313 --- /dev/null +++ b/test/route-test-app/.meteor/.finished-upgraders @@ -0,0 +1,12 @@ +# This file contains information which helps Meteor properly upgrade your +# app when you run 'meteor update'. You should check it into version control +# with your project. + +notices-for-0.9.0 +notices-for-0.9.1 +0.9.4-platform-file +notices-for-facebook-graph-api-2 +1.2.0-standard-minifiers-package +1.2.0-meteor-platform-split +1.2.0-cordova-changes +1.2.0-breaking-changes diff --git a/test/route-test-app/.meteor/.gitignore b/test/route-test-app/.meteor/.gitignore new file mode 100644 index 0000000..4083037 --- /dev/null +++ b/test/route-test-app/.meteor/.gitignore @@ -0,0 +1 @@ +local diff --git a/test/route-test-app/.meteor/.id b/test/route-test-app/.meteor/.id new file mode 100644 index 0000000..3ae4c1b --- /dev/null +++ b/test/route-test-app/.meteor/.id @@ -0,0 +1,7 @@ +# This file contains a token that is unique to your project. +# Check it into your repository along with the rest of this directory. +# It can be used for purposes such as: +# - ensuring you don't accidentally deploy one app on top of another +# - providing package authors with aggregated statistics + +1wiz6wtybu4fj1vmrr8m diff --git a/test/route-test-app/.meteor/packages b/test/route-test-app/.meteor/packages new file mode 100644 index 0000000..334bfd8 --- /dev/null +++ b/test/route-test-app/.meteor/packages @@ -0,0 +1,23 @@ +# Meteor packages used by this project, one per line. +# Check this file (and the other files in this directory) into your repository. +# +# 'meteor add' and 'meteor remove' will edit this file for you, +# but you can also edit it by hand. + +meteor-base # Packages every Meteor app needs to have +mobile-experience # Packages for a great mobile UX +mongo # The database Meteor supports right now +blaze-html-templates # Compile .html files into Meteor Blaze views +session # Client-side reactive dictionary for your app +jquery # Helpful client-side library +tracker # Meteor's client-side reactive programming library + +standard-minifiers # JS/CSS minifiers run for production mode +es5-shim # ECMAScript 5 compatibility for older browsers. +ecmascript # Enable ECMAScript2015+ syntax in app code + +autopublish # Publish all data to the clients (for prototyping) +insecure # Allow all DB writes from clients (for prototyping) +kadira:flow-router +kadira:blaze-layout +houston:admin diff --git a/test/route-test-app/.meteor/platforms b/test/route-test-app/.meteor/platforms new file mode 100644 index 0000000..efeba1b --- /dev/null +++ b/test/route-test-app/.meteor/platforms @@ -0,0 +1,2 @@ +server +browser diff --git a/test/route-test-app/.meteor/release b/test/route-test-app/.meteor/release new file mode 100644 index 0000000..3a05e0a --- /dev/null +++ b/test/route-test-app/.meteor/release @@ -0,0 +1 @@ +METEOR@1.2.1 diff --git a/test/route-test-app/.meteor/versions b/test/route-test-app/.meteor/versions new file mode 100644 index 0000000..78e49de --- /dev/null +++ b/test/route-test-app/.meteor/versions @@ -0,0 +1,84 @@ +accounts-base@1.2.2 +accounts-password@1.1.4 +autopublish@1.0.4 +autoupdate@1.2.4 +babel-compiler@5.8.24_1 +babel-runtime@0.1.4 +base64@1.0.4 +binary-heap@1.0.4 +blaze@2.1.3 +blaze-html-templates@1.0.1 +blaze-tools@1.0.4 +boilerplate-generator@1.0.4 +caching-compiler@1.0.0 +caching-html-compiler@1.0.2 +callback-hook@1.0.4 +check@1.1.0 +coffeescript@1.0.11 +cosmos:browserify@0.5.1 +dburles:mongo-collection-instances@0.3.4 +ddp@1.2.2 +ddp-client@1.2.1 +ddp-common@1.2.2 +ddp-rate-limiter@1.0.0 +ddp-server@1.2.2 +deps@1.0.9 +diff-sequence@1.0.1 +ecmascript@0.1.6 +ecmascript-runtime@0.2.6 +ejson@1.0.7 +email@1.0.8 +es5-shim@4.1.14 +fastclick@1.0.7 +geojson-utils@1.0.4 +hot-code-push@1.0.0 +houston:admin@2.0.6 +html-tools@1.0.5 +htmljs@1.0.5 +http@1.1.1 +id-map@1.0.4 +insecure@1.0.4 +jquery@1.11.4 +kadira:blaze-layout@2.2.0 +kadira:flow-router@2.8.0 +lai:collection-extensions@0.1.4 +launch-screen@1.0.4 +livedata@1.0.15 +localstorage@1.0.5 +logging@1.0.8 +meteor@1.1.10 +meteor-base@1.0.1 +minifiers@1.1.7 +minimongo@1.0.10 +mobile-experience@1.0.1 +mobile-status-bar@1.0.6 +mongo@1.1.3 +mongo-id@1.0.1 +npm-bcrypt@0.7.8_2 +npm-mongo@1.4.39_1 +observe-sequence@1.0.7 +ordered-dict@1.0.4 +promise@0.5.1 +random@1.0.5 +rate-limit@1.0.0 +reactive-dict@1.1.3 +reactive-var@1.0.6 +reload@1.1.4 +retry@1.0.4 +routepolicy@1.0.6 +service-configuration@1.0.5 +session@1.1.1 +sha@1.0.4 +spacebars@1.0.7 +spacebars-compiler@1.0.7 +srp@1.0.4 +standard-minifiers@1.0.2 +templating@1.1.5 +templating-tools@1.0.0 +tmeasday:paginated-subscription@0.2.4 +tracker@1.0.9 +ui@1.0.8 +underscore@1.0.4 +url@1.0.5 +webapp@1.2.3 +webapp-hashing@1.0.5 diff --git a/test/route-test-app/packages/houston:admin b/test/route-test-app/packages/houston:admin new file mode 120000 index 0000000..1b20c9f --- /dev/null +++ b/test/route-test-app/packages/houston:admin @@ -0,0 +1 @@ +../../../ \ No newline at end of file diff --git a/test/route-test-app/route-test-app.css b/test/route-test-app/route-test-app.css new file mode 100644 index 0000000..b6b4052 --- /dev/null +++ b/test/route-test-app/route-test-app.css @@ -0,0 +1 @@ +/* CSS declarations go here */ diff --git a/test/route-test-app/route-test-app.html b/test/route-test-app/route-test-app.html new file mode 100644 index 0000000..c445cfc --- /dev/null +++ b/test/route-test-app/route-test-app.html @@ -0,0 +1,9 @@ + + + diff --git a/test/route-test-app/route-test-app.js b/test/route-test-app/route-test-app.js new file mode 100644 index 0000000..2348883 --- /dev/null +++ b/test/route-test-app/route-test-app.js @@ -0,0 +1,75 @@ +Posts = new Meteor.Collection("posts"); +globalCollection = new Meteor.Collection("GlobalCollection"); + +if (Meteor.isClient) { + // counter starts at 0 + Session.setDefault('counter', 0); + +// Router.route('/routeme', function () { +// this.render('hello'); +// }); + + FlowRouter.route('/routeme/:stuff', { + action: function(params, queryParams) { + console.log("Yeah! We are on the post:", params.stuff); + BlazeLayout.render('mainLayout', {content: 'hello'}); + } + }); + + Template.hello.helpers({ + counter: function () { + return Session.get('counter'); + } + }); + + Template.hello.events({ + 'click button': function () { + // increment the counter when button is clicked + Session.set('counter', Session.get('counter') + 1); + } + }); +} + +if (Meteor.isServer) { + Meteor.methods({ + "test/clear_users": function() { + Meteor.users.remove({}); + Houston._admins.remove({}); + } + }); + + Meteor.startup(function () { + // Local variable so it needs to be added to Houston manually + // var hiddenCollection = new Meteor.Collection("HiddenCollection"); + + globalCollection.remove({}); + Meteor.users.remove({}); + Houston._admins.remove({}); + //Houston._collections.collections.remove({}); + // hiddenCollection.remove({}); + Posts.remove({}); + Houston.methods(Posts, { + "Publish": function (post) { + Posts.update(post._id, {$set: {published: true}}); + return post.title + " has been published."; + } + }); + + + //Houston.add_collection(hiddenCollection); + + Posts.insert({title:"First Post", author: "Rocketman", body: "So excited"}); + Posts.insert({title:"Welcome to Houston", author: "Rocketman", body: "Great to be here"}); + // code to run on server at startup + if (!globalCollection.findOne()) { + //hiddenCollection.insert({str: "hidden test", bool: true}); + _.range(1000).forEach(function(number) { + globalCollection.insert({ + str: "test" + number, + number: number + }); + }); + console.log("loading done"); + } + }); +} diff --git a/test/test_app/.meteor/versions b/test/test_app/.meteor/versions index 1585651..dc37943 100644 --- a/test/test_app/.meteor/versions +++ b/test/test_app/.meteor/versions @@ -30,7 +30,7 @@ email@1.0.7 fastclick@1.0.7 geojson-utils@1.0.4 hot-code-push@1.0.0 -houston:admin@2.0.5 +houston:admin@2.0.6 html-tools@1.0.5 htmljs@1.0.5 http@1.1.1