<commit_before>/*global $*/
const m = require('mithril');

const UserModel = require('../models/user');
const DataDisplay = require('../components/datadisplay');

const platformImg = {
  facebook: '/admin/img/facebook.png'
};

const Users = module.exports = {
  controller: function () {
    let ctrl = this;

    ctrl.columns = m.prop(['id', 'name', 'followers', 'platform', 'actions']);

    ctrl.names = m.prop({
      id: 'Id',
      name: 'Name',
      followers: 'Followers',
      platform: 'Platform',
      actions: 'Actions'
    });

    let selectConfig = {
      config: () => { $('select').material_select(); }, // for materialize-css
      onchange: m.withAttr('value', m.route)
    };

    let getPlatform = (platform) => m('img', {src: platformImg[platform]});

    let getActions = (id) => [
      m('select', selectConfig, [
        m('option', {disabled: true, selected: true}, 'Choose...'),
        m('option', {value: '/users/view/' + id}, 'View / Edit')
      ]),
      m('label', 'Items per Page')
    ];

    let parse = (users) => users.map(
        function (user) {
          return {
            id: user.id(),
            name: user.alias(),
            followers: '42', // TODO: Get user's follower count
            platform: getPlatform(user.platform()),
            actions: getActions(user.id())
          };
        }
    );

    ctrl.data = UserModel.list().then(parse);
  },
  view: function (ctrl) {
    return [m('h1', 'Users'),
      m.component(DataDisplay, {
        columns: ctrl.columns(),
        names: ctrl.names(),
        data: ctrl.data
      })
    ];
  }
};<commit_msg>Change terminology (follow -> subscribe)<commit_after>/*global $*/
const m = require('mithril');

const UserModel = require('../models/user');
const DataDisplay = require('../components/datadisplay');

const platformImg = {
  facebook: '/admin/img/facebook.png'
};

const Users = module.exports = {
  controller: function () {
    let ctrl = this;

    ctrl.columns = m.prop(['id', 'name', 'subscribers', 'platform', 'actions']);

    ctrl.names = m.prop({
      id: 'Id',
      name: 'Name',
      subscribers: 'Subscribers',
      platform: 'Platform',
      actions: 'Actions'
    });

    let selectConfig = {
      config: () => { $('select').material_select(); }, // for materialize-css
      onchange: m.withAttr('value', m.route)
    };

    let getPlatform = (platform) => m('img', {src: platformImg[platform]});

    let getActions = (id) => [
      m('select', selectConfig, [
        m('option', {disabled: true, selected: true}, 'Choose...'),
        m('option', {value: '/users/view/' + id}, 'View / Edit')
      ]),
      m('label', 'Items per Page')
    ];

    let parse = (users) => users.map(
        function (user) {
          return {
            id: user.id(),
            name: user.alias(),
            subscribers: '42', // TODO: Get user's subscriber count
            platform: getPlatform(user.platform()),
            actions: getActions(user.id())
          };
        }
    );

    ctrl.data = UserModel.list().then(parse);
  },
  view: function (ctrl) {
    return [m('h1', 'Users'),
      m.component(DataDisplay, {
        columns: ctrl.columns(),
        names: ctrl.names(),
        data: ctrl.data
      })
    ];
  }
};
{'fraction_non_alphanumeric': 0.1872522110399512, 'fraction_numerical': 0.0018298261665141812, 'mean_word_length': 2.313131313131313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3422824', 'n_tokens_mistral': 1020, 'n_tokens_neox': 987, 'n_words': 229}