From c457b5d8c0419764690dc369ed2c4c07f5c5c9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 14:49:10 +0200 Subject: [PATCH 01/17] callregistry: based on callinfo/ not on dailycalls.yaml The configured parameters is the dailycalls file but CallRegistry takes its parent dir for the rest of the managed files. This commit still receives the dailycalls configuration but computes the parent in the constructor and then just relies on the parent. --- tomatic/callregistry.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index 94cf15779..cec49d2df 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -13,14 +13,15 @@ def fillConfigurationInfo(): class CallRegistry(object): def __init__(self, path=None, size=20): - self.path = Path(path or CONFIG.my_calls_log) - self.path.parent.mkdir(parents=True, exist_ok=True) + self.callregistry_path = Path(path or CONFIG.my_calls_log) + self.path = self.callregistry_path.parent + self.path.mkdir(parents=True, exist_ok=True) self.size = size def _calls(self): - if not self.path.exists(): + if not self.callregistry_path.exists(): return ns() - return ns.load(self.path) + return ns.load(self.callregistry_path) def callsByExtension(self, extension): return self._calls().get(extension,[]) @@ -38,7 +39,7 @@ def updateCall(self, extension, fields): if self.size: extensionCalls=extensionCalls[-self.size:] - calls.dump(self.path) + calls.dump(self.callregistry_path) def annotateCall(self, fields): from . import persons @@ -53,7 +54,7 @@ def annotateCall(self, fields): self._appendToExtensionDailyInfo('cases', fields) def _appendToExtensionDailyInfo(self, prefix, info, date=datetime.today()): - path = self.path.parent / prefix / '{:%Y%m%d}.yaml'.format(date) + path = self.path / prefix / '{:%Y%m%d}.yaml'.format(date) warn("Saving {}", path) dailyInfo = ns() if path.exists(): @@ -63,7 +64,7 @@ def _appendToExtensionDailyInfo(self, prefix, info, date=datetime.today()): dailyInfo.dump(str(path)) def _categoriesFile(self): - return self.path.parent/'categories.yaml' + return self.path/'categories.yaml' def updateAnnotationCategories(self, erp): """Takes the topics (crm categories and atc subtypes)""" @@ -89,8 +90,8 @@ def annotationCategories(self): def uploadCases(self, erp, date): claims = Claims(erp) - path = self.path.parent / 'cases' / '{:%Y%m%d}.yaml'.format(date) - log = self.path.parent / 'cases' / 'logs' / '{:%Y%m%d}.log'.format(date) + path = self.path / 'cases' / '{:%Y%m%d}.yaml'.format(date) + log = self.path / 'cases' / 'logs' / '{:%Y%m%d}.log'.format(date) cases = ns() if path.exists(): cases = ns.load(path) From 0669ff2ad8388d6dcb78c071754e7436c629e6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 15:08:57 +0200 Subject: [PATCH 02/17] callregistry: my_calls_log -> callinfoPath Instead of configure a concrete callinfo log file, configure the path. callregistry relies now on that file. --- b2bdata/inputs/config-2days2lines.yaml | 1 - b2bdata/inputs/config-3days6lines.yaml | 1 - b2bdata/inputs/config-4days6lines.yaml | 1 - b2bdata/inputs/load-2020-03-02/config.yaml | 1 - .../inputs/load-and-schedule-2-days/config.yaml | 1 - config.yaml | 2 +- tomatic/callregistry.py | 4 ++-- tomatic/callregistry_test.py | 16 ++++++++-------- 8 files changed, 11 insertions(+), 16 deletions(-) diff --git a/b2bdata/inputs/config-2days2lines.yaml b/b2bdata/inputs/config-2days2lines.yaml index 8b8be9240..9e9aaeb9e 100644 --- a/b2bdata/inputs/config-2days2lines.yaml +++ b/b2bdata/inputs/config-2days2lines.yaml @@ -319,7 +319,6 @@ websocket_port: 4445 call_reasons_document: "Trucades_3354" credential_name: "drive-certificate.json" threshold_hits: 21 -my_calls_log: "my_calls_log.yaml" busyFiles: - b2bdata/inputs/indisponibilitats-2days2lines.conf diff --git a/b2bdata/inputs/config-3days6lines.yaml b/b2bdata/inputs/config-3days6lines.yaml index 946f3320e..73beb3ba9 100644 --- a/b2bdata/inputs/config-3days6lines.yaml +++ b/b2bdata/inputs/config-3days6lines.yaml @@ -320,7 +320,6 @@ websocket_port: 4445 call_reasons_document: "Trucades_3354" credential_name: "drive-certificate.json" threshold_hits: 21 -my_calls_log: "my_calls_log.yaml" busyFiles: - b2bdata/inputs/indisponibilitats-3days6lines.conf diff --git a/b2bdata/inputs/config-4days6lines.yaml b/b2bdata/inputs/config-4days6lines.yaml index 484d00dc4..e89d7f43b 100644 --- a/b2bdata/inputs/config-4days6lines.yaml +++ b/b2bdata/inputs/config-4days6lines.yaml @@ -426,7 +426,6 @@ websocket_port: 4445 call_reasons_document: "Trucades_3354" credential_name: "drive-certificate.json" threshold_hits: 21 -my_calls_log: "my_calls_log.yaml" busyFiles: - b2bdata/inputs/indisponibilitats.conf - b2bdata/inputs/indisponibilitats-vacances.conf diff --git a/b2bdata/inputs/load-2020-03-02/config.yaml b/b2bdata/inputs/load-2020-03-02/config.yaml index ecc90d218..dd21f09eb 100644 --- a/b2bdata/inputs/load-2020-03-02/config.yaml +++ b/b2bdata/inputs/load-2020-03-02/config.yaml @@ -126,4 +126,3 @@ websocket_port: 4445 call_reasons_document: Trucades_3354 credential_name: drive-certificate.json threshold_hits: 21 -my_calls_log: my_calls_log.yaml diff --git a/b2bdata/inputs/load-and-schedule-2-days/config.yaml b/b2bdata/inputs/load-and-schedule-2-days/config.yaml index 4a13fc131..c9b33a4da 100644 --- a/b2bdata/inputs/load-and-schedule-2-days/config.yaml +++ b/b2bdata/inputs/load-and-schedule-2-days/config.yaml @@ -67,4 +67,3 @@ forced: {} call_reasons_document: Trucades_3354 credential_name: drive-certificate.json threshold_hits: 21 -my_calls_log: callinfo/dailycalls.yaml diff --git a/config.yaml b/config.yaml index 33266ee38..4f65bbe92 100644 --- a/config.yaml +++ b/config.yaml @@ -125,4 +125,4 @@ commented_forced: call_reasons_document: Trucades_3354 credential_name: drive-certificate.json threshold_hits: 21 -my_calls_log: callinfo/dailycalls.yaml +callinfoPath: callinfo diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index cec49d2df..e926d1296 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -13,9 +13,9 @@ def fillConfigurationInfo(): class CallRegistry(object): def __init__(self, path=None, size=20): - self.callregistry_path = Path(path or CONFIG.my_calls_log) - self.path = self.callregistry_path.parent + self.path = Path(path or CONFIG.callinfoPath) self.path.mkdir(parents=True, exist_ok=True) + self.callregistry_path = self.path / 'dailycalls.yaml' self.size = size def _calls(self): diff --git a/tomatic/callregistry_test.py b/tomatic/callregistry_test.py index 4a7cd55e0..12e42ae21 100644 --- a/tomatic/callregistry_test.py +++ b/tomatic/callregistry_test.py @@ -28,12 +28,12 @@ def tearDown(self): from yamlns.testutils import assertNsEqual def test_updateCall_behavesAtStartUp(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) assert not (self.dir/'dailycalls.yaml').exists() self.assertEqual(reg.callsByExtension('alice'), []) def test_updateCall_updatesAfterWrite(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) reg.updateCall('alice', ns( attribute="value", tag="content", @@ -51,7 +51,7 @@ def test_updateCall_updatesAfterWrite(self): """) def test_updateCall_sameTimeExtension_updates(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) reg.updateCall('alice', ns( data="2021-02-01T20:21:22.555Z", attribute="value", @@ -77,7 +77,7 @@ def test_updateCall_sameTimeExtension_updates(self): """) def test_updateCall_differentTime_appends(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) reg.updateCall('alice', ns( data="2021-02-01T20:21:22.555Z", attribute="value", @@ -109,7 +109,7 @@ def test_updateCall_differentTime_appends(self): """) def test_updateCall_differentExtension_splits(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) reg.updateCall('alice', ns( data="2021-02-02T20:21:22.555Z", @@ -154,7 +154,7 @@ def assertDirContent(self, expected): ) def test_appendDaily(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) reg._appendToExtensionDailyInfo('prefix', ns( user="alice", @@ -181,7 +181,7 @@ def test_appendDaily(self): def test_annotateCall_writesCallLog(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) reg.annotateCall(ns( user="alice", date="2021-02-01T20:21:22.555Z", @@ -202,7 +202,7 @@ def test_annotateCall_writesCallLog(self): """) def test_annotateCall_writesFiles(self): - reg = CallRegistry(self.dailycalls) + reg = CallRegistry(self.dir) persons(self.dir/'persons.yaml') reg.annotateCall(ns( user="alice", From 57db4f2e7d7f64239ebaf92b5ac99f3291f25fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 15:12:32 +0200 Subject: [PATCH 03/17] doc updates for the callinfo config and others --- CHANGES.md | 3 +++ TODO.md | 3 ++- doc/development.md | 13 +++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cd331d9a3..4b77b67d5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ - Update notes: - npm install required (emotion and babel dependencies) + - config.yaml `callinfoPath` should point to the parent of current `my_calls_log`. + If not specified it will be `callinfo` by default (relative to the working path). + - config.yaml: `my_calls_log` should be removed ## 4.6.0 2022-07-12 diff --git a/TODO.md b/TODO.md index 3d80cc1b9..fb61d03fa 100644 --- a/TODO.md +++ b/TODO.md @@ -20,6 +20,7 @@ - [ ] Ask before deleting, killing, uploading... - Scheduler: - [ ] Join load computation into the scheduler script + - [ ] Like we did with callinfo, review files loaded and dumped to rationalize it - Person editor: - [ ] Disable ok until all fields are valid - [ ] Check extension not taken already @@ -29,7 +30,7 @@ - [ ] List/admin mode - [ ] Nicer date picker for one-shot busy - Callinfo - - [ ] config `callinfo_data` instead of `my_calls_log` parent folder + - [x] config `callinfoPath` instead of `my_calls_log` parent folder - [ ] Edit previous annotations - [ ] /api/info/ringring -> api/call/ringring (ext) (caution: used by partners) - [ ] /api/personlog/ en els casos de fallada returnar una llista buida sense errors (no son de fallada, encara no hi ha logs i prou) diff --git a/doc/development.md b/doc/development.md index 8c303b281..2001ed3de 100644 --- a/doc/development.md +++ b/doc/development.md @@ -105,7 +105,7 @@ What smoke tests you should be doing after an upgrade to check most components s - `execution.py`: Encapsulates an asynchronous execution of a sandboxed process (used by `planner_api.py`) - `remote.py`: Simplifies remote process execution and access to files via SSH - `directmessage`: modules that abstract actual direct message (hangouts or equivalents) -- `directmessage/hangouts`: Google hangouts implementation of directmessage +- `directmessage/hangouts.py`: Google hangouts implementation of directmessage - `backchannel.py`: Abstracting server initiated comunication with the clients (Websocket or equivalent) ### Information Access @@ -129,9 +129,10 @@ What smoke tests you should be doing after an upgrade to check most components s - `claims.py`: Access the ERP's Claim objects (Backend of callregistry) -## Data Files +## Callinfo Data Files -This is a review of the callinfo files. +Callinfo data directory is `callinfo/` by default +but can be configured using `callinfoPath` in `config.yaml`. - `callinfo/categories.yaml` - Categories to choose when annotating calls @@ -140,7 +141,11 @@ This is a review of the callinfo files. - Each category has `code`, `name`, `isClaim`, `section` - `callinfo/dailycalls.yaml` - "registre de trucades (reclamaciĆ³ i no reclamacio)" - - `config.my_calls_log` - person dict to a list of incomming calls of the day - `callinfo/cases/YYYY-MM-DD.yaml` Daily call log +## Scheduler Data Files + +TODO: Document which files are readed, which ones are generated and how configuration and commandline affects them + + From 0f1392099c0571b3373ca5534e5a42c8603f6477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 15:52:31 +0200 Subject: [PATCH 04/17] using user instead of extension to log calls This way call log and annotation log are even more closer and we avoid handling both types of index. Sandwich criteria, pbxsends us extensions, internally we manage just tomatic users. --- tomatic/api.py | 8 ++++---- tomatic/callregistry.py | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tomatic/api.py b/tomatic/api.py index 20ead1714..39599ff65 100644 --- a/tomatic/api.py +++ b/tomatic/api.py @@ -433,7 +433,7 @@ async def notifyIncommingCall(phone: str, extension: str): user = persons.byExtension(extension) phone = phone.replace('+','').replace('-','').replace(' ','') phone = re.sub(r'^[+]?0?0?34','', phone) - CallRegistry().updateCall(extension, fields=ns( + CallRegistry().updateCall(user, fields=ns( data = time, telefon = phone, motius = "", @@ -449,9 +449,9 @@ async def notifyIncommingCall(phone: str, extension: str): return yamlfy(result='ok') -@app.get('/api/personlog/{extension}') -def getCallLog(extension): - calls = CallRegistry().callsByExtension(extension) +@app.get('/api/personlog/{user}') +def getCallLog(user): + calls = CallRegistry().callsByExtension(user) return yamlfy( info=ns( info=calls, diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index e926d1296..747f0c82b 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -23,12 +23,12 @@ def _calls(self): return ns() return ns.load(self.callregistry_path) - def callsByExtension(self, extension): - return self._calls().get(extension,[]) + def callsByExtension(self, user): + return self._calls().get(user,[]) - def updateCall(self, extension, fields): + def updateCall(self, user, fields): calls = self._calls() - extensionCalls = calls.setdefault(extension,[]) + extensionCalls = calls.setdefault(user,[]) for call in extensionCalls: if call.data == fields.data: call.update(fields) @@ -43,8 +43,7 @@ def updateCall(self, extension, fields): def annotateCall(self, fields): from . import persons - extension = persons.extension(fields.user) or fields.user - self.updateCall(extension, ns( + self.updateCall(fields.user, ns( data = fields.date, telefon = fields.phone, partner = fields.partner, From 6c38a272dcf1ca8636c21bfce599324211c999e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 16:01:07 +0200 Subject: [PATCH 05/17] callsByExtension -> callsByUser to be consistent with the semantics of the former commit. Indeed tests used user names as well. --- tomatic/api.py | 2 +- tomatic/callregistry.py | 2 +- tomatic/callregistry_test.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tomatic/api.py b/tomatic/api.py index 39599ff65..0c25fba1e 100644 --- a/tomatic/api.py +++ b/tomatic/api.py @@ -451,7 +451,7 @@ async def notifyIncommingCall(phone: str, extension: str): @app.get('/api/personlog/{user}') def getCallLog(user): - calls = CallRegistry().callsByExtension(user) + calls = CallRegistry().callsByUser(user) return yamlfy( info=ns( info=calls, diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index 747f0c82b..396642b02 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -23,7 +23,7 @@ def _calls(self): return ns() return ns.load(self.callregistry_path) - def callsByExtension(self, user): + def callsByUser(self, user): return self._calls().get(user,[]) def updateCall(self, user, fields): diff --git a/tomatic/callregistry_test.py b/tomatic/callregistry_test.py index 12e42ae21..95938690f 100644 --- a/tomatic/callregistry_test.py +++ b/tomatic/callregistry_test.py @@ -30,7 +30,7 @@ def tearDown(self): def test_updateCall_behavesAtStartUp(self): reg = CallRegistry(self.dir) assert not (self.dir/'dailycalls.yaml').exists() - self.assertEqual(reg.callsByExtension('alice'), []) + self.assertEqual(reg.callsByUser('alice'), []) def test_updateCall_updatesAfterWrite(self): reg = CallRegistry(self.dir) @@ -44,7 +44,7 @@ def test_updateCall_updatesAfterWrite(self): tag: content """) self.assertNsEqual( - ns(calls = reg.callsByExtension('alice')), """\ + ns(calls = reg.callsByUser('alice')), """\ calls: - attribute: value tag: content @@ -69,7 +69,7 @@ def test_updateCall_sameTimeExtension_updates(self): tag: second content """) self.assertNsEqual( - ns(calls = reg.callsByExtension('alice')), """\ + ns(calls = reg.callsByUser('alice')), """\ calls: - data: "2021-02-01T20:21:22.555Z" attribute: second value @@ -98,7 +98,7 @@ def test_updateCall_differentTime_appends(self): data: "2021-02-02T20:21:22.555Z" """) self.assertNsEqual( - ns(calls = reg.callsByExtension('alice')), """\ + ns(calls = reg.callsByUser('alice')), """\ calls: - data: "2021-02-01T20:21:22.555Z" attribute: value @@ -133,14 +133,14 @@ def test_updateCall_differentExtension_splits(self): """) self.assertNsEqual( - ns(calls = reg.callsByExtension('alice')), """\ + ns(calls = reg.callsByUser('alice')), """\ calls: - data: "2021-02-02T20:21:22.555Z" attribute: value tag: content """) self.assertNsEqual( - ns(calls = reg.callsByExtension('barbara')), """\ + ns(calls = reg.callsByUser('barbara')), """\ calls: - data: "2021-02-02T20:21:22.555Z" attribute: second value From def9ca01425f6d0350a02abb0222d95aa33e6b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 16:44:34 +0200 Subject: [PATCH 06/17] appendDaily updates if the call exists This fixes a rare bug that stores twice the same annotation when opened in two different windows. Also prepares the way to be able to write unannotated calls in the case registry. --- tomatic/callregistry.py | 8 +++++++- tomatic/callregistry_test.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index 396642b02..de0af69a4 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -58,7 +58,13 @@ def _appendToExtensionDailyInfo(self, prefix, info, date=datetime.today()): dailyInfo = ns() if path.exists(): dailyInfo = ns.load(str(path)) - dailyInfo.setdefault(info.user, []).append(info) + userInfo = dailyInfo.setdefault(info.user, []) + for call in userInfo: + if call.date == info.date: + call.update(info) + break + else: + userInfo.append(info) path.parent.mkdir(parents=True, exist_ok=True) dailyInfo.dump(str(path)) diff --git a/tomatic/callregistry_test.py b/tomatic/callregistry_test.py index 95938690f..7f9e8e6bc 100644 --- a/tomatic/callregistry_test.py +++ b/tomatic/callregistry_test.py @@ -179,6 +179,40 @@ def test_appendDaily(self): user: alice """) + def test_appendDaily_sameUserDateUpdates(self): + reg = CallRegistry(self.dir) + + reg._appendToExtensionDailyInfo('prefix', ns( + user="alice", + date="2021-02-01T20:21:22.555Z", + phone="555444333", + partner="", + contract="", + reason="", + ), date=date(2021,2,1)) + reg._appendToExtensionDailyInfo('prefix', ns( + user="alice", + date="2021-02-01T20:21:22.555Z", + phone="555444333", + partner="S00000", + contract="100000", + reason="CODE", + ), date=date(2021,2,1)) + self.assertDirContent([ + 'test_callregistry/prefix', + 'test_callregistry/prefix/20210201.yaml', + ]) + self.assertNsEqual(ns.load('test_callregistry/prefix/20210201.yaml'), + """ + alice: + - date: "2021-02-01T20:21:22.555Z" + phone: '555444333' + partner: 'S00000' + contract: '100000' + reason: CODE + user: alice + """) + def test_annotateCall_writesCallLog(self): reg = CallRegistry(self.dir) From 7090660ec1651779e8aaa09f2630677910250310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 17:01:31 +0200 Subject: [PATCH 07/17] ringring uses annotateCall instead updateCall Having a single entry point from the api The case uploader still could identify unnanotated by checking the reason Field mapping already done inside annotateCall, now centralized and hidden. --- tomatic/api.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tomatic/api.py b/tomatic/api.py index 0c25fba1e..ab5cbe881 100644 --- a/tomatic/api.py +++ b/tomatic/api.py @@ -433,12 +433,13 @@ async def notifyIncommingCall(phone: str, extension: str): user = persons.byExtension(extension) phone = phone.replace('+','').replace('-','').replace(' ','') phone = re.sub(r'^[+]?0?0?34','', phone) - CallRegistry().updateCall(user, fields=ns( - data = time, - telefon = phone, - motius = "", - partner = "", - contracte = "", + CallRegistry().annotateCall(ns( + user = user, + date = time, + phone = phone, + partner = '', + contract = '', + reason = '', )) notifications = backchannel.notifyIncommingCall(user, phone, time) if not notifications: From 22dbb47c0c4880a7f3c169d7f8eec3e6556c2797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 17:01:50 +0200 Subject: [PATCH 08/17] getLogPerson uses username not extension --- tomatic/ui/components/callinfo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tomatic/ui/components/callinfo.js b/tomatic/ui/components/callinfo.js index b317287e0..987ad6fbf 100644 --- a/tomatic/ui/components/callinfo.js +++ b/tomatic/ui/components/callinfo.js @@ -319,13 +319,13 @@ CallInfo.updateCategories = function() { CallInfo.getLogPerson = function () { CallInfo.callLog = [] - var extension = Login.currentExtension(); - if (extension === -1) { + var username = Login.myName(); + if (username === -1) { return 0 } CallInfo.callLog.push("lookingfor") api.request({ - url: '/api/personlog/' + extension, + url: '/api/personlog/' + username, }).then(function(response){ console.debug("Info GET Response: ",response) if (response.info.message !== "ok" ) { From 749e6248832a5ad2abcc6f62b5f137b64f5d9ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 17:02:53 +0200 Subject: [PATCH 09/17] nobody uses Login.currentExtension anymore, remove --- tomatic/ui/components/login.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tomatic/ui/components/login.js b/tomatic/ui/components/login.js index 356916a8f..f77382ac3 100644 --- a/tomatic/ui/components/login.js +++ b/tomatic/ui/components/login.js @@ -59,13 +59,6 @@ Login.myName = function() { return user; } -Login.currentExtension = function() { - var cookie_value = getCookie(tomaticCookie); - if (cookie_value === ":") return -1; - var extension = cookie_value.split(":")[1].toString(); - return extension === "" ? -1 : extension; -} - var setCookieInfo = function(vnode){ var name_button = vnode.target.innerText; var persons = Tomatic.persons().extensions; From cb74af285aa3e208fe409435a01e8be4c90b4d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 21:35:20 +0200 Subject: [PATCH 10/17] deconvoluting Login: not taking color from the cookie There is no need to codify the color in the cookie if we can obtain it from Tomatic object. On load, person info might not available yet, so the conditional keeps ups safe --- tomatic/ui/components/login.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tomatic/ui/components/login.js b/tomatic/ui/components/login.js index f77382ac3..e06daee59 100644 --- a/tomatic/ui/components/login.js +++ b/tomatic/ui/components/login.js @@ -156,7 +156,9 @@ Login.identification = function() { var aux = info.split(":"); var id = aux[0]; nom = Tomatic.formatName(id); - color = "#" + aux[2]; + if (Tomatic.persons().colors) { + color = "#" + Tomatic.persons().colors[id]; + } } return m('.login-buttons', [ From 6383a85b6cdfa1d0be8bd2493f44a65385fa5a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 21:39:37 +0200 Subject: [PATCH 11/17] deconvoluting Login: centralize name parsing By centralizing this op, it will be easier to change what it does --- tomatic/ui/components/login.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tomatic/ui/components/login.js b/tomatic/ui/components/login.js index e06daee59..19b8bd6d6 100644 --- a/tomatic/ui/components/login.js +++ b/tomatic/ui/components/login.js @@ -23,8 +23,7 @@ var previousLogin = null; // To detect login changes Login.loginWatchTimer = 0; Login.watchLoginChanges = function() { clearTimeout(Login.loginWatchTimer); - var cookie = whoAreYou(); - var user = cookie.split(":")[0]; + var user = Login.myName(); if (user !== previousLogin) { console.log("Detected login change",previousLogin,"->",user); previousLogin = user; From afa6e98ebf94c490d60f76038b80bf3c764fdb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 21:41:08 +0200 Subject: [PATCH 12/17] deconvoluting Login: whoAreYou -> userCookie whoAreYou was a quite messy name provided that myName and tellMeWhoIAm are spread around with quite different semantics (one gives the user cookie and the other the user id) --- tomatic/ui/components/login.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tomatic/ui/components/login.js b/tomatic/ui/components/login.js index 19b8bd6d6..70812a61e 100644 --- a/tomatic/ui/components/login.js +++ b/tomatic/ui/components/login.js @@ -52,8 +52,13 @@ Date.prototype.addHours = function(h) { return this; } +var userCookie = function() { + var cookie = getCookie(tomaticCookie); + return (cookie === "" ? ":" : cookie); +} + Login.myName = function() { - var cookie = whoAreYou(); + var cookie = userCookie(); var user = cookie.split(":")[0]; return user; } @@ -135,11 +140,6 @@ Login.askWhoAreYou = function() { };},{id:'whoAreYou'}); } -var whoAreYou = function() { - var cookie = getCookie(tomaticCookie); - return (cookie === "" ? ":" : cookie); -} - var exitIcon = function(){ return m(".icon-exit", [ m("i.fas.fa-times-circle"), @@ -147,7 +147,7 @@ var exitIcon = function(){ } Login.identification = function() { - var info = whoAreYou(); + var info = userCookie(); var nom = "IDENTIFICAR"; var color = 'rgba(255, 255, 255, 0.7)'; From ecc49c96fb96d830094e8119f28cd2e94143e409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 17:30:42 +0200 Subject: [PATCH 13/17] deconvoluting Login: just use the id --- tomatic/ui/components/login.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tomatic/ui/components/login.js b/tomatic/ui/components/login.js index 70812a61e..7c962a16d 100644 --- a/tomatic/ui/components/login.js +++ b/tomatic/ui/components/login.js @@ -147,13 +147,11 @@ var exitIcon = function(){ } Login.identification = function() { - var info = userCookie(); var nom = "IDENTIFICAR"; var color = 'rgba(255, 255, 255, 0.7)'; + var id = Login.myName(); - if (info !== ":") { - var aux = info.split(":"); - var id = aux[0]; + if (id !== "") { nom = Tomatic.formatName(id); if (Tomatic.persons().colors) { color = "#" + Tomatic.persons().colors[id]; From 8a6cb7497377f061d7cd1de4c2c14432204defa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 17:45:35 +0200 Subject: [PATCH 14/17] deconvoluting Login: bye colon-coding --- tomatic/ui/components/login.js | 12 ++---------- tomatic/ui/components/utils.js | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/tomatic/ui/components/login.js b/tomatic/ui/components/login.js index 7c962a16d..19f653922 100644 --- a/tomatic/ui/components/login.js +++ b/tomatic/ui/components/login.js @@ -52,15 +52,8 @@ Date.prototype.addHours = function(h) { return this; } -var userCookie = function() { - var cookie = getCookie(tomaticCookie); - return (cookie === "" ? ":" : cookie); -} - Login.myName = function() { - var cookie = userCookie(); - var user = cookie.split(":")[0]; - return user; + return getCookie(tomaticCookie); } var setCookieInfo = function(vnode){ @@ -75,10 +68,9 @@ var setCookieInfo = function(vnode){ } } if(found){ - var value = id + ":" + Tomatic.persons().extensions[id] + ":" + Tomatic.persons().colors[id]; var exp = new Date().addHours(3); var expires = "expires="+ exp.toUTCString(); - document.cookie = tomaticCookie + "=" + value + ";" + expires + ";SameSite=Strict;path=/"; + document.cookie = tomaticCookie + "=" + id + ";" + expires + ";SameSite=Strict;path=/"; } Login.onLogin.map(function(callback) { callback(); diff --git a/tomatic/ui/components/utils.js b/tomatic/ui/components/utils.js index 2052dda25..90a26f48f 100644 --- a/tomatic/ui/components/utils.js +++ b/tomatic/ui/components/utils.js @@ -1,7 +1,7 @@ var getCookie = function(name) { function escape(s) { return s.replace(/([.*+?\^$(){}|\[\]\/\\])/g, '\\$1'); } var match = document.cookie.match(RegExp('(?:^|;\\s*)' + escape(name) + '=([^;]*)')); - return match ? match[1] : ":"; + return match ? match[1] : ""; } module.exports = { From 88a5b0fa05c5ab10c41518f7227aeaa0b41c32c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 20:25:55 +0200 Subject: [PATCH 15/17] renamed calllist fields to match annotation ones --- tomatic/callregistry.py | 10 +++++----- tomatic/callregistry_test.py | 9 ++++----- tomatic/ui/components/callinfopage.js | 26 +++++++++++++------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index de0af69a4..c91f1c0a2 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -30,7 +30,7 @@ def updateCall(self, user, fields): calls = self._calls() extensionCalls = calls.setdefault(user,[]) for call in extensionCalls: - if call.data == fields.data: + if call.date == fields.date: call.update(fields) break else: # exiting when not found @@ -44,11 +44,11 @@ def updateCall(self, user, fields): def annotateCall(self, fields): from . import persons self.updateCall(fields.user, ns( - data = fields.date, - telefon = fields.phone, + date = fields.date, + phone = fields.phone, partner = fields.partner, - contracte = fields.contract, - motius = fields.reason, + contract = fields.contract, + reason = fields.reason, )) self._appendToExtensionDailyInfo('cases', fields) diff --git a/tomatic/callregistry_test.py b/tomatic/callregistry_test.py index 7f9e8e6bc..bd39d4414 100644 --- a/tomatic/callregistry_test.py +++ b/tomatic/callregistry_test.py @@ -227,12 +227,11 @@ def test_annotateCall_writesCallLog(self): content = ns.load(self.dailycalls) self.assertNsEqual(content, """\ alice: - - data: "2021-02-01T20:21:22.555Z" - telefon: '555444333' + - date: "2021-02-01T20:21:22.555Z" + phone: '555444333' partner: 'S00000' - contracte: '100000' - motius: CODE - + contract: '100000' + reason: CODE """) def test_annotateCall_writesFiles(self): diff --git a/tomatic/ui/components/callinfopage.js b/tomatic/ui/components/callinfopage.js index a11e8f0e5..6914a66dd 100644 --- a/tomatic/ui/components/callinfopage.js +++ b/tomatic/ui/components/callinfopage.js @@ -145,20 +145,20 @@ var customerSearch = function() { } var responsesMessage = function(info) { - var time = (new Date(info.data)).toLocaleTimeString(); + var time = (new Date(info.date)).toLocaleTimeString(); return m('', m('span.time', time), ' ', - m('span.phone', info.telefon ? info.telefon : "Registre Manual"), + m('span.phone', info.phone ? info.phone : "Registre Manual"), m.trust(' '), m.trust(' '), - info.motius? + info.reason? m('span.partner', {title: "Persona Atesa"}, info.partner ? info.partner : "Sense informaciĆ³") : '', - (info.motius && info.contracte)? [ + (info.reason && info.contract)? [ m.trust(' '), - m('span.contract', {title: "Contracte"}, info.contracte) + m('span.contract', {title: "Contracte"}, info.contract) ]:'', - !info.motius ? m('span.pending', " Pendent d'anotar"):'', + !info.reason ? m('span.pending', " Pendent d'anotar"):'', '' ); } @@ -179,20 +179,20 @@ var attendedCallList = function() { } var currentDate = new Date().toLocaleDateString(); items = CallInfo.callLog.slice(0).reverse().map(function(item, index) { - var isSelected = CallInfo.isLogSelected(item.data); + var isSelected = CallInfo.isLogSelected(item.date); var itemClicked = function(ev) { - if (item.motius !== "") return; - CallInfo.toggleLog(item.data, item.telefon) + if (item.reason !== "") return; + CallInfo.toggleLog(item.date, item.phone) } var needsDate = false; - var itemDate = new Date(item.data).toLocaleDateString(); - var itemWeekDay = new Date(item.data).toLocaleDateString(undefined, {weekday:'long'}); + var itemDate = new Date(item.date).toLocaleDateString(); + var itemWeekDay = new Date(item.date).toLocaleDateString(undefined, {weekday:'long'}); if (itemDate !== currentDate) { currentDate = itemDate; needsDate = true; } var missatge = responsesMessage(item); - var solved = item.motius !== ""; + var solved = item.reason !== ""; return [ needsDate? m(ListTile, { className:'registres dateseparator', @@ -207,7 +207,7 @@ var attendedCallList = function() { hoverable: !solved, ink: !solved, title: missatge, - subtitle: item.motius, + subtitle: item.reason, selected: false, events: { onclick: itemClicked, From 9933add2d566289c1958658373e8355494f40066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 22:07:29 +0200 Subject: [PATCH 16/17] callregistry_test: fixed date attributes on tests --- tomatic/callregistry_test.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tomatic/callregistry_test.py b/tomatic/callregistry_test.py index bd39d4414..ee64b4480 100644 --- a/tomatic/callregistry_test.py +++ b/tomatic/callregistry_test.py @@ -53,25 +53,25 @@ def test_updateCall_updatesAfterWrite(self): def test_updateCall_sameTimeExtension_updates(self): reg = CallRegistry(self.dir) reg.updateCall('alice', ns( - data="2021-02-01T20:21:22.555Z", + date="2021-02-01T20:21:22.555Z", attribute="value", tag="content", )) reg.updateCall('alice', ns( - data="2021-02-01T20:21:22.555Z", + date="2021-02-01T20:21:22.555Z", attribute="second value", tag="second content", )) self.assertNsEqual(ns.load(self.dailycalls), """\ alice: - - data: "2021-02-01T20:21:22.555Z" + - date: "2021-02-01T20:21:22.555Z" attribute: second value tag: second content """) self.assertNsEqual( ns(calls = reg.callsByUser('alice')), """\ calls: - - data: "2021-02-01T20:21:22.555Z" + - date: "2021-02-01T20:21:22.555Z" attribute: second value tag: second content """) @@ -79,12 +79,12 @@ def test_updateCall_sameTimeExtension_updates(self): def test_updateCall_differentTime_appends(self): reg = CallRegistry(self.dir) reg.updateCall('alice', ns( - data="2021-02-01T20:21:22.555Z", + date="2021-02-01T20:21:22.555Z", attribute="value", tag="content", )) reg.updateCall('alice', ns( - data="2021-02-02T20:21:22.555Z", + date="2021-02-02T20:21:22.555Z", attribute="second value", tag="second content", )) @@ -92,42 +92,42 @@ def test_updateCall_differentTime_appends(self): alice: - attribute: value tag: content - data: "2021-02-01T20:21:22.555Z" + date: "2021-02-01T20:21:22.555Z" - attribute: second value tag: second content - data: "2021-02-02T20:21:22.555Z" + date: "2021-02-02T20:21:22.555Z" """) self.assertNsEqual( ns(calls = reg.callsByUser('alice')), """\ calls: - - data: "2021-02-01T20:21:22.555Z" + - date: "2021-02-01T20:21:22.555Z" attribute: value tag: content - - data: "2021-02-02T20:21:22.555Z" + - date: "2021-02-02T20:21:22.555Z" attribute: second value tag: second content """) - def test_updateCall_differentExtension_splits(self): + def test_updateCall_differentUser_splits(self): reg = CallRegistry(self.dir) reg.updateCall('alice', ns( - data="2021-02-02T20:21:22.555Z", + date="2021-02-02T20:21:22.555Z", attribute="value", tag="content", )) reg.updateCall('barbara', ns( - data="2021-02-02T20:21:22.555Z", + date="2021-02-02T20:21:22.555Z", attribute="second value", tag="second content", )) self.assertNsEqual(ns.load(self.dailycalls), """\ alice: - - data: "2021-02-02T20:21:22.555Z" + - date: "2021-02-02T20:21:22.555Z" attribute: value tag: content barbara: - - data: "2021-02-02T20:21:22.555Z" + - date: "2021-02-02T20:21:22.555Z" attribute: second value tag: second content """) @@ -135,14 +135,14 @@ def test_updateCall_differentExtension_splits(self): self.assertNsEqual( ns(calls = reg.callsByUser('alice')), """\ calls: - - data: "2021-02-02T20:21:22.555Z" + - date: "2021-02-02T20:21:22.555Z" attribute: value tag: content """) self.assertNsEqual( ns(calls = reg.callsByUser('barbara')), """\ calls: - - data: "2021-02-02T20:21:22.555Z" + - date: "2021-02-02T20:21:22.555Z" attribute: second value tag: second content """) From 73b4807b67088f9ac295ebb99e3a048a52a00149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Mon, 18 Jul 2022 22:22:39 +0200 Subject: [PATCH 17/17] fix: older call removal had no effect Adding a test to ensure we can refactor without losing that functionality test_updateCall_limitedSize_forgetsOlder Indeed it raised the bug that made the call log grow forever. Assigning to a local var does not update the original list. --- tomatic/callregistry.py | 2 +- tomatic/callregistry_test.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tomatic/callregistry.py b/tomatic/callregistry.py index c91f1c0a2..47aeed96a 100644 --- a/tomatic/callregistry.py +++ b/tomatic/callregistry.py @@ -37,7 +37,7 @@ def updateCall(self, user, fields): extensionCalls.append(fields) if self.size: - extensionCalls=extensionCalls[-self.size:] + del extensionCalls[:-self.size] calls.dump(self.callregistry_path) diff --git a/tomatic/callregistry_test.py b/tomatic/callregistry_test.py index ee64b4480..07cd12846 100644 --- a/tomatic/callregistry_test.py +++ b/tomatic/callregistry_test.py @@ -147,6 +147,27 @@ def test_updateCall_differentUser_splits(self): tag: second content """) + def test_updateCall_limitedSize_forgetsOlder(self): + reg = CallRegistry(self.dir, size=1) + + reg.updateCall('alice', ns( + date="2021-02-01T20:21:22.555Z", + attribute="value", + tag="content", + )) + reg.updateCall('alice', ns( + date="2021-02-02T20:21:22.555Z", + attribute="second value", + tag="second content", + )) + self.assertNsEqual( + ns(calls = reg.callsByUser('alice')), """\ + calls: + - date: "2021-02-02T20:21:22.555Z" + attribute: second value + tag: second content + """) + def assertDirContent(self, expected): self.assertEqual( [str(x) for x in sorted(self.dir.glob('**/*'))],