mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-27 15:54:23 +02:00
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:
parent
791e0969e9
commit
c4a2c48eae
@ -22,6 +22,8 @@ class DashboardListTicketsPage extends React.Component {
|
|||||||
tickets: []
|
tickets: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateTicketListRequestId = 0;
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
tickets: [],
|
tickets: [],
|
||||||
pages: 1,
|
pages: 1,
|
||||||
@ -85,6 +87,7 @@ class DashboardListTicketsPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateTicketList({users, page, ownTickets}) {
|
updateTicketList({users, page, ownTickets}) {
|
||||||
|
let id = ++this.updateTicketListRequestId;
|
||||||
let usersIds = users.map((item) => {
|
let usersIds = users.map((item) => {
|
||||||
return item.id
|
return item.id
|
||||||
})
|
})
|
||||||
@ -97,6 +100,7 @@ class DashboardListTicketsPage extends React.Component {
|
|||||||
supervisedUsers: JSON.stringify(usersIds)
|
supervisedUsers: JSON.stringify(usersIds)
|
||||||
}
|
}
|
||||||
}).then((r) => {
|
}).then((r) => {
|
||||||
|
if (id === this.updateTicketListRequestId){
|
||||||
this.setState({
|
this.setState({
|
||||||
tickets: r.data.tickets,
|
tickets: r.data.tickets,
|
||||||
pages: r.data.pages,
|
pages: r.data.pages,
|
||||||
@ -104,6 +108,7 @@ class DashboardListTicketsPage extends React.Component {
|
|||||||
message: '',
|
message: '',
|
||||||
loading: false
|
loading: false
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}).catch((r) => {
|
}).catch((r) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
tickets: [],
|
tickets: [],
|
||||||
|
@ -25,7 +25,7 @@ class Autocomplete extends React.Component {
|
|||||||
comparerFunction: React.PropTypes.func
|
comparerFunction: React.PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
id = 1;
|
searchApiRequestId = 1;
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
selectedItems: [],
|
selectedItems: [],
|
||||||
@ -238,17 +238,18 @@ class Autocomplete extends React.Component {
|
|||||||
|
|
||||||
searchApi(query, blacklist=this.getSelectedItems()) {
|
searchApi(query, blacklist=this.getSelectedItems()) {
|
||||||
const { getItemListFromQuery } = this.props;
|
const { getItemListFromQuery } = this.props;
|
||||||
let id = ++this.id;
|
let id = ++this.searchApiRequestId;
|
||||||
|
|
||||||
getItemListFromQuery && getItemListFromQuery(query, blacklist.map(
|
getItemListFromQuery && getItemListFromQuery(query, blacklist.map(
|
||||||
item => {return item.isStaff !== undefined ? {isStaff: item.isStaff, id: item.id} : item.id}
|
item => {return item.isStaff !== undefined ? {isStaff: item.isStaff, id: item.id} : item.id}
|
||||||
))
|
))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if(id === this.id)
|
if (id === this.searchApiRequestId){
|
||||||
this.setState({
|
this.setState({
|
||||||
itemsFromQuery: result,
|
itemsFromQuery: result,
|
||||||
loading: false,
|
loading: false,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => this.setState({
|
.catch(() => this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<?php
|
<?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 {
|
class Tag extends DataStore {
|
||||||
const TABLE = 'tag';
|
const TABLE = 'tag';
|
||||||
|
|
||||||
|
@ -5,9 +5,44 @@ use RedBeanPHP\Facade as RedBean;
|
|||||||
print 'Begin update v4.8.0...' . PHP_EOL;
|
print 'Begin update v4.8.0...' . PHP_EOL;
|
||||||
|
|
||||||
// Update ticket table
|
// Update ticket table
|
||||||
|
|
||||||
print '[1/3] Updating ticket table...'. PHP_EOL;
|
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");
|
$mysql->query("ALTER TABLE ticket DROP priority");
|
||||||
} else {
|
} else {
|
||||||
print 'priority column already deleted' . PHP_EOL;
|
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;");
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;");
|
||||||
|
|
||||||
print 'Update Completed!' . PHP_EOL;
|
print 'Update Completed!' . PHP_EOL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
30
version_upgrades/4.8.0/models/Tag.php
Normal file
30
version_upgrades/4.8.0/models/Tag.php
Normal 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
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
231
version_upgrades/4.8.0/models/Ticket.php
Executable file
231
version_upgrades/4.8.0/models/Ticket.php
Executable 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user