From c83695128560dca37a1fcb3b9a85b39485004ba2 Mon Sep 17 00:00:00 2001 From: 0xADADA <0xadada.pub@0xadada.pub> Date: Tue, 13 Feb 2018 23:53:43 -0500 Subject: [PATCH] [#31] Remove jQuery * [x] Strip jQuery in ember-cli-build.js * [x] Try to ember-data to use ember-fetch instead of $.ajax * [x] app/adapters/application.js added the authorization: header to outgoing requests * [x] ma-create-media guards against disabled button * [x] updated dependencies --- app/adapters/application.js | 24 ++++++++++++++++--- app/components/ma-create-media.js | 3 ++- ember-cli-build.js | 5 +++- mirage/config.js | 2 ++ package.json | 2 +- yarn.lock | 38 +++++++++++++++---------------- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/app/adapters/application.js b/app/adapters/application.js index 432f8a2..78c0ca2 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -1,12 +1,30 @@ -import DS from 'ember-data'; +import { get } from '@ember/object'; +import { inject as service } from '@ember/service'; +import AdapterFetch from 'ember-fetch/mixins/adapter-fetch'; import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; import config from 'mir/config/environment'; -export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { +const TOKEN_KEY = 'session.session.authenticated.access_token'; + +export default JSONAPIAdapter.extend(AdapterFetch, DataAdapterMixin, { + session: service(), + /* Ember */ host: config.DS.host, namespace: config.DS.namespace, /* ember-simple-auth */ - authorizer: 'authorizer:oauth2' + authorizer: 'authorizer:oauth2', + + /* mir */ + ajaxOptions() { + this._super(...arguments); + const options = this._super(...arguments) || {}; + const token = get(this, TOKEN_KEY); + options.headers = options.headers || {}; + options.headers['Content-Type'] = 'application/vnd.api+json'; + options.headers['Authorization'] = `Bearer ${token}`; + return options; + } }); diff --git a/app/components/ma-create-media.js b/app/components/ma-create-media.js index f0928de..5ebb05c 100644 --- a/app/components/ma-create-media.js +++ b/app/components/ma-create-media.js @@ -100,7 +100,8 @@ export default Component.extend({ actions: { add(changeset) { - this._createMedia(changeset); + let isDisabled = get(this, 'isDisabled'); + if (!isDisabled) this._createMedia(changeset); } } }); diff --git a/ember-cli-build.js b/ember-cli-build.js index 9e8dbf7..077cf9f 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -7,7 +7,6 @@ const VERSION = GETENVJSON().version; module.exports = function(defaults) { let app = new EmberApp(defaults, { - // Add options here fingerprint: { extensions: ['css', 'gif', 'js', 'jpg', 'png', 'map', 'svg'] }, @@ -30,6 +29,10 @@ module.exports = function(defaults) { svgJar: { sourceDirs: ['public/images'] + }, + + vendorFiles: { + 'jquery.js': null // removes jQuery from build } }); diff --git a/mirage/config.js b/mirage/config.js index 7acb79f..984ea2e 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -71,5 +71,7 @@ export default function() { this.del('/medias/:id', (schema, request) => { let media = schema.medias.find(request.params.id); media.destroy(); + // TODO: Hacks + return { data: null }; // i shouldn't have to return anything here }); } diff --git a/package.json b/package.json index 8bebdf6..a1e972d 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "ember-resolver": "^4.5.0", "ember-route-action-helper": "^2.0.6", "ember-simple-auth": "^1.4.2", - "ember-source": "~3.0.0-beta.3", + "ember-source": "~3.0.0", "ember-svg-jar": "^0.12.0", "ember-test-component": "^0.2.1", "eslint": "^4.17.0", diff --git a/yarn.lock b/yarn.lock index 2de213e..e2fddfc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2347,9 +2347,9 @@ columnify@~1.5.4: strip-ansi "^3.0.0" wcwidth "^1.0.0" -combined-stream@^1.0.5, combined-stream@~1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" +combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.5: + version "1.0.6" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818" dependencies: delayed-stream "~1.0.0" @@ -3396,16 +3396,16 @@ ember-cli@~3.0.0-beta.1: watch-detector "^0.1.0" yam "0.0.22" -ember-cookies@^0.1.0: - version "0.1.3" - resolved "https://registry.yarnpkg.com/ember-cookies/-/ember-cookies-0.1.3.tgz#de4fc36752a0b0d8a17ef4644a3e03a10a6d1f05" +"ember-cookies@^0.1.0 || ^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/ember-cookies/-/ember-cookies-0.2.0.tgz#81195a31a36447240fb97af47d01ad582f747d47" dependencies: ember-cli-babel "^6.8.2" ember-getowner-polyfill "^1.1.0 || ^2.0.0" ember-data@^2.18.0: - version "2.18.0" - resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-2.18.0.tgz#8e374e540ea7c3b101983eb51cd0beedaa4d230d" + version "2.18.1" + resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-2.18.1.tgz#306d8fb272f113ab35db022f9a47a298720ba2dc" dependencies: amd-name-resolver "0.0.7" babel-plugin-ember-modules-api-polyfill "^1.4.2" @@ -3438,8 +3438,8 @@ ember-data@^2.18.0: silent-error "^1.0.0" ember-data@~3.0.0-beta.1: - version "3.0.0" - resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-3.0.0.tgz#0401f02ab34e0183f77278b108c6c0564ec3e28d" + version "3.0.1" + resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-3.0.1.tgz#555bddde064c72ff9dde4ae4c8c635afe8158b8b" dependencies: amd-name-resolver "0.0.7" babel-plugin-ember-modules-api-polyfill "^1.4.2" @@ -3637,7 +3637,7 @@ ember-runtime-enumerable-includes-polyfill@^2.0.0: ember-simple-auth@0xadada/ember-simple-auth#new-ember-qunit-release, ember-simple-auth@^1.4.2: version "1.4.2" - resolved "https://codeload.github.com/0xadada/ember-simple-auth/tar.gz/872d97cd3f7b8d3b6a18c5f0607b2758b6a08cc0" + resolved "https://codeload.github.com/0xadada/ember-simple-auth/tar.gz/0638ea3c23e90882bde10119eebd36c8c495233e" dependencies: base-64 "^0.1.0" broccoli-file-creator "^1.1.1" @@ -3650,9 +3650,9 @@ ember-simple-auth@0xadada/ember-simple-auth#new-ember-qunit-release, ember-simpl ember-getowner-polyfill "^1.1.0 || ^2.0.0" silent-error "^1.0.0" -ember-source@~3.0.0-beta.3: - version "3.0.0-beta.6" - resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-3.0.0-beta.6.tgz#e8042c1781de4f125993bb41b067cb32fc61c419" +ember-source@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-3.0.0.tgz#51811cae98d2ceec53bcfbaa876d02b2b5b2159f" dependencies: broccoli-funnel "^2.0.1" broccoli-merge-trees "^2.0.0" @@ -4446,11 +4446,11 @@ form-data@~2.1.1: mime-types "^2.1.12" form-data@~2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf" + version "2.3.2" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.2.tgz#4970498be604c20c005d4f5c23aecd21d6b49099" dependencies: asynckit "^0.4.0" - combined-stream "^1.0.5" + combined-stream "1.0.6" mime-types "^2.1.12" forwarded@~0.1.2: @@ -8969,8 +8969,8 @@ source-map@~0.2.0: amdefine ">=0.0.4" sourcemap-validator@^1.0.5: - version "1.0.6" - resolved "https://registry.yarnpkg.com/sourcemap-validator/-/sourcemap-validator-1.0.6.tgz#abd2f1ecdae6a3c46c2c96c5f256705b2147c9c0" + version "1.0.7" + resolved "https://registry.yarnpkg.com/sourcemap-validator/-/sourcemap-validator-1.0.7.tgz#d76aaadbe2c6ec269293b5f212100fad91eef260" dependencies: jsesc "~0.3.x" lodash.foreach "~2.3.x"