From 8f03d38d166338a2a549b7d0ba6d5c8a6cc7465a Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 26 Jan 2018 13:50:10 -0300 Subject: [PATCH] update commit --- .../components/ordered-filtered-table.coffee | 8 +++++ addon/helpers/dunlop-can.coffee | 2 ++ .../components/ordered-filtered-table.hbs | 24 ++++++++++++++ .../ordered-filtered-table/property.emblem | 1 + addon/utils/paged-remote-array.coffee | 22 +++++++++++++ app/components/ordered-filtered-table.js | 1 + .../ordered-filtered-table/property.js | 1 + package.json | 18 +++++------ tests/dummy/app/router.coffee | 3 ++ .../app/routes/table-ordering/test1.coffee | 32 +++++++++++++++++++ .../app/templates/global/-top-menu.emblem | 2 ++ .../app/templates/table-ordering/test1.emblem | 13 ++++++++ .../app/templates/table-ordering/test2.emblem | 1 + .../ordered-filtered-table-test.coffee | 25 +++++++++++++++ .../property-test.coffee | 25 +++++++++++++++ 15 files changed, 169 insertions(+), 9 deletions(-) create mode 100644 addon/components/ordered-filtered-table.coffee create mode 100644 addon/templates/components/ordered-filtered-table.hbs create mode 100644 addon/templates/components/ordered-filtered-table/property.emblem create mode 100644 addon/utils/paged-remote-array.coffee create mode 100644 app/components/ordered-filtered-table.js create mode 100644 app/components/ordered-filtered-table/property.js create mode 100644 tests/dummy/app/routes/table-ordering/test1.coffee create mode 100644 tests/dummy/app/templates/table-ordering/test1.emblem create mode 100644 tests/dummy/app/templates/table-ordering/test2.emblem create mode 100644 tests/integration/components/ordered-filtered-table-test.coffee create mode 100644 tests/integration/components/ordered-filtered-table/property-test.coffee diff --git a/addon/components/ordered-filtered-table.coffee b/addon/components/ordered-filtered-table.coffee new file mode 100644 index 0000000..c53658a --- /dev/null +++ b/addon/components/ordered-filtered-table.coffee @@ -0,0 +1,8 @@ +import Ember from 'ember' +import layout from '../templates/components/ordered-filtered-table' + +export default Ember.Component.extend + layout: layout + tagName: 'table' + classNames: ['ui', 'compact', 'table'] + test_name: 'Oooo' diff --git a/addon/helpers/dunlop-can.coffee b/addon/helpers/dunlop-can.coffee index 2ed9446..c3ce80b 100644 --- a/addon/helpers/dunlop-can.coffee +++ b/addon/helpers/dunlop-can.coffee @@ -7,6 +7,8 @@ import Ember from 'ember' # export default DunlopCan.extend # # allow all epots scoped model on read adpter permission # custom_compute: (permission, type, target, roles) -> +# return true if 'manage-adapter-epots' in roles +# # if permission is 'read' and type is 'model' and target.match(/^epots/) # return 'read-adapter-epots' in roles # false diff --git a/addon/templates/components/ordered-filtered-table.hbs b/addon/templates/components/ordered-filtered-table.hbs new file mode 100644 index 0000000..6332270 --- /dev/null +++ b/addon/templates/components/ordered-filtered-table.hbs @@ -0,0 +1,24 @@ + + + {{#each properties as |p|}} + {{p.header}} + {{/each}} + + + {{#each properties as |p|}} + {{p.filter}} + {{/each}} + + + +{{#each content as |record|}} + + {{#each properties as |p|}} + {{p.display record=record}} + {{/each}} + +{{/each}} + +{{yield (hash + property=(component "ordered-filtered-table/property" table=self) +)}} diff --git a/addon/templates/components/ordered-filtered-table/property.emblem b/addon/templates/components/ordered-filtered-table/property.emblem new file mode 100644 index 0000000..0a90f09 --- /dev/null +++ b/addon/templates/components/ordered-filtered-table/property.emblem @@ -0,0 +1 @@ += yield diff --git a/addon/utils/paged-remote-array.coffee b/addon/utils/paged-remote-array.coffee new file mode 100644 index 0000000..84ae631 --- /dev/null +++ b/addon/utils/paged-remote-array.coffee @@ -0,0 +1,22 @@ +import PagedRemoteArray from 'ember-cli-pagination/remote/paged-remote-array' + +export default PagedRemoteArray.extend + a: 42 + #params: {} + filters: {} + init: -> + query = @get('filters')?.toProperties() || {} + @otherParams ||= {} + @otherParams['q'] = query + #@setOtherParam('q', query) # explicitly not, init does not trigger operational callbacks + @_super arguments... + reload: -> + query = @get('filters')?.toProperties() || {} + @set 'page', 1 + @set 'lastPage', null + @setOtherParam('q', query) + paramMapping: + total_pages: 'total-pages' + total_count: 'total-count' + + diff --git a/app/components/ordered-filtered-table.js b/app/components/ordered-filtered-table.js new file mode 100644 index 0000000..b587e02 --- /dev/null +++ b/app/components/ordered-filtered-table.js @@ -0,0 +1 @@ +export { default } from 'ember-cli-dunlop/components/ordered-filtered-table'; diff --git a/app/components/ordered-filtered-table/property.js b/app/components/ordered-filtered-table/property.js new file mode 100644 index 0000000..d372ba1 --- /dev/null +++ b/app/components/ordered-filtered-table/property.js @@ -0,0 +1 @@ +export { default } from 'ember-cli-dunlop/components/ordered-filtered-table/property'; diff --git a/package.json b/package.json index 29ea3b0..d3ac844 100644 --- a/package.json +++ b/package.json @@ -26,27 +26,27 @@ }, "devDependencies": { "broccoli-asset-rev": "^2.4.5", - "ember-ajax": "^2.4.1", - "ember-cli": "2.12.1", + "ember-ajax": "^3.0.0", + "ember-cli": "2.16.2", "ember-cli-coffeescript": "^1.16.1", "ember-cli-dependency-checker": "^1.3.0", - "ember-cli-eslint": "^3.0.0", - "ember-cli-htmlbars-inline-precompile": "^0.3.6", + "ember-cli-eslint": "^4.2.3", + "ember-cli-htmlbars-inline-precompile": "^1.0.2", "ember-cli-inject-live-reload": "^1.4.1", "ember-cli-moment-shim": "^3.5.0", "ember-cli-pagination": "^3.0.2", - "ember-cli-qunit": "^3.1.0", + "ember-cli-qunit": "^4.3.0", "ember-cli-shims": "^1.0.2", "ember-cli-sri": "^2.1.0", "ember-cli-uglify": "^1.2.0", "ember-export-application-global": "^1.0.5", "ember-get-config": "^0.2.1", - "ember-load-initializers": "^0.6.0", + "ember-load-initializers": "^1.0.0", "ember-one-way-controls": "^2.0.1", - "ember-resolver": "^2.0.3", + "ember-resolver": "^4.5.0", "ember-semantic-ui-calendar": "^0.2.0", - "ember-simple-auth": "^1.2.2", - "ember-source": "~2.12.0", + "ember-simple-auth": "^1.4.2", + "ember-source": "~2.16.2", "ember-truth-helpers": "^1.3.0", "loader.js": "^4.2.3", "semantic-ui-ember": "^2.0.1" diff --git a/tests/dummy/app/router.coffee b/tests/dummy/app/router.coffee index c47b72d..3a6ca1f 100644 --- a/tests/dummy/app/router.coffee +++ b/tests/dummy/app/router.coffee @@ -10,6 +10,9 @@ Router.map -> @route 'table-filters', -> @route 'test1' @route 'test2' + @route 'table-ordering', -> + @route 'test1' + @route 'test2' @route 'helpers', -> @route 'number-to-xls-header' diff --git a/tests/dummy/app/routes/table-ordering/test1.coffee b/tests/dummy/app/routes/table-ordering/test1.coffee new file mode 100644 index 0000000..c471fe1 --- /dev/null +++ b/tests/dummy/app/routes/table-ordering/test1.coffee @@ -0,0 +1,32 @@ +import Ember from 'ember' +import PagedArray from 'ember-cli-pagination/local/paged-array' + +export default_filter = Ember.Object.create + name: '' + target_week: '' + target_date_gteq: moment() + target_date_lteq: null + s: 'name asc' + +test_model = [ + {name: 'Record1'} +] +export default Ember.Route.extend + queryParams: + q: + refreshModel: true + setupController: (controller, model) -> + controller.set 'filters', default_filter + controller.set 'option_buttons_options', [1, 'two'] + @_super arguments... + + model: (params) -> + #@store.findAll('epots/migration-window-planning') + otherParams = {q: default_filter.toProperties()} + result = PagedArray.create test_model, perPage: 7 + result.setOtherParam = (param, q) -> + window.last_set_param ||= {} + window.last_set_param[param] = q # all is allowed for the purpose of testing and time conservation :devil: + result + test_model + diff --git a/tests/dummy/app/templates/global/-top-menu.emblem b/tests/dummy/app/templates/global/-top-menu.emblem index 024e042..9bf9de1 100644 --- a/tests/dummy/app/templates/global/-top-menu.emblem +++ b/tests/dummy/app/templates/global/-top-menu.emblem @@ -4,6 +4,8 @@ span ember-cli-dunlop dummy  = link-to 'table-filters.test1' class='item' span Filters + = link-to 'table-ordering.test1' class='item' + span Tables = link-to 'helpers' class='item' span Helpers diff --git a/tests/dummy/app/templates/table-ordering/test1.emblem b/tests/dummy/app/templates/table-ordering/test1.emblem new file mode 100644 index 0000000..b5c09a2 --- /dev/null +++ b/tests/dummy/app/templates/table-ordering/test1.emblem @@ -0,0 +1,13 @@ +h1= model.length += ordered-filtered-table content=model filters=filters settings=table_settings class='celled striped' as |tbl filter| + = tbl.head as |head| + = head.property key='name' as |property| + = property.title + = t property.key scope='attribtes.my_model' + = tbl.property as |property| + = property.header + = t 'attribtes.my_model.name' + = property.filter + = filter.input key='name' + = property.display + = property.name diff --git a/tests/dummy/app/templates/table-ordering/test2.emblem b/tests/dummy/app/templates/table-ordering/test2.emblem new file mode 100644 index 0000000..a2b84a0 --- /dev/null +++ b/tests/dummy/app/templates/table-ordering/test2.emblem @@ -0,0 +1 @@ +h1 Test222 diff --git a/tests/integration/components/ordered-filtered-table-test.coffee b/tests/integration/components/ordered-filtered-table-test.coffee new file mode 100644 index 0000000..356e62e --- /dev/null +++ b/tests/integration/components/ordered-filtered-table-test.coffee @@ -0,0 +1,25 @@ +import { test, moduleForComponent } from 'ember-qunit' +import hbs from 'htmlbars-inline-precompile' + +moduleForComponent 'ordered-filtered-table', 'Integration | Component | ordered filtered table', { + integration: true +} + +test 'it renders', (assert) -> + assert.expect 2 + + # Set any properties with @set 'myProperty', 'value' + # Handle any actions with @on 'myAction', (val) -> + + @render hbs """{{ordered-filtered-table}}""" + + assert.equal @$().text().trim(), '' + + # Template block usage: + @render hbs """ + {{#ordered-filtered-table}} + template block text + {{/ordered-filtered-table}} + """ + + assert.equal @$().text().trim(), 'template block text' diff --git a/tests/integration/components/ordered-filtered-table/property-test.coffee b/tests/integration/components/ordered-filtered-table/property-test.coffee new file mode 100644 index 0000000..dccb443 --- /dev/null +++ b/tests/integration/components/ordered-filtered-table/property-test.coffee @@ -0,0 +1,25 @@ +import { test, moduleForComponent } from 'ember-qunit' +import hbs from 'htmlbars-inline-precompile' + +moduleForComponent 'ordered-filtered-table/property', 'Integration | Component | ordered filtered table/property', { + integration: true +} + +test 'it renders', (assert) -> + assert.expect 2 + + # Set any properties with @set 'myProperty', 'value' + # Handle any actions with @on 'myAction', (val) -> + + @render hbs """{{ordered-filtered-table/property}}""" + + assert.equal @$().text().trim(), '' + + # Template block usage: + @render hbs """ + {{#ordered-filtered-table/property}} + template block text + {{/ordered-filtered-table/property}} + """ + + assert.equal @$().text().trim(), 'template block text'