[Задача 12794] Доделал отображение карточек, добавил метод для получения…

[Задача 12794] Доделал отображение карточек, добавил метод для получения опечаток в модель и контроллер
parent d1909774
...@@ -100,6 +100,17 @@ class Typos extends CI_Controller { ...@@ -100,6 +100,17 @@ class Typos extends CI_Controller {
echo json_encode($this->typo->getMessagesList($data)); echo json_encode($this->typo->getMessagesList($data));
} }
function getSiteTypos($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->getSiteTypos($siteId)));
}
/*Управление сайтами*/ /*Управление сайтами*/
function panel_sites() { function panel_sites() {
$id_site = $this->input->get("id"); $id_site = $this->input->get("id");
......
...@@ -181,6 +181,20 @@ class Typo extends CI_Model { ...@@ -181,6 +181,20 @@ class Typo extends CI_Model {
return $this->db->get()->result(); return $this->db->get()->result();
} }
/**
* Получает список опечаток текущего пользователя для данного
* сайта. Возвращает список.
*
* @param $siteId
*/
function getSiteTypos($siteId) {
$this->db->select("id, text as originalText, context, comment as correctedText, date, status as isCorrected");
$this->db->from("messages");
$this->db->where("site_id", $siteId);
return $this->db->get()->result();
}
/* Получаем список сообщений об опечатках */ /* Получаем список сообщений об опечатках */
function getMessagesList($data) { function getMessagesList($data) {
......
import React from 'react'; import React from 'react';
import Typo from './Typo' import Typo from './Typo/index'
export default class Application extends Component { export default class Application extends Component {
render() { render() {
......
...@@ -33,7 +33,7 @@ export default class SiteList extends React.Component { ...@@ -33,7 +33,7 @@ export default class SiteList extends React.Component {
loadSiteTypos(siteId, done) { loadSiteTypos(siteId, done) {
$.ajax({ $.ajax({
url: window.baseUrl + "/users/typos/getSiteTypos?siteId=" + this.sites[siteId], url: `${window.baseUrl}/users/typos/getSiteTypos/${this.sites[siteId].id}`,
}).done((typos) => { }).done((typos) => {
this.typos = typos; this.typos = typos;
......
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Card, CardBody, CardText} from 'reactstrap' import {Card, CardHeader, CardTitle, CardFooter, CardBody, CardText} from 'reactstrap'
import './style.css'
export default class Typo extends Component { export default class Typo extends Component {
...@@ -11,22 +13,32 @@ export default class Typo extends Component { ...@@ -11,22 +13,32 @@ export default class Typo extends Component {
const {typo} = this.props; const {typo} = this.props;
const display = this.state.show ? "d-block" : "d-none"; const display = this.state.show ? "d-block" : "d-none";
const textColor = "text-white";
const backgroundColor = "bg-primary";
const className = `TypoCard text-center ${display} ${backgroundColor} ${textColor}`;
return ( return (
<Card className={display}> <Card className={className}>
<CardHeader> <CardHeader>
Опечатка #{typo.id} Опечатка #{typo.id}
</CardHeader> </CardHeader>
<CardBody> <CardBody>
<CardTitle><del>{typo.original}</del> -> {typo.corrected}</CardTitle> <CardTitle><del>{typo.originalText}</del> -> {typo.correctedText}</CardTitle>
<CardText>{typo.context}</CardText> <CardText>{typo.context}</CardText>
<a href="#" className="btn btn-primary">Исправить</a> <div className="card-buttons">
<a href="#" className="btn btn-danger">Отклонить</a> <div className="buttons-wrapper">
<button className="accept-button btn btn-success">Исправить</button>
<CardFooter>{typo.comment}</CardFooter> <button className="decline-button btn btn-danger">Отклонить</button>
</div>
</div>
</CardBody> </CardBody>
<CardFooter>
<p>Тут должен отображаться комментарий</p>
Добавлена <small>{typo.date}</small>
</CardFooter>
</Card> </Card>
); );
} }
......
import React, {Component} from 'react'; import React, {Component} from 'react';
import Typo from "./Typo"; import Typo from "./Typo/index";
export default class TypoList extends Component { export default class TypoList extends Component {
typos = this.props.typos;
state = { state = {
currentTypo: 0 currentTypo: 0
}; };
render() { render() {
const typoCards = this.typos.map((typo, index) => const {typos} = this.props;
<Typo typo={this.typos[this.state.currentTypo]}
const typoCards = typos.map((typo, index) =>
<Typo key={typo.id} typo={typos[this.state.currentTypo]}
show={this.state.currentTypo === index}/> show={this.state.currentTypo === index}/>
); );
return <div> return (
{typoCards} <div>
</div> {typoCards}
</div>
)
} }
} }
\ 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