How to use api - 10 common examples

To help you get started, we’ve selected a few api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rafi16jan / rapyd-framework / client / src / components / Field.jsx View on Github external
api.globals.onchange_running = false;
    window.models.env.context.active_error && (window.models.env.context.active_error.field_map[this.props.name] = false);
    if (this.input_type && this.input_type === 'file' && value) {
      value = await api.readAsDataURL(value);
      value = value.split('base64,')[1];
    }
    if (!this.props.cellEdit) window.models.env.context.active_id[this.props.name] = value;
    else return window.models.env.context.refresh();
    await window.models.env.context.active_id._wait_promise();
    const model = props.model;// || window.models.env.context.active_model;
    const field = window.models.env[model]._fields[props.name];
    const type = field.type;
    if (this.refs.input) {
      await this.setInputValue(value);
    }
    else if (api.hasValue(['many2many', 'one2many', 'many2one', 'one2one'], type) && !props.children) {
      await this.setSelectivityValue(altvalue);
    }
    else if (type === 'selection') {
      if (this.props.widget === 'statusbar') return this.setState({value});
      await this.setSelectivityValue(altvalue);
    }
    else if (api.hasValue(['date', 'datetime'], type)) {
      await this.setState({value, input: this.refs.date_input.base.querySelector('input')});
    }
    else {
      await this.setState({value: altvalue || value});
    }
    return window.models.env.context.refresh();
  }
github bitshares / bitshares-ui / app / actions / MarketsActions.js View on Github external
cancelLimitOrder(accountID, orderID) {
        // Set the fee asset to use
        let fee_asset_id = accountUtils.getFinalFeeAsset(
            accountID,
            "limit_order_cancel"
        );

        var tr = WalletApi.new_transaction();
        tr.add_type_operation("limit_order_cancel", {
            fee: {
                amount: 0,
                asset_id: fee_asset_id
            },
            fee_paying_account: accountID,
            order: orderID
        });
        return WalletDb.process_transaction(tr, null, true).catch(error => {
            console.log("cancel error:", error);
        });
    }
github huridocs / uwazi / app / api / search / specs / fixtures.js View on Github external
/* eslint-disable max-len */
import db from 'api/utils/testing_db';

const batmanFinishesId = db.id();
const unpublishedId = db.id();
const syncPropertiesEntityId = db.id();
const templateId = db.id();
const userId = db.id();

export default {
  entities: [
    { _id: batmanFinishesId, sharedId: 'shared', template: templateId, language: 'en', title: 'Batman finishes', published: true, user: userId },
    { _id: unpublishedId, sharedId: 'unpublished', template: db.id(), language: 'en', title: 'unpublished', published: false, user: userId },
    { _id: db.id(), sharedId: 'shared', language: 'es', title: 'Penguin almost done', creationDate: 1, published: true },
    {
      _id: db.id(), sharedId: 'shared', language: 'pt', title: 'Penguin almost done', creationDate: 1, published: true, metadata: { text: 'test' }
    },
    //select/multiselect/date sync
    { _id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', language: 'en', title: 'EN', published: true, metadata: { text: 'text' } },
    { _id: db.id(), template: templateId, sharedId: 'shared1', language: 'es', title: 'ES', creationDate: 1, published: true, metadata: { text: 'text' } },
    { _id: db.id(), template: templateId, sharedId: 'shared1', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: { text: 'text' } }
github huridocs / uwazi / app / api / sync / specs / fixtures.js View on Github external
/* eslint-disable max-len */
import db from 'api/utils/testing_db';

const oldDoc1 = db.id();
const oldDoc2 = db.id();

const newDoc1 = db.id();
const newDoc2 = db.id();
const newDoc3 = db.id();
const newDoc4 = db.id();
const newDoc5 = db.id();
const newDoc6 = db.id();
const newDoc7 = db.id();
const newDoc8 = db.id();
const newDoc9 = db.id();
const newDoc10 = db.id();

const template1 = db.id();

const template1Property1 = db.id();
const template1Property2 = db.id();
const template1Property3 = db.id();
const template1PropertyThesauri1Select = db.id();
const template1PropertyThesauri2Select = db.id();
const template1PropertyThesauri3MultiSelect = db.id();
const template1PropertyRelationship1 = db.id();
const template1PropertyRelationship2 = db.id();

const template2 = db.id();
github huridocs / uwazi / app / api / documents / specs / fixtures.js View on Github external
/* eslint-disable */
import db from 'api/utils/testing_db';

const batmanFinishesId = db.id();
const syncPropertiesEntityId = db.id();
const templateId = db.id();
const referenceId = db.id();

export default {
  entities: [
    {_id: batmanFinishesId, sharedId: 'shared', template: templateId, language: 'en', title: 'Batman finishes', published: true, user: {username: 'username'}, file: {filename: '8202c463d6158af8065022d9b5014cc1.pdf', originalname: 'Batman original.jpg'}},
    {_id: db.id(), sharedId: 'shared', language: 'es', title: 'Penguin almost done', creationDate: 1, published: true, user: {username: 'username'}, file: {filename: '8202c463d6158af8065022d9b5014ccb.pdf', fullText: 'fullText'}, attachments: [{filename: '8202c463d6158af8065022d9b5014ccc.pdf'}]},
    {
      _id: db.id(), sharedId: 'shared', language: 'pt', title: 'Penguin almost done', creationDate: 1, published: true, metadata: {text: 'test'},
      user: {username: 'username'}
    },
    //select/multiselect/date sync
    {_id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', language: 'en', title: 'EN', published: true, metadata: {text: 'text'}, user: {username: 'username'}},
    {_id: db.id(), template: templateId, sharedId: 'shared1', language: 'es', title: 'ES', creationDate: 1, published: true, metadata: {text: 'text'}, user: {username: 'username'}},
    {_id: db.id(), template: templateId, sharedId: 'shared1', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: {text: 'text'}, user: {username: 'username'}}
  ],
  settings: [
    {_id: db.id(), languages: [{key: 'es'}, {key: 'pt'}, {key: 'en'}]}
  ],
  templates: [
    {_id: templateId, name: 'template_test', properties: [
      {type: 'text', name: 'text'},
      {type: 'select', name: 'select'},
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
fetchQueryExecutionAnalysis(options) {
    const self = this;
    //var url = '/metadata/api/workload_analytics/get_impala_query/';
    const url = '/impala/api/query/alanize';
    const deferred = $.Deferred();

    let tries = 0;

    const cancellablePromises = [];

    const promise = new CancellablePromise(deferred, undefined, cancellablePromises);

    const pollForAnalysis = () => {
      if (tries === 10) {
        deferred.reject();
        return;
      }
      tries++;
      cancellablePromises.pop(); // Remove the last one
      cancellablePromises.push(
        deferred,
        self
          .simplePost(
            url,
            {
              cluster: JSON.stringify(options.compute),
              query_id: '"' + options.queryId + '"'
github Tencent / TSW / bin / proxy / master.js View on Github external
true
            && (nowDate.getHours() % 8 === 0)
            && nowDate.getMinutes() === 1
            && nowDate.getSeconds() <= 10
        ) {
            // 8小时一次
            require('api/keyman/runtimeAdd.js').hello();
        }

        // after 1 minute
        if (checkWorkerAliveCount % 12 === 0) {
            const info = network.getNetInfo();

            // network report
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXBIT', info.external.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXPCK', info.external.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXBIT', info.external.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXPCK', info.external.transmit.packets);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXBIT', info.internal.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXPCK', info.internal.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXBIT', info.internal.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXPCK', info.internal.transmit.packets);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXBIT', info.local.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXPCK', info.local.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXBIT', info.local.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXPCK', info.local.transmit.packets);

            // cpu load report
            cpuUtil.getCpuLoadAsync().then(function(data) {
                if (!data) {
                    return;
                }
github Tencent / TSW / bin / tsw / util / logger / logger.js View on Github external
};

    freqCache.detail[mod_act] = cfg;
  }

  cfg.count++;

  // 最后一条报错信息也记录下来
  // cfg.errMsg = merge(str, obj);

  // 总错误量超过了上限
  if (freqCache.count > errFreqConfig.count) {
    exceed = true;

    logger && logger.drop();
    tnm2.Attr_API('SUM_TSW_ERROR_LOG_DROP', 1);
  }

  return exceed;
}
github Tencent / TSW / bin / proxy / master.js View on Github external
if (checkWorkerAliveCount % 12 === 0) {
            const info = network.getNetInfo();

            // network report
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXBIT', info.external.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXPCK', info.external.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXBIT', info.external.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXPCK', info.external.transmit.packets);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXBIT', info.internal.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXPCK', info.internal.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXBIT', info.internal.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXPCK', info.internal.transmit.packets);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXBIT', info.local.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXPCK', info.local.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXBIT', info.local.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXPCK', info.local.transmit.packets);

            // cpu load report
            cpuUtil.getCpuLoadAsync().then(function(data) {
                if (!data) {
                    return;
                }

                tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_1', data.L1);
                tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_5', data.L5);
                tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_15', data.L15);
            });
        }

        tnm2.Attr_API_Set('AVG_TSW_CPU_USED', global.cpuUsed);
    }, checkWorkerAliveTimeout);
}
github Tencent / TSW / bin / proxy / master.js View on Github external
// after 1 minute
        if (checkWorkerAliveCount % 12 === 0) {
            const info = network.getNetInfo();

            // network report
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXBIT', info.external.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXPCK', info.external.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXBIT', info.external.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXPCK', info.external.transmit.packets);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXBIT', info.internal.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXPCK', info.internal.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXBIT', info.internal.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXPCK', info.internal.transmit.packets);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXBIT', info.local.receive.bytes);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXPCK', info.local.receive.packets);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXBIT', info.local.transmit.bytes);
            tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXPCK', info.local.transmit.packets);

            // cpu load report
            cpuUtil.getCpuLoadAsync().then(function(data) {
                if (!data) {
                    return;
                }

                tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_1', data.L1);
                tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_5', data.L5);
                tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_15', data.L15);
            });
        }

        tnm2.Attr_API_Set('AVG_TSW_CPU_USED', global.cpuUsed);
    }, checkWorkerAliveTimeout);