Commit 476eccac authored by Soldatoff's avatar Soldatoff

Added a function to get the number of typos. And displaying their number for all sites.

parent 929100e7
......@@ -196,6 +196,17 @@ class Typos extends CI_Controller {
->set_output(json_encode($this->typo->getSiteTypos($siteId)));
}
function getCountTypos($siteId = null) {
if (is_null($siteId)) {
return $this->output->set_status_header(400)
->set_output("Missing siteId parameter!");
}
return $this->output->set_content_type("application/json")
->set_status_header(200)
->set_output(json_encode($this->typo->getCountTypos($siteId)));
}
/**
* Получить список сообщений об опечатках для пользователя
* OLD
......
......@@ -202,6 +202,14 @@ class Typo extends CI_Model {
return $this->db->get()->result();
}
function getCountTypos($siteId) {
$this->db->select("count(*)");
$this->db->from("messages");
$this->db->where("site_id", $siteId);
$this->db->where("status", 0);
return $this->db->get()->result();
}
/* Получаем список сообщений об опечатках */
function getMessagesList($data) {
......
......@@ -11,6 +11,7 @@ export default class SiteList extends React.Component {
super(props);
this.sites = this.props.sites;
this.updateCountTypos();
console.log("Render SiteList");
this.state = {
......@@ -56,6 +57,12 @@ export default class SiteList extends React.Component {
);
}
updateCountTypos(){
for (let i = 0; i < this.sites.length; i += 1) {
this.getCountTypos(this.sites[i], i)
}
}
loadSiteTypos(siteId, done) {
$.ajax({
url: `${window.baseUrl}/users/typos/getSiteTypos/${this.sites[siteId].id}`,
......@@ -83,21 +90,31 @@ export default class SiteList extends React.Component {
});
}
getCountTypos(site, num) {
$.ajax({
url: `${window.baseUrl}/users/typos/getCountTypos/${this.sites[num].id}`,
}).done((count) => {
const count_typos = count;
this.sites[num].count = count_typos[0]["count(*)"];
}).fail((error) => {
console.log(error);
});
}
render() {
const tabItems = this.sites.map((site, index) =>
<NavItem key={index}>
<NavLink className={this.state.activeTab === index ? "active" : ""}
onClick={() => { this.updateTab(index) }}>
onClick={() => { this.updateTab(index), this.updateCountTypos()}}>
{site.name}
<Badge id={site.id + "-typos-count"} className={"typos-count"}
hidden={this.state.activeTab !== index}>
{this.state.typos.length}
<Badge id={site.id + "-typos-count"} className={"typos-count"}>
{site.count}
</Badge>
</NavLink>
{this.state.activeTab === index &&
<FaRefresh className="refresh-site" title="Обновить"
onClick={ () => { this.updateTab() } } />}
onClick={ () => { this.updateTab(index), this.updateCountTypos() } } />}
</NavItem>
);
......
......@@ -156,6 +156,6 @@ export default class TypoList extends Component {
* @private
*/
updateSiteTyposCount() {
$(`#${this.state.siteId}-typos-count`).text(this.props.typos.length);
$(`#${this.state.siteId}-typos-count`);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment