From 48cf0730beabf53f12ae52e4ad69aabe0d96a989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerardo=20P=C3=A9rez=20P=C3=A9rez?= Date: Sat, 21 Jan 2017 19:21:17 -0600 Subject: [PATCH] Rewrite code to work with ember 2.10.x --- README.md | 8 +- addon/mixins/filterset.js | 190 +++++++++--------- addon/privateclasses/actions.js | 27 +-- addon/privateclasses/modal.js | 2 +- app/components/crud-table.js | 10 +- app/instance-initializers/google-maps.js | 7 +- .../ember-cli-crudtable/default/base.hbs | 2 +- .../ember-cli-crudtable/default/body.hbs | 5 +- .../ember-cli-crudtable/default/top.hbs | 6 +- app/templates/ember-cli-crudtable/spinner.hbs | 4 +- .../ember-cli-crudtable/table-modal.hbs | 19 +- changelog.md | 4 + config/ember-try.js | 2 +- package.json | 2 +- tests/unit/components/crud-table-test.js | 159 +++++++++------ 15 files changed, 240 insertions(+), 207 deletions(-) diff --git a/README.md b/README.md index 31589a2..b9a1aee 100755 --- a/README.md +++ b/README.md @@ -6,9 +6,6 @@ This addon allows you to easily create a CRUD Table, it will take you only 5s!. This component is compatible with bootstrap and ember-data. - -Current Build Status for ember versions: - [![Build Status](http://travisjobsbadges.bitsun.com.mx/gerard2p/ember-cli-crudtable/filters.svg)](https://travis-ci.org/gerard2p/ember-cli-crudtable) [![NPM Downlaads](http://img.shields.io/npm/dm/ember-cli-crudtable.svg?style=flat-square)](https://www.npmjs.org/package/ember-cli-crudtable)[![Ember Observer Score](http://emberobserver.com/badges/ember-cli-crudtable.svg?style=flat-square)](http://emberobserver.com/addons/ember-cli-crudtable)[![Issue Count](https://codeclimate.com/github/gerard2p/ember-cli-crudtable/badges/issue_count.svg)](https://codeclimate.com/github/gerard2p/ember-cli-crudtable) @@ -411,7 +408,6 @@ That's all. You'll have a new field rendered as a link which is pointing to 'sch ##Upcoming -I'll create a website to show some examples if the downloads still increasing, thank you for using it. +I'll rewrite this component, I might change the name and deprecate this repo, this idea it's to make it 100% compatible with my new project [Koaton](https://github.com/gerard2p/koaton). -I'm in a little hurry but as soon as possible i'll be adding more features and also providing a more detailed doc about the functions. -But try it, is quite simple to have your fully functional CRUD application. +See you soon. diff --git a/addon/mixins/filterset.js b/addon/mixins/filterset.js index 493b587..84abe63 100644 --- a/addon/mixins/filterset.js +++ b/addon/mixins/filterset.js @@ -26,96 +26,96 @@ export default Ember.Mixin.create({ '==': 'Equal', 'like': 'Contains' }, - createFiltergroup(filters, link) { - let that = this; - return Ember.ArrayProxy.extend({ - Link: null, - LinkLocale: Ember.computed('Link', function() { - return that.links[this.Link]; - }), - isvalid: Ember.computed('content.@each.Ready', function() { - let a = this.content.filterBy('Ready', false); - return this.content.filterBy('Ready', false).length === 0; - }) - }).create({ - Link: link || "or", - content: filters || [] //Ember.ArrayProxy.create() - }); - }, - create(base) { - let that = this; - return Ember.Object.extend({ - Display: null, - Key: null, - - Condition: null, - ConditionMask: Ember.computed('Condition', function() { - return (this.Options || {})[this.Condition] || ""; - }), - - Value: null, - ValueMask: null, - - display:Ember.computed.alias('Display'), - key:Ember.computed.alias('Key'), - condition:Ember.computed.alias('Condition'), - value:Ember.computed.alias('Value'), - valuemask:Ember.computed.alias('ValueMask'), - link:Ember.computed.alias('Link'), - - - //Type:null, - SelectObject: false, - Options: null, - Link: null, - Readable: Ember.computed('Display', 'ConditionMask', 'ValueMask', function() { - return this.Display + " " + this.get('ConditionMask') + " " + this.ValueMask; - }), - Ready: Ember.computed('Display', 'Condition', 'Value', function() { - return !!(this.Display && this.Condition && this.Value); - // return `${this.get('Key')} ${this.get('Condition')} ${this.get('Display')}`; - }), - LinkLocale: Ember.computed('Link', function() { - return that.links[this.Link]; - }) - }).create(base || {}); - }, - init(filters) { - this.set('filtergroups', Ember.ArrayProxy.extend({ - areValid: Ember.computed('content.@each.isvalid', function() { - return this.content.filterBy('isvalid', false).length === 0; - }) - }).create({ - content: [] - })); - (filters || this.createFiltergroup().addObject(this.create())).forEach(function(filter, index, arr) { - let link = index > 0 ? arr[index - 1].link : null; - this.AddFilterGroup(filter.filters, link); - }.bind(this)); - }, - change(filters){ - this.init(filters); - this.set('filterupdated',!this.set('filterupdated')); - }, - localelink(link) { - return this.links[link]; - }, - makefilter(filter) { - return filter; - }, - AddFilterGroup(filters, link) { - let that = this; - filters = filters || [this.create()]; - link = link || "or"; - filters = filters.map((filter) => { - return that.create(filter) - }); - if (this.filtergroups.content.length > 0) { - let filt = this.filtergroups.objectAt(this.filtergroups.content.length - 1); - filt.set('Link', link); - } - this.filtergroups.addObject(this.createFiltergroup(filters, link)); - }, +// createFiltergroup(filters, link) { +// let that = this; +// return Ember.ArrayProxy.extend({ +// Link: null, +// LinkLocale: Ember.computed('Link', function() { +// return that.links[this.Link]; +// }), +// isvalid: Ember.computed('content.@each.Ready', function() { +// let a = this.content.filterBy('Ready', false); +// return this.content.filterBy('Ready', false).length === 0; +// }) +// }).create({ +// Link: link || "or", +// content: filters || [] //Ember.ArrayProxy.create() +// }); +// }, +// create(base) { +// let that = this; +// return Ember.Object.extend({ +// Display: null, +// Key: null, +// +// Condition: null, +// ConditionMask: Ember.computed('Condition', function() { +// return (this.Options || {})[this.Condition] || ""; +// }), +// +// Value: null, +// ValueMask: null, +// +// display:Ember.computed.alias('Display'), +// key:Ember.computed.alias('Key'), +// condition:Ember.computed.alias('Condition'), +// value:Ember.computed.alias('Value'), +// valuemask:Ember.computed.alias('ValueMask'), +// link:Ember.computed.alias('Link'), +// +// +// //Type:null, +// SelectObject: false, +// Options: null, +// Link: null, +// Readable: Ember.computed('Display', 'ConditionMask', 'ValueMask', function() { +// return this.Display + " " + this.get('ConditionMask') + " " + this.ValueMask; +// }), +// Ready: Ember.computed('Display', 'Condition', 'Value', function() { +// return !!(this.Display && this.Condition && this.Value); +// // return `${this.get('Key')} ${this.get('Condition')} ${this.get('Display')}`; +// }), +// LinkLocale: Ember.computed('Link', function() { +// return that.links[this.Link]; +// }) +// }).create(base || {}); +// }, +// init(filters) { +// this.set('filtergroups', Ember.ArrayProxy.extend({ +// areValid: Ember.computed('content.@each.isvalid', function() { +// return this.content.filterBy('isvalid', false).length === 0; +// }) +// }).create({ +// content: [] +// })); +// (filters || this.createFiltergroup().addObject(this.create())).forEach(function(filter, index, arr) { +// let link = index > 0 ? arr[index - 1].link : null; +// this.AddFilterGroup(filter.filters, link); +// }.bind(this)); +// }, +// change(filters){ +// this.init(filters); +// this.set('filterupdated',!this.set('filterupdated')); +// }, +// localelink(link) { +// return this.links[link]; +// }, +// makefilter(filter) { +// return filter; +// }, +// AddFilterGroup(filters, link) { +// let that = this; +// filters = filters || [this.create()]; +// link = link || "or"; +// filters = filters.map((filter) => { +// return that.create(filter) +// }); +// if (this.filtergroups.content.length > 0) { +// let filt = this.filtergroups.objectAt(this.filtergroups.content.length - 1); +// filt.set('Link', link); +// } +// this.filtergroups.addObject(this.createFiltergroup(filters, link)); +// }, getBody(query) { query.filterset = (this.filtergroups||[]).map((filter) => { return { @@ -131,9 +131,9 @@ export default Ember.Mixin.create({ }; }); }, - Query:Ember.computed('filtergroups.content.@each.isvalid',function(){ - let query = {filterset:{}}; - this.getBody(query); - return query.filterset; - }) +// Query:Ember.computed('filtergroups.content.@each.isvalid',function(){ +// let query = {filterset:{}}; +// this.getBody(query); +// return query.filterset; +// }) }); diff --git a/addon/privateclasses/actions.js b/addon/privateclasses/actions.js index cc16387..1ef7d0c 100644 --- a/addon/privateclasses/actions.js +++ b/addon/privateclasses/actions.js @@ -312,7 +312,7 @@ export default { }); deferred = Ember.RSVP.defer('crud-table#updateRecord'); let geocoder = new google.maps.Geocoder(); - geocoder.geocodefunction({ + geocoder.geocode({ 'latLng': map }, function(results, status) { if (status === google.maps.GeocoderStatus.OK) { @@ -388,7 +388,9 @@ export default { if (google === undefined) { return; } - this.set('showMap', true); + let component = this; + component.set('showMap', true); + component.set('isLoading', true); modal.show(); function mapit(id, latlng) { @@ -397,26 +399,27 @@ export default { } let mapOptions = { zoom: latlng.zoom, - center: new google.maps.LatLng(latlng.lat, latlng.lng), + center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; let map = new google.maps.Map(document.getElementById(id), mapOptions); record.set('map', map); + component.set('isLoading', false); return true; } let cord = ""; record.forEach(function(prop) { if (prop.Type === kind) { - cord = prop.Value.split(','); + cord = (prop.Value || '20.677632,-101.341632').split(','); cord = { - lat: cord[0], - lng: cord[1], - zoom: prop.Zoom.value + lat: parseFloat(cord[0], 10), + lng: parseFloat(cord[1], 10), + zoom: prop.Zoom.value || 11 }; } }); - let component = this; + let waitforgoogle = function(fn) { if (google === undefined) { setTimeout(function() { @@ -434,7 +437,10 @@ export default { }, 10); } }; - waitforgoogle(waitforgoogle); + setTimeout(function(){ + waitforgoogle(waitforgoogle); + },1000); + }, internal_create() { let component = this; @@ -443,9 +449,6 @@ export default { let deferred = Ember.RSVP.defer('crud-table#newRecord'); component.sendAction('getRecord', deferred); deferred.promise.then(function(record) { - // Object.keys(component.fieldDefinition).forEach(function(field) { - // record.set(field, component.fieldDefinition[field](component.get('targetObject').get('model'))); - // }); if (record._internalModel !== undefined) { records.addObject(record._internalModel); } else { diff --git a/addon/privateclasses/modal.js b/addon/privateclasses/modal.js index 92e3168..cb2e945 100644 --- a/addon/privateclasses/modal.js +++ b/addon/privateclasses/modal.js @@ -41,7 +41,7 @@ export default { console.log(data); }); }); - $('body').append($("#CrudTableDeleteRecordModal")); + $('[data-role=crud-table]').parent().append($("#CrudTableDeleteRecordModal")); }, hide() { if(this.target.modal){ diff --git a/app/components/crud-table.js b/app/components/crud-table.js index 73a85a8..cc7928c 100755 --- a/app/components/crud-table.js +++ b/app/components/crud-table.js @@ -2,9 +2,11 @@ import Ember from 'ember'; import CRUD from 'ember-cli-crudtable/components/crud-table'; import paginator from '../paginator/crudtable'; import filterset from '../filterset/crudtable'; + export default Ember.Component.extend(CRUD, { - paginator() { - return paginator.create(); - }, - filterset: filterset.create() + renderer: {}, + filterset: filterset.create(), + paginator() { + return paginator.create(); + } }); diff --git a/app/instance-initializers/google-maps.js b/app/instance-initializers/google-maps.js index ce9fd0e..6965885 100644 --- a/app/instance-initializers/google-maps.js +++ b/app/instance-initializers/google-maps.js @@ -5,12 +5,15 @@ export default { if (ENV['ember-cli-crudtable']) { if (ENV['ember-cli-crudtable']['google-api-key']) { window.onload = function () { + window.initMap = function () { + window.mapstarted = true; + } var script = document.createElement("script"); script.type = "text/javascript"; - script.src = "http://maps.googleapis.com/maps/api/js?key=" + ENV['ember-cli-crudtable']['google-api-key'] + "&sensor=TRUE&callback=pront"; + script.src = "http://maps.googleapis.com/maps/api/js?key=" + ENV['ember-cli-crudtable']['google-api-key']+ '&callback=initMap'; document.body.appendChild(script); } } } } -}; \ No newline at end of file +}; diff --git a/app/templates/ember-cli-crudtable/default/base.hbs b/app/templates/ember-cli-crudtable/default/base.hbs index 9c18dfb..febba18 100644 --- a/app/templates/ember-cli-crudtable/default/base.hbs +++ b/app/templates/ember-cli-crudtable/default/base.hbs @@ -10,4 +10,4 @@ {{/if}} {{yield}} -{{partial 'ember-cli-crudtable/table-modal'}} +{{partial 'ember-cli-crudtable/table-modal'}} \ No newline at end of file diff --git a/app/templates/ember-cli-crudtable/default/body.hbs b/app/templates/ember-cli-crudtable/default/body.hbs index f67a1b8..b2a62ba 100644 --- a/app/templates/ember-cli-crudtable/default/body.hbs +++ b/app/templates/ember-cli-crudtable/default/body.hbs @@ -16,7 +16,6 @@ {{#unless this.isLoading}} - {{#each this.ComplexModel key="@index" as |row index|}} {{#if row}} @@ -38,7 +37,7 @@ {{else}} - {{partial template='ember-cli-crudtable.spinner' model=this.newRecord}} + {{partial 'ember-cli-crudtable/spinner'}} @@ -74,4 +73,4 @@ {{/if}} {{/if}} - + \ No newline at end of file diff --git a/app/templates/ember-cli-crudtable/default/top.hbs b/app/templates/ember-cli-crudtable/default/top.hbs index 992f8b2..d57f38e 100644 --- a/app/templates/ember-cli-crudtable/default/top.hbs +++ b/app/templates/ember-cli-crudtable/default/top.hbs @@ -29,7 +29,7 @@ {{/each}} - {{/if}} + {{/if}} {{#if this.canRefresh}} {{/if}} {{#if this.createRecord}} @@ -48,10 +48,10 @@
- {{input enter="internal_search" value=this.SearchTerm placeholder="Search" class="input-sm form-control" name="SearchTerm" }} + {{input enter="internal_search" value=this.SearchTerm placeholder="Search" class="input-sm form-control" id="SearchTerm" }}
-{{/if}} +{{/if}} \ No newline at end of file diff --git a/app/templates/ember-cli-crudtable/spinner.hbs b/app/templates/ember-cli-crudtable/spinner.hbs index ef77652..c9f6480 100755 --- a/app/templates/ember-cli-crudtable/spinner.hbs +++ b/app/templates/ember-cli-crudtable/spinner.hbs @@ -1,4 +1,4 @@ -
+