Beispiel #1
0
module.exports = function (url) {
  return AmpCollection.extend({
    model: user,
    url: url,
    comparator: 'name'
  })
}
Beispiel #2
0
  initialize: function () {
    var self = this
    this.collection = null

    var CompaniesCollection = AmpersandRestCollection.extend({
      url: '/api/companies?event=' + app.me.selectedEvent + '&member=' + self.model.id,
      model: Company
    })
    var companies = new CompaniesCollection()

    var options = {
      success: function () {
        self.collection = companies
        self.render()
      }
    }

    companies.fetch(options)
  },
Beispiel #3
0
import Collection from 'ampersand-rest-collection'
import Library from './library'

export default Collection.extend({
  url: 'https://bibdata.princeton.edu/locations/libraries.json',

  model: Library,

  getByCode (locCode) {
    let model = this.findWhere({code: locCode})

    if (!model) {
      model = new Library({code: locCode})
    }

    model.fetch()

    return model
  }

})
Beispiel #4
0
var Collection = require('ampersand-rest-collection');
var Howl = require('./howl');

module.exports = Collection.extend({
    model: Howl,
    url: 'http://wolves.technology/howls',
    comparator: function (model) {
        return -1 * model.createdAt.valueOf();
    },

    fetchRealtime: function () {
        this.fetch();

        var self = this;
        var socket = new WebSocket('ws://wolves.technology');

        socket.onmessage = function (event) {
            var data = JSON.parse(event.data);

            if (data.channel === self.url && data.action === 'update') {
                console.log('Got a howl with id', data.id);
                self.fetchById(data.id);
            }
        };
    }
});
import Collection from 'ampersand-rest-collection'
import githubMixin from '../helpers/github-mixin'
import Label from './label'

export default Collection.extend(githubMixin, {
  model: Label,

  url () {
    return 'https://api.github.com/repos/' + this.parent.full_name + '/labels'
  }
})
import Collection from 'ampersand-rest-collection'
import Label from './label'
import githubApiMixin from '../helpers/github-api-mixin'

export default Collection.extend(githubApiMixin, {
	url () {
		return this.parent.url() + '/labels'
	},
	
	model: Label
})
Beispiel #7
0
var Collection = require("ampersand-rest-collection");
var StrikeList = require("./StrikeList.js");

module.exports = Collection.extend({
    model: StrikeList,
    url: "/apiv1/lists",
    parse: function(response) {
        return response.lists;
    }
});
Beispiel #8
0
import ajaxConfig from "../misc/ajax_config";
import Collection from "ampersand-rest-collection";
import SeriesModel from "./a_series";

export default Collection.extend(ajaxConfig, {
	url() {
		return this.urlRoot;
	},
	urlRoot: "/series",
	mainIndex: "slug",
	model: SeriesModel
});
import Collection from 'ampersand-rest-collection';
import Label from './label.js';
import githubMixin from '../helpers/github-mixin.js';

export default Collection.extend(githubMixin, {
  url () {
    return `${this.parent.url()}/labels`;
    // return `https://api.github.com/repos/${owner}/${repo}`;
  },

  model: Label
});
var AmpersandCollection = require('ampersand-rest-collection');
var Package = require('../models/package');

module.exports = AmpersandCollection.extend({
    model: Package,
    pages: 0,
    current_page: 0,
    results: 0,
    param: "",
    url: function() {
        var url = '/api/search?q={"name": "' + this.param + '"}';
        if(isNaN(this.page_no) == false)
            url = url + "&page=" + this.page_no;

        return url;
    },
    parse: function(res, options) {
        this.pages = res.total_pages;
        this.current_page = res.page;
        this.results = res.num_results;
        return res.objects;
    },
    search: function(param, page_no) {
        this.param = param;
        this.page_no = page_no;
        this.fetch({reset: true});
    }
});

var Collection = require('ampersand-rest-collection');
var Person = require('./person');


module.exports = Collection.extend({
    url: '/api/people',
    model: Person
});
'use strict';

var Collection = require('ampersand-rest-collection');
var localforageMixin = require('./localforage-mixin');

module.exports = Collection.extend(localforageMixin);
const Collection = require('ampersand-rest-collection');
const Comment = require('../models/comment');


module.exports = Collection.extend({
    model: Comment,
    url: 'http://jsonplaceholder.typicode.com/posts/1/comments'
});
Beispiel #14
0
export default Collection.extend({
  model: Experiment,
  indexes: ['slug'],
  url: '/api/experiments.json',
  comparator: 'order',

  // Ampersand.sync doesn't seem to pass correct Accept headers by default.
  // This supposedly is fixed by https://github.com/AmpersandJS/ampersand-sync/pull/24
  // but still seems busted. Maybe the deps of the dependents haven't been
  // updated yet? TODO: investigate
  ajaxConfig: { headers: { 'Accept': 'application/json' }},

  initialize() {
    app.on('webChannel:addon-self:uninstalled', () => {
      this.models.forEach(m => m.enabled = false);
    });
  },

  fetch(optionsIn) {
    return new Promise((resolve, reject) => {
      const options = optionsIn || {};
      options.success = resolve;
      options.error = reject;
      Collection.prototype.fetch.call(this, options);
    });
  },

  // django-rest-framework returns the actual models under 'results'
  parse(response) {
    return response.results;
  }
});
var LastFmModel = require('./lastfm.model');
var _ = require("lodash");
var Collection = require("ampersand-rest-collection");

var LastFmCollection = Collection.extend({
    model: LastFmModel,
    url: 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=ryu85&limit=10&api_key=158ae35ee8765aa3463a2e74cbb6d9d3&format=json',
    initialize: function(){
        this.fetch();
    },
    parse: function(data) {
        return _.map(data.recenttracks.track, function(track) {

            var nowplaying =  (track['@attr']) ? track['@attr'].nowplaying : false;

            return {
                track: track.name,
                artist: track.artist['#text'],
                cover: track.image[0]['#text'],
                link: track.url,
                playing: Boolean(nowplaying)
            };
        });
    }
});

module.exports = LastFmCollection;
Beispiel #16
0
var Collection = require('ampersand-rest-collection');
var Tournament = require('../models/tournament');

module.exports = Collection.extend({
    model: Tournament,
    url: '/tournaments',

    findBySlug: function(slug) {
      return this.findWhere({slug: slug});
    },

    findByID: function(id) {
      return this.findWhere({id: id});
    }
});
Beispiel #17
0
const RestCollection = require('ampersand-rest-collection');
const UserModel = require('./user_model');
const config = require('../api/config');
const sync = require('../api/api_sync');

const UserCollection = RestCollection.extend({
  model: UserModel,

  url() {
    return config.api.host + '/timeline/v1/' + this.parent.id + '/members';
  },

  sync
});

module.exports = UserCollection;
// MyModel Collection - my-model-collection.js
var AmpCollection = require('ampersand-rest-collection');
var MyModel = require('./my-model');


module.exports = AmpCollection.extend({
    model: MyModel,
    url: '/api/my-model'
});
var $ = require('jquery');
var RestCollection = require('ampersand-rest-collection');

var BaseRestCollection = RestCollection.extend({
  ajaxConfig: function() {
    return {
      xhrFields: {
        timeout: 120000 // defaults to 5 sec
      }
    };
  },
  fetchDeferred: function() {
    var deferred = $.Deferred();

    this.fetch({
      success: function(collection) {
        deferred.resolveWith(this, collection);
      }
    });

    return deferred.promise();
  }
});

module.exports = BaseRestCollection;
Beispiel #20
0
var Collection = require('ampersand-rest-collection');
var Todo = require('./todo');


module.exports = Collection.extend({
    model: Todo,
    url: '/api/todos'
});
var Collection = require('ampersand-rest-collection')
  , User = require('./user');

module.exports = Collection.extend({
  urlRoot: '/api/v1/user',
  model: User
});
import Collection from 'ampersand-rest-collection';
import Repo from './repo';
import githubMixin from '../helpers/github-mixin';

export default Collection.extend(githubMixin, {
    url: 'https://api.github.com/user/repos',

    model: Repo,

    getByFullName(fullName) {
        let model = this.findWhere({full_name: fullName});

        if(!model) {
            model = new Repo({ full_name: fullName});
        }

        model.fetch();

        return model;
    }
});
var Collection = require('ampersand-rest-collection');
var PatternRowModel = require('./pattern-row');

var PatternRowsCollection = Collection.extend({
	model: PatternRowModel
});

module.exports = PatternRowsCollection;
Beispiel #24
0
var AmpCollection = require('ampersand-rest-collection')
var session = require('./session')

module.exports = AmpCollection.extend({
  model: session,
  url: '/api/sessions'
})
Beispiel #25
0
import Collection from 'ampersand-rest-collection'
import Repo from './repo'
import githubMixin from '../helpers/github-mixin'

export default Collection.extend(githubMixin, {
  url: 'https://api.github.com/user/repos',

  model: Repo
})
// StatusLine Collection - status-line-collection.js
var AmpCollection = require('ampersand-rest-collection');
var StatusLine = require('./status-line');


module.exports = AmpCollection.extend({
    model: StatusLine,
    url: '/api/status-line'
});
Beispiel #27
0
var AmpCollection = require('ampersand-rest-collection');
var Ninja = require('./ninja');

module.exports = AmpCollection.extend({
  model: Ninja,
  url: '/api/ninjas'
});
import Collection from 'ampersand-rest-collection'
import RepoModel from './repo'
import githubMixin from '../helpers/github-mixin'

export default Collection.extend(githubMixin, {
  url: 'https://api.github.com/user/repos',

  model: RepoModel,

  getModelByName (name) {
    let model = this.findWhere({full_name: name})
    if (!model) {
      model = new RepoModel({full_name: name})
    }
    model.fetch()
    return model
  }
})
import Collection from 'ampersand-rest-collection';
import Label from './label';
import xhr from 'xhr';
import githubMixin from '../helpers/githubMixin'

export default Collection.extend(githubMixin, {
    url() {
        return this.parent.url() + '/labels';
    },
    model: Label,
    addNewLabel(attributes) {
        xhr({
            url: this.url(),
            method: 'POST',
            json: attributes,
            headers: {
                Authorization: 'token ' + app.me.token,
            },
        }, function (err, res, body) {
            console.log(res);
        });
    }
})
var setBearer = require('../../ajax-config');
var API_ROOT = require('../../api-root');

module.exports = Collection.extend({
  typeAttribute: 'modelType',
  ajaxConfig: setBearer,

  getType: function() {
    return this[this.typeAttribute];
  },

  url: function() {
    return API_ROOT + '/' + this.getType();
  },

  parse: function(data) {
    return parse(this.getType(), data);
  },

  serialize: function() {
    var wrapped = {};
    var type = this.getType();

    wrapped[type] = this.map(function(model) {
      return model.serialize()[type];
    });

    return wrapped;
  }
});