gitlab-org--gitlab-foss/app/assets/javascripts/activities.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-06-16 09:20:30 -04:00
/* eslint-disable class-methods-use-this */
2017-03-11 01:45:34 -05:00
import $ from 'jquery';
2017-03-11 01:45:34 -05:00
import Cookies from 'js-cookie';
import createFlash from '~/flash';
import { s__ } from '~/locale';
import { localTimeAgo } from './lib/utils/datetime_utility';
import Pager from './pager';
export default class Activities {
constructor(containerSelector = '') {
this.containerSelector = containerSelector;
this.containerEl = this.containerSelector
? document.querySelector(this.containerSelector)
: undefined;
this.$contentList = $('.content_list');
this.loadActivities();
$('.event-filter-link').on('click', (e) => {
e.preventDefault();
this.toggleFilter(e.currentTarget);
this.reloadActivities();
});
}
2016-07-24 16:45:11 -04:00
loadActivities() {
Pager.init({
limit: 20,
preload: true,
prepareData: (data) => data,
successCallback: () => this.updateTooltips(),
errorCallback: () =>
createFlash({
message: s__(
'Activity|An error occured while retrieving activity. Reload the page to try again.',
),
parent: this.containerEl,
}),
container: this.containerSelector,
});
}
updateTooltips() {
localTimeAgo(document.querySelectorAll('.content_list .js-timeago'));
}
2016-07-24 16:45:11 -04:00
reloadActivities() {
this.$contentList.html('');
this.loadActivities();
}
toggleFilter(sender) {
const $sender = $(sender);
const filter = $sender.attr('id').split('_')[0];
2016-07-24 16:45:11 -04:00
$('.event-filter .active').removeClass('active');
Cookies.set('event_filter', filter);
2016-07-24 16:45:11 -04:00
$sender.closest('li').toggleClass('active');
}
}