From b57676650c283441fdcc6fb583ba1e54816a8662 Mon Sep 17 00:00:00 2001 From: rlx Date: Thu, 9 Aug 2018 17:02:18 +0100 Subject: [PATCH] add rename keword dialog; minor cosmetic updates --- static/js/localInit.cms.js | 12 +- static/js/manageKeywordsDialog.cms.js | 185 ++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 static/js/manageKeywordsDialog.cms.js diff --git a/static/js/localInit.cms.js b/static/js/localInit.cms.js index 9f1a638..ed4b036 100644 --- a/static/js/localInit.cms.js +++ b/static/js/localInit.cms.js @@ -29,9 +29,9 @@ pandora.localInit = function() { }, $item = Ox.MenuButton({ items: [ - {'id': 'rename', title: 'Rename Keyword'}, - {'id': 'ontology_graph', title: 'Ontology Graph'}, - {'id': 'ontology', title: 'Ontology Overview'}, + {id: 'rename', title: 'Rename Keyword...'}, + {id: 'manage', title: 'Manage Keywords...'}, + {id: 'ontology', title: 'Open Ontology Graph'}, ], style: 'rounded', title: 'set', @@ -41,10 +41,10 @@ pandora.localInit = function() { click: function(data) { if (data.id == 'rename') { pandora.ui.renameKeywordDialog().open() - } else if (data.id == 'ontology_graph') { - pandora.openLink('/static/ontology/'); + } else if (data.id == 'manage') { + pandora.ui.manageKeywordsDialog().open() } else if (data.id == 'ontology') { - pandora.openLink('/static/ontology/ontology.html'); + pandora.openLink('/static/ontology/'); } }, }), diff --git a/static/js/manageKeywordsDialog.cms.js b/static/js/manageKeywordsDialog.cms.js new file mode 100644 index 0000000..478a628 --- /dev/null +++ b/static/js/manageKeywordsDialog.cms.js @@ -0,0 +1,185 @@ +pandora.ui.manageKeywordsDialog = function() { + + function getOntology(callback) { + function parseNodes(parents, nodes) { + parsed = [] + Object.keys(nodes).forEach(function(name) { + let fullName = parents ? parents + ': ' + name : name + let children = parseNodes(fullName, nodes[name]) + if (children.length == 0) { + strings.push(fullName) + } + parsed.push({ + 'name': fullName, + 'children': children + }) + }) + return parsed + } + let strings = [] + let paths = {} + Ox.get('/static/ontology/ontology.json', function(data) { + let ontology = JSON.parse(data) + parseNodes('', ontology) + strings.forEach(function(string) { + let parts = string.split(': ') + if (parts.length >= 2) { + parts.pop() + paths[parts.pop()] = parts.join(': ') + } + }) + callback(paths) + }) + } + + function getKeywords(callback) { + let keywords = {} + pandora.api.find({ + query: {conditions: [ + {key: 'id', operator: '!=', value: 'BA'} // "Blue" + ], operator: ''} + }, function(result) { + let length = result.data.items + let count = 0 + pandora.api.find({ + keys: ['id'], + query: {conditions: [], operator: ''}, + range: [0, 1000000], + sort: [{key: 'id', operator: '+'}] + }, function(result) { + result.data.items.forEach(function(item) { + pandora.api.get({ + id: item.id, + keys: ['layers'] + }, function(result) { + result.data.layers.keywords.forEach(function(keyword) { + let value = keyword.value + if (!keywords[value]) { + keywords[value] = { + created: keyword.created, + count: 1 + } + } else { + if (keyword.created < keywords[value].created) { + keywords[value].created = keyword.created + } + keywords[value].count += 1 + } + }) + if (++count == length) { + let items = Object.keys(keywords).map(function(value) { + return Object.assign(keywords[value], { + keyword: value + }) + }) + callback(items) + } + }) + }) + }) + }) + } + + let $loadingScreen = Ox.LoadingScreen() + let $dialog = Ox.Dialog({ + buttons: [ + Ox.Button({ + title: Ox._('Close'), + width: 64 + }).bindEvent({ + click: function() { + $dialog.close() + } + }) + ], + closeButton: true, + content: $loadingScreen, + height: window.innerHeight * 0.9 - 48, + title: Ox._('Keywords'), + width: 968 + }).bindEvent({ + open: function() { + $loadingScreen.start() + getOntology(function(paths) { + getKeywords(function(keywords) { + keywords.forEach(function(keyword) { + let parent_ = '' + if (keyword.keyword.includes(': ')) { + parent_ = keyword.keyword.split(': ')[0] + } + keyword.ontology = (paths[parent_] ? paths[parent_] : 'unknown') + + ': ' + keyword.keyword + }) + let $list = Ox.TableList({ + columns: [ + { + format: function(value) { + return '' + value + '' + }, + id: 'keyword', + operator: '+', + title: Ox._('Keyword'), + visible: true, + width: 256 + }, + { + id: 'ontology', + operator: '+', + title: Ox._('Ontology'), + visible: true, + width: 512 + }, + { + format: function(value) { + return value.replace('T', ' ').replace('Z', '') + }, + id: 'created', + operator: '-', + title: Ox._('Created'), + visible: true, + width: 144 + }, + { + align: 'right', + format: Ox.formatNumber, + id: 'count', + operator: '-', + title: Ox._('Count'), + visible: true, + width: 48 + } + ], + columnsMovable: true, + columnsResizable: true, + columnsVisible: true, + items: keywords, + scrollbarVisible: true, + sort: [{key: 'created', operator: '-'}] + }).bindEvent({ + init: function(data) { + $status.html(Ox.formatNumber(data.items) + ' ' + Ox._('keywords')) + } + }) + $loadingScreen.stop() + $dialog.options({ + content: $list + }) + }) + }) + } + }) + let $status = Ox.Element().css({ + fontSize: '9px', + height: '10px', + marginLeft: '96px', + position: 'absolute', + textAlign: 'center', + top: '6px', + width: '776px' + }).appendTo($dialog.find('.OxButtonsbar')) + + return $dialog + +}