add rename keword dialog; minor cosmetic updates

This commit is contained in:
rlx 2018-08-09 17:02:18 +01:00
parent 1bb74f4f63
commit b57676650c
2 changed files with 191 additions and 6 deletions

View file

@ -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/');
}
},
}),

View file

@ -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 '<a href="/clip/modified/keywords=='
+ value.replace(/ /g, '_')
+ '" target="_blank">' + value + '</a>'
},
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
}