Skip to content

Instantly share code, notes, and snippets.

@jkarsrud
Created August 19, 2016 12:15
Show Gist options
  • Save jkarsrud/28c7cb8eef52d81703a9518032d8e9d4 to your computer and use it in GitHub Desktop.
Save jkarsrud/28c7cb8eef52d81703a9518032d8e9d4 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
ajax: Ember.inject.service(),
appSession: Ember.inject.service(),
redirect(model, transition) {
if (this.get('appSession').get('isAuthenticated') && this.get('appSession').get('hasPublisher') && this.get('appSession').get('hasPublisherToken')) {
this.replaceWith('/');
}
},
setupController(controller, model) {
controller.set('model', model);
if (!this.get('appSession.hasPublisherURL') && !this.get('appSession.hasPublisherToken')) {
controller.set('isNew', true);
} else if (!this.get('appSession').get('hasPublisherToken')) {
controller.set('isNew', false);
controller.set('existingPublisherURL', this.get('ajax').get('publisherWordpressURL'));
controller.set('publisherURL', this.get('ajax').get('publisherWordpressURL'));
controller.set('publisherPlatform', this.get('appSession').get('publisherPlatform'));
controller.set('platformPluginAvailable', true);
controller.set('urlChanged', false);
}
},
checkWebsitePlatform(url) {
let checkWebsiteURL = "/api/publishers/detect/website" + "?publisher[url]=" + url;
let controller = this.controllerFor('getStarted');
var self = this;
controller.set('couldNotDetectPlatform', false);
this.get('ajax').request(checkWebsiteURL).then((data) => {
controller.set('isChecking', false);
controller.set('urlChanged', false);
if (data.publisher_url.website === "Sorry! Unable to detect the URL") {
controller.set('platformPluginAvailable', data.publisher_url.status);
controller.set('couldNotDetectPlatform', true);
} else {
controller.set('showStatusMessage', true);
}
});
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:application', 'TODO: put something here', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});
test('it exists', function(assert) {
let route = this.subject();
assert.ok(route);
});
test('check website\'s platform availability', function(assert) {
var self = this;
Ember.run(function() {
const controller = Ember.Object.create();
controller.set('testprop', 'testing');
let route = self.subject();
route.controller = controller;
route.setupController(controller);
assert.equal(route.controller.get('testProp'), 'testing');
route.send('checkWebsitePlatform', "http://test.com");
assert.notOk(controller.get('couldNotDetectPlatform'), 'Check platform availability');
assert.ok(controller.get('isChecking'), 'Default check status');
});
});
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.0",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment