reference.once('value', function(data) { currentData = data.val(); postData = currentData.posts[postId]; assert(postData.comments[commentId] === true, 'the hasMany link should exist'); assert(Ember.isArray(postData.comments) === false); done(); });
_setReturns(responseKey, options) { let json, model, models; switch (responseKey) { case 'id': model = FactoryGuy.store.peekRecord(this.modelName, options.id); Ember.assert(`argument ( id ) should refer to a model of type ${this.modelName} that is in the store. But no ${this.modelName} with id ${options.id} was found in the store`, (model instanceof DS.Model && model.constructor.modelName === this.modelName)); return this.returns({ model }); case 'model': model = options.model; Ember.assert(`argument ( model ) must be a DS.Model instance - found type:' ${Ember.typeOf(model)}`, (model instanceof DS.Model)); json = { id: model.id, type: model.constructor.modelName }; this.responseJson = FactoryGuy.fixtureBuilder.convertForBuild(this.modelName, json); break; case 'ids': const store = FactoryGuy.store; models = options.ids.map((id)=> store.peekRecord(this.modelName, id)); return this.returns({ models }); case 'models': models = options.models; Ember.assert(`argument ( models ) must be an array - found type:' ${Ember.typeOf(models)}`, Ember.isArray(models)); json = models.map(function(model) { return { id: model.id, type: model.constructor.modelName }; }); json = FactoryGuy.fixtureBuilder.convertForBuild(this.modelName, json); this.setResponseJson(json); break; case 'json': this.responseJson = options.json; break; case 'attrs': let currentId = this.responseJson.get('id'); let modelParams = assign({id: currentId}, options.attrs); json = FactoryGuy.fixtureBuilder.convertForBuild(this.modelName, modelParams); this.setResponseJson(json); break; case 'headers': this.addResponseHeaders(options.headers); break; } }
breadcrumbs: function () { var currentPath = this.get('controllers.application.currentPath'), availableRoutes = this.get('target.availableRoutes'), breads = []; if (Ember.isArray(availableRoutes) && availableRoutes.length > 0) { breads = findRouteMap(currentPath, availableRoutes); } return breads; }.property('controllers.application.currentPath', 'target.availableRoutes'),
getCellContent: function(row) { var path = get(this, 'contentPath'); Ember.assert('You must either provide a contentPath or override ' + 'getCellContent in your column definition', path != null); var value = Ember.get(row, path); if (Ember.isArray(value)) { //is Array return value.join(', '); } else { return value; } },
canComplete: function() { var isNew = this.get('model.isNew'), labTypeName = this.get('model.labTypeName'), selectedLabType = this.get('selectedLabType'); if (isNew && (Ember.isEmpty(labTypeName) || (Ember.isArray(selectedLabType) && selectedLabType.length > 1))) { return false; } else { return this.currentUserCan('complete_lab'); } }.property('selectedLabType.[]', 'model.labTypeName'),
var pushValidatableObject = function(model, property) { var content = get(model, property); model.removeObserver(property, pushValidatableObject); if (Ember.isArray(content)) { model.validators.pushObject(ArrayValidatorProxy.create({model: model, property: property, contentBinding: 'model.' + property})); } else { model.validators.pushObject(content); } };
this.getSelectedPricing('selectedLabType').then(function(pricingRecords) { if (Ember.isArray(pricingRecords)) { this.createMultipleRequests(pricingRecords, 'labType', 'labs', 'Lab'); } else { this.set('model.labType', pricingRecords); this.addChildToVisit(newLab, 'labs', 'Lab').then(function() { this.saveModel(); }.bind(this)); } }.bind(this));
addDiagnosis: function(newDiagnosis) { var additionalDiagnoses = this.get('additionalDiagnoses'); if (!Ember.isArray(additionalDiagnoses)) { additionalDiagnoses = []; } additionalDiagnoses.addObject(newDiagnosis); this.set('additionalDiagnoses', additionalDiagnoses); this.send('update', true); this.send('closeModal'); },
validate: function(name, value) { const values = this.get('values'); Ember.assert('You must define an array of Enum values in order to validate.', Ember.isPresent(values) && Ember.isArray(values)); if(hasValue(value) && values.indexOf(value) < 0) { return this.format(values.join(', ')); } }
function serialize(type, payload) { var response = {}; if (Ember.isArray(payload)) { type = Ember.String.pluralize(type); } response[type] = payload; return response; }
_syncValueToActiveButtons: observer('value', '*****@*****.**', '_inDOM', function() { if (!this._inDOM) { return; } let value = this.get('value'); let values = Ember.A(!Ember.isArray(value) ? [value] : value); this.get('children') .forEach(function(button) { button.set('active', values.contains(button.get('value'))); }); }),
formErrorMessage: Ember.computed('errorMessages.[]', function() { let message = ''; let errorMessages = this.get('errorMessages'); if (Ember.isArray(errorMessages)) { errorMessages.forEach((currentErrorMessage) => { message += '<li>' + currentErrorMessage + '</li>'; }); } return new Ember.Handlebars.SafeString('<ul>' + message + '</ul>'); }),
test('it works', function(assert) { let stringToDeserialize = '+type.name-moderated'; let result = deserializeSortingParam(stringToDeserialize); assert.ok(result); assert.ok(Ember.isArray(result)); assert.equal(result.length, 2); assert.equal(result[0].propName, 'type.name'); assert.equal(result[0].direction, 'asc'); assert.equal(result[1].propName, 'moderated'); assert.equal(result[1].direction, 'desc'); });
return (data, i, element) => { // if we exited the group label undo for the group if (Ember.isArray(data.values)) { element = element.parentNode.parentNode; } // Undo hover style stuff d3.select(element).classed('hovered', false); // Hide Tooltip return this.hideTooltip(); };
keys.forEach(function(key) { var vals = opt.filter[key]; if ( !Ember.isArray(vals) ) { vals = [vals]; } vals.forEach(function(val) { url += (url.indexOf('?') >= 0 ? '&' : '?') + encodeURIComponent(key) + '=' + encodeURIComponent(val); }); });
Object.keys(data).forEach(function(key) { if (!Ember.isNone(data[key])) { if (Ember.isArray(data[key])) { return _this._recursiveArrayAppend(formData,"" + root + "[" + key + "]",data,key); }else if(Object.prototype.toString.call(data[key]) === '[object Object]'){ return _this._recursiveObjectAppend(formData,"" + root + "[" + key + "]",data,key); } else { return formData.append("" + root + "[" + key + "]", data[key]); } } });
/** * 设置快照 * @param options * @returns {*} * @private */ function _setupSnapshot(options) { var requestData = get(options, 'requestData'), snapshot; if (Ember.isArray(requestData)) { snapshot = Ember.A(requestData).invoke('_createSnapshot') } else { snapshot = requestData._createSnapshot(); } options.snapshot = snapshot; return snapshot; }
filesDidChange: function(files) { if(Ember.isArray(files)){ this.send('start', files); }else if (!Ember.isEmpty(files)) { this.set('fileObject', fileObject.create({ fileToUpload: files[0] })); if (this.get('autoUpload')) { this.send('start'); } } },
this._find = function(collection, ids) { var _this = this; if (Ember.isArray(ids)) { return ids.map(function(id) { return _this._findRecordForId(collection, id); }); } else { return this._findRecordForId(collection, ids); } };
generateURI: function(type, id, snapshot) { var url = []; if (type) { url.push(this.pathForType(type)); } //We might get passed in an array of ids from findMany //in which case we don't want to modify the url, as the //ids will be passed in through a query param if (id && !Ember.isArray(id)) { url.push(encodeURIComponent(id)); } return url.join('/'); },
normalizeResponse: function (store, primaryModelClass, payload/*, id, requestType*/) { payload.meta = payload.metadata || {}; delete payload.metadata; if (Ember.isArray(payload.data)) { payload.data = payload.data.map(this._mapDataset); } else { payload.data = this._mapDataset(payload.data); } return payload; },
export function convert (source, rawOption) { let option = ConvertedOption.create({ source }) if (Ember.isArray(rawOption)) { let [value, text, description] = rawOption option.setProperties({ value, text, description }) } else if (rawOption.hasOwnProperty('value')) { option.setProperties(rawOption) } else { option.set('value', rawOption) } return option }
// Used in API request fail handlers to parse a standard api error // response json for the message to display export default function getRequestErrorMessage(request, performConcat) { var message, msgDetail; // Can't really continue without a request if (!request) { return null; } // Seems like a sensible default message = request.statusText; // If a non 200 response if (request.status !== 200) { try { // Try to parse out the error, or default to 'Unknown' if (request.responseJSON.errors && Ember.isArray(request.responseJSON.errors)) { message = request.responseJSON.errors.map(function (errorItem) { return errorItem.message; }); } else { message = request.responseJSON.error || 'Unknown Error'; } } catch (e) { msgDetail = request.status ? request.status + ' - ' + request.statusText : 'Server was not available'; message = 'The server returned an error (' + msgDetail + ').'; } } if (performConcat && Ember.isArray(message)) { message = message.join('<br />'); } // return an array of errors by default if (!performConcat && typeof message === 'string') { message = [message]; } return message; }
addValue: function(key, value) { if (Ember.isArray(value)) { if (value.length === 1) { return this.queryStringAttributes[key] = value[0]; } else if (value.length > 1) { return this.queryStringAttributes[key + "[in]"] = value.join(","); } } else if (isSerializableDate(value)) { return this.queryStringAttributes[key] = value.toISOString(); } else if (!Ember.isBlank(value)) { return this.queryStringAttributes[key] = value; } },
var traverse = function(object, callback) { if(!object) { return; } if(typeof(object) === 'object' && !Ember.isArray(object)) { callback(object); } if(Ember.isArray(object)) { for(let item of object) { traverse(item, callback); } } else if(typeof object === 'object') { for(let key in object) { if(object.hasOwnProperty(key)) { let item = object[key]; traverse(item, callback); } } } };
this.sendAction = (...args) => { let actionName = args[0]; let originalSendActionIsOverridden = originalSendAction !== Ember.Component.prototype.sendAction; let outerActionHandlerIsDefined = Ember.typeOf(this.get(`attrs.${actionName}`)) === 'function' || Ember.typeOf(this.get(`attrs.${actionName}`)) === 'string'; // Call for overridden send action, or call for standard 'sendAction' (sending action outside). // Overridden 'sendAction' must be called anywhere, // but call for standard 'sendAction' must be executed only if outer action handler is defined, // otherwise ember will call to component's inner method with the same name (as action name), // for example if you send 'remove' action, then (if outer handler isn't defined) component's // 'remove' method will be called, what will cause unexpected behavior and exceptions. if (originalSendActionIsOverridden || outerActionHandlerIsDefined) { originalSendAction.apply(this, args); } let dynamicActions = this.get(`_dynamicActions.${actionName}`); // If no dynamic actions defined for action with given name, // break custom 'sendAction' logic then. if (!Ember.isArray(dynamicActions)) { return; } // Call handlers defined in dynamic actions. // Here we can be sure that all dynamic actions are fully valid, // because they were validated in process of '_dynamicActions' computation. for (let i = 0, len = dynamicActions.length; i < len; i++) { let dynamicAction = dynamicActions[i]; let actionHandler = Ember.get(dynamicAction, 'actionHandler'); let actionName = Ember.get(dynamicAction, 'actionName'); let actionContext = Ember.get(dynamicAction, 'actionContext'); let actionArguments = Ember.get(dynamicAction, 'actionArguments') || []; // Original action arguments (without action name passed to 'sendAction' method). let originalActionArguments = args.slice(1); // Combined action arguments. let combinedActionArguments = [...actionArguments, ...originalActionArguments]; // Call to action handler (if defined). if (Ember.typeOf(actionHandler) === 'function') { actionHandler.apply(actionContext, combinedActionArguments); } // Send action (if defined). if (Ember.typeOf(actionName) === 'string') { actionContext.send(actionName, ...combinedActionArguments); } } };
followLink: function(name, opt) { var url = this.linkFor(name); opt = opt || {}; if (!url) { throw new Error('Unknown link'); } if ( opt.include ) { if ( !Ember.isArray(opt.include) ) { opt.include = [opt.include]; } opt.include.forEach(function(key) { url += (url.indexOf('?') >= 0 ? '&' : '?') + 'include=' + encodeURIComponent(key); }); } if ( opt.sort ) { if ( !Ember.isArray(opt.sort) ) { opt.sort = [opt.sort]; } opt.sort.forEach(function(key) { url += (url.indexOf('?') >= 0 ? '&' : '?') + 'sort=' + encodeURIComponent(key); }); } return this.request({ method: 'GET', url: url }); },
createRecord: function(jsonApiRecord, included) { included = included || {}; let record = {}; if (jsonApiRecord) { record = { _id: jsonApiRecord.id, _type: jsonApiRecord.type }; if (jsonApiRecord.attributes) { Object.assign(record, jsonApiRecord.attributes); } if (jsonApiRecord.relationships) { for (let rel of Object.keys(jsonApiRecord.relationships)) { let {data} = jsonApiRecord.relationships[rel]; if (Ember.isArray(data)) { record[rel] = data.map((item) => { let relation = included[`${item.type}:::${item.id}`]; if (relation) { return this.db[relation.type].createRecord(relation); } else { return {_id: item.id, _type: item.type}; } }); } else { let relation = included[`${data.type}:::${data.id}`]; if (relation) { record[rel] = this.db[relation.type].createRecord(relation); } else { record[rel] = {_id: data.id, _type: data.type}; } } } } } // return this.createInstance(record); record = Ember.Object.create(record); let modelMeta = this.get('modelMeta'); return this.get('modelClass').create({ content: record, meta: modelMeta }); },
}).then(function (response) { // manually update the roles for the users that just changed roles // because store.pushPayload is not working with embedded relations if (response && Ember.isArray(response.users)) { response.users.forEach(function (userJSON) { var user = self.store.getById('user', userJSON.id), role = self.store.getById('role', userJSON.roles[0].id); user.set('role', role); }); } self.notifications.showSuccess('Ownership successfully transferred to ' + user.get('name')); }).catch(function (error) {
return Ember.RSVP.hash(dependencies, 'Load container dependencies').then(function(results) { var data, healthCheckData; if ( results.existing ) { data = results.existing.serializeForNew(); data.ports = (data.ports||[]).map((port) => { delete port.id; return port; }); if ( Ember.isArray(data.instanceLinks) ) { data.instanceLinks = (data.instanceLinks||[]).map((link) => { delete link.id; return link; }); } if ( !data.environment ) { data.environment = {}; } healthCheckData = data.healthCheck; delete data.healthCheck; } else { data = { type: 'container', requestedHostId: params.hostId, tty: true, stdinOpen: true, }; } var instance = store.createRecord(data); if ( healthCheckData ) { // The type isn't set on an existing one healthCheckData.type = 'instanceHealthCheck'; instance.set('healthCheck', store.createRecord(healthCheckData)); } return Ember.Object.create({ instance: instance, allHosts: results.allHosts, }); });