debian-mirror-gitlab/app/assets/javascripts/pages/users/user_overview_block.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-12-05 23:21:45 +05:30
import axios from '~/lib/utils/axios_utils';
const DEFAULT_LIMIT = 20;
export default class UserOverviewBlock {
constructor(options = {}) {
this.container = options.container;
this.url = options.url;
this.requestParams = {
limit: DEFAULT_LIMIT,
...options.requestParams,
};
2019-02-15 15:39:39 +05:30
this.postRenderCallback = options.postRenderCallback;
2018-12-05 23:21:45 +05:30
this.loadData();
}
loadData() {
2019-03-02 22:35:43 +05:30
const containerEl = document.querySelector(this.container);
const loadingEl = containerEl.querySelector(`.loading`);
2018-12-05 23:21:45 +05:30
loadingEl.classList.remove('hide');
axios
.get(this.url, {
params: this.requestParams,
})
.then(({ data }) => this.render(data))
.catch(() => loadingEl.classList.add('hide'));
}
render(data) {
const { html, count } = data;
2019-02-15 15:39:39 +05:30
const containerEl = document.querySelector(this.container);
const contentList = containerEl.querySelector('.overview-content-list');
2018-12-05 23:21:45 +05:30
contentList.innerHTML += html;
2019-02-15 15:39:39 +05:30
const loadingEl = containerEl.querySelector('.loading');
2018-12-05 23:21:45 +05:30
if (count && count > 0) {
2019-02-15 15:39:39 +05:30
containerEl.querySelector('.js-view-all').classList.remove('hide');
2018-12-05 23:21:45 +05:30
} else {
2019-02-15 15:39:39 +05:30
const nothingHereBlock = containerEl.querySelector('.nothing-here-block');
if (nothingHereBlock) {
2019-03-02 22:35:43 +05:30
nothingHereBlock.classList.add('p-5');
2019-02-15 15:39:39 +05:30
}
2018-12-05 23:21:45 +05:30
}
loadingEl.classList.add('hide');
2019-02-15 15:39:39 +05:30
if (this.postRenderCallback) {
this.postRenderCallback.call(this);
}
2018-12-05 23:21:45 +05:30
}
}