Skip to content

Commit

Permalink
Fix #184
Browse files Browse the repository at this point in the history
  • Loading branch information
joelthorner committed Sep 4, 2019
1 parent aca548e commit 56cca11
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
28 changes: 16 additions & 12 deletions js/inject/zendesk/ticket-consume-source-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@
*/

function TicketConsumeTab_getDataTrs(trs) {
let data = ''
var data = '';
for (let index = 0; index < trs.length; index++) {
let organization = $(trs[index]).find('td:first-child').text().toLowerCase().trim(),
tickets = parseInt($(trs[index]).find('td:last-child').text()),
sla = $(trs[index]).closest('table').attr('id').replace('table', '').toLowerCase();
if ($(trs[index]).find('td').length) {
let organization = $(trs[index]).find('td:first-child').text().toLowerCase().trim(),
tickets = parseInt($(trs[index]).find('td:last-child').text()),
sla = $(trs[index]).closest('table').attr('id').replace('table', '').toLowerCase();

data += `
"${organization}": {
"tickets": ${tickets},
"sla": "${sla}"
}${index < trs.length - 1 ? ',' : ''}`;
data += `
"${organization}": {
"tickets": ${tickets},
"sla": "${sla}"
}${index < trs.length - 1 ? ',' : ''}`;
}
}
return data;
}

let data = '{';
var data = '{';

let si = setInterval(() => {
const doc = $(document).contents()[1];
let trs = doc.querySelectorAll('#tablePlatinium tbody tr, #tableGold tbody tr, #tableSilver tbody tr');
const doc = $(document)[0];
let trs = doc.querySelectorAll('#tablePlatinium tbody tr:not(.no-records-found), #tableGold tbody tr:not(.no-records-found), #tableSilver tbody tr:not(.no-records-found)');
console.log(trs);


if (trs.length) {
clearInterval(si);
Expand Down
43 changes: 26 additions & 17 deletions js/inject/zendesk/ticket-consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ TicketConsume = {
if (TicketConsume.user.role == 'agent') {
try {
chrome.runtime.sendMessage({ name: 'openTicketConsumeTab' });
} catch (error) {}
} catch (error) {
console.log(error);

}
}
});
}
Expand All @@ -78,23 +81,28 @@ TicketConsume = {
console.log(data);
$.extend(true,TicketConsume.data, data)

$('[data-test-id="customercontext-userinfo-organization"] [href*="organizations"]').each(function (index, ticketOrg) {
let $ticketOrg = $(ticketOrg);
if (typeof $ticketOrg.data('ovserved-org') === 'undefined') {

$ticketOrg.data('ovserved-org', true);
let findOrgId = $ticketOrg.attr('href').match(/\d{1,}/);

if (findOrgId) {
let orgId = findOrgId[0], orgName = $ticketOrg.text().trim().toLowerCase();

TicketConsume.observerInit(orgId, orgName, $ticketOrg);
}
$(document).off('DOMSubtreeModified').on('DOMSubtreeModified', function (event) {
if ($(event.target).find('[href*="organizations"]').length) {
$('[data-test-id="customercontext-userinfo-organization"] [href*="organizations"]').each(function (index, ticketOrg) {
let $ticketOrg = $(ticketOrg);
if (typeof $ticketOrg.data('ovserved-org') === 'undefined') {

$ticketOrg.data('ovserved-org', true);
let findOrgId = $ticketOrg.attr('href').match(/\d{1,}/);

if (findOrgId) {
let orgId = findOrgId[0], orgName = $ticketOrg.text().trim().toLowerCase();

TicketConsume.observerInit(orgId, orgName, $ticketOrg);
}
}
})
TicketConsume.initIntervals();
}
})
TicketConsume.initIntervals();
});
} catch (error) {
log('TicketConsume invalid data', 'danger');
console.log(message.data);
}
});
},
Expand Down Expand Up @@ -133,7 +141,7 @@ TicketConsume = {

ZendeskApi_showOrganization(TicketConsume.data[orgName].id).then((responseData) => {
let newData = TicketConsume.getNotesText(responseData.organization.notes);
newData += TicketConsume.splitVal + '\n' + JSON.stringify(TicketConsume.data[orgName].customData);
newData += `\n\n${TicketConsume.splitVal}\n${JSON.stringify(TicketConsume.data[orgName].customData)}`;

ZendeskApi_updateOrganization(TicketConsume.data[orgName].id, {
"organization": { "notes": newData }
Expand Down Expand Up @@ -344,7 +352,7 @@ TicketConsume = {
let json = [],
valueSplitted = value.trim().split(TicketConsume.splitVal);

if (value.trim().length && valueSplitted) {
if (value.trim().length && valueSplitted && value.trim().match(TicketConsume.splitVal)) {
json = valueSplitted[valueSplitted.length - 1];
try {
json = JSON.parse(json);
Expand Down Expand Up @@ -372,6 +380,7 @@ TicketConsume = {
if (typeof TicketConsume.user !== 'undefined' && TicketConsume.user.role == 'agent') {
ZendeskApi_showOrganization(orgId).then((responseData) => {
let customData = TicketConsume.parseOrganizationNotes(responseData.organization.notes);

if (TicketConsume.data[orgName]) {
TicketConsume.data[orgName].id = orgId;
TicketConsume.data[orgName].customData = customData;
Expand Down
6 changes: 6 additions & 0 deletions js/options/changelog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const CHANGELOG = [
{
version: 'v2.3.14', date: '04 Sep 2019',
lines: [
'FIXED Ticket consume get wrong data #184',
'IMPROVED Ticket consume better open window minimized instead of sticky tab #184#issuecomment-528098098'
]
}, {
version: 'v2.3.13', date: '02 Sep 2019',
lines: [
'CHANGED Update dependencies #182',
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
"version": "2.3.13",
"version": "2.3.14",
"manifest_version": 2,
"author": "joelthorner",
"description": "__MSG_appDesc__",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tlmanager",
"version": "2.3.13",
"version": "2.3.14",
"description": "Development tool",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit 56cca11

Please sign in to comment.