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
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
// eslint-disable-next-line no-unsanitized/property
|
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
|
|
|
}
|
|
|
|
}
|