function applyPromiseWithCallback(fnName, callback, args_) { try { let args = args_ if (!_.isArray(args_)) { const fnParameters = jayson.Utils.getParameterNames(rippleAPI[fnName]) args = fnParameters.map(name => args_[name]) const defaultArgs = _.omit(args_, fnParameters) assert(_.size(defaultArgs) <= 1, 'Function must have no more than one default argument') if (_.size(defaultArgs) > 0) { args.push(defaultArgs[_.keys(defaultArgs)[0]]) } } Promise.resolve(rippleAPI[fnName](...args)) .then(res => callback(null, res)) .catch(err => { callback({code: 99, message: err.message, data: {name: err.name}}) }) } catch (err) { callback({code: 99, message: err.message, data: {name: err.name}}) } }
p.then(() => { assert.lengthOf(fetchMock.calls("/_admin/v1/uidata"), 1); assert.lengthOf(_.keys(state), 2); assert.equal(state[uiKey1].state, uidata.UIDataState.SAVING); assert.equal(state[uiKey2].state, uidata.UIDataState.SAVING); assert.isUndefined(state[uiKey1].data); assert.isUndefined(state[uiKey2].data); assert.notProperty(state[uiKey1], "data"); assert.notProperty(state[uiKey2], "data"); assert.isUndefined(state[uiKey1].error); assert.isUndefined(state[uiKey2].error); setTimeout( () => { assert.equal(state[uiKey1].state, uidata.UIDataState.SAVE_ERROR); assert.equal(state[uiKey2].state, uidata.UIDataState.SAVE_ERROR); assert.instanceOf(state[uiKey1].error, Error); assert.instanceOf(state[uiKey2].error, Error); done(); }, 1000, ); });
function(res) { var valittuOppiaine: any = {}; valittuOppiaine.oppiaine = res; valittuOppiaine.vuosiluokkakokonaisuudet = _.zipBy( res.vuosiluokkakokonaisuudet, "_vuosiluokkaKokonaisuus" ); $scope.valittuOppiaine = valittuOppiaine; var valittavaVuosiluokka = $scope.valittuOppiaine.vuosiluokkakokonaisuudet[ $scope.filtterit.valittuKokonaisuus ] ? $scope.filtterit.valittuKokonaisuus : _.first(_.keys($scope.valittuOppiaine.vuosiluokkakokonaisuudet)); if ($scope.currentSection === "vlk") { valittavaVuosiluokka = $scope.valittuVuosiluokkakokonaisuus.id; } $scope.valitseOppiaineenVuosiluokka(valittavaVuosiluokka, true); $scope.activeSection = "sisalto"; },
fields.forEach(field => { let newVal: any; let oldVal: any; // for dates we want to compare the time stamp if (oldObj[field] instanceof Date) { newVal = newObj[field] ? new Date(newObj[field]).getTime() : undefined; oldVal = oldObj[field] ? new Date(oldObj[field]).getTime() : undefined; // for objects, serialize first. } else if (isObject(oldObj[field])) { newVal = newObj[field] ? JSON.stringify(newObj[field]) : undefined; oldVal = oldObj[field] ? JSON.stringify(pick(oldObj[field], keys(newObj[field] || {}))) : undefined; // otherwise, take raw values. } else { newVal = newObj[field]; oldVal = oldObj[field]; } if (newVal && newVal !== oldVal) { modifiedFields.push(field); } });
function slackFieldify(inputObj: Object, short?: boolean, prefix?: string) { var prefix = prefix ? prefix + '_' : '' var short = short ? true : false if (Array.isArray(inputObj) && inputObj.length === 1) { inputObj = inputObj[0] } var result = _.map(_.keys(inputObj), function(key){ if (!_.isObject(inputObj[key])) { return { title: s(prefix + key).humanize().titleize().value(), value: inputObj[key], short: short } } else { return slackFieldify(inputObj[key], short, prefix + key) } }) result = _.flatten(result) return result }
public selectNewCertificateType(stack: Array<any>) { let self = this, objectType = Model.CryptoCertificate, columnIndex = 2, parentContext = stack[columnIndex - 1], context: any = { columnIndex: columnIndex, objectType: objectType, parentContext: parentContext, isCreatePrevented: true, path: parentContext.path + '/create' }; return Promise.all([ Promise.all(_.map(_.keys(CryptoCertificateType), (type) => this.cryptoCertificateRepository.getNewCryptoCertificate(type))), this.modelDescriptorService.getUiDescriptorForType(objectType) ]).spread(function(cryptoCertificates: Array<any>, uiDescriptor) { (cryptoCertificates as any)._objectType = objectType; context.object = _.compact(cryptoCertificates); context.userInterfaceDescriptor = uiDescriptor; return self.updateStackWithContext(stack, context); }); }
}).then((backingData: Partial<IEcsServerGroupCommandBackingData>) => { let loadBalancerReloader = this.$q.when(null); backingData.accounts = keys(backingData.credentialsKeyedByAccount); backingData.filtered = {} as IEcsServerGroupCommandBackingDataFiltered; command.backingData = backingData as IEcsServerGroupCommandBackingData; this.configureVpcId(command); this.configureAvailableIamRoles(command); this.configureAvailableMetricAlarms(command); this.configureAvailableEcsClusters(command); if (command.loadBalancers && command.loadBalancers.length) { // verify all load balancers are accounted for; otherwise, try refreshing load balancers cache const loadBalancerNames = this.getLoadBalancerNames(command); if (intersection(loadBalancerNames, command.loadBalancers).length < command.loadBalancers.length) { loadBalancerReloader = this.refreshLoadBalancers(command, true); } } return this.$q.all([loadBalancerReloader]).then(() => { this.applyOverrides('afterConfiguration', command); this.attachEventHandlers(command); }); });
app.route('/api/threads/:id').post((req, res) => { const payload = req.body; const threadId = parseInt(req.params.id), participantId = parseInt(req.headers['userid']); const message: Message = { id: messageIdCounter++, threadId, timestamp: new Date().getTime(), text: payload.text, participantId }; // save the new message, it's // already linked to a thread dbMessages[message.id] = message; const thread = findThreadById(threadId); thread.messageIds.push(message.id); const otherParticipantIds = _.keys(thread.participants).filter(id => parseInt(id) !== participantId); otherParticipantIds.forEach(participantId => { thread.participants[participantId] += 1; dbMessagesQueuePerUser[participantId].push(message.id); }); thread.participants[participantId] = 0; res.status(200).send(); });
changePlugin(newPlugin: PanelPlugin) { const pluginId = newPlugin.meta.id; const oldOptions: any = this.getOptionsToRemember(); const oldPluginId = this.type; // for angular panels we must remove all events and let angular panels do some cleanup if (this.plugin.angularPanelCtrl) { this.destroy(); } // remove panel type specific options for (const key of _.keys(this)) { if (mustKeepProps[key]) { continue; } delete (this as any)[key]; } this.cachedPluginOptions[oldPluginId] = oldOptions; this.restorePanelOptions(pluginId); // switch this.type = pluginId; this.plugin = newPlugin; // Let panel plugins inspect options from previous panel and keep any that it can use if (newPlugin.onPanelTypeChanged) { this.options = this.options || {}; const old = oldOptions && oldOptions.options ? oldOptions.options : {}; Object.assign(this.options, newPlugin.onPanelTypeChanged(this.options, oldPluginId, old)); } if (newPlugin.onPanelMigration) { this.pluginVersion = getPluginVersion(newPlugin); } }
function addAnnotations(options) { if (!annotations || annotations.length === 0) { return; } var types = {}; for (var i = 0; i < annotations.length; i++) { var item = annotations[i]; if (!types[item.source.name]) { types[item.source.name] = { color: item.source.iconColor, position: 'BOTTOM', markerSize: 5, }; } } options.events = { levels: _.keys(types).length + 1, data: annotations, types: types, }; }