Changed tag export structure
This commit is contained in:
parent
35b893db9d
commit
8f03c68ec8
3 changed files with 22 additions and 16 deletions
|
@ -46,11 +46,15 @@ App.Controls.AutoCompleteInput = function($input) {
|
||||||
if (cachedSource) {
|
if (cachedSource) {
|
||||||
return cachedSource;
|
return cachedSource;
|
||||||
} else {
|
} else {
|
||||||
var source = source || tagList.getTags();
|
var source = tagList.getTags();
|
||||||
source = _.pairs(source);
|
source = _.sortBy(source, function(a) { return -a.usages; });
|
||||||
source = _.sortBy(source, function(a) { return -a[1]; });
|
source = _.filter(source, function(a) { return a.usages > 0; });
|
||||||
source = _.filter(source, function(a) { return a[1] > 0; });
|
source = _.map(source, function(a) {
|
||||||
source = _.map(source, function(a) { return [a[0], a[0] + ' (' + a[1] + ')']; });
|
return {
|
||||||
|
tag: a.name,
|
||||||
|
caption: a.name + ' (' + a.usages + ')',
|
||||||
|
};
|
||||||
|
});
|
||||||
cachedSource = source;
|
cachedSource = source;
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
@ -152,12 +156,12 @@ App.Controls.AutoCompleteInput = function($input) {
|
||||||
function getResultsFilter(textToFind) {
|
function getResultsFilter(textToFind) {
|
||||||
if (textToFind.length < options.minLengthToArbitrarySearch) {
|
if (textToFind.length < options.minLengthToArbitrarySearch) {
|
||||||
return options.caseSensitive ?
|
return options.caseSensitive ?
|
||||||
function(resultItem) { return resultItem[0].indexOf(textToFind) === 0; } :
|
function(resultItem) { return resultItem.tag.indexOf(textToFind) === 0; } :
|
||||||
function(resultItem) { return resultItem[0].toLowerCase().indexOf(textToFind.toLowerCase()) === 0; };
|
function(resultItem) { return resultItem.tag.toLowerCase().indexOf(textToFind.toLowerCase()) === 0; };
|
||||||
} else {
|
} else {
|
||||||
return options.caseSensitive ?
|
return options.caseSensitive ?
|
||||||
function(resultItem) { return resultItem[0].indexOf(textToFind) >= 0; } :
|
function(resultItem) { return resultItem.tag.indexOf(textToFind) >= 0; } :
|
||||||
function(resultItem) { return resultItem[0].toLowerCase().indexOf(textToFind.toLowerCase()) >= 0; };
|
function(resultItem) { return resultItem.tag.toLowerCase().indexOf(textToFind.toLowerCase()) >= 0; };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +178,7 @@ App.Controls.AutoCompleteInput = function($input) {
|
||||||
|
|
||||||
function applyAutocomplete() {
|
function applyAutocomplete() {
|
||||||
if (options.onApply) {
|
if (options.onApply) {
|
||||||
options.onApply(results[activeResult][0]);
|
options.onApply(results[activeResult].tag);
|
||||||
} else {
|
} else {
|
||||||
var val = $input.val();
|
var val = $input.val();
|
||||||
var start = getSelectionStart();
|
var start = getSelectionStart();
|
||||||
|
@ -186,7 +190,7 @@ App.Controls.AutoCompleteInput = function($input) {
|
||||||
prefix = val.substring(0, index + 1);
|
prefix = val.substring(0, index + 1);
|
||||||
middle = val.substring(index + 1);
|
middle = val.substring(index + 1);
|
||||||
}
|
}
|
||||||
$input.val(prefix + results[activeResult][0] + ' ' + suffix.trimLeft());
|
$input.val(prefix + results[activeResult].tag + ' ' + suffix.trimLeft());
|
||||||
$input.focus();
|
$input.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,8 +204,8 @@ App.Controls.AutoCompleteInput = function($input) {
|
||||||
$list.empty();
|
$list.empty();
|
||||||
_.each(results, function(resultItem, resultIndex) {
|
_.each(results, function(resultItem, resultIndex) {
|
||||||
var $listItem = jQuery('<li/>');
|
var $listItem = jQuery('<li/>');
|
||||||
$listItem.text(resultItem[1]);
|
$listItem.text(resultItem.caption);
|
||||||
$listItem.attr('data-key', resultItem[0]);
|
$listItem.attr('data-key', resultItem.tag);
|
||||||
$listItem.hover(function(e) {
|
$listItem.hover(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
activeResult = resultIndex;
|
activeResult = resultIndex;
|
||||||
|
|
|
@ -73,7 +73,9 @@ class TagService
|
||||||
$tags = [];
|
$tags = [];
|
||||||
foreach ($this->tagDao->findAll() as $tag)
|
foreach ($this->tagDao->findAll() as $tag)
|
||||||
{
|
{
|
||||||
$tags[$tag->getName()] = $tag->getUsages();
|
$tags[$tag->getId()] = [
|
||||||
|
'name' => $tag->getName(),
|
||||||
|
'usages' => $tag->getUsages()];
|
||||||
}
|
}
|
||||||
$json = json_encode($tags);
|
$json = json_encode($tags);
|
||||||
$this->fileDao->save('tags.json', $json);
|
$this->fileDao->save('tags.json', $json);
|
||||||
|
|
|
@ -78,7 +78,7 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
||||||
$tagService = $this->getTagService();
|
$tagService = $this->getTagService();
|
||||||
$tagService->createTags([$tag1]);
|
$tagService->createTags([$tag1]);
|
||||||
$tagService->exportJson();
|
$tagService->exportJson();
|
||||||
$this->assertEquals('{"test":0}', $fileDao->load('tags.json'));
|
$this->assertEquals('{"1":{"name":"test","usages":0}}', $fileDao->load('tags.json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExportMultiple()
|
public function testExportMultiple()
|
||||||
|
@ -93,7 +93,7 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
||||||
$tagService = $this->getTagService();
|
$tagService = $this->getTagService();
|
||||||
$tagService->createTags([$tag1, $tag2]);
|
$tagService->createTags([$tag1, $tag2]);
|
||||||
$tagService->exportJson();
|
$tagService->exportJson();
|
||||||
$this->assertEquals('{"test1":0,"test2":0}', $fileDao->load('tags.json'));
|
$this->assertEquals('{"1":{"name":"test1","usages":0},"2":{"name":"test2","usages":0}}', $fileDao->load('tags.json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPublicFileDao()
|
private function getPublicFileDao()
|
||||||
|
|
Loading…
Reference in a new issue