and create tags instead priority script 4.8 (#849)

* and create tags instead priority script 4.8

* change names request ticket ids

* add tag model documentation

* .
This commit is contained in:
Guillermo Giuliana 2020-07-22 13:24:40 -03:00 committed by GitHub
parent 791e0969e9
commit c4a2c48eae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 327 additions and 23 deletions

View File

@ -21,7 +21,9 @@ class DashboardListTicketsPage extends React.Component {
static defaultProps = {
tickets: []
};
updateTicketListRequestId = 0;
state = {
tickets: [],
pages: 1,
@ -84,7 +86,8 @@ class DashboardListTicketsPage extends React.Component {
});
}
updateTicketList({users, page, ownTickets}) {
updateTicketList({users, page, ownTickets}) {
let id = ++this.updateTicketListRequestId;
let usersIds = users.map((item) => {
return item.id
})
@ -97,13 +100,15 @@ class DashboardListTicketsPage extends React.Component {
supervisedUsers: JSON.stringify(usersIds)
}
}).then((r) => {
this.setState({
tickets: r.data.tickets,
pages: r.data.pages,
page: r.data.page,
message: '',
loading: false
})
if (id === this.updateTicketListRequestId){
this.setState({
tickets: r.data.tickets,
pages: r.data.pages,
page: r.data.page,
message: '',
loading: false
})
}
}).catch((r) => {
this.setState({
tickets: [],

View File

@ -25,7 +25,7 @@ class Autocomplete extends React.Component {
comparerFunction: React.PropTypes.func
};
id = 1;
searchApiRequestId = 1;
state = {
selectedItems: [],
@ -238,17 +238,18 @@ class Autocomplete extends React.Component {
searchApi(query, blacklist=this.getSelectedItems()) {
const { getItemListFromQuery } = this.props;
let id = ++this.id;
let id = ++this.searchApiRequestId;
getItemListFromQuery && getItemListFromQuery(query, blacklist.map(
item => {return item.isStaff !== undefined ? {isStaff: item.isStaff, id: item.id} : item.id}
))
.then(result => {
if(id === this.id)
this.setState({
itemsFromQuery: result,
loading: false,
});
if (id === this.searchApiRequestId){
this.setState({
itemsFromQuery: result,
loading: false,
});
}
})
.catch(() => this.setState({
loading: false,

View File

@ -1,6 +1,11 @@
<?php
//documentacion
/**
* @api {OBJECT} Tag Tag
* @apiVersion 4.8.0
* @apiGroup Data Structures
* @apiParam {String} name The name of the tag.
* @apiParam {String} color The color of the tag.
*/
class Tag extends DataStore {
const TABLE = 'tag';

View File

@ -5,9 +5,44 @@ use RedBeanPHP\Facade as RedBean;
print 'Begin update v4.8.0...' . PHP_EOL;
// Update ticket table
print '[1/3] Updating ticket table...'. PHP_EOL;
if($mysql->query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'ticket' AND COLUMN_NAME = 'priority' AND TABLE_SCHEMA = '$mysql_db'")->num_rows == 0){
if($mysql->query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'ticket' AND COLUMN_NAME = 'priority' AND TABLE_SCHEMA = '$mysql_db'")->num_rows != 0){
$tagHigh = new Tag();
$tagHigh->setProperties([
'name' => 'High',
'color' => '#eb144c'
]);
$tagHigh->store();
$tagMedium = new Tag();
$tagMedium->setProperties([
'name' => 'Medium',
'color' => '#0693e3'
]);
$tagMedium->store();
$tagLow = new Tag();
$tagLow->setProperties([
'name' => 'Low',
'color' => '#00d084'
]);
$tagLow->store();
$ticketList = Ticket::getAll();
foreach($ticketList as $ticket) {
if($ticket->priority == "low") {
$ticket->sharedTagList->add($tagLow);
}
if($ticket->priority == "medium") {
$ticket->sharedTagList->add($tagMedium);
}
if($ticket->priority == "high") {
$ticket->sharedTagList->add($tagHigh);
}
$ticket->store();
}
$mysql->query("ALTER TABLE ticket DROP priority");
} else {
print 'priority column already deleted' . PHP_EOL;
@ -30,6 +65,3 @@ $mysql->query("CREATE TABLE IF NOT EXISTS supervisedrelation (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;");
print 'Update Completed!' . PHP_EOL;

View File

@ -0,0 +1,30 @@
<?php
/**
* @api {OBJECT} Tag Tag
* @apiVersion 4.8.0
* @apiGroup Data Structures
* @apiParam {String} name The name of the tag.
* @apiParam {String} color The color of the tag.
*/
class Tag extends DataStore {
const TABLE = 'tag';
public static function getProps() {
return [
'name',
'color'
];
}
public function toArray($minimized = false) {
if($minimized){
return $this->name;
} else {
return [
'id'=> $this->id,
'name'=> $this->name,
'color' => $this->color
];
}
}
}

View File

@ -0,0 +1,231 @@
<?php
/**
* @api {OBJECT} Ticket Ticket
* @apiVersion 4.8.0
* @apiGroup Data Structures
* @apiParam {Number} ticketNumber The number of the ticket.
* @apiParam {String} title The title of the ticket.
* @apiParam {String} content The content of the ticket.
* @apiParam {Object} department The department of the ticket.
* @apiParam {Number} department.id The id of the department of the ticket.
* @apiParam {String} department.name The department's name of the ticket.
* @apiParam {String} file The filename of the ticket if attached.
* @apiParam {String} language The language of the ticket.
* @apiParam {Boolean} unread Indicates if the user has already read the last comment.
* @apiParam {Boolean} unreadStaff Indicates if the staff has already read the last comment.
* @apiParam {Boolean} closed Indicates if the ticket is closed.
* @apiParam {Object} author The author of the ticket.
* @apiParam {Number} author.id The id of the author of the ticket.
* @apiParam {String} author.name The author's name of the ticket.
* @apiParam {String} author.email The author's email of the ticket.
* @apiParam {Object} owner The owner of the ticket.
* @apiParam {Number} owner.id The owner's id of the ticket.
* @apiParam {String} owner.name The owner's name of the ticket.
* @apiParam {String} owner.email The owner's email of the ticket.
* @apiParam {[TicketEvent](#api-Data_Structures-ObjectTicketevent)[]} events Events related to the ticket.
*/
use RedBeanPHP\Facade as RedBean;
class Ticket extends DataStore {
const TABLE = 'ticket';
public static function getProps() {
return array(
'ticketNumber',
'title',
'content',
'language',
'department',
'file',
'date',
'unread',
'closed',
'author',
'authorStaff',
'owner',
'ownTicketeventList',
'unreadStaff',
'language',
'authorEmail',
'authorName',
'sharedTagList',
'editedContent',
'editedTitle'
);
}
public static function getFetchAs() {
return [
'author' => 'user',
'authorStaff' => 'staff',
'owner' => 'staff',
];
}
public static function getTicket($value, $property = 'id') {
return parent::getDataStore($value, $property);
}
public static function getByTicketNumber($value) {
return Ticket::getTicket($value, 'ticketNumber');
}
public function setAuthor($author) {
if($author instanceof User) {
$this->author = $author;
} else if($author instanceof Staff) {
$this->authorStaff = $author;
}
}
public function getAuthor() {
if($this->author && !$this->author->isNull()) {
return $this->author;
} else {
return $this->authorStaff;
}
}
public function getDefaultProps() {
return array(
'unread' => false,
'unreadStaff' => true,
'ticketNumber' => $this->generateUniqueTicketNumber()
);
}
public function store() {
parent::store();
}
public function delete() {
parent::delete();
}
public function generateUniqueTicketNumber() {
$linearCongruentialGenerator = new LinearCongruentialGenerator();
if (Ticket::count() === 0) {
$ticketNumber = Setting::getSetting('ticket-first-number')->value;
} else {
$lastTicketId = Ticket::findOne(' ORDER BY id DESC')->id;
$linearCongruentialGenerator->setGap(Setting::getSetting('ticket-gap')->value);
$linearCongruentialGenerator->setFirst(Setting::getSetting('ticket-first-number')->value);
$ticketNumber = $linearCongruentialGenerator->generate($lastTicketId + 1);
}
return $ticketNumber;
}
public function toArray($minimized = false) {
return [
'ticketNumber' => $this->ticketNumber,
'title' => $this->title,
'content' => $minimized ? strip_tags($this->content) : $this->content,
'department' => [
'id' => $this->department->id,
'name' => $this->department->name
],
'date' => $this->date,
'file' => $this->file,
'language' => $this->language,
'unread' => !!$this->unread,
'unreadStaff' => !!$this->unreadStaff,
'closed' => !!$this->closed,
'author' => $this->authorToArray(),
'owner' => $this->ownerToArray(),
'events' => $minimized ? [] : $this->eventsToArray(),
'tags' => $this->sharedTagList->toArray(true),
'edited' => $this->editedContent,
'editedTitle' => $this->editedTitle
];
}
public function authorToArray() {
$author = $this->getAuthor();
if ($author && !$author->isNull()) {
return [
'id' => $author->id,
'name' => $author->name,
'staff' => $author instanceof Staff,
'profilePic' => ($author instanceof Staff) ? $author->profilePic : null,
'email' => $author->email,
'customfields' => $author->xownCustomfieldvalueList ? $author->xownCustomfieldvalueList->toArray() : [],
];
} else {
return [
'id' => NULL,
'staff' => false,
'name' => $this->authorName,
'email' => $this->authorEmail
];
}
}
public function ownerToArray() {
$owner = $this->owner;
if ($owner && !$owner->isNull()) {
return [
'id' => $owner->id,
'name' => $owner->name,
'email' => $owner->email
];
} else {
return null;
}
}
public function eventsToArray() {
$events = [];
foreach ($this->ownTicketeventList as $ticketEvent) {
$event = [
'type' => $ticketEvent->type,
'content'=> $ticketEvent->content,
'author' => [],
'date'=> $ticketEvent->date,
'file'=> $ticketEvent->file,
'private'=> $ticketEvent->private,
'edited' => $ticketEvent->editedContent,
'id' => $ticketEvent->id
];
$author = $ticketEvent->getAuthor();
if($author && !$author->isNull()) {
$event['author'] = [
'id'=> $author->id,
'name' => $author->name,
'email' =>$author->email,
'profilePic' => ($author instanceof Staff) ? $author->profilePic : null,
'staff' => $author instanceof Staff
];
}
if(!Controller::isStaffLogged() && $ticketEvent->private) {
continue;
}
$events[] = $event;
}
return $events;
}
public function addEvent(Ticketevent $event) {
$this->ownTicketeventList->add($event);
}
public function isAuthor($user) {
$ticketAuthor = $this->authorToArray();
if(is_string($user)) return $user == $ticketAuthor['email'];
if(!($user instanceof DataStore) || $user->isNull()) return false;
return $user->id == $ticketAuthor['id'] && ($user instanceof Staff) == $ticketAuthor['staff'];
}
public function isOwner($user) {
return !$user->isNull() && $this->owner && $user->id == $this->owner->id && ($user instanceof Staff);
}
}