add the ticket apply function
parent
d2c59271a7
commit
6d0c298923
|
@ -107,6 +107,10 @@ api.add_route('/ticket/types',
|
|||
# Get Ticket List
|
||||
api.add_route('/ticket/list',
|
||||
ticket.TicketListCollection())
|
||||
|
||||
# Apply One Ticket
|
||||
api.add_route('/ticket/apply/{id_}',
|
||||
ticket.TicketApplicationCollection())
|
||||
########################################################################################################################
|
||||
# Routes for System Core
|
||||
########################################################################################################################
|
||||
|
|
|
@ -103,6 +103,97 @@ class TicketListCollection:
|
|||
|
||||
resp.text = json.dumps(result)
|
||||
|
||||
|
||||
class TicketApplicationCollection:
|
||||
@staticmethod
|
||||
def __init__():
|
||||
""""Initializes ContactCollection"""
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def on_options(req, resp, id_):
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
@staticmethod
|
||||
def on_get(req, resp, id_):
|
||||
if not id_.isdigit() or int(id_) <= 0:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, '400 Bad Request')
|
||||
|
||||
cnx = mysql.connector.connect(**config.loonflow)
|
||||
cursor = cnx.cursor()
|
||||
|
||||
# Get workflow custom field
|
||||
query = (" SELECT id, field_type_id, field_key, field_name, order_id, default_value, description, "
|
||||
" field_template, boolean_field_display "
|
||||
" FROM workflow_customfield"
|
||||
" WHERE workflow_id = %s "
|
||||
" ORDER BY id ")
|
||||
cursor.execute(query, (id_,))
|
||||
rows = cursor.fetchall()
|
||||
|
||||
field_result = {}
|
||||
if rows is not None and len(rows) > 0:
|
||||
for row in rows:
|
||||
field_key = row[2]
|
||||
field_result[field_key] = {
|
||||
'id': row[0],
|
||||
'field_type_id': row[1],
|
||||
'field_key': row[2],
|
||||
'field_name': row[3],
|
||||
'order_id': row[4],
|
||||
'default_value': row[5],
|
||||
'description': row[6],
|
||||
'field_template': row[7],
|
||||
'boolean_field_display': row[8],
|
||||
}
|
||||
|
||||
# Get workflow start state
|
||||
query = (" SELECT id, name, state_field_str "
|
||||
" FROM workflow_state "
|
||||
" WHERE workflow_id = %s and type_id = 1"
|
||||
" ORDER BY id ")
|
||||
cursor.execute(query, (id_,))
|
||||
row = cursor.fetchone()
|
||||
|
||||
workflow_state_id = None
|
||||
workflow_state_name = None
|
||||
state_field_str = None
|
||||
fields = []
|
||||
result = {
|
||||
"id": None,
|
||||
"name": None,
|
||||
"fields": []
|
||||
}
|
||||
if row is not None and len(row) > 0:
|
||||
workflow_state_id = row[0]
|
||||
workflow_state_name = row[1]
|
||||
state_field_str = json.loads(row[2])
|
||||
for key in state_field_str.keys():
|
||||
if key == "title":
|
||||
fields.append(
|
||||
{
|
||||
"id": 0,
|
||||
"field_type_id": 5,
|
||||
"field_key": "title",
|
||||
"field_name": "标题",
|
||||
"order_id": 20,
|
||||
"default_value": None,
|
||||
"description": "",
|
||||
"field_template": "",
|
||||
}
|
||||
)
|
||||
if key in field_result.keys():
|
||||
fields.append(field_result[key])
|
||||
else:
|
||||
continue
|
||||
|
||||
result['id'] = workflow_state_id
|
||||
result['name'] = workflow_state_name
|
||||
result['fields'] = fields
|
||||
|
||||
resp.text = json.dumps(result)
|
||||
|
||||
|
||||
class ContactItem:
|
||||
@staticmethod
|
||||
def __init__():
|
||||
|
|
|
@ -53,9 +53,10 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
let table = createRef();
|
||||
|
||||
// State
|
||||
const [selectedTicketType, setSelectedTicketType] = useState(undefined);
|
||||
const [selectedTicketType, setSelectedTicketType] = useState(1);
|
||||
const [ticketTypes, setTicketTypes] = useState([]);
|
||||
const [ticketList, setTicketList] = useState([]);
|
||||
const [ticketApplicationfields, setTicketApplicationfields] = useState({});
|
||||
|
||||
const [selectedSpaceName, setSelectedSpaceName] = useState(undefined);
|
||||
const [cascaderOptions, setCascaderOptions] = useState(undefined);
|
||||
|
@ -234,10 +235,47 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
let onWorkflowTypeChange = ({ target }) => {
|
||||
setSelectedTicketType(target.value);
|
||||
};
|
||||
|
||||
let applyTicket = () => {
|
||||
console.log("you apply the ticket!!", selectedTicketType);
|
||||
|
||||
let isResponseOK = false;
|
||||
fetch(APIBaseURL + '/ticket/apply/' + selectedTicketType, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: null
|
||||
})
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
if (response.ok) {
|
||||
isResponseOK = true;
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(json => {
|
||||
if (isResponseOK) {
|
||||
console.log('/ticket/apply', json);
|
||||
setTicketApplicationfields(json);
|
||||
} else {
|
||||
toast.error(json.description);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log('selectedTicketType', selectedTicketType);
|
||||
}, [selectedTicketType]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('ticketApplicationfields', ticketApplicationfields);
|
||||
}, [ticketApplicationfields]);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<div>
|
||||
|
@ -270,7 +308,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
icon="external-link-alt"
|
||||
transform="shrink-3 down-2"
|
||||
color="falcon-default"
|
||||
onClick={console.log('Apply The Ticket')}
|
||||
onClick={applyTicket}
|
||||
>
|
||||
{t('Apply')}
|
||||
</ButtonIcon>
|
||||
|
|
Loading…
Reference in New Issue