Change the way config is stored
On ember-cli config is stored in config/environment.js file and it can be accessed at any time of app being booted. Till now we were using Travis.config which was making things hard, because we needed an application instance to get any config value. This commit moves config to config/environment.js and allows to access it at any point of loading the app.
This commit is contained in:
parent
6460c6692d
commit
b0b1ef305b
|
@ -7,7 +7,8 @@ App = Ember.Application.extend(Ember.Evented,
|
|||
#LOG_RESOLVER: true
|
||||
|
||||
setup: ->
|
||||
@pusher = new Travis.Pusher(key: Travis.config.pusher_key, host: Travis.config.pusher_host) if Travis.config.pusher_key
|
||||
if @config.pusher.key
|
||||
@pusher = new Travis.Pusher(@config.pusher)
|
||||
@tailing = new Travis.Tailing($(window), '#tail', '#log')
|
||||
@toTop = new Travis.ToTop($(window), '.to-top', '#log-container')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'travis/limited-array'
|
||||
require 'utils/limited-array'
|
||||
|
||||
Repo = Travis.Repo
|
||||
limit = Ember.computed.limit
|
||||
|
|
|
@ -1,76 +1,16 @@
|
|||
loadConfig = ->
|
||||
pages_endpoint = $('meta[rel="travis.pages_endpoint"]').attr('href')
|
||||
billing_endpoint = $('meta[rel="travis.billing_endpoint"]').attr('href')
|
||||
customer_io_site_id = $('meta[name="travis.customer_io_site_id"]').attr('value')
|
||||
setupCustomerio(customer_io_site_id) if customer_io_site_id
|
||||
require 'config/environment'
|
||||
|
||||
enterprise = $('meta[name="travis.enterprise"]').attr('value') == 'true'
|
||||
|
||||
# for now I set pro to true also for enterprise, but it should be changed
|
||||
# to allow more granular config later
|
||||
pro = $('meta[name="travis.pro"]').attr('value') == 'true' || enterprise
|
||||
|
||||
if config.pro
|
||||
pusher =
|
||||
channels: []
|
||||
channel_prefix: 'private-'
|
||||
encrypted: true
|
||||
key: ''
|
||||
else
|
||||
pusher =
|
||||
channels: ['common']
|
||||
channel_prefix: ''
|
||||
encrypted: false
|
||||
|
||||
return {
|
||||
syncingPageRedirectionTime: 5000
|
||||
api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href')
|
||||
source_endpoint: $('meta[rel="travis.source_endpoint"]').attr('href')
|
||||
pusher_key: $('meta[name="travis.pusher_key"]').attr('value')
|
||||
pusher_host: $('meta[name="travis.pusher_host"]').attr('value')
|
||||
pusher_path: $('meta[name="travis.pusher_path"]').attr('value')
|
||||
ga_code: $('meta[name="travis.ga_code"]').attr('value')
|
||||
code_climate: $('meta[name="travis.code_climate"]').attr('value')
|
||||
ssh_key_enabled: $('meta[name="travis.ssh_key_enabled"]').attr('value') == 'true'
|
||||
code_climate_url: $('meta[name="travis.code_climate_url"]').attr('value')
|
||||
caches_enabled: $('meta[name="travis.caches_enabled"]').attr('value') == 'true'
|
||||
show_repos_hint: 'private'
|
||||
avatar_default_url: 'https://travis-ci.org/images/ui/default-avatar.png'
|
||||
pusher_log_fallback: $('meta[name="travis.pusher_log_fallback"]').attr('value') == 'true'
|
||||
pro: pro
|
||||
enterprise: enterprise
|
||||
sidebar_support_box: pro && !enterprise
|
||||
|
||||
pages_endpoint: pages_endpoint || billing_endpoint
|
||||
billing_endpoint: billing_endpoint
|
||||
|
||||
url_legal: "#{billing_endpoint}/pages/legal"
|
||||
url_imprint: "#{billing_endpoint}/pages/imprint"
|
||||
url_security: "#{billing_endpoint}/pages/security"
|
||||
url_terms: "#{billing_endpoint}/pages/terms"
|
||||
customer_io_site_id: customer_io_site_id
|
||||
|
||||
intervals: { times: -1, updateTimes: 1000 }
|
||||
pusher: pusher
|
||||
}
|
||||
config = ENV.config
|
||||
|
||||
initialize = (container, application) ->
|
||||
config = application.config
|
||||
application.register 'config:main', config, { instantiate: false }
|
||||
|
||||
application.inject('controller', 'config', 'config:main')
|
||||
application.inject('route', 'config', 'config:main')
|
||||
application.inject('auth', 'config', 'config:main')
|
||||
|
||||
application.pusher.config = config
|
||||
|
||||
ConfigInitializer =
|
||||
name: 'config'
|
||||
initialize: initialize
|
||||
|
||||
Ember.onLoad 'Ember.Application', (Application) ->
|
||||
Application.config loadConfig()
|
||||
|
||||
Application.ajax.pro = Application.config.pro
|
||||
|
||||
Application.initializer ConfigInitializer
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Travis.Model = Model
|
||||
Model = Travis.Model
|
||||
|
||||
SshKey = Model.extend
|
||||
value: DS.attr()
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'travis/location'
|
||||
require 'routes/application'
|
||||
|
||||
config = ENV.config
|
||||
|
||||
Router = Ember.Router.extend
|
||||
location: 'history'
|
||||
|
||||
|
@ -32,14 +34,14 @@ Router.map ->
|
|||
@resource 'pullRequests', path: '/pull_requests'
|
||||
@resource 'branches', path: '/branches'
|
||||
@resource 'requests', path: '/requests'
|
||||
@resource 'caches', path: '/caches'
|
||||
@resource 'caches', path: '/caches' if config.endpoints.caches
|
||||
@resource 'request', path: '/requests/:request_id'
|
||||
|
||||
@resource 'settings', ->
|
||||
@route 'index', path: '/'
|
||||
@resource 'env_vars', ->
|
||||
@route 'new'
|
||||
@resource 'ssh_key'
|
||||
@resource 'ssh_key' if config.endpoints.ssh_key
|
||||
|
||||
@route 'first_sync'
|
||||
@route 'insufficient_oauth_permissions'
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
config = ENV.config
|
||||
|
||||
Auth = Ember.Object.extend
|
||||
state: "signed-out"
|
||||
receivingEnd: "#{location.protocol}//#{location.host}"
|
||||
|
@ -9,7 +11,7 @@ Auth = Ember.Object.extend
|
|||
Travis.sessionStorage.getItem('travis.token')
|
||||
|
||||
endpoint: (->
|
||||
@config.api_endpoint
|
||||
config.api_endpoint
|
||||
).property(),
|
||||
|
||||
signOut: ->
|
||||
|
@ -50,7 +52,7 @@ Auth = Ember.Object.extend
|
|||
|
||||
validateUser: (user) ->
|
||||
fieldsToValidate = ['id', 'login', 'token', 'correct_scopes']
|
||||
if @config.pro
|
||||
if config.pro
|
||||
fieldsToValidate.push 'channels'
|
||||
|
||||
fieldsToValidate.every( (field) => @validateHas(field, user) ) && user.correct_scopes
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Ember.computed.limit = function(dependentKey, limitKey) {
|
||||
limit = function(dependentKey, limitKey) {
|
||||
var options = {
|
||||
addedItem: function(array, item, changeMeta, instanceMeta) {
|
||||
var limit = Ember.get(this, limitKey);
|
||||
|
@ -24,3 +24,5 @@ Ember.computed.limit = function(dependentKey, limitKey) {
|
|||
};
|
||||
return Ember.arrayComputed(dependentKey, limitKey, options);
|
||||
};
|
||||
|
||||
Ember.computed.limit = limit;
|
|
@ -1,7 +1,9 @@
|
|||
computedLimit = Ember.computed.limit
|
||||
|
||||
LimitedArray = Ember.ArrayProxy.extend
|
||||
limit: 10
|
||||
isLoadedBinding: 'content.isLoaded'
|
||||
arrangedContent: Ember.computed.limit('content', 'limit')
|
||||
arrangedContent: computedLimit('content', 'limit')
|
||||
|
||||
totalLength: (->
|
||||
@get('content.length')
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
config = ENV.config
|
||||
|
||||
TravisPusher = (config) ->
|
||||
@init(config)
|
||||
this
|
||||
|
@ -7,7 +9,7 @@ TravisPusher.prototype.active_channels = []
|
|||
TravisPusher.prototype.init = (config) ->
|
||||
Pusher.warn = @warn.bind(this)
|
||||
Pusher.host = config.host if config.host
|
||||
@pusher = new Pusher(config.key, encrypted: @config.pusher.encrypted, disableStats: true)
|
||||
@pusher = new Pusher(config.key, encrypted: config.encrypted, disableStats: true)
|
||||
|
||||
@callbacksToProcess = []
|
||||
|
||||
|
@ -97,9 +99,9 @@ TravisPusher.prototype.ignoreCode = (code) ->
|
|||
TravisPusher.prototype.ignoreMessage = (message) ->
|
||||
message.indexOf('Existing subscription') == 0 or message.indexOf('No current subscription') == 0
|
||||
|
||||
Pusher.SockJSTransport.isSupported = -> false if pusher_host != 'ws.pusherapp.com'
|
||||
Pusher.SockJSTransport.isSupported = -> false if config.pusher.host != 'ws.pusherapp.com'
|
||||
|
||||
if Travis.config.pro
|
||||
if config.pro
|
||||
Pusher.channel_auth_transport = 'bulk_ajax'
|
||||
|
||||
Pusher.authorizers.bulk_ajax = (socketId, _callback) ->
|
||||
|
@ -122,8 +124,8 @@ if Travis.config.pro
|
|||
Pusher.getDefaultStrategy = (config) ->
|
||||
[
|
||||
[":def", "ws_options", {
|
||||
hostUnencrypted: config.wsHost + ":" + config.wsPort + (pusher_path && "/#{pusher_path}" || ''),
|
||||
hostEncrypted: config.wsHost + ":" + config.wssPort + (pusher_path && "/#{pusher_path}" || '')
|
||||
hostUnencrypted: config.wsHost + ":" + config.wsPort + (config.pusher.path && "/#{config.pusher.path}" || ''),
|
||||
hostEncrypted: config.wsHost + ":" + config.wssPort + (config.pusher.path && "/#{config.pusher.path}" || '')
|
||||
path: config.path
|
||||
}],
|
||||
[":def", "sockjs_options", {
|
||||
|
|
70
assets/scripts/config/environment.js
Normal file
70
assets/scripts/config/environment.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
var billing_endpoint, customer_io_site_id, enterprise, pages_endpoint, pro, pusher, pusher_host, pusher_key, pusher_log_fallback, pusher_path;
|
||||
|
||||
pages_endpoint = $('meta[rel="travis.pages_endpoint"]').attr('href');
|
||||
billing_endpoint = $('meta[rel="travis.billing_endpoint"]').attr('href');
|
||||
customer_io_site_id = $('meta[name="travis.customer_io_site_id"]').attr('value');
|
||||
|
||||
if (customer_io_site_id) {
|
||||
setupCustomerio(customer_io_site_id);
|
||||
}
|
||||
|
||||
enterprise = $('meta[name="travis.enterprise"]').attr('value') === 'true';
|
||||
pro = $('meta[name="travis.pro"]').attr('value') === 'true' || enterprise;
|
||||
pusher_key = $('meta[name="travis.pusher_key"]').attr('value');
|
||||
pusher_host = $('meta[name="travis.pusher_host"]').attr('value');
|
||||
pusher_path = $('meta[name="travis.pusher_path"]').attr('value');
|
||||
pusher_log_fallback = $('meta[name="travis.pusher_log_fallback"]').attr('value') === 'true';
|
||||
|
||||
if (pro) {
|
||||
pusher = {
|
||||
channels: [],
|
||||
channel_prefix: 'private-',
|
||||
encrypted: true
|
||||
};
|
||||
} else {
|
||||
pusher = {
|
||||
channels: ['common'],
|
||||
channel_prefix: '',
|
||||
encrypted: false
|
||||
};
|
||||
}
|
||||
|
||||
pusher.key = pusher_key;
|
||||
pusher.host = pusher_host;
|
||||
pusher.path = pusher_path;
|
||||
pusher.log_fallback = pusher_log_fallback;
|
||||
|
||||
config = {
|
||||
syncingPageRedirectionTime: 5000,
|
||||
api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href'),
|
||||
source_endpoint: $('meta[rel="travis.source_endpoint"]').attr('href'),
|
||||
ga_code: $('meta[name="travis.ga_code"]').attr('value'),
|
||||
code_climate: $('meta[name="travis.code_climate"]').attr('value'),
|
||||
endpoints: {
|
||||
ssh_key: $('meta[name="travis.ssh_key_enabled"]').attr('value') === 'true',
|
||||
caches: $('meta[name="travis.caches_enabled"]').attr('value') === 'true'
|
||||
},
|
||||
code_climate_url: $('meta[name="travis.code_climate_url"]').attr('value'),
|
||||
show_repos_hint: 'private',
|
||||
avatar_default_url: 'https://travis-ci.org/images/ui/default-avatar.png',
|
||||
pro: pro,
|
||||
enterprise: enterprise,
|
||||
sidebar_support_box: pro && !enterprise,
|
||||
pages_endpoint: pages_endpoint || billing_endpoint,
|
||||
billing_endpoint: billing_endpoint,
|
||||
url_legal: billing_endpoint + "/pages/legal",
|
||||
url_imprint: billing_endpoint + "/pages/imprint",
|
||||
url_security: billing_endpoint + "/pages/security",
|
||||
url_terms: billing_endpoint + "/pages/terms",
|
||||
customer_io_site_id: customer_io_site_id,
|
||||
intervals: {
|
||||
times: -1,
|
||||
updateTimes: 1000
|
||||
},
|
||||
pusher: pusher
|
||||
};
|
||||
|
||||
if(!window.ENV) {
|
||||
window.ENV = {};
|
||||
}
|
||||
window.ENV.config = config;
|
|
@ -1,3 +1,5 @@
|
|||
config = ENV.config
|
||||
|
||||
jQuery.support.cors = true
|
||||
|
||||
default_options =
|
||||
|
@ -18,7 +20,7 @@ Travis.ajax = Em.Object.create
|
|||
@ajax(url, 'patch', data: data, success: callback)
|
||||
|
||||
needsAuth: (method, url) ->
|
||||
return true if Travis.ajax.pro
|
||||
return true if config.pro
|
||||
return true if method != 'GET'
|
||||
|
||||
publicEndpoint = @publicEndpoints.find (pattern) ->
|
||||
|
@ -36,7 +38,7 @@ Travis.ajax = Em.Object.create
|
|||
method = method || "GET"
|
||||
method = method.toUpperCase()
|
||||
|
||||
endpoint = Travis.config.api_endpoint || ''
|
||||
endpoint = config.api_endpoint || ''
|
||||
options = options || {}
|
||||
|
||||
token = Travis.sessionStorage.getItem('travis.token')
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require 'ext/jquery'
|
||||
require 'ext/ember/namespace'
|
||||
require 'ext/ember/computed'
|
||||
require 'config/environment'
|
||||
require 'utils/computed-limit'
|
||||
require 'app'
|
||||
|
||||
window.ENV ||= {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user