6 Commits

8 changed files with 63 additions and 51 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 3CX TAPI // @name 3CX TAPI
// @namespace http://cp-solutions.at // @namespace http://cp-solutions.at
// @version 7.0.0 // @version 7.0.3
// @author Daniel Triendl <d.triendl@cp-solutions.at> // @author Daniel Triendl <d.triendl@cp-solutions.at>
// @copyright Copyright 2020 CP Solutions GmbH // @copyright Copyright 2020 CP Solutions GmbH
// @source http://scootaloo.cp-austria.at/gitlist/3cx_tapi.git // @source http://scootaloo.cp-austria.at/gitlist/3cx_tapi.git
@ -3502,7 +3502,7 @@ var external_axiosGmxhrAdapter_default = /*#__PURE__*/__webpack_require__.n(exte
external_axios_default.a.defaults.adapter = external_axiosGmxhrAdapter_default.a; external_axios_default.a.defaults.adapter = external_axiosGmxhrAdapter_default.a;
function extractNumber(s) { function extractNumber(s) {
var match = /(\+?[0-9]+)/.exec(s); var match = /(\+?[0-9]{4,})/.exec(s);
if (!match) { if (!match) {
return undefined; return undefined;
} }
@ -3530,9 +3530,9 @@ class call_history_CallHistory {
this.callerIds = {}; this.callerIds = {};
} }
updateCallHistoryEntry(call, callerId) { updateCallHistoryEntry(call, callerId) {
if (callerId.tD_NAME !== '') { var span = call.querySelector('span');
var span = call.querySelector('span'); this.showTimeManager(call, span.nextSibling.textContent.trim(), callerId);
this.showTimeManager(call, span.nextSibling.textContent, callerId); if (callerId && callerId.tD_NAME !== '') {
var text = span.textContent; var text = span.textContent;
span.textContent = callerId.tD_NAME; span.textContent = callerId.tD_NAME;
var br = document.createElement('br'); var br = document.createElement('br');
@ -3543,36 +3543,38 @@ class call_history_CallHistory {
span.parentNode.insertBefore(span2, span.nextSibling); span.parentNode.insertBefore(span2, span.nextSibling);
} }
} }
showTimeManager(call, time, callerId) { showTimeManager(call, date, callerId) {
if (!callerId.tD_ID) { var dateParts = date.match(/^(?<date>.*), (?<duration>[0-9]{2}:[0-9]{2}:[0-9]{2})$/);
return;
}
var timeParts = time.split(/, /);
var duration = '00:00:00'; var duration = '00:00:00';
if (timeParts.length >= 1) { if (dateParts) {
time = timeParts[0]; date = dateParts.groups.date;
duration = dateParts.groups.duration;
} }
if (timeParts.length >= 2) { var parsedDate = dist["de"].parseDate(date);
duration = timeParts[1];
}
var parsedDate = dist["de"].parseDate(time);
if (!parsedDate) { if (!parsedDate) {
parsedDate = dist["parseDate"](time); parsedDate = dist["parseDate"](date);
} }
if (!parsedDate) { if (!parsedDate) {
return; return;
} }
// Date parsing is awful, just assume the first number is the day of month
var day = date.match(/[0-9]+/)[0];
var parsedDuration = dist["parseDate"](duration); var parsedDuration = dist["parseDate"](duration);
console.log('TAPI call history time:', time, 'parsedDate:', parsedDate, 'duration:', duration, 'parsedDuration:', parsedDuration); console.log('TAPI call history time:', date, 'parsedDate:', parsedDate, 'duration:', duration, 'parsedDuration:', parsedDuration);
var connect = parsedDate.getFullYear().toString() + var connect = parsedDate.getFullYear().toString() +
(parsedDate.getMonth() + 1).toString().padStart(2, '0') + // (January gives 0) (parsedDate.getMonth() + 1).toString().padStart(2, '0') + // (January gives 0)
parsedDate.getDate().toString().padStart(2, '0') + day.toString().padStart(2, '0') +
parsedDate.getHours().toString().padStart(2, '0') + parsedDate.getHours().toString().padStart(2, '0') +
parsedDate.getMinutes().toString().padStart(2, '0'); parsedDate.getMinutes().toString().padStart(2, '0');
var length = (parsedDuration.getHours() * 60 + parsedDuration.getMinutes()).toString(); var length = (parsedDuration.getHours() * 60 + parsedDuration.getMinutes()).toString();
var toolbar = call.querySelector('.wcToolbarTiles'); var toolbar = call.querySelector('.wcToolbarTiles');
var href = 'domizil://PM/Zeitbuchung?';
if (callerId && callerId.tD_ID) {
href += 'KontaktId=' + callerId.tD_ID + '&';
}
href += 'connect=' + connect + '&length=' + length;
var a = document.createElement('a'); var a = document.createElement('a');
var href = 'domizil://PM/Zeitbuchung?KontaktId=' + callerId.tD_ID + '&connect=' + connect + '&length=' + length; a.title = 'PM Zeitbuchung';
a.dataset.domizilLink = href; a.dataset.domizilLink = href;
a.onclick = () => { a.onclick = () => {
window.open(href); window.open(href);
@ -3596,6 +3598,7 @@ class call_history_CallHistory {
var span = element.querySelector('span'); var span = element.querySelector('span');
var number = extractNumber(span.textContent); var number = extractNumber(span.textContent);
if (!number) { if (!number) {
this.updateCallHistoryEntry(element, undefined);
return; return;
} }
if (this.callerIds[number] !== undefined) { if (this.callerIds[number] !== undefined) {
@ -3645,7 +3648,7 @@ class call_notification_CallNotification {
if (response.status === 200) { if (response.status === 200) {
var callerId = response.data; var callerId = response.data;
if (callerId) { if (callerId) {
notification.text = callerId.tD_NAME + '\r\n' + number; notification.text = callerId.tD_NAME + '\r\n' + number + ' (' + callerId.tD_MEDIUM + ')';
} }
} }
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
@ -3723,7 +3726,7 @@ class search_Search {
line1.appendChild(document.createTextNode(contact.tD_NAME)); line1.appendChild(document.createTextNode(contact.tD_NAME));
resultText.appendChild(line1); resultText.appendChild(line1);
var line2 = document.createElement('div'); var line2 = document.createElement('div');
line2.appendChild(document.createTextNode(contact.tD_NUMBER_TAPI)); line2.appendChild(document.createTextNode(contact.tD_MEDIUM + ': ' + contact.tD_NUMBER_TAPI));
resultText.appendChild(line2); resultText.appendChild(line2);
resultList.appendChild(li); resultList.appendChild(li);
}); });
@ -3736,7 +3739,10 @@ class search_Search {
form.style.float = 'right'; form.style.float = 'right';
form.style.marginRight = '20px'; form.style.marginRight = '20px';
form.onsubmit = () => { form.onsubmit = () => {
var items = document.getElementsByClassName('tapi-search-result'); var items = document.getElementsByClassName('tapi-search-result-selected');
if (items.length === 0) {
items = document.getElementsByClassName('tapi-search-result');
}
if (items.length > 0) { if (items.length > 0) {
this.dial(items[0].dataset.tapiNumber); this.dial(items[0].dataset.tapiNumber);
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "3cp-tapi", "name": "3cp-tapi",
"description": "Build your UserScript with webpack", "description": "Build your UserScript with webpack",
"version": "7.0.0", "version": "7.0.3",
"author": { "author": {
"name": "Daniel Triendl", "name": "Daniel Triendl",
"email": "d.triendl@cp-solutions.at" "email": "d.triendl@cp-solutions.at"
@ -29,8 +29,7 @@
"dependencies": { "dependencies": {
"axios": "0.20.0", "axios": "0.20.0",
"axios-userscript-adapter": "0.0.7", "axios-userscript-adapter": "0.0.7",
"chrono-node": "2.1.9", "chrono-node": "2.1.9"
"jquery": "3.5.1"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "4.3.0", "@typescript-eslint/eslint-plugin": "4.3.0",

View File

@ -50,4 +50,4 @@ And commit 3CX_TAPI.user.js
## see also ## see also
Based on [webpack-userscript-template](https://github.com/Trim21/webpack-userscript-template/. Based on [webpack-userscript-template](https://github.com/Trim21/webpack-userscript-template/)

View File

@ -6,11 +6,10 @@ export class CallHistory {
private callerIds: { [number: string]: TapiContact } = {} private callerIds: { [number: string]: TapiContact } = {}
private updateCallHistoryEntry (call: HTMLElement, callerId: TapiContact) { private updateCallHistoryEntry (call: HTMLElement, callerId: TapiContact) {
if (callerId.tD_NAME !== '') { var span = call.querySelector('span')
var span = call.querySelector('span') this.showTimeManager(call, span.nextSibling.textContent.trim(), callerId)
this.showTimeManager(call, span.nextSibling.textContent, callerId)
if (callerId && callerId.tD_NAME !== '') {
var text = span.textContent var text = span.textContent
span.textContent = callerId.tD_NAME span.textContent = callerId.tD_NAME
var br = document.createElement('br') var br = document.createElement('br')
@ -22,40 +21,43 @@ export class CallHistory {
} }
} }
private showTimeManager (call: HTMLElement, time: string, callerId: TapiContact) { private showTimeManager (call: HTMLElement, date: string, callerId: TapiContact) {
if (!callerId.tD_ID) { var dateParts = date.match(/^(?<date>.*), (?<duration>[0-9]{2}:[0-9]{2}:[0-9]{2})$/)
return var duration = '00:00:00'
if (dateParts) {
date = dateParts.groups.date
duration = dateParts.groups.duration
} }
var timeParts = time.split(/, /) var parsedDate = chrono.de.parseDate(date)
var duration = '00:00:00'
if (timeParts.length >= 1) {
time = timeParts[0]
}
if (timeParts.length >= 2) {
duration = timeParts[1]
}
var parsedDate = chrono.de.parseDate(time)
if (!parsedDate) { if (!parsedDate) {
parsedDate = chrono.parseDate(time) parsedDate = chrono.parseDate(date)
} }
if (!parsedDate) { if (!parsedDate) {
return return
} }
// Date parsing is awful, just assume the first number is the day of month
var day = date.match(/[0-9]+/)[0]
var parsedDuration = chrono.parseDate(duration) var parsedDuration = chrono.parseDate(duration)
console.log('TAPI call history time:', time, 'parsedDate:', parsedDate, 'duration:', duration, 'parsedDuration:', parsedDuration) console.log('TAPI call history time:', date, 'parsedDate:', parsedDate, 'duration:', duration, 'parsedDuration:', parsedDuration)
var connect = parsedDate.getFullYear().toString() + var connect = parsedDate.getFullYear().toString() +
(parsedDate.getMonth() + 1).toString().padStart(2, '0') + // (January gives 0) (parsedDate.getMonth() + 1).toString().padStart(2, '0') + // (January gives 0)
parsedDate.getDate().toString().padStart(2, '0') + day.toString().padStart(2, '0') +
parsedDate.getHours().toString().padStart(2, '0') + parsedDate.getHours().toString().padStart(2, '0') +
parsedDate.getMinutes().toString().padStart(2, '0') parsedDate.getMinutes().toString().padStart(2, '0')
var length = (parsedDuration.getHours() * 60 + parsedDuration.getMinutes()).toString() var length = (parsedDuration.getHours() * 60 + parsedDuration.getMinutes()).toString()
var toolbar = call.querySelector('.wcToolbarTiles') var toolbar = call.querySelector('.wcToolbarTiles')
var href = 'domizil://PM/Zeitbuchung?'
if (callerId && callerId.tD_ID) {
href += 'KontaktId=' + callerId.tD_ID + '&'
}
href += 'connect=' + connect + '&length=' + length
var a = document.createElement('a') var a = document.createElement('a')
var href = 'domizil://PM/Zeitbuchung?KontaktId=' + callerId.tD_ID + '&connect=' + connect + '&length=' + length a.title = 'PM Zeitbuchung'
a.dataset.domizilLink = href a.dataset.domizilLink = href
a.onclick = () => { a.onclick = () => {
window.open(href) window.open(href)
@ -79,6 +81,7 @@ export class CallHistory {
var span = element.querySelector('span') var span = element.querySelector('span')
var number = extractNumber(span.textContent) var number = extractNumber(span.textContent)
if (!number) { if (!number) {
this.updateCallHistoryEntry(element, undefined)
return return
} }

View File

@ -21,7 +21,7 @@ export class CallNotification {
if (response.status === 200) { if (response.status === 200) {
var callerId = response.data var callerId = response.data
if (callerId) { if (callerId) {
notification.text = callerId.tD_NAME + '\r\n' + number notification.text = callerId.tD_NAME + '\r\n' + number + ' (' + callerId.tD_MEDIUM + ')'
} }
} }

View File

@ -13,7 +13,10 @@ export class Search {
form.style.float = 'right' form.style.float = 'right'
form.style.marginRight = '20px' form.style.marginRight = '20px'
form.onsubmit = () => { form.onsubmit = () => {
var items = document.getElementsByClassName('tapi-search-result') var items = document.getElementsByClassName('tapi-search-result-selected')
if (items.length === 0) {
items = document.getElementsByClassName('tapi-search-result')
}
if (items.length > 0) { if (items.length > 0) {
this.dial((<HTMLElement>items[0]).dataset.tapiNumber) this.dial((<HTMLElement>items[0]).dataset.tapiNumber)
} }
@ -148,7 +151,7 @@ export class Search {
resultText.appendChild(line1) resultText.appendChild(line1)
var line2 = document.createElement('div') var line2 = document.createElement('div')
line2.appendChild(document.createTextNode(contact.tD_NUMBER_TAPI)) line2.appendChild(document.createTextNode(contact.tD_MEDIUM + ': ' + contact.tD_NUMBER_TAPI))
resultText.appendChild(line2) resultText.appendChild(line2)
resultList.appendChild(li) resultList.appendChild(li)

View File

@ -4,4 +4,5 @@ export interface TapiContact {
tD_NAME: string; tD_NAME: string;
tD_NUMBER?: string; tD_NUMBER?: string;
tD_NUMBER_TAPI?: string; tD_NUMBER_TAPI?: string;
tD_MEDIUM?: string;
} }

View File

@ -19,7 +19,7 @@ axios.defaults.adapter = adapter
export { axios } export { axios }
export function extractNumber (s: string) { export function extractNumber (s: string) {
var match = /(\+?[0-9]+)/.exec(s) var match = /(\+?[0-9]{4,})/.exec(s)
if (!match) { if (!match) {
return undefined return undefined
} }